X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=shhhercommand.cpp;h=19ffc899d60ac778ac4eedbeb2034a62b5e04bd7;hb=96dbe925073caefaed6e6db85659c144a806aeb1;hp=8ae76d9836c31b0d3a37ac41d58a6aa54db6e859;hpb=2c97dd48b8e27ee0a6a86c7a082f4c504c3357c6;p=mothur.git diff --git a/shhhercommand.cpp b/shhhercommand.cpp index 8ae76d9..19ffc89 100644 --- a/shhhercommand.cpp +++ b/shhhercommand.cpp @@ -47,6 +47,30 @@ string ShhherCommand::getHelpString(){ } } //********************************************************************************************************************** +string ShhherCommand::getOutputFileNameTag(string type, string inputName=""){ + try { + string outputFileName = ""; + map >::iterator it; + + //is this a type this command creates + it = outputTypes.find(type); + if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } + else { + if (type == "fasta") { outputFileName = "shhh.fasta"; } + else if (type == "name") { outputFileName = "shhh.names"; } + else if (type == "group") { outputFileName = "shhh.groups"; } + else if (type == "counts") { outputFileName = "shhh.counts"; } + else if (type == "qfile") { outputFileName = "shhh.qual"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } + } + return outputFileName; + } + catch(exception& e) { + m->errorOut(e, "ShhherCommand", "getOutputFileNameTag"); + exit(1); + } +} +//********************************************************************************************************************** ShhherCommand::ShhherCommand(){ try { @@ -54,8 +78,12 @@ ShhherCommand::ShhherCommand(){ setParameters(); //initialize outputTypes -// vector tempOutNames; -// outputTypes["pn.dist"] = tempOutNames; + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["counts"] = tempOutNames; + outputTypes["qfile"] = tempOutNames; } catch(exception& e) { @@ -96,9 +124,13 @@ ShhherCommand::ShhherCommand(string option) { } //initialize outputTypes - vector tempOutNames; -// outputTypes["pn.dist"] = tempOutNames; - // outputTypes["fasta"] = tempOutNames; + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["counts"] = tempOutNames; + outputTypes["qfile"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); @@ -744,8 +776,8 @@ int ShhherCommand::execute(){ if(compositeFASTAFileName != ""){ - outputNames.push_back(compositeFASTAFileName); - outputNames.push_back(compositeNamesFileName); + outputNames.push_back(compositeFASTAFileName); outputTypes["fasta"].push_back(compositeFASTAFileName); + outputNames.push_back(compositeNamesFileName); outputTypes["name"].push_back(compositeNamesFileName); } m->mothurOutEndLine(); @@ -770,7 +802,7 @@ string ShhherCommand::createNamesFile(){ duplicateNames[mapSeqToUnique[i]] += seqNameVector[i] + ','; } - string nameFileName = flowFileName.substr(0,flowFileName.find_last_of('.')) + ".shhh.names"; + string nameFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("name"); ofstream nameFile; m->openOutputFile(nameFileName, nameFile); @@ -1007,7 +1039,12 @@ void ShhherCommand::getFlowData(){ float intensity; - flowFile >> numFlowCells; + string numFlowTest; + flowFile >> numFlowTest; + + if (!m->isContainingOnlyDigits(numFlowTest)) { m->mothurOut("[ERROR]: expected a number and got " + numFlowTest + ", quitting. Did you use the flow parameter instead of the file parameter?"); m->mothurOutEndLine(); exit(1); } + else { convert(numFlowTest, numFlowCells); } + int index = 0;//pcluster while(!flowFile.eof()){ @@ -1344,17 +1381,17 @@ string ShhherCommand::cluster(string distFileName, string namesFileName){ try { ReadMatrix* read = new ReadColumnMatrix(distFileName); - read->setCutoff(cutoff); - - NameAssignment* clusterNameMap = new NameAssignment(namesFileName); - clusterNameMap->readMap(); - read->read(clusterNameMap); - - ListVector* list = read->getListVector(); - SparseMatrix* matrix = read->getMatrix(); + read->setCutoff(cutoff); + + NameAssignment* clusterNameMap = new NameAssignment(namesFileName); + clusterNameMap->readMap(); + read->read(clusterNameMap); - delete read; - delete clusterNameMap; + ListVector* list = read->getListVector(); + SparseDistanceMatrix* matrix = read->getDMatrix(); + + delete read; + delete clusterNameMap; RAbundVector* rabund = new RAbundVector(list->getRAbundVector()); @@ -1614,7 +1651,7 @@ void ShhherCommand::writeQualities(vector otuCounts){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string qualityFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.qual"; + string qualityFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("qfile"); ofstream qualityFile; m->openOutputFile(qualityFileName, qualityFile); @@ -1706,7 +1743,7 @@ void ShhherCommand::writeQualities(vector otuCounts){ } } qualityFile.close(); - outputNames.push_back(qualityFileName); + outputNames.push_back(qualityFileName); outputTypes["qfile"].push_back(qualityFileName); } catch(exception& e) { @@ -1721,7 +1758,7 @@ void ShhherCommand::writeSequences(vector otuCounts){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string fastaFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.fasta"; + string fastaFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("fasta"); ofstream fastaFile; m->openOutputFile(fastaFileName, fastaFile); @@ -1751,7 +1788,7 @@ void ShhherCommand::writeSequences(vector otuCounts){ } fastaFile.close(); - outputNames.push_back(fastaFileName); + outputNames.push_back(fastaFileName); outputTypes["fasta"].push_back(fastaFileName); if(compositeFASTAFileName != ""){ m->appendFiles(fastaFileName, compositeFASTAFileName); @@ -1769,7 +1806,7 @@ void ShhherCommand::writeNames(vector otuCounts){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string nameFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.names"; + string nameFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("name"); ofstream nameFile; m->openOutputFile(nameFileName, nameFile); @@ -1788,7 +1825,7 @@ void ShhherCommand::writeNames(vector otuCounts){ } } nameFile.close(); - outputNames.push_back(nameFileName); + outputNames.push_back(nameFileName); outputTypes["name"].push_back(nameFileName); if(compositeNamesFileName != ""){ @@ -1807,17 +1844,20 @@ void ShhherCommand::writeGroups(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string fileRoot = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)); - string groupFileName = fileRoot + "shhh.groups"; + string fileRoot = m->getRootName(m->getSimpleName(flowFileName)); + int pos = fileRoot.find_first_of('.'); + string fileGroup = fileRoot; + if (pos != string::npos) { fileGroup = fileRoot.substr(pos+1, (fileRoot.length()-1-(pos+1))); } + string groupFileName = thisOutputDir + fileRoot + getOutputFileNameTag("group"); ofstream groupFile; m->openOutputFile(groupFileName, groupFile); for(int i=0;icontrol_pressed) { break; } - groupFile << seqNameVector[i] << '\t' << fileRoot << endl; + groupFile << seqNameVector[i] << '\t' << fileGroup << endl; } groupFile.close(); - outputNames.push_back(groupFileName); + outputNames.push_back(groupFileName); outputTypes["group"].push_back(groupFileName); } catch(exception& e) { @@ -1832,7 +1872,7 @@ void ShhherCommand::writeClusters(vector otuCounts){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string otuCountsFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.counts"; + string otuCountsFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) +getOutputFileNameTag("counts"); ofstream otuCountsFile; m->openOutputFile(otuCountsFileName, otuCountsFile); @@ -1877,7 +1917,7 @@ void ShhherCommand::writeClusters(vector otuCounts){ } } otuCountsFile.close(); - outputNames.push_back(otuCountsFileName); + outputNames.push_back(otuCountsFileName); outputTypes["counts"].push_back(otuCountsFileName); } catch(exception& e) { @@ -1891,7 +1931,7 @@ void ShhherCommand::writeClusters(vector otuCounts){ int ShhherCommand::execute(){ try { - if (abort == true) { return 0; } + if (abort == true) { if (calledHelp) { return 0; } return 2; } getSingleLookUp(); if (m->control_pressed) { return 0; } getJointLookUp(); if (m->control_pressed) { return 0; } @@ -1908,8 +1948,8 @@ int ShhherCommand::execute(){ #endif if(compositeFASTAFileName != ""){ - outputNames.push_back(compositeFASTAFileName); - outputNames.push_back(compositeNamesFileName); + outputNames.push_back(compositeFASTAFileName); outputTypes["fasta"].push_back(compositeFASTAFileName); + outputNames.push_back(compositeNamesFileName); outputTypes["name"].push_back(compositeNamesFileName); } m->mothurOutEndLine(); @@ -1994,7 +2034,7 @@ int ShhherCommand::createProcesses(vector filenames){ //Windows version shared memory, so be careful when passing variables through the shhhFlowsData struct. //Above fork() will clone, so memory is separate, but that's not the case with windows, ////////////////////////////////////////////////////////////////////////////////////////////////////// - + /* vector pDataArray; DWORD dwThreadIdArray[processors-1]; HANDLE hThreadArray[processors-1]; @@ -2025,7 +2065,7 @@ int ShhherCommand::createProcesses(vector filenames){ CloseHandle(hThreadArray[i]); delete pDataArray[i]; } - + */ #endif for (int i=0;i filenames, string thisCompositeFASTAFil if (m->control_pressed) { break; } vector otuCounts(numOTUs, 0); - for(int i=0;i filenames, string thisCompositeFASTAFil if ((large) && (g == 0)) { flowFileName = filenames[i]; theseFlowFileNames[0] = filenames[i]; } string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir = m->hasPath(flowFileName); } - string qualityFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.qual"; - string fastaFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.fasta"; - string nameFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.names"; - string otuCountsFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.counts"; - string fileRoot = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)); - string groupFileName = fileRoot + "shhh.groups"; + string qualityFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("qfile"); + string fastaFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("fasta"); + string nameFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("name"); + string otuCountsFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("counts"); + string fileRoot = m->getRootName(m->getSimpleName(flowFileName)); + int pos = fileRoot.find_first_of('.'); + string fileGroup = fileRoot; + if (pos != string::npos) { fileGroup = fileRoot.substr(pos+1, (fileRoot.length()-1-(pos+1))); } + string groupFileName = thisOutputDir + fileRoot + getOutputFileNameTag("group"); writeQualities(numOTUs, numFlowCells, qualityFileName, otuCounts, nSeqsPerOTU, seqNumber, singleTau, flowDataIntI, uniqueFlowgrams, cumNumSeqs, mapUniqueToSeq, seqNameVector, centroids, aaI); if (m->control_pressed) { break; } writeSequences(thisCompositeFASTAFileName, numOTUs, numFlowCells, fastaFileName, otuCounts, uniqueFlowgrams, seqNameVector, aaI, centroids);if (m->control_pressed) { break; } writeNames(thisCompositeNamesFileName, numOTUs, nameFileName, otuCounts, seqNameVector, aaI, nSeqsPerOTU); if (m->control_pressed) { break; } writeClusters(otuCountsFileName, numOTUs, numFlowCells,otuCounts, centroids, uniqueFlowgrams, seqNameVector, aaI, nSeqsPerOTU, lengths, flowDataIntI); if (m->control_pressed) { break; } - writeGroups(groupFileName, fileRoot, numSeqs, seqNameVector); if (m->control_pressed) { break; } + writeGroups(groupFileName, fileGroup, numSeqs, seqNameVector); if (m->control_pressed) { break; } if (large) { if (g > 0) { - m->appendFiles(qualityFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + "shhh.qual")); + m->appendFiles(qualityFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("qfile"))); m->mothurRemove(qualityFileName); - m->appendFiles(fastaFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + "shhh.fasta")); + m->appendFiles(fastaFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("fasta"))); m->mothurRemove(fastaFileName); - m->appendFiles(nameFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + "shhh.names")); + m->appendFiles(nameFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("name"))); m->mothurRemove(nameFileName); - m->appendFiles(otuCountsFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + "shhh.counts")); + m->appendFiles(otuCountsFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("counts"))); m->mothurRemove(otuCountsFileName); - m->appendFiles(groupFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + "shhh.groups")); + m->appendFiles(groupFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("group"))); m->mothurRemove(groupFileName); } m->mothurRemove(theseFlowFileNames[g]); @@ -2344,7 +2387,12 @@ int ShhherCommand::getFlowData(string filename, vector& thisSeqNameVecto thisFlowDataIntI.clear(); thisNameMap.clear(); - flowFile >> numFlowCells; + string numFlowTest; + flowFile >> numFlowTest; + + if (!m->isContainingOnlyDigits(numFlowTest)) { m->mothurOut("[ERROR]: expected a number and got " + numFlowTest + ", quitting. Did you use the flow parameter instead of the file parameter?"); m->mothurOutEndLine(); exit(1); } + else { convert(numFlowTest, numFlowCells); } + if (m->debug) { m->mothurOut("[DEBUG]: numFlowCells = " + toString(numFlowCells) + ".\n"); } int index = 0;//pcluster while(!flowFile.eof()){ @@ -2594,7 +2642,7 @@ int ShhherCommand::cluster(string filename, string distFileName, string namesFil read->read(clusterNameMap); ListVector* list = read->getListVector(); - SparseMatrix* matrix = read->getMatrix(); + SparseDistanceMatrix* matrix = read->getDMatrix(); delete read; delete clusterNameMap; @@ -3218,7 +3266,7 @@ void ShhherCommand::writeQualities(int numOTUs, int numFlowCells, string quality } } qualityFile.close(); - outputNames.push_back(qualityFileName); + outputNames.push_back(qualityFileName); outputTypes["qfile"].push_back(qualityFileName); } catch(exception& e) { @@ -3262,7 +3310,7 @@ void ShhherCommand::writeSequences(string thisCompositeFASTAFileName, int numOTU } fastaFile.close(); - outputNames.push_back(fastaFileName); + outputNames.push_back(fastaFileName); outputTypes["fasta"].push_back(fastaFileName); if(thisCompositeFASTAFileName != ""){ m->appendFiles(fastaFileName, thisCompositeFASTAFileName); @@ -3297,7 +3345,7 @@ void ShhherCommand::writeNames(string thisCompositeNamesFileName, int numOTUs, s } } nameFile.close(); - outputNames.push_back(nameFileName); + outputNames.push_back(nameFileName); outputTypes["name"].push_back(nameFileName); if(thisCompositeNamesFileName != ""){ @@ -3322,7 +3370,7 @@ void ShhherCommand::writeGroups(string groupFileName, string fileRoot, int numSe groupFile << seqNameVector[i] << '\t' << fileRoot << endl; } groupFile.close(); - outputNames.push_back(groupFileName); + outputNames.push_back(groupFileName); outputTypes["group"].push_back(groupFileName); } catch(exception& e) { @@ -3381,7 +3429,7 @@ void ShhherCommand::writeClusters(string otuCountsFileName, int numOTUs, int num } } otuCountsFile.close(); - outputNames.push_back(otuCountsFileName); + outputNames.push_back(otuCountsFileName); outputTypes["counts"].push_back(otuCountsFileName); } catch(exception& e) {