File: fasta.cpp

package info (click to toggle)
patman 1.2.2%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 220 kB
  • sloc: cpp: 783; makefile: 92; sh: 12
file content (47 lines) | stat: -rw-r--r-- 1,189 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// PatMaN DNA pattern matcher
// (C) 2007 Kay Pruefer, Udo Stenzel
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or (at
// your option) any later version.  See the LICENSE file for details.

#include "fasta.h"

using namespace std ;

fasta* fasta_fac::get(  ) 
{
	string headline ;
	fasta* ret = new fasta ;
	ret->null = 0 ;
	// headline
	getline( in, ret->headerline ) ;
	line++ ;
	if ( ret->headerline[0] != '>' ) {
		if ( !in.eof() ) cerr << "No headerline in fasta file at line " << line << endl ;
		ret->null = 1 ;
		return ret ;
	} else {
		// cut the '>' in headerline
		ret->headerline = ret->headerline.substr( 1, ret->headerline.size()-1 ) ;

		// read the sequence
		// handles eof, \n and '>', everything else is
		// considered part of the sequence.
		int i ;
		while ( (i = in.get()) && in.good() ) {
			if ( i == '>' ) {
				in.putback( i ) ;
				return ret ;
			} else {
				// add to seq ;
				if ( i != '\n' ) 
					ret->seq += static_cast<char>(i) ;
				else 
					line++ ;
			}
		}
		return ret ;
	}
}