| 1 | // PatMaN DNA pattern matchercxx . . $ `<file>/fasta.cpp`/ |
| 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"cxx . . $ `<file>/fasta.h`/ |
| 10 | |
| 11 | using namespace std ; |
| 12 | |
| 13 | fastacxx . . $ fasta#* fasta_faccxx . . $ fasta_fac#::getcxx . . $ fasta_fac#get(e7de4abdd4bb2f0).( ) |
| 14 | { |
| 15 | stringcxx . . $ std/string# headlinecxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391). ; |
| 16 | fastacxx . . $ fasta#* ret = new fastacxx . . $ fasta# ; |
| 17 | ret->nullcxx . . $ fasta#null. = 0 ; |
| 18 | // headline |
| 19 | getlinecxx . . $ std/getline(4ec722ed0b69c2ab).( incxx . . $ fasta_fac#in., ret->headerlinecxx . . $ fasta#headerline. ) ; |
| 20 | linecxx . . $ fasta_fac#line.++ ; |
| 21 | if ( ret->headerlinecxx . . $ fasta#headerline.[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).0] != '>' ) { |
| 22 | if ( !incxx . . $ fasta_fac#in..eofcxx . . $ std/basic_ios#eof(50ce9a9e25b4a850).() ) cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "No headerline in fasta file at line " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). linecxx . . $ fasta_fac#line. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9). ; |
| 23 | ret->nullcxx . . $ fasta#null. = 1 ; |
| 24 | return ret ; |
| 25 | } else { |
| 26 | // cut the '>' in headerline |
| 27 | ret->headerlinecxx . . $ fasta#headerline. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). ret->headerlinecxx . . $ fasta#headerline..substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).( 1, ret->headerlinecxx . . $ fasta#headerline..sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).()-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 = incxx . . $ fasta_fac#in..getcxx . . $ std/basic_istream#get(3a3be259693afdc2).()) && incxx . . $ fasta_fac#in..goodcxx . . $ std/basic_ios#good(50ce9a9e25b4a850).() ) { |
| 34 | if ( i == '>' ) { |
| 35 | incxx . . $ fasta_fac#in..putbackcxx . . $ std/basic_istream#putback(52c6630ac51d3970).( i ) ; |
| 36 | return ret ; |
| 37 | } else { |
| 38 | // add to seq ; |
| 39 | if ( i != '\n' ) |
| 40 | ret->seqcxx . . $ fasta#seq. +=cxx . . $ std/__cxx11/basic_string#`operator+=`(63cc1ae870623930). static_cast<char>(i) ; |
| 41 | else |
| 42 | linecxx . . $ fasta_fac#line.++ ; |
| 43 | } |
| 44 | } |
| 45 | return ret ; |
| 46 | } |
| 47 | } |