]> git.donarmstrong.com Git - mothur.git/blob - readnexus.cpp
added distance command and filterseqs
[mothur.git] / readnexus.cpp
1 /*
2  *  readnexusaln.cpp
3  *  Mothur
4  *
5  *  Created by Thomas Ryabin on 4/22/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "readnexus.h"
11 #include <iostream>
12 #include <fstream>
13
14 /*******************************************************************************/
15 ReadNexus::ReadNexus(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 ReadNexus::~ReadNexus(){
29 //      for(int i = 0; i < sequencedb.getNumSeqs(); i++)
30 //              delete sequencedb.get(i);
31 }
32 /*******************************************************************************/
33 void ReadNexus::read() {
34         string temp;
35         string name;
36         string sequence;
37         for(int i = 0; i < 5; i++)
38                 filehandle >> temp;
39         
40         int numSeqs = atoi(temp.substr(temp.find_first_of("=")+1, temp.length() - temp.find_first_of("=") - 1).c_str());
41         
42         for(int i = 0; i < 9; i++)
43                 filehandle >> temp;
44         
45         int count = 0;
46         bool firstDone = false; 
47         while(!filehandle.eof()){
48                 filehandle >> name;
49                 filehandle >> sequence;
50                 if(name.compare(";") != 0) {
51                         if(!firstDone) {
52                                 Sequence newSeq(name, sequence);
53                                 sequencedb.add(newSeq);
54                         } 
55                         else 
56                                 sequencedb.set(count, sequencedb.get(count).getUnaligned() + sequence);
57                         
58                         count++;
59                         if(count == numSeqs) {
60                                 if(!firstDone)
61                                         firstDone = true;
62                                 count = 0;
63                         }
64                 }
65         }
66         filehandle.close();
67 }
68
69 /*********************************************************************************/
70 SequenceDB* ReadNexus::getDB() {
71         return &sequencedb;
72 }