]> git.donarmstrong.com Git - mothur.git/blob - readclustal.cpp
modified filter.seqs to not store all seqs in memory but to read off disc
[mothur.git] / readclustal.cpp
1 /*
2  *  readclustal.cpp
3  *  Mothur
4  *
5  *  Created by Thomas Ryabin on 4/24/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "readclustal.h"
11 #include <iostream>
12 #include <fstream>
13
14 /*******************************************************************************/
15 ReadClustal::ReadClustal(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 ReadClustal::~ReadClustal(){
29 //      for(int i = 0; i < sequencedb.getNumSeqs(); i++)
30 //              delete sequencedb.get(i);
31 }
32 /*******************************************************************************/
33 void ReadClustal::read() {
34         string temp;
35         string name;
36         string sequence;
37         string firstName = "";
38         for(int i = 0; i < 6; i++)
39                 filehandle >> temp;
40         
41         int count = 0;
42         int numSeqs = 0;
43         int lastSeqLength = 0;
44         bool firstDone = false; 
45         
46         while(!filehandle.eof()) {
47                 filehandle >> name;
48                 if(numSeqs != 0) {
49                         if(count == numSeqs)
50                                 count = 0;
51                 }
52                 else if(!firstDone && firstName.compare("") == 0)
53                         firstName = name;
54                 else if(!firstDone && firstName.compare(name) == 0) {
55                         numSeqs = count;
56                         firstDone = true;
57                         count = 0;
58                 }
59
60                 if(name.find_first_of("*") == -1) {
61                         filehandle >> sequence;
62                         lastSeqLength = sequence.length();
63                         if(!firstDone) {
64                                 Sequence newSeq(name, sequence);
65                                 sequencedb.add(newSeq);
66                         } 
67                         else 
68                                 sequencedb.set(count, sequencedb.get(count).getUnaligned() + sequence);
69                                 
70                         count++;
71                 }
72         }
73         if(count == 1)
74                 sequencedb.set(0, sequencedb.get(0).getUnaligned().substr(0, sequencedb.get(0).getUnaligned().length() - lastSeqLength));
75                 
76         filehandle.close();
77 }
78
79 /*********************************************************************************/
80 SequenceDB* ReadClustal::getDB() {
81         return &sequencedb;
82 }