X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=binsequencecommand.cpp;h=f1ba8b5f38effa755a215e93a87dcf322001dc6d;hb=81a77fdce5e9b060c71b162305ddd9fa4308f78a;hp=7810ea9f793255e31e44c854a5a4c21639019c60;hpb=b1ac9e686514752c0aa7df045a3b2ab70ceaec89;p=mothur.git diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp index 7810ea9..f1ba8b5 100644 --- a/binsequencecommand.cpp +++ b/binsequencecommand.cpp @@ -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());