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