]> git.donarmstrong.com Git - mothur.git/blobdiff - getseqscommand.cpp
changes while testing
[mothur.git] / getseqscommand.cpp
index 779ea912ebebbe58ec22e65723899c4ea566b85f..83fdf73e9af36fd9826f5a8c2efcc11655ac938e 100644 (file)
@@ -45,7 +45,7 @@ string GetSeqsCommand::getHelpString(){
                helpString += "The get.seqs command reads an .accnos file and any of the following file types: fasta, name, group, count, list, taxonomy, quality or alignreport file.\n";
                helpString += "It outputs a file containing only the sequences in the .accnos file.\n";
                helpString += "The get.seqs command parameters are accnos, fasta, name, group, list, taxonomy, qfile, alignreport and dups.  You must provide accnos unless you have a valid current accnos file, and at least one of the other parameters.\n";
-               helpString += "The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=false. \n";
+               helpString += "The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=true. \n";
                helpString += "The get.seqs command should be in the following format: get.seqs(accnos=yourAccnos, fasta=yourFasta).\n";
                helpString += "Example get.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n";
                helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n";
@@ -427,7 +427,14 @@ int GetSeqsCommand::readFasta(){
                        
                        Sequence currSeq(in);
                        name = currSeq.getName();
+            
+            if (!dups) {//adjust name if needed
+                map<string, string>::iterator it = uniqueMap.find(name);
+                if (it != uniqueMap.end()) { currSeq.setName(it->second); }
+            }
                        
+            name = currSeq.getName();
+            
                        if (name != "") {
                                //if this name is in the accnos file
                                if (names.count(name) != 0) {
@@ -485,13 +492,18 @@ int GetSeqsCommand::readQual(){
                        string name = "";
                        string scores = "";
                        
-                       in >> name; 
+                       in >> name;
+            
+            if (!dups) {//adjust name if needed
+                map<string, string>::iterator it = uniqueMap.find(name);
+                if (it != uniqueMap.end()) { name = it->second; }
+            }
                                
                        if (name.length() != 0) { 
                                saveName = name.substr(1);
                                while (!in.eof())       {       
                                        char c = in.get(); 
-                                       if (c == 10 || c == 13){        break;  }
+                                       if (c == 10 || c == 13 || c == -1){     break;  }
                                        else { name += c; }     
                                } 
                                m->gobble(in);
@@ -577,7 +589,7 @@ int GetSeqsCommand::readCount(){
         //check for groups that have been eliminated
         CountTable ct;
         if (ct.testGroups(outputFileName)) {
-            ct.readTable(outputFileName);
+            ct.readTable(outputFileName, true);
             ct.printTable(outputFileName);
         }
                
@@ -700,7 +712,7 @@ int GetSeqsCommand::readName(){
                
                        if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName);  return 0; }
 
-                       in >> firstCol;                         
+                       in >> firstCol;                 m->gobble(in);
                        in >> secondCol;
                        
                        string hold = "";
@@ -724,6 +736,7 @@ int GetSeqsCommand::readName(){
                                selectedCount += parsedNames.size();
                 if (m->debug) { sanity["name"].insert(firstCol); }
                        }else {
+                
                                selectedCount += validSecond.size();
                                
                                //if the name in the first column is in the set then print it and any other names in second column also in set
@@ -742,12 +755,15 @@ int GetSeqsCommand::readName(){
                                
                                //make first name in set you come to first column and then add the remaining names to second column
                                }else {
+                    
                                        //you want part of this row
                                        if (validSecond.size() != 0) {
                                        
                                                wroteSomething = true;
                                                
                                                out << validSecond[0] << '\t';
+                        //we are changing the unique name in the fasta file
+                        uniqueMap[firstCol] = validSecond[0];
                                        
                                                //you know you have at least one valid second since first column is valid
                                                for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
@@ -805,6 +821,7 @@ int GetSeqsCommand::readGroup(){
 
                        in >> name;                             //read from first column
                        in >> group;                    //read from second column
+            
                        
                        //if this name is in the accnos file
                        if (names.count(name) != 0) {
@@ -862,6 +879,11 @@ int GetSeqsCommand::readTax(){
 
                        in >> name;                             //read from first column
                        in >> tax;                      //read from second column
+            
+            if (!dups) {//adjust name if needed
+                map<string, string>::iterator it = uniqueMap.find(name);
+                if (it != uniqueMap.end()) { name = it->second; }
+            }
                        
                        //if this name is in the accnos file
                        if (names.count(name) != 0) {
@@ -924,6 +946,11 @@ int GetSeqsCommand::readAlign(){
 
 
                        in >> name;                             //read from first column
+            
+            if (!dups) {//adjust name if needed
+                map<string, string>::iterator it = uniqueMap.find(name);
+                if (it != uniqueMap.end()) { name = it->second; }
+            }
                        
                        //if this name is in the accnos file
                        if (names.count(name) != 0) {