]> git.donarmstrong.com Git - mothur.git/blobdiff - binsequencecommand.cpp
modified bin.seqs and get.oturep commands to include use of a groupfile if provided...
[mothur.git] / binsequencecommand.cpp
index 7810ea9f793255e31e44c854a5a4c21639019c60..f1ba8b5f38effa755a215e93a87dcf322001dc6d 100644 (file)
@@ -15,8 +15,15 @@ BinSeqCommand::BinSeqCommand(){
                globaldata = GlobalData::getInstance();
                fastafile = globaldata->getFastaFile();
                namesfile = globaldata->getNameFile();
+               groupfile = globaldata->getGroupFile();
                openInputFile(fastafile, in);
                
+               if (groupfile != "") {
+                       //read in group map info.
+                       groupMap = new GroupMap(groupfile);
+                       groupMap->readMap();
+               }
+               
                fasta = new FastaMap();
        }
        catch(exception& e) {
@@ -36,6 +43,9 @@ BinSeqCommand::~BinSeqCommand(){
        delete read;
        delete fasta;
        delete list;
+       if (groupfile != "") {
+               delete groupMap;
+       }
 }
 
 //**********************************************************************************************************************
@@ -83,9 +93,23 @@ int BinSeqCommand::execute(){
                                                //do work for that name
                                                sequence = fasta->getSequence(name);
                                                if (sequence != "not found") {
-                                                       name = name + "|" + toString(i+1);
-                                                       out << ">" << name << endl;
-                                                       out << sequence << endl;
+                                                       //if you don't have groups
+                                                       if (groupfile == "") {
+                                                               name = name + "|" + toString(i+1);
+                                                               out << ">" << name << endl;
+                                                               out << sequence << endl;
+                                                       }else {//if you do have groups
+                                                               string group = groupMap->getGroup(name);
+                                                               if (group == "not found") {  
+                                                                       cout << name << " is missing from your group file. Please correct. " << endl;
+                                                                       remove(outputFileName.c_str());
+                                                                       return 0;
+                                                               }else{
+                                                                       name = name + "|" + group + "|" + toString(i+1);
+                                                                       out << ">" << name << endl;
+                                                                       out << sequence << endl;
+                                                               }
+                                                       }
                                                }else { 
                                                        cout << name << " is missing from your fasta or name file. Please correct. " << endl; 
                                                        remove(outputFileName.c_str());
@@ -97,9 +121,23 @@ int BinSeqCommand::execute(){
                                        //get last name
                                        sequence = fasta->getSequence(binnames);
                                        if (sequence != "not found") {
-                                               name = binnames + '|' + toString(i+1);
-                                               out << ">" << name << endl;
-                                               out << sequence << endl;
+                                               //if you don't have groups
+                                               if (groupfile == "") {
+                                                       binnames = binnames + "|" + toString(i+1);
+                                                       out << ">" << binnames << endl;
+                                                       out << sequence << endl;
+                                               }else {//if you do have groups
+                                                       string group = groupMap->getGroup(binnames);
+                                                       if (group == "not found") {  
+                                                               cout << binnames << " is missing from your group file. Please correct. " << endl;
+                                                               remove(outputFileName.c_str());
+                                                               return 0;
+                                                       }else{
+                                                               binnames = binnames + "|" + group + "|" + toString(i+1);
+                                                               out << ">" << binnames << endl;
+                                                               out << sequence << endl;
+                                                       }
+                                               }
                                        }else { 
                                                cout << binnames << " is missing from your fasta or name file. Please correct. " << endl; 
                                                remove(outputFileName.c_str());