| 1 | // PatMaN DNA pattern matcher |
| 2 | // (C) 2007 Kay Pruefer, Udo Stenzel |
| 3 | // |
| 4 | // This program is free software; you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation; either version 2 of the License, or (at |
| 7 | // your option) any later version. See the LICENSE file for details. |
| 8 | |
| 9 | #include "fasta.h" |
| 10 | |
| 11 | using namespace std ; |
| 12 | |
| 13 | fasta* fasta_fac::get( ) |
| 14 | { |
| 15 | string headline ; |
| 16 | fasta* ret = new fasta ; |
| 17 | ret->null = 0 ; |
| 18 | // headline |
| 19 | getline( in, ret->headerline ) ; |
| 20 | line++ ; |
| 21 | if ( ret->headerline[0] != '>' ) { |
| 22 | if ( !in.eof() ) cerr << "No headerline in fasta file at line " << line << endl ; |
| 23 | ret->null = 1 ; |
| 24 | return ret ; |
| 25 | } else { |
| 26 | // cut the '>' in headerline |
| 27 | ret->headerline = ret->headerline.substr( 1, ret->headerline.size()-1 ) ; |
| 28 | |
| 29 | // read the sequence |
| 30 | // handles eof, \n and '>', everything else is |
| 31 | // considered part of the sequence. |
| 32 | int i ; |
| 33 | while ( (i = in.get()) && in.good() ) { |
| 34 | if ( i == '>' ) { |
| 35 | in.putback( i ) ; |
| 36 | return ret ; |
| 37 | } else { |
| 38 | // add to seq ; |
| 39 | if ( i != '\n' ) |
| 40 | ret->seq += static_cast<char>(i) ; |
| 41 | else |
| 42 | line++ ; |
| 43 | } |
| 44 | } |
| 45 | return ret ; |
| 46 | } |
| 47 | } |