From: westcott Date: Mon, 8 Nov 2010 14:40:33 +0000 (+0000) Subject: changes to dist.seqs and pairwise.seqs and cluster.classic no longer resizes X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=173a1a82a4e4aa6bef8e4ba77bce342fb9c6563e changes to dist.seqs and pairwise.seqs and cluster.classic no longer resizes --- diff --git a/clusterclassic.cpp b/clusterclassic.cpp index 0e48690..287332a 100644 --- a/clusterclassic.cpp +++ b/clusterclassic.cpp @@ -279,10 +279,10 @@ void ClusterClassic::clusterBins(){ rabund->set(smallRow, rabund->get(smallRow)+rabund->get(smallCol)); rabund->set(smallCol, 0); - for (int i = smallCol+1; i < rabund->size(); i++) { + /*for (int i = smallCol+1; i < rabund->size(); i++) { rabund->set((i-1), rabund->get(i)); } - rabund->resize((rabund->size()-1)); + rabund->resize((rabund->size()-1));*/ rabund->setLabel(toString(smallDist)); // cout << '\t' << rabund->get(smallRow) << '\t' << rabund->get(smallCol) << endl; @@ -300,10 +300,10 @@ void ClusterClassic::clusterNames(){ list->set(smallRow, list->get(smallRow)+','+list->get(smallCol)); list->set(smallCol, ""); - for (int i = smallCol+1; i < list->size(); i++) { + /*for (int i = smallCol+1; i < list->size(); i++) { list->set((i-1), list->get(i)); } - list->resize((list->size()-1)); + list->resize((list->size()-1));*/ list->setLabel(toString(smallDist)); // cout << '\t' << list->get(smallRow) << '\t' << list->get(smallCol) << endl; @@ -356,7 +356,7 @@ void ClusterClassic::update(double& cutOFF){ clusterNames(); //resize each row - for(int i=0;i DistanceCommand::getValidParameters(){ try { @@ -210,13 +211,7 @@ DistanceCommand::DistanceCommand(string option) { //********************************************************************************************************************** -DistanceCommand::~DistanceCommand(){ - - for(int i=0;istart = int (sqrt(float(i)/float(processors)) * numSeqs); - lines[i]->end = int (sqrt(float(i+1)/float(processors)) * numSeqs); + lines[i].start = int (sqrt(float(i)/float(processors)) * numSeqs); + lines[i].end = int (sqrt(float(i+1)/float(processors)) * numSeqs); }else{ - lines[i]->start = int ((float(i)/float(processors)) * numSeqs); - lines[i]->end = int ((float(i+1)/float(processors)) * numSeqs); + lines[i].start = int ((float(i)/float(processors)) * numSeqs); + lines[i].end = int ((float(i+1)/float(processors)) * numSeqs); } - //cout << i << '\t' << lines[i]->start << '\t' << lines[i]->end << endl; + } - + createProcesses(outputFile); } #else @@ -543,8 +539,8 @@ void DistanceCommand::createProcesses(string filename) { 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){ - if (output != "square") { driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", cutoff); } - else { driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", "square"); } + if (output != "square") { driver(lines[process].start, lines[process].end, filename + toString(getpid()) + ".temp", cutoff); } + else { driver(lines[process].start, lines[process].end, filename + toString(getpid()) + ".temp", "square"); } exit(0); }else { m->mothurOut("[ERROR]: unable to spawn the necessary processes. Error code: " + toString(pid)); m->mothurOutEndLine(); @@ -555,8 +551,8 @@ void DistanceCommand::createProcesses(string filename) { } //parent does its part - if (output != "square") { driver(lines[0]->start, lines[0]->end, filename, cutoff); } - else { driver(lines[0]->start, lines[0]->end, filename, "square"); } + if (output != "square") { driver(lines[0].start, lines[0].end, filename, cutoff); } + else { driver(lines[0].start, lines[0].end, filename, "square"); } //force parent to wait until all the processes are done @@ -1157,7 +1153,7 @@ bool DistanceCommand::sanityCheck() { } catch(exception& e) { - m->errorOut(e, "DistanceCommand", "m->appendFiles"); + m->errorOut(e, "DistanceCommand", "sanityCheck"); exit(1); } } diff --git a/distancecommand.h b/distancecommand.h index 3e3dc70..595483d 100644 --- a/distancecommand.h +++ b/distancecommand.h @@ -31,9 +31,10 @@ public: void help(); private: - struct linePair { + struct distlinePair { int start; int end; + }; Dist* distCalculator; @@ -44,7 +45,7 @@ private: int processors, numNewFasta; float cutoff; vector processIDS; //end line, processid - vector lines; + vector lines; bool abort; vector Estimators, outputNames; //holds estimators to be used diff --git a/mothur b/mothur index 607932c..e33ddcd 100755 Binary files a/mothur and b/mothur differ diff --git a/mothur.h b/mothur.h index bfe0692..337e5b3 100644 --- a/mothur.h +++ b/mothur.h @@ -116,6 +116,17 @@ struct seqDist { seqDist(int s1, int s2, float d) : seq1(s1), seq2(s2), dist(d) {} ~seqDist() {} }; +/************************************************************/ +struct distlinePair { + int start; + int end; + +}; +/************************************************************/ +//sorts lowest to highest +inline bool compareDistLinePairs(distlinePair left, distlinePair right){ + return (left.end < right.end); +} //******************************************************************************************************************** //sorts lowest to highest inline bool compareSequenceDistance(seqDist left, seqDist right){ diff --git a/pairwiseseqscommand.cpp b/pairwiseseqscommand.cpp index 18412fd..f261dd9 100644 --- a/pairwiseseqscommand.cpp +++ b/pairwiseseqscommand.cpp @@ -442,27 +442,18 @@ int PairwiseSeqsCommand::execute(){ }else{ //you have multiple processors for (int i = 0; i < processors; i++) { - lines.push_back(new linePair()); + distlinePair tempLine; + lines.push_back(tempLine); if (output != "square") { - lines[i]->start = int (sqrt(float(i)/float(processors)) * numSeqs); - lines[i]->end = int (sqrt(float(i+1)/float(processors)) * numSeqs); + lines[i].start = int (sqrt(float(i)/float(processors)) * numSeqs); + lines[i].end = int (sqrt(float(i+1)/float(processors)) * numSeqs); }else{ - lines[i]->start = int ((float(i)/float(processors)) * numSeqs); - lines[i]->end = int ((float(i+1)/float(processors)) * numSeqs); + lines[i].start = int ((float(i)/float(processors)) * numSeqs); + lines[i].end = int ((float(i+1)/float(processors)) * numSeqs); } } - - createProcesses(outputFile); - - map::iterator it = processIDS.begin(); - rename((outputFile + toString(it->second) + ".temp").c_str(), outputFile.c_str()); - it++; - //append and remove temp files - for (; it != processIDS.end(); it++) { - m->appendFiles((outputFile + toString(it->second) + ".temp"), outputFile); - remove((outputFile + toString(it->second) + ".temp").c_str()); - } + createProcesses(outputFile); } #else //ifstream inFASTA; @@ -522,7 +513,7 @@ int PairwiseSeqsCommand::execute(){ void PairwiseSeqsCommand::createProcesses(string filename) { try { #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) - int process = 0; + int process = 1; processIDS.clear(); //loop through and create all the processes you want @@ -530,24 +521,35 @@ void PairwiseSeqsCommand::createProcesses(string filename) { int pid = fork(); if (pid > 0) { - processIDS[lines[process]->end] = pid; //create map from line number to pid so you can append files in correct order later + processIDS.push_back(pid); process++; }else if (pid == 0){ - if (output != "square") { driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", cutoff); } - else { driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", "square"); } + if (output != "square") { driver(lines[process].start, lines[process].end, filename + toString(getpid()) + ".temp", cutoff); } + else { driver(lines[process].start, lines[process].end, filename + toString(getpid()) + ".temp", "square"); } exit(0); }else { m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); - for (map::iterator it = processIDS.begin(); it != processIDS.end(); it++) { int temp = it->second; kill (temp, SIGINT); } + for (int i=0;i::iterator it = processIDS.begin(); it != processIDS.end(); it++) { - int temp = it->second; + for (int i=0;iappendFiles((filename + toString(processIDS[i]) + ".temp"), filename); + remove((filename + toString(processIDS[i]) + ".temp").c_str()); + } #endif } catch(exception& e) { diff --git a/pairwiseseqscommand.h b/pairwiseseqscommand.h index b40d6c9..cf73f3e 100644 --- a/pairwiseseqscommand.h +++ b/pairwiseseqscommand.h @@ -32,12 +32,14 @@ public: void help(); private: - struct linePair { + struct distlinePair { int start; int end; }; - map processIDS; //end line, processid - vector lines; + + + vector processIDS; //end line, processid + vector lines; map > outputTypes; Alignment* alignment; diff --git a/screenseqscommand.cpp b/screenseqscommand.cpp index 98b6681..bdc6658 100644 --- a/screenseqscommand.cpp +++ b/screenseqscommand.cpp @@ -507,13 +507,13 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ outputNames.push_back(goodNameFile); outputTypes["name"].push_back(goodNameFile); ofstream goodNameOut; m->openOutputFile(goodNameFile, goodNameOut); - + while(!inputNames.eof()){ if (m->control_pressed) { goodNameOut.close(); inputNames.close(); remove(goodNameFile.c_str()); return 0; } inputNames >> seqName >> seqList; it = badSeqNames.find(seqName); - + if(it != badSeqNames.end()){ badSeqNames.erase(it); @@ -558,7 +558,7 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); remove(goodNameFile.c_str()); remove(goodGroupFile.c_str()); return 0; } inputGroups >> seqName >> group; - + it = badSeqGroups.find(seqName); if(it != badSeqGroups.end()){ @@ -580,7 +580,8 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ } } } - + + return 0; }