]> git.donarmstrong.com Git - mothur.git/blobdiff - chimera.cpp
working on chimeras
[mothur.git] / chimera.cpp
index 7e997b9824439e4e42f495f95a2d101b58a89600..bf16de4e34b795694d1a894ea1005f32353be110 100644 (file)
 #include "chimera.h"
 
 //***************************************************************************************************************
-//this is a vertical filter
+//this is a vertical soft filter
 void Chimera::createFilter(vector<Sequence*> seqs) {
        try {
-               
+               filterString = "";
                int threshold = int (0.5 * seqs.size());
 //cout << "threshhold = " << threshold << endl;
                
@@ -40,6 +40,7 @@ void Chimera::createFilter(vector<Sequence*> seqs) {
                        }
                }
                
+               //zero out spot where all sequences have blanks
                //zero out spot where all sequences have blanks
                int numColRemoved = 0;
                for(int i = 0;i < seqs[0]->getAligned().length(); i++){
@@ -48,6 +49,7 @@ void Chimera::createFilter(vector<Sequence*> seqs) {
                        else if (((a[i] < threshold) && (t[i] < threshold) && (g[i] < threshold) && (c[i] < threshold))) {      filterString[i] = '0';  numColRemoved++;  }
                        //cout << "a = " << a[i] <<  " t = " << t[i] <<  " g = " << g[i] <<  " c = " << c[i] << endl;
                }
+       
 //cout << "filter = " << filterString << endl; 
 
                mothurOut("Filter removed " + toString(numColRemoved) + " columns.");  mothurOutEndLine();
@@ -58,46 +60,52 @@ void Chimera::createFilter(vector<Sequence*> seqs) {
        }
 }
 //***************************************************************************************************************
-void Chimera::runFilter(vector<Sequence*> seqs) {
+void Chimera::runFilter(Sequence* seq) {
        try {
                
-               //for each sequence
-               for (int i = 0; i < seqs.size(); i++) {
-               
-                       string seqAligned = seqs[i]->getAligned();
-                       string newAligned = "";
-                       
-                       for (int j = 0; j < seqAligned.length(); j++) {
-                               //if this spot is a gap
-                               if (filterString[j] == '1') { newAligned += seqAligned[j]; }
-                       }
+               string seqAligned = seq->getAligned();
+               string newAligned = "";
                        
-                       seqs[i]->setAligned(newAligned);
+               for (int j = 0; j < seqAligned.length(); j++) {
+                       //if this spot is a gap
+                       if (filterString[j] == '1') { newAligned += seqAligned[j]; }
                }
-               
+                       
+               seq->setAligned(newAligned);
        }
        catch(exception& e) {
                errorOut(e, "Chimera", "runFilter");
                exit(1);
        }
 }
-
 //***************************************************************************************************************
 vector<Sequence*> Chimera::readSeqs(string file) {
        try {
+       
+               mothurOut("Reading sequences... "); cout.flush();
                ifstream in;
                openInputFile(file, in);
                vector<Sequence*> container;
+               int count = 0;
+               int length = 0;
+               unaligned = false;
                
                //read in seqs and store in vector
                while(!in.eof()){
                        
-                       Sequence* current = new Sequence(in);
-                       container.push_back(current);
-                       gobble(in);
+                       Sequence* current = new Sequence(in);  gobble(in);
+                       
+                       if (count == 0) {  length = current->getAligned().length();  count++;  } //gets first seqs length
+                       else if (length != current->getAligned().length()) { //seqs are unaligned
+                               unaligned = true;
+                       }
+                       
+                       if (current->getName() != "") {  container.push_back(current);  }
                }
                
                in.close();
+               mothurOut("Done."); mothurOutEndLine();
+               
                return container;
        }
        catch(exception& e) {
@@ -142,7 +150,7 @@ vector< vector<float> > Chimera::readQuantiles() {
                openInputFile(quanfile, in);
                
                vector< vector<float> > quan;
-               vector <float> temp;
+               vector <float> temp; temp.resize(6, 0);
                
                //to fill 0
                quan.push_back(temp); 
@@ -177,6 +185,31 @@ vector< vector<float> > Chimera::readQuantiles() {
        }
 }
 //***************************************************************************************************************
+Sequence* Chimera::getSequence(string name) {
+       try{
+               Sequence* temp;
+               
+               //look through templateSeqs til you find it
+               int spot = -1;
+               for (int i = 0; i < templateSeqs.size(); i++) {
+                       if (name == templateSeqs[i]->getName()) {  
+                               spot = i;
+                               break;
+                       }
+               }
+               
+               if(spot == -1) { mothurOut("Error: Could not find sequence."); mothurOutEndLine(); return NULL; }
+               
+               temp = new Sequence(templateSeqs[spot]->getName(), templateSeqs[spot]->getAligned());
+               
+               return temp;
+       }
+       catch(exception& e) {
+               errorOut(e, "Chimera", "getSequence");
+               exit(1);
+       }
+}
+//***************************************************************************************************************