X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=preclustercommand.cpp;h=951b2008b062c26c5fabb54dfd8ef2d2a858da67;hb=f509429e06e545bde69c97cacc0eb436775bd329;hp=cf4256851eb583a78b78fd5ab800bbfa5d46f5e8;hpb=7f0cae4f4853cc3f12bc751ee06ea31c7c97496e;p=mothur.git diff --git a/preclustercommand.cpp b/preclustercommand.cpp index cf42568..951b200 100644 --- a/preclustercommand.cpp +++ b/preclustercommand.cpp @@ -51,7 +51,28 @@ string PreClusterCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string PreClusterCommand::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 = "precluster" + m->getExtension(inputName); } + else if (type == "name") { outputFileName = "precluster.names"; } + else if (type == "map") { outputFileName = "precluster.map"; } + 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, "PreClusterCommand", "getOutputFileNameTag"); + exit(1); + } +} //********************************************************************************************************************** PreClusterCommand::PreClusterCommand(){ try { @@ -147,7 +168,7 @@ PreClusterCommand::PreClusterCommand(string option) { // ...at some point should added some additional type checking... namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not found") { namefile = ""; } - else if (namefile == "not open") { abort = true; } + else if (namefile == "not open") { namefile = ""; abort = true; } else { m->setNameFile(namefile); } groupfile = validParameter.validFile(parameters, "group", true); @@ -156,13 +177,16 @@ PreClusterCommand::PreClusterCommand(string option) { else { m->setGroupFile(groupfile); bygroup = true; } string temp = validParameter.validFile(parameters, "diffs", false); if(temp == "not found"){ temp = "1"; } - convert(temp, diffs); + m->mothurConvert(temp, diffs); temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); - convert(temp, processors); - + m->mothurConvert(temp, processors); + if (namefile == "") { + vector files; files.push_back(fastafile); + parser.getNameFile(files); + } } } @@ -181,9 +205,9 @@ int PreClusterCommand::execute(){ int start = time(NULL); string fileroot = outputDir + m->getRootName(m->getSimpleName(fastafile)); - string newFastaFile = fileroot + "precluster" + m->getExtension(fastafile); - string newNamesFile = fileroot + "precluster.names"; - string newMapFile = fileroot + "precluster.map"; //add group name if by group + string newFastaFile = fileroot + getOutputFileNameTag("fasta", fastafile); + string newNamesFile = fileroot + getOutputFileNameTag("name"); + string newMapFile = fileroot + getOutputFileNameTag("map"); //add group name if by group outputNames.push_back(newFastaFile); outputTypes["fasta"].push_back(newFastaFile); outputNames.push_back(newNamesFile); outputTypes["name"].push_back(newNamesFile); @@ -214,17 +238,19 @@ int PreClusterCommand::execute(){ m->mothurOutEndLine(); 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(); m->renameFile(filenames["fasta"][0], newFastaFile); + m->renameFile(filenames["name"][0], newNamesFile); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to run pre.cluster."); m->mothurOutEndLine(); @@ -299,7 +325,7 @@ int PreClusterCommand::createProcessesGroups(SequenceParser* parser, string newF lines.push_back(linePair(startIndex, endIndex)); } -#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) { @@ -309,7 +335,17 @@ int PreClusterCommand::createProcessesGroups(SequenceParser* parser, string newF processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later process++; }else if (pid == 0){ + outputNames.clear(); num = driverGroups(parser, newFName + toString(getpid()) + ".temp", newNName + toString(getpid()) + ".temp", newMFile, lines[process].start, lines[process].end, groups); + + string tempFile = toString(getpid()) + ".outputNames.temp"; + ofstream outTemp; + m->openOutputFile(tempFile, outTemp); + + outTemp << outputNames.size(); + for (int i = 0; i < outputNames.size(); i++) { outTemp << outputNames[i] << endl; } + outTemp.close(); + exit(0); }else { m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); @@ -326,7 +362,23 @@ int PreClusterCommand::createProcessesGroups(SequenceParser* parser, string newF int temp = processIDS[i]; wait(&temp); } - + + for (int i = 0; i < processIDS.size(); i++) { + string tempFile = toString(processIDS[i]) + ".outputNames.temp"; + ifstream intemp; + m->openInputFile(tempFile, intemp); + + int num; + intemp >> num; + for (int k = 0; k < num; k++) { + string name = ""; + intemp >> name; m->gobble(intemp); + + outputNames.push_back(name); outputTypes["map"].push_back(name); + } + intemp.close(); + m->mothurRemove(tempFile); + } #else ////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -372,6 +424,9 @@ int PreClusterCommand::createProcessesGroups(SequenceParser* parser, string newF //append output files for(int i=0;igetFullPathName(".\\" + newFName); + //newNName = m->getFullPathName(".\\" + newNName); + m->appendFiles((newFName + toString(processIDS[i]) + ".temp"), newFName); m->mothurRemove((newFName + toString(processIDS[i]) + ".temp")); @@ -508,7 +563,7 @@ int PreClusterCommand::readFASTA(){ m->openInputFile(fastafile, inFasta); //string firstCol, secondCol, nameString; - length = 0; + set lengths; while (!inFasta.eof()) { @@ -534,17 +589,21 @@ int PreClusterCommand::readFASTA(){ else{ seqPNode tempNode(itSize->second, seq, names[seq.getName()]); alignSeqs.push_back(tempNode); - if (seq.getAligned().length() > length) { length = seq.getAligned().length(); } + lengths.insert(seq.getAligned().length()); } }else { //no names file, you are identical to yourself seqPNode tempNode(1, seq, seq.getName()); alignSeqs.push_back(tempNode); - if (seq.getAligned().length() > length) { length = seq.getAligned().length(); } + lengths.insert(seq.getAligned().length()); } } } inFasta.close(); //inNames.close(); + + if (lengths.size() > 1) { m->control_pressed = true; m->mothurOut("[ERROR]: your sequences are not all the same length. pre.cluster requires sequences to be aligned."); m->mothurOutEndLine(); } + else if (lengths.size() == 1) { length = *(lengths.begin()); } + return alignSeqs.size(); } @@ -556,7 +615,7 @@ int PreClusterCommand::readFASTA(){ /**************************************************************************************************/ int PreClusterCommand::loadSeqs(map& thisName, vector& thisSeqs){ try { - length = 0; + set lengths; alignSeqs.clear(); map::iterator it; bool error = false; @@ -579,15 +638,18 @@ int PreClusterCommand::loadSeqs(map& thisName, vector& seqPNode tempNode(numReps, thisSeqs[i], it->second); alignSeqs.push_back(tempNode); - if (thisSeqs[i].getAligned().length() > length) { length = thisSeqs[i].getAligned().length(); } + lengths.insert(thisSeqs[i].getAligned().length()); } }else { //no names file, you are identical to yourself seqPNode tempNode(1, thisSeqs[i], thisSeqs[i].getName()); alignSeqs.push_back(tempNode); - if (thisSeqs[i].getAligned().length() > length) { length = thisSeqs[i].getAligned().length(); } + lengths.insert(thisSeqs[i].getAligned().length()); } } + if (lengths.size() > 1) { error = true; m->mothurOut("[ERROR]: your sequences are not all the same length. pre.cluster requires sequences to be aligned."); m->mothurOutEndLine(); } + else if (lengths.size() == 1) { length = *(lengths.begin()); } + //sanity check if (error) { m->control_pressed = true; }