]> git.donarmstrong.com Git - mothur.git/blob - readfasta.cpp
ff39e01cfe5a5e5ee90c717bb4a160648914f808
[mothur.git] / readfasta.cpp
1 /*
2  *  readfasta.cpp
3  *  Mothur
4  *
5  *  Created by Thomas Ryabin on 4/21/09.
6  *  Copyright 2009 __MyCompanyName__. All rights reserved.
7  *
8  */
9
10 #include "readfasta.h"
11 #include <iostream>
12 #include <fstream>
13
14 /*******************************************************************************/
15 ReadFasta::ReadFasta(string file) {
16         try {
17                 openInputFile(file, filehandle);
18                 fastaFile = file;
19                 globaldata = GlobalData::getInstance();
20         }
21         catch(exception& e) {
22                 cout << "Standard Error: " << e.what() << " has occurred in the ReadTree class Function ReadTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
23                 exit(1);
24         }
25         catch(...) {
26                 cout << "An unknown error has occurred in the ReadTree class function ReadTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
27                 exit(1);
28         }               
29 }
30 /*******************************************************************************/
31 ReadFasta::~ReadFasta(){
32         //for(int i = 0; i < sequencedb.getNumSeqs(); i++)
33                 //delete sequencedb.get(i);
34 }
35 /*******************************************************************************/
36 void ReadFasta::read() {
37         string name = "";
38         string sequence = "";
39         string temp;
40         int count = 0;
41         while(!filehandle.eof()){
42                 if(count == 0)
43                         filehandle >> temp;
44                 if(temp.substr(0,1).compare(">") == 0) {
45                         if(count != 0) {
46                                 Sequence newSequence(name, sequence);
47                                 sequencedb.add(newSequence);
48                                 sequence = "";
49                         }
50                         else
51                                 count++;
52                         name = temp.substr(1,temp.length()-1);
53                 }
54                 else 
55                         sequence += temp;
56                 
57                 filehandle >> temp;
58         }
59         Sequence newSequence(name, sequence);
60         sequencedb.add(newSequence);
61
62         filehandle.close();
63 }
64
65 /*********************************************************************************/
66 SequenceDB* ReadFasta::getDB() {
67         return &sequencedb;
68 }