From: Kathryn Iverson Date: Tue, 3 Jul 2012 18:48:49 +0000 (-0400) Subject: updated mgcluster to take count file X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=7a2c74cd89b3c21e9ec2207e529304db68f1391a updated mgcluster to take count file --- diff --git a/mgclustercommand.cpp b/mgclustercommand.cpp index 4ca0cdf..878d6a4 100644 --- a/mgclustercommand.cpp +++ b/mgclustercommand.cpp @@ -14,7 +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 plarge("large", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(plarge); + 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); @@ -165,6 +166,13 @@ 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("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; } @@ -237,9 +245,11 @@ int MGClusterCommand::execute(){ list = new ListVector(nameMap->getListVector()); RAbundVector* rabund = NULL; - if(large) { - map nameMapCounts = m->readNames(namefile); - createRabund(nameMapCounts); + if(countfile != "") { + //map nameMapCounts = m->readNames(namefile); + CountTable ct = new CountTable(); + ct.readTable(countfile); + createRabund(ct, list); rabund = &rav; }else { rabund = new RAbundVector(list->getRAbundVector()); @@ -714,14 +724,25 @@ void MGClusterCommand::sortHclusterFiles(string unsortedDist, string unsortedOve //********************************************************************************************************************** -void MGClusterCommand::createRabund(map nameMapCounts){ +void MGClusterCommand::createRabund(CountTable ct, ListVector list){ try { - //RAbundVector rav; - map::iterator it; - //it = nameMapCounts.begin(); - //for(int i = 0; i < list->getNumBins(); i++) { rav.push_back((*it).second); it++; } - for ( it=nameMapCounts.begin(); it!=nameMapCounts.end(); it++ ) { rav.push_back( it->second ); } + //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]); + } + rav.push_back(total); + } + + } catch(exception& e) { m->errorOut(e, "MGClusterCommand", "createRabund"); diff --git a/mgclustercommand.h b/mgclustercommand.h index ce3ffec..6f44533 100644 --- a/mgclustercommand.h +++ b/mgclustercommand.h @@ -18,6 +18,7 @@ #include "hcluster.h" #include "rabundvector.hpp" #include "sabundvector.hpp" +#include "counttable.h" /**********************************************************************/ @@ -51,7 +52,7 @@ private: vector overlapMatrix; vector outputNames; - string blastfile, method, namefile, overlapFile, distFile, outputDir; + string blastfile, method, namefile, countfile, overlapFile, distFile, outputDir; ofstream sabundFile, rabundFile, listFile; double cutoff; float penalty; @@ -62,7 +63,7 @@ private: ListVector* mergeOPFs(map, float); void sortHclusterFiles(string, string); vector getSeqs(ifstream&); - void createRabund(map); + void createRabund(CountTable); };