]> git.donarmstrong.com Git - mothur.git/commitdiff
add primary_seqname command to determine the primary sequence (first before ,)
authorDon Armstrong <don@donarmstrong.com>
Fri, 11 Apr 2014 21:43:41 +0000 (14:43 -0700)
committerDon Armstrong <don@donarmstrong.com>
Fri, 11 Apr 2014 21:43:41 +0000 (14:43 -0700)
deconvolutecommand.cpp
deconvolutecommand.h

index cf1646e1a6806cfe3de4280d5ee0bb5a1af1bcba..94d01b5b881549dd4bb39871de88630f136c2343 100644 (file)
@@ -278,10 +278,10 @@ int DeconvoluteCommand::execute() {
                       m->mothurOut("[ERROR]: " + seq.getName() + " is in your fasta file, and not in your namefile, please correct.");
                       m->mothurOutEndLine();
                     } else if (countfile != "") { 
-                        int num = ct.getNumSeqs(seq.getName()); //checks to make sure seq is in table
-                        if (num != 0) { //its in the table
-                            ct.mergeCounts(itStrings->second.second, seq.getName()); //merges counts and saves in uniques name
-                        }
+                      int num = ct.getNumSeqs(seq.getName()); //checks to make sure seq is in table
+                      if (num != 0) { //its in the table
+                        ct.mergeCounts(primary_seqname(itStrings->second.second), seq.getName()); //merges counts and saves in uniques name
+                      }
                     }
                     itStrings->second.second += "," + seq.getName();
                                }
@@ -311,22 +311,10 @@ int DeconvoluteCommand::execute() {
                        
             if (countfile == "") {
               //get rep name
-              int pos = (it->second.second).find_first_of(',');
-              
-              if (pos == string::npos) { // only reps itself
-                outNames << it->second.second << '\t' << it->second.second << endl;
-              }else {
-                outNames << (it->second.second).substr(0, pos) << '\t' << it->second.second << endl;
-              }
+              outNames << primary_seqname(it->second.second) << '\t' << it->second.second << endl;
             } else {
               //get rep name
-              int pos = (it->second.second).find_first_of(',');
-              if (pos == string::npos) { // only reps itself
-                ct.printSeq(outNames, it->second.second);
-              } else {
-                m->mothurOut("Duplicate " + it->second.second + " " + (it->second.second).substr(0,pos) + "\n");
-                ct.printSeq(outNames, (it->second.second).substr(0,pos));
-              }
+              ct.printSeq(outNames,primary_seqname(it->second.second);
             }
         }
                outNames.close();
@@ -392,3 +380,12 @@ multimap<size_t,std::pair<std::streampos,string>>::iterator
   fasta_file.seekg(cur_pos);
   return seq_strings.end();
 }
+
+
+string primary_seqname(string name) {
+  int pos = name.find_first_of(',');
+  if (pos == string::npos) {
+    return name;
+  }
+  return name.substr(0,pos);
+}
index 36343064db2879e690ada12d97b04cfa8f8b7c8e..7f3628dfd14e662e30ea6d97e3de7ae1769dfcc0 100644 (file)
@@ -51,4 +51,6 @@ multimap<size_t,std::pair<std::streampos,string>>::iterator
                             Sequence&,
                             ifstream&);
 
+string primary_seqname(string);
+
 #endif