X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=seqsummarycommand.cpp;h=0e3b70c1db3824084a51fb0db1c88630285878c2;hp=fb43503b2e7cc987e56ee58f591f5fe75d47aaa1;hb=d1c97b8c04bb75faca1e76ffad60b37a4d789d3d;hpb=79a7d3273749b08d4f9f8dfe350c964ff0c4351e diff --git a/seqsummarycommand.cpp b/seqsummarycommand.cpp index fb43503..0e3b70c 100644 --- a/seqsummarycommand.cpp +++ b/seqsummarycommand.cpp @@ -13,12 +13,12 @@ //********************************************************************************************************************** vector SeqSummaryCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","summary",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -48,24 +48,19 @@ string SeqSummaryCommand::getHelpString(){ } } //********************************************************************************************************************** -string SeqSummaryCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SeqSummaryCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "summary") { outputFileName = "summary"; } - 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, "SeqSummaryCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "summary") { pattern = "[filename],summary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SeqSummaryCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** @@ -193,7 +188,9 @@ int SeqSummaryCommand::execute(){ //set current fasta to fastafile m->setFastaFile(fastafile); - string summaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + string summaryFile = getOutputFileName("summary",variables); int numSeqs = 0; @@ -206,7 +203,7 @@ int SeqSummaryCommand::execute(){ if (namefile != "") { nameMap = m->readNames(namefile); } else if (countfile != "") { CountTable ct; - ct.readTable(countfile); + ct.readTable(countfile, false); nameMap = ct.getNameMap(); } @@ -367,7 +364,7 @@ int SeqSummaryCommand::execute(){ int size = startPosition.size(); //find means - double meanStartPosition, meanEndPosition, meanSeqLength, meanAmbigBases, meanLongHomoPolymer; + unsigned long long meanStartPosition, meanEndPosition, meanSeqLength, meanAmbigBases, meanLongHomoPolymer; meanStartPosition = 0; meanEndPosition = 0; meanSeqLength = 0; meanAmbigBases = 0; meanLongHomoPolymer = 0; for (int i = 0; i < size; i++) { meanStartPosition += startPosition[i]; @@ -377,8 +374,9 @@ int SeqSummaryCommand::execute(){ meanLongHomoPolymer += longHomoPolymer[i]; } - //this is an int divide so the remainder is lost - meanStartPosition /= (float) size; meanEndPosition /= (float) size; meanLongHomoPolymer /= (float) size; meanSeqLength /= (float) size; meanAmbigBases /= (float) size; + double meanstartPosition, meanendPosition, meanseqLength, meanambigBases, meanlongHomoPolymer; + + meanstartPosition = meanStartPosition / (double) size; meanendPosition = meanEndPosition /(double) size; meanlongHomoPolymer = meanLongHomoPolymer / (double) size; meanseqLength = meanSeqLength / (double) size; meanambigBases = meanAmbigBases /(double) size; int ptile0_25 = int(size * 0.025); int ptile25 = int(size * 0.250); @@ -402,7 +400,7 @@ int SeqSummaryCommand::execute(){ m->mothurOut("75%-tile:\t" + toString(startPosition[ptile75]) + "\t" + toString(endPosition[ptile75]) + "\t" + toString(seqLength[ptile75]) + "\t" + toString(ambigBases[ptile75]) + "\t" + toString(longHomoPolymer[ptile75]) + "\t" + toString(ptile75+1)); m->mothurOutEndLine(); m->mothurOut("97.5%-tile:\t" + toString(startPosition[ptile97_5]) + "\t" + toString(endPosition[ptile97_5]) + "\t" + toString(seqLength[ptile97_5]) + "\t" + toString(ambigBases[ptile97_5]) + "\t" + toString(longHomoPolymer[ptile97_5]) + "\t" + toString(ptile97_5+1)); m->mothurOutEndLine(); m->mothurOut("Maximum:\t" + toString(startPosition[ptile100]) + "\t" + toString(endPosition[ptile100]) + "\t" + toString(seqLength[ptile100]) + "\t" + toString(ambigBases[ptile100]) + "\t" + toString(longHomoPolymer[ptile100]) + "\t" + toString(ptile100+1)); m->mothurOutEndLine(); - m->mothurOut("Mean:\t" + toString(meanStartPosition) + "\t" + toString(meanEndPosition) + "\t" + toString(meanSeqLength) + "\t" + toString(meanAmbigBases) + "\t" + toString(meanLongHomoPolymer)); m->mothurOutEndLine(); + m->mothurOut("Mean:\t" + toString(meanstartPosition) + "\t" + toString(meanendPosition) + "\t" + toString(meanseqLength) + "\t" + toString(meanambigBases) + "\t" + toString(meanlongHomoPolymer)); m->mothurOutEndLine(); if ((namefile == "") && (countfile == "")) { m->mothurOut("# of Seqs:\t" + toString(numSeqs)); m->mothurOutEndLine(); } else { m->mothurOut("# of unique seqs:\t" + toString(numSeqs)); m->mothurOutEndLine(); m->mothurOut("total # of seqs:\t" + toString(startPosition.size())); m->mothurOutEndLine(); } @@ -418,6 +416,13 @@ int SeqSummaryCommand::execute(){ } #endif + //set fasta file as new current fastafile + string current = ""; + itTypes = outputTypes.find("summary"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSummaryFile(current); } + } + return 0; } catch(exception& e) { @@ -448,11 +453,15 @@ int SeqSummaryCommand::driverCreateSummary(vector& startPosition, vectorcontrol_pressed) { in.close(); outSummary.close(); return 1; } - + + if (m->debug) { m->mothurOut("[DEBUG]: count = " + toString(count) + "\n"); } + Sequence current(in); m->gobble(in); if (current.getName() != "") { + if (m->debug) { m->mothurOut("[DEBUG]: " + current.getName() + '\t' + toString(current.getNumBases()) + "\n"); } + int num = 1; if ((namefile != "") || (countfile != "")) { //make sure this sequence is in the namefile, else error @@ -476,6 +485,8 @@ int SeqSummaryCommand::driverCreateSummary(vector& startPosition, vectordebug) { m->mothurOut("[DEBUG]: " + current.getName() + '\t' + toString(current.getNumBases()) + "\n"); } } #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) @@ -484,13 +495,8 @@ int SeqSummaryCommand::driverCreateSummary(vector& startPosition, vectormothurOut(toString(count)); m->mothurOutEndLine(); } } - //report progress - //if((count) % 100 != 0){ m->mothurOut(toString(count)); m->mothurOutEndLine(); } - + in.close(); return count; @@ -538,7 +544,7 @@ int SeqSummaryCommand::MPICreateSummary(int start, int num, vector& startPo } //for each sequence this sequence represents - for (int i = 0; i < num; i++) { + for (int j = 0; j < num; j++) { startPosition.push_back(current.getStartPos()); endPosition.push_back(current.getEndPos()); seqLength.push_back(current.getNumBases()); @@ -678,6 +684,9 @@ int SeqSummaryCommand::createProcessesCreateSummary(vector& startPosition, //Close all thread handles and free memory allocations. for(int i=0; i < pDataArray.size(); i++){ num += pDataArray[i]->count; + if (pDataArray[i]->count != pDataArray[i]->end) { + m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true; + } for (int k = 0; k < pDataArray[i]->startPosition.size(); k++) { startPosition.push_back(pDataArray[i]->startPosition[k]); } for (int k = 0; k < pDataArray[i]->endPosition.size(); k++) { endPosition.push_back(pDataArray[i]->endPosition[k]); } for (int k = 0; k < pDataArray[i]->seqLength.size(); k++) { seqLength.push_back(pDataArray[i]->seqLength[k]); }