X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=chimeraslayercommand.cpp;h=59dd0a55a27c13eb80dd521ea83516770c97ed4a;hb=529ec122f7cac4af987e121d150b878d7c7a0d5d;hp=0512be1a70b1d12b0667f5945e4d1acb5b4768d8;hpb=88fbc534a92cb91900e98a3288dfa1f68828b69b;p=mothur.git diff --git a/chimeraslayercommand.cpp b/chimeraslayercommand.cpp index 0512be1..59dd0a5 100644 --- a/chimeraslayercommand.cpp +++ b/chimeraslayercommand.cpp @@ -98,6 +98,28 @@ string ChimeraSlayerCommand::getHelpString(){ } } //********************************************************************************************************************** +string ChimeraSlayerCommand::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 == "chimera") { outputFileName = "slayer.chimeras"; } + else if (type == "accnos") { outputFileName = "slayer.accnos"; } + else if (type == "fasta") { outputFileName = "slayer.fasta"; } + 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, "ChimeraSlayerCommand", "getOutputFileNameTag"); + exit(1); + } +} +//********************************************************************************************************************** ChimeraSlayerCommand::ChimeraSlayerCommand(){ try { abort = true; calledHelp = true; @@ -383,7 +405,7 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); - convert(temp, processors); + m->mothurConvert(temp, processors); temp = validParameter.validFile(parameters, "save", false); if (temp == "not found"){ temp = "f"; } save = m->isTrue(temp); @@ -441,34 +463,34 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { temp = validParameter.validFile(parameters, "ksize", false); if (temp == "not found") { temp = "7"; } - convert(temp, ksize); + m->mothurConvert(temp, ksize); temp = validParameter.validFile(parameters, "window", false); if (temp == "not found") { temp = "50"; } - convert(temp, window); + m->mothurConvert(temp, window); temp = validParameter.validFile(parameters, "match", false); if (temp == "not found") { temp = "5"; } - convert(temp, match); + m->mothurConvert(temp, match); temp = validParameter.validFile(parameters, "mismatch", false); if (temp == "not found") { temp = "-4"; } - convert(temp, mismatch); + m->mothurConvert(temp, mismatch); temp = validParameter.validFile(parameters, "divergence", false); if (temp == "not found") { temp = "1.007"; } - convert(temp, divR); + m->mothurConvert(temp, divR); temp = validParameter.validFile(parameters, "minsim", false); if (temp == "not found") { temp = "90"; } - convert(temp, minSimilarity); + m->mothurConvert(temp, minSimilarity); temp = validParameter.validFile(parameters, "mincov", false); if (temp == "not found") { temp = "70"; } - convert(temp, minCoverage); + m->mothurConvert(temp, minCoverage); temp = validParameter.validFile(parameters, "minbs", false); if (temp == "not found") { temp = "90"; } - convert(temp, minBS); + m->mothurConvert(temp, minBS); temp = validParameter.validFile(parameters, "minsnp", false); if (temp == "not found") { temp = "10"; } - convert(temp, minSNP); + m->mothurConvert(temp, minSNP); temp = validParameter.validFile(parameters, "parents", false); if (temp == "not found") { temp = "3"; } - convert(temp, parents); + m->mothurConvert(temp, parents); temp = validParameter.validFile(parameters, "realign", false); if (temp == "not found") { temp = "t"; } realign = m->isTrue(temp); @@ -482,27 +504,27 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { search = validParameter.validFile(parameters, "search", false); if (search == "not found") { search = "blast"; } temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "1000"; } - convert(temp, iters); + m->mothurConvert(temp, iters); temp = validParameter.validFile(parameters, "increment", false); if (temp == "not found") { temp = "5"; } - convert(temp, increment); + m->mothurConvert(temp, increment); temp = validParameter.validFile(parameters, "numwanted", false); if (temp == "not found") { temp = "15"; } - convert(temp, numwanted); + m->mothurConvert(temp, numwanted); blastlocation = validParameter.validFile(parameters, "blastlocation", false); if (blastlocation == "not found") { blastlocation = ""; } else { //add / to name if needed string lastChar = blastlocation.substr(blastlocation.length()-1); -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) if (lastChar != "/") { blastlocation += "/"; } #else if (lastChar != "\\") { blastlocation += "\\"; } #endif blastlocation = m->getFullPathName(blastlocation); string formatdbCommand = ""; -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) formatdbCommand = blastlocation + "formatdb"; #else formatdbCommand = blastlocation + "formatdb.exe"; @@ -515,7 +537,7 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { if(ableToOpen == 1) { m->mothurOut("[ERROR]: " + formatdbCommand + " file does not exist. mothur requires formatdb.exe to run chimera.slayer."); m->mothurOutEndLine(); abort = true; } string blastCommand = ""; -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) blastCommand = blastlocation + "megablast"; #else blastCommand = blastlocation + "megablast.exe"; @@ -533,7 +555,7 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { if (hasGroup && (templatefile != "self")) { m->mothurOut("You have provided a group file and the reference parameter is not set to self. I am not sure what reference you are trying to use, aborting."); m->mothurOutEndLine(); abort=true; } //until we resolve the issue 10-18-11 -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) #else //processors=1; #endif @@ -556,9 +578,9 @@ int ChimeraSlayerCommand::execute(){ int start = time(NULL); if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it - string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "slayer.chimera"; - string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "slayer.accnos"; - string trimFastaFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "slayer.fasta"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("chimera"); + string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("accnos"); + string trimFastaFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("fasta"); //clears files ofstream out, out1, out2; @@ -594,13 +616,14 @@ int ChimeraSlayerCommand::execute(){ #else //break up file vector positions; -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) positions = m->divideFile(thisFastaName, processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } #else if (processors == 1) { lines.push_back(linePair(0, 1000)); } else { positions = m->setFilePosFasta(thisFastaName, numSeqs); + if (positions.size() < processors) { processors = positions.size(); } //figure out how many sequences you have to process int numSeqsPerProcessor = numSeqs / processors; @@ -632,6 +655,7 @@ int ChimeraSlayerCommand::execute(){ #endif totalChimeras = deconvoluteResults(parser, outputFileName, accnosFileName, trimFastaFileName); + m->mothurOutEndLine(); m->mothurOut(toString(totalChimeras) + " chimera found."); m->mothurOutEndLine(); #ifdef USE_MPI } MPI_Barrier(MPI_COMM_WORLD); //make everyone wait @@ -640,7 +664,7 @@ int ChimeraSlayerCommand::execute(){ if (parser != NULL) { delete parser; } - m->mothurOutEndLine(); m->mothurOut(toString(totalChimeras) + " chimera found."); m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine(); + m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine(); } //set accnos file as new current accnosfile @@ -900,6 +924,16 @@ int ChimeraSlayerCommand::deconvoluteResults(SequenceParser* parser, string outp map uniqueNames = parser->getAllSeqsMap(); map::iterator itUnique; int total = 0; + + if (trimera) { //add in more potential uniqueNames + map newUniqueNames = uniqueNames; + for (map::iterator it = uniqueNames.begin(); it != uniqueNames.end(); it++) { + newUniqueNames[(it->first)+"_LEFT"] = (it->first)+"_LEFT"; + newUniqueNames[(it->first)+"_RIGHT"] = (it->first)+"_RIGHT"; + } + uniqueNames = newUniqueNames; + newUniqueNames.clear(); + } //edit accnos file ifstream in2; @@ -1147,14 +1181,15 @@ string ChimeraSlayerCommand::getNamesFile(string& inputFile){ string inputString = "fasta=" + inputFile; m->mothurOut("/******************************************/"); m->mothurOutEndLine(); m->mothurOut("Running command: unique.seqs(" + inputString + ")"); m->mothurOutEndLine(); - + m->mothurCalling = true; + Command* uniqueCommand = new DeconvoluteCommand(inputString); uniqueCommand->execute(); map > filenames = uniqueCommand->getOutputFiles(); delete uniqueCommand; - + m->mothurCalling = false; m->mothurOut("/******************************************/"); m->mothurOutEndLine(); nameFile = filenames["name"][0]; @@ -1187,7 +1222,7 @@ int ChimeraSlayerCommand::driverGroups(string outputFName, string accnos, string m->mothurOutEndLine(); m->mothurOut("Checking sequences from group: " + fileGroup[thisFastaName] + "."); m->mothurOutEndLine(); lines.clear(); -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) int proc = 1; vector positions = m->divideFile(thisFastaName, proc); lines.push_back(linePair(positions[0], positions[1])); @@ -1244,7 +1279,7 @@ int ChimeraSlayerCommand::createProcessesGroups(string outputFName, string accno breakUp.push_back(thisFileToPriority); } -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) //loop through and create all the processes you want while (process != processors) { int pid = fork(); @@ -1447,7 +1482,7 @@ int ChimeraSlayerCommand::driver(linePair filePos, string outputFName, string fi count++; } - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) unsigned long long pos = inFASTA.tellg(); if ((pos == -1) || (pos >= filePos.end)) { break; } #else @@ -1628,7 +1663,7 @@ int ChimeraSlayerCommand::createProcesses(string outputFileName, string filename int num = 0; processIDS.clear(); -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) //loop through and create all the processes you want while (process != processors) { int pid = fork();