X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=classifyseqscommand.cpp;h=b6dc24fe5751867c6b79f71fb50e3b7b74ad75a6;hb=050e1297eaf24fabbbe0e9b76c3a5acfb90eed7d;hp=328cd58f1f32bc265de857de4ede5aa557c2cd94;hpb=16abd6271c455bd01b34ff89a2e3641bef0fa128;p=mothur.git diff --git a/classifyseqscommand.cpp b/classifyseqscommand.cpp index 328cd58..b6dc24f 100644 --- a/classifyseqscommand.cpp +++ b/classifyseqscommand.cpp @@ -457,13 +457,15 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { search = "kmer"; } - if (namefileNames.size() == 0){ - vector files; files.push_back(fastaFileNames[fastaFileNames.size()-1]); - parser.getNameFile(files); - } - - } - + if (!abort) { + if (namefileNames.size() == 0){ + if (fastaFileNames.size() != 0) { + vector files; files.push_back(fastaFileNames[fastaFileNames.size()-1]); + parser.getNameFile(files); + } + } + } + } } catch(exception& e) { m->errorOut(e, "ClassifySeqsCommand", "ClassifySeqsCommand"); @@ -482,7 +484,7 @@ ClassifySeqsCommand::~ClassifySeqsCommand(){ int ClassifySeqsCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - + if(method == "bayesian"){ classify = new Bayesian(taxonomyFileName, templateFileName, search, kmerSize, cutoff, iters, rand(), flip); } else if(method == "knn"){ classify = new Knn(taxonomyFileName, templateFileName, search, kmerSize, gapOpen, gapExtend, match, misMatch, numWanted, rand()); } else { @@ -500,11 +502,17 @@ int ClassifySeqsCommand::execute(){ string baseTName = taxonomyFileName; if (taxonomyFileName == "saved") {baseTName = rdb->getSavedTaxonomy(); } - string RippedTaxName = m->getRootName(m->getSimpleName(baseTName)); - RippedTaxName = m->getExtension(RippedTaxName.substr(0, RippedTaxName.length()-1)); - if (RippedTaxName[0] == '.') { RippedTaxName = RippedTaxName.substr(1, RippedTaxName.length()); } - RippedTaxName += "."; - + //set rippedTaxName to + string RippedTaxName = ""; + bool foundDot = false; + for (int i = baseTName.length()-1; i >= 0; i--) { + cout << baseTName[i] << endl; + if (foundDot && (baseTName[i] != '.')) { RippedTaxName = baseTName[i] + RippedTaxName; } + else if (foundDot && (baseTName[i] == '.')) { break; } + else if (!foundDot && (baseTName[i] == '.')) { foundDot = true; } + } + if (RippedTaxName != "") { RippedTaxName += "."; } + if (outputDir == "") { outputDir += m->hasPath(fastaFileNames[s]); } string newTaxonomyFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + "taxonomy"; string newaccnosFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + "flip.accnos"; @@ -615,7 +623,7 @@ int ClassifySeqsCommand::execute(){ #else vector positions; -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) positions = m->divideFile(fastaFileNames[s], processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); } #else @@ -623,6 +631,7 @@ int ClassifySeqsCommand::execute(){ lines.push_back(new linePair(0, 1000)); }else { positions = m->setFilePosFasta(fastaFileNames[s], numFastaSeqs); + if (positions.size() < processors) { processors = positions.size(); } //figure out how many sequences you have to process int numSeqsPerProcessor = numFastaSeqs / processors; @@ -821,7 +830,7 @@ int ClassifySeqsCommand::createProcesses(string taxFileName, string tempTaxFile, int num = 0; processIDS.clear(); -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) int process = 1; //loop through and create all the processes you want @@ -881,7 +890,7 @@ int ClassifySeqsCommand::createProcesses(string taxFileName, string tempTaxFile, string extension = ""; if (i != 0) { extension = toString(i) + ".temp"; processIDS.push_back(i); } - classifyData* tempclass = new classifyData((accnos + extension), probs, method, templateFileName, taxonomyFileName, (taxFileName + extension), (tempTaxFile + extension), filename, search, kmerSize, iters, numWanted, m, lines[i]->start, lines[i]->end, match, misMatch, gapOpen, gapExtend, cutoff, i, flipThreshold); + classifyData* tempclass = new classifyData((accnos + extension), probs, method, templateFileName, taxonomyFileName, (taxFileName + extension), (tempTaxFile + extension), filename, search, kmerSize, iters, numWanted, m, lines[i]->start, lines[i]->end, match, misMatch, gapOpen, gapExtend, cutoff, i, flip); pDataArray.push_back(tempclass); //MySeqSumThreadFunction is in header. It must be global or static to work with the threads. @@ -905,16 +914,35 @@ int ClassifySeqsCommand::createProcesses(string taxFileName, string tempTaxFile, } #endif - + vector nonBlankAccnosFiles; + if (!(m->isBlank(accnos))) { nonBlankAccnosFiles.push_back(accnos); } + else { m->mothurRemove(accnos); } //remove so other files can be renamed to it + for(int i=0;iisBlank(accnos + toString(processIDS[i]) + ".temp"))) { + nonBlankAccnosFiles.push_back(accnos + toString(processIDS[i]) + ".temp"); + }else { m->mothurRemove((accnos + toString(processIDS[i]) + ".temp")); } + m->mothurRemove((m->getFullPathName(taxFileName) + toString(processIDS[i]) + ".temp")); m->mothurRemove((m->getFullPathName(tempTaxFile) + toString(processIDS[i]) + ".temp")); - m->mothurRemove((m->getFullPathName(accnos) + toString(processIDS[i]) + ".temp")); } + //append accnos files + if (nonBlankAccnosFiles.size() != 0) { + rename(nonBlankAccnosFiles[0].c_str(), accnos.c_str()); + + for (int h=1; h < nonBlankAccnosFiles.size(); h++) { + appendTaxFiles(nonBlankAccnosFiles[h], accnos); + m->mothurRemove(nonBlankAccnosFiles[h]); + } + }else { //recreate the accnosfile if needed + ofstream out; + m->openOutputFile(accnos, out); + out.close(); + } + return num; } @@ -1002,7 +1030,7 @@ int ClassifySeqsCommand::driver(linePair* filePos, string taxFName, string tempT } delete candidateSeq; - #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