From 902e0fcab76e75009ac43d3f4537e08182628d6f Mon Sep 17 00:00:00 2001 From: pschloss Date: Tue, 8 Feb 2011 21:49:42 +0000 Subject: [PATCH] changes to trim.flows command --- Mothur.xcodeproj/project.pbxproj | 4 +- flowdata.cpp | 13 ++++ flowdata.h | 2 +- trimflowscommand.cpp | 116 +++++++++++++++++++------------ trimflowscommand.h | 2 +- 5 files changed, 88 insertions(+), 49 deletions(-) diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 7ddaecc..9216cc1 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -1610,7 +1610,7 @@ attributes = { ORGANIZATIONNAME = "Schloss Lab"; }; - buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "mothur" */; + buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "Mothur" */; compatibilityVersion = "Xcode 3.1"; developmentRegion = English; hasScannedForEncodings = 1; @@ -2030,7 +2030,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "mothur" */ = { + 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "Mothur" */ = { isa = XCConfigurationList; buildConfigurations = ( 1DEB928A08733DD80010E9CD /* Debug */, diff --git a/flowdata.cpp b/flowdata.cpp index eb6f9bf..39c1f83 100644 --- a/flowdata.cpp +++ b/flowdata.cpp @@ -212,3 +212,16 @@ void FlowData::printFlows(ofstream& outFlowFile, string scrapCode){ } //********************************************************************************************************************** + +string FlowData::getName(){ + + try{ + return seqName; + } + catch(exception& e) { + m->errorOut(e, "FlowData", "getSequence"); + exit(1); + } +} + +//********************************************************************************************************************** diff --git a/flowdata.h b/flowdata.h index 09426f9..612ed37 100644 --- a/flowdata.h +++ b/flowdata.h @@ -21,7 +21,7 @@ public: FlowData(int, float, float, int); ~FlowData(); bool getNext(ifstream&); - + string getName(); void capFlows(int); bool hasMinFlows(int); Sequence getSequence(); diff --git a/trimflowscommand.cpp b/trimflowscommand.cpp index 5c5d28b..960a59d 100644 --- a/trimflowscommand.cpp +++ b/trimflowscommand.cpp @@ -14,14 +14,10 @@ vector TrimFlowsCommand::getValidParameters(){ try { - string Array[] = {"flow", "totalflows", "minflows", + string Array[] = {"flow", "maxflows", "minflows", "fasta", "minlength", "maxlength", "maxhomop", "signal", "noise" "oligos", "pdiffs", "bdiffs", "tdiffs", "allfiles", "processors", - - - -// "group", "outputdir","inputdir" }; @@ -108,7 +104,7 @@ TrimFlowsCommand::TrimFlowsCommand(string option) { else { //valid paramters for this command - string AlignArray[] = {"flow", "totalflows", "minflows", + string AlignArray[] = {"flow", "maxflows", "minflows", "fasta", "minlength", "maxlength", "maxhomop", "signal", "noise", "oligos", "pdiffs", "bdiffs", "tdiffs", "allfiles", "processors", @@ -184,11 +180,11 @@ TrimFlowsCommand::TrimFlowsCommand(string option) { // ...at some point should added some additional type checking... string temp; - temp = validParameter.validFile(parameters, "minflows", false); if (temp == "not found") { temp = "360"; } + temp = validParameter.validFile(parameters, "minflows", false); if (temp == "not found") { temp = "360"; } convert(temp, minFlows); - temp = validParameter.validFile(parameters, "totalflows", false); if (temp == "not found") { temp = "720"; } - convert(temp, totalFlows); + temp = validParameter.validFile(parameters, "maxflows", false); if (temp == "not found") { temp = "720"; } + convert(temp, maxFlows); temp = validParameter.validFile(parameters, "oligos", true); @@ -284,10 +280,12 @@ int TrimFlowsCommand::execute(){ if (m->control_pressed) { return 0; } + string flowFilesFileName; + ofstream output; + if(allFiles){ - ofstream output; - string flowFilesFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "flow.files"; + flowFilesFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "flow.files"; m->openOutputFile(flowFilesFileName, output); for(int i=0;imothurOut("deleting: " + barcodePrimerComboFileNames[i][j] + '\n'); remove(barcodePrimerComboFileNames[i][j].c_str()); } else{ -// m->mothurOut("saving: " + barcodePrimerComboFileNames[i][j] + '\n'); output << barcodePrimerComboFileNames[i][j] << endl; } } } output.close(); } + else{ + flowFilesFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "flow.files"; + m->openOutputFile(flowFilesFileName, output); + + output << trimFlowFileName << endl; + + output.close(); + } + outputTypes["flow.files"].push_back(flowFilesFileName); m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -346,17 +351,19 @@ int TrimFlowsCommand::driverCreateTrim(string flowFileName, string trimFlowFileN scrapFlowFile.setf(ios::fixed, ios::floatfield); scrapFlowFile.setf(ios::showpoint); if(line->start == 4){ - scrapFlowFile << totalFlows << endl; - trimFlowFile << totalFlows << endl; - for(int i=0;iopenOutputFile(barcodePrimerComboFileNames[i][j], temp); - temp << totalFlows << endl; - temp.close(); - } - } + scrapFlowFile << maxFlows << endl; + trimFlowFile << maxFlows << endl; + if(allFiles){ + for(int i=0;iopenOutputFile(barcodePrimerComboFileNames[i][j], temp); + temp << maxFlows << endl; + temp.close(); + } + } + } } FlowData flowData(numFlows, signal, noise, maxHomoP); @@ -371,7 +378,7 @@ int TrimFlowsCommand::driverCreateTrim(string flowFileName, string trimFlowFileN int count = 0; bool moreSeqs = 1; - + while(moreSeqs) { int success = 1; @@ -379,7 +386,7 @@ int TrimFlowsCommand::driverCreateTrim(string flowFileName, string trimFlowFileN string trashCode = ""; flowData.getNext(flowFile); - flowData.capFlows(totalFlows); + flowData.capFlows(maxFlows); Sequence currSeq = flowData.getSequence(); if(!flowData.hasMinFlows(minFlows)){ //screen to see if sequence is of a minimum number of flows @@ -395,7 +402,8 @@ int TrimFlowsCommand::driverCreateTrim(string flowFileName, string trimFlowFileN } } - int primerIndex, barcodeIndex; + int primerIndex = 0; + int barcodeIndex = 0; if(barcodes.size() != 0){ success = stripBarcode(currSeq, barcodeIndex); @@ -415,16 +423,14 @@ int TrimFlowsCommand::driverCreateTrim(string flowFileName, string trimFlowFileN success = stripReverse(currSeq); if(!success) { trashCode += 'r'; } } - - + if(trashCode.length() == 0){ + flowData.printFlows(trimFlowFile); + + if(fasta) { currSeq.printSequence(fastaFile); } - if(fasta){ - currSeq.printSequence(fastaFile); - } - - if(barcodes.size() != 0 || primers.size() != 0){ + if(allFiles){ // string fileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + barcodePrimerCombos[barcodeIndex][primerIndex] + ".flow"; ofstream output; m->openOutputFileAppend(barcodePrimerComboFileNames[barcodeIndex][primerIndex], output); @@ -541,13 +547,27 @@ void TrimFlowsCommand::getOligos(vector >& outFlowFileNames){ } oligosFile.close(); - //add in potential combos + if(barcodeNameVector.size() == 0 && primerNameVector[0] == ""){ allFiles = 0; } + + //add in potential combos + if(barcodeNameVector.size() == 0){ + barcodes[""] = 0; + barcodeNameVector.push_back(""); + } + + if(primerNameVector.size() == 0){ + primers[""] = 0; + primerNameVector.push_back(""); + } + + outFlowFileNames.resize(barcodeNameVector.size()); for(int i=0;i::iterator itBar = barcodes.begin();itBar != barcodes.end();itBar++){ for(map::iterator itPrimer = primers.begin();itPrimer != primers.end(); itPrimer++){ @@ -562,7 +582,12 @@ void TrimFlowsCommand::getOligos(vector >& outFlowFileNames){ fileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + comboGroupName + ".flow"; } else{ - comboGroupName = barcodeNameVector[itBar->second] + "." + primerNameVector[itPrimer->second]; + if(barcodeName == ""){ + comboGroupName = primerNameVector[itPrimer->second]; + } + else{ + comboGroupName = barcodeNameVector[itBar->second] + "." + primerNameVector[itPrimer->second]; + } fileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + comboGroupName + ".flow"; } @@ -726,7 +751,7 @@ int TrimFlowsCommand::stripForward(Sequence& seq, int& group){ } //if you found the barcode or if you don't want to allow for diffs - if ((pdiffs == 0) || (success == 0)) { return success; } + if ((pdiffs == 0) || (success == 0)) { return success; } else { //try aligning and see if you can find it @@ -1016,16 +1041,17 @@ int TrimFlowsCommand::createProcessesCreateTrim(string flowFileName, string trim }else if (pid == 0){ vector > tempBarcodePrimerComboFileNames = barcodePrimerComboFileNames; - for(int i=0;iopenOutputFile(tempBarcodePrimerComboFileNames[i][j], temp); - temp.close(); - + if(allFiles){ + for(int i=0;iopenOutputFile(tempBarcodePrimerComboFileNames[i][j], temp); + temp.close(); + + } } } - driverCreateTrim(flowFileName, (trimFlowFileName + toString(getpid()) + ".temp"), (scrapFlowFileName + toString(getpid()) + ".temp"), diff --git a/trimflowscommand.h b/trimflowscommand.h index 15c698c..99103ba 100644 --- a/trimflowscommand.h +++ b/trimflowscommand.h @@ -61,7 +61,7 @@ private: bool allFiles; int processors; int numFPrimers, numRPrimers; - int totalFlows, minFlows, minLength, maxLength, maxHomoP, tdiffs, bdiffs, pdiffs; + int maxFlows, minFlows, minLength, maxLength, maxHomoP, tdiffs, bdiffs, pdiffs; int numFlows; float signal, noise; bool fasta; -- 2.39.2