]> git.donarmstrong.com Git - mothur.git/blob - readnexus.cpp
altered venn command to make use of sharedchao for any number of groups, fixed window...
[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) {
16         try {
17                 openInputFile(file, filehandle);
18                 nexusFile = 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 ReadNexus::~ReadNexus(){
32 //      for(int i = 0; i < sequencedb.getNumSeqs(); i++)
33 //              delete sequencedb.get(i);
34 }
35 /*******************************************************************************/
36 void ReadNexus::read() {
37         string temp;
38         string name;
39         string sequence;
40         for(int i = 0; i < 5; i++)
41                 filehandle >> temp;
42         
43         int numSeqs = atoi(temp.substr(temp.find_first_of("=")+1, temp.length() - temp.find_first_of("=") - 1).c_str());
44         
45         for(int i = 0; i < 9; i++)
46                 filehandle >> temp;
47         
48         int count = 0;
49         bool firstDone = false; 
50         while(!filehandle.eof()){
51                 filehandle >> name;
52                 filehandle >> sequence;
53                 if(name.compare(";") != 0) {
54                         if(!firstDone) {
55                                 Sequence newSeq(name, sequence);
56                                 sequencedb.add(newSeq);
57                         } 
58                         else 
59                                 sequencedb.set(count, sequencedb.get(count).getAligned() + sequence);
60                         
61                         count++;
62                         if(count == numSeqs) {
63                                 if(!firstDone)
64                                         firstDone = true;
65                                 count = 0;
66                         }
67                 }
68         }
69         filehandle.close();
70 }
71
72 /*********************************************************************************/
73 SequenceDB* ReadNexus::getDB() {
74         return &sequencedb;
75 }