X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=mgclustercommand.cpp;h=6ef968c2248de78e304291f3c781a2baa44ad8ea;hb=ccae9eef0b44f2d63fdf4a707d0d40243aa1b990;hp=61e130647c6734ee49ba99b0bcded20804ee103d;hpb=38491018f166c7c5517518cfa64832582f20dd85;p=mothur.git diff --git a/mgclustercommand.cpp b/mgclustercommand.cpp index 61e1306..6ef968c 100644 --- a/mgclustercommand.cpp +++ b/mgclustercommand.cpp @@ -14,6 +14,8 @@ vector MGClusterCommand::setParameters(){ try { CommandParameter pblast("blast", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pblast); CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pcount); + //CommandParameter plarge("large", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(plarge); CommandParameter plength("length", "Number", "", "5", "", "", "",false,false); parameters.push_back(plength); CommandParameter ppenalty("penalty", "Number", "", "0.10", "", "", "",false,false); parameters.push_back(ppenalty); CommandParameter pcutoff("cutoff", "Number", "", "0.70", "", "", "",false,false); parameters.push_back(pcutoff); @@ -164,11 +166,21 @@ MGClusterCommand::MGClusterCommand(string option) { if (namefile == "not open") { abort = true; } else if (namefile == "not found") { namefile = ""; } else { m->setNameFile(namefile); } + + countfile = validParameter.validFile(parameters, "count", true); + if (countfile == "not open") { abort = true; } + else if (countfile == "not found") { countfile = ""; } + else { m->setCountTableFile(countfile); } + + if (countfile != "" && namefile != "") { m->mothurOut("[ERROR]: Cannot have both a name file and count file. Please use one or the other."); m->mothurOutEndLine(); abort = true; } if ((blastfile == "")) { m->mothurOut("When executing a mgcluster command you must provide a blastfile."); m->mothurOutEndLine(); abort = true; } //check for optional parameter and set defaults string temp; + temp = validParameter.validFile(parameters, "large", false); if (temp == "not found") { temp = "false"; } + large = m->isTrue(temp); + temp = validParameter.validFile(parameters, "precision", false); if (temp == "not found") { temp = "100"; } precisionLength = temp.length(); m->mothurConvert(temp, precision); @@ -199,7 +211,7 @@ MGClusterCommand::MGClusterCommand(string option) { hclusterWanted = m->isTrue(temp); temp = validParameter.validFile(parameters, "hard", false); if (temp == "not found") { temp = "T"; } - hard = m->isTrue(temp); + hard = m->isTrue(temp); } } @@ -211,7 +223,6 @@ MGClusterCommand::MGClusterCommand(string option) { //********************************************************************************************************************** int MGClusterCommand::execute(){ try { - if (abort == true) { if (calledHelp) { return 0; } return 2; } //read names file @@ -225,14 +236,28 @@ int MGClusterCommand::execute(){ time_t start; float previousDist = 0.00000; float rndPreviousDist = 0.00000; - + //read blastfile - creates sparsematrices for the distances and overlaps as well as a listvector //must remember to delete those objects here since readBlast does not read = new ReadBlast(blastfile, cutoff, penalty, length, minWanted, hclusterWanted); read->read(nameMap); - - list = new ListVector(nameMap->getListVector()); - RAbundVector* rabund = new RAbundVector(list->getRAbundVector()); + + list = new ListVector(nameMap->getListVector()); + RAbundVector* rabund = NULL; + + if(countfile != "") { + //map nameMapCounts = m->readNames(namefile); + ct = new CountTable(); + ct->readTable(countfile); + rabund = new RAbundVector(); + createRabund(ct, list, rabund); + }else { + rabund = new RAbundVector(list->getRAbundVector()); + } + + + //list = new ListVector(nameMap->getListVector()); + //rabund = new RAbundVector(list->getRAbundVector()); if (m->control_pressed) { outputTypes.clear(); delete nameMap; delete read; delete list; delete rabund; return 0; } @@ -503,8 +528,8 @@ int MGClusterCommand::execute(){ m->mothurRemove(overlapFile); } - delete list; - delete rabund; + delete list; + if (!large) {delete rabund;} listFile.close(); sabundFile.close(); rabundFile.close(); @@ -699,7 +724,33 @@ void MGClusterCommand::sortHclusterFiles(string unsortedDist, string unsortedOve //********************************************************************************************************************** +void MGClusterCommand::createRabund(CountTable*& ct, ListVector*& list, RAbundVector*& rabund){ + try { + //vector names = ct.getNamesOfSeqs(); + //for ( int i; i < ct.getNumGroups(); i++ ) { rav.push_back( ct.getNumSeqs(names[i]) ); } + //return rav; + + for(int i = 0; i < list->getNumBins(); i++) { + vector binNames; + string bin = list->get(i); + m->splitAtComma(bin, binNames); + int total = 0; + for (int j = 0; j < binNames.size(); j++) { + total += ct->getNumSeqs(binNames[j]); + } + rabund->push_back(total); + } + + + } + catch(exception& e) { + m->errorOut(e, "MGClusterCommand", "createRabund"); + exit(1); + } + +} +//**********************************************************************************************************************