vector<string> outputNames;
for (int s = 0; s < candidateFileNames.size(); s++) {
+ if (m->control_pressed) { return 0; }
+
m->mothurOut("Aligning sequences from " + candidateFileNames[s] + " ..." ); m->mothurOutEndLine();
if (outputDir == "") { outputDir += hasPath(candidateFileNames[s]); }
lines.push_back(new linePair(0, numFastaSeqs));
- int exitCommand = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
- if (exitCommand == 0) {
+ driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+
+ if (m->control_pressed) {
remove(accnosFileName.c_str());
remove(alignFileName.c_str());
remove(reportFileName.c_str());
lines.push_back(new linePair(startPos, numSeqsPerProcessor));
}
- int exitCommand = createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+ createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
rename((alignFileName + toString(processIDS[0]) + ".temp").c_str(), alignFileName.c_str());
rename((reportFileName + toString(processIDS[0]) + ".temp").c_str(), reportFileName.c_str());
m->mothurOutEndLine();
}else{ hasAccnos = false; }
- if (exitCommand == 0) {
+ if (m->control_pressed) {
remove(accnosFileName.c_str());
remove(alignFileName.c_str());
remove(reportFileName.c_str());
lines.push_back(new linePair(0, numFastaSeqs));
- int exitCommand = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
- if (exitCommand == 0) {
+ driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+
+ if (m->control_pressed) {
remove(accnosFileName.c_str());
remove(alignFileName.c_str());
remove(reportFileName.c_str());
try {
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
int process = 0;
- int exitCommand;
+ int exitCommand = 1;
// processIDS.resize(0);
//loop through and create all the processes you want
while (!fastaFile.eof()) {
Sequence temp(fastaFile); gobble(fastaFile);
+ if (m->control_pressed) { templateSequences.clear(); break; }
+
if (temp.getName() != "") {
templateSequences.push_back(temp);
//save longest base
search = new KmerDB(fastaFileName, 8);
}
- if (needToGenerate) {
-
- //add sequences to search
- for (int i = 0; i < templateSequences.size(); i++) {
- search->addSequence(templateSequences[i]);
+ if (!(m->control_pressed)) {
+ if (needToGenerate) {
+ //add sequences to search
+ for (int i = 0; i < templateSequences.size(); i++) {
+ search->addSequence(templateSequences[i]);
+ }
+ search->generateDB();
+
+ }else if ((method == "kmer") && (!needToGenerate)) {
+ ifstream kmerFileTest(kmerDBName.c_str());
+ search->readKmerDB(kmerFileTest);
}
- search->generateDB();
- }else if ((method == "kmer") && (!needToGenerate)) {
- ifstream kmerFileTest(kmerDBName.c_str());
- search->readKmerDB(kmerFileTest);
+ search->setNumSeqs(numSeqs);
}
-
- search->setNumSeqs(numSeqs);
}
catch(exception& e) {
m->errorOut(e, "AlignmentDB", "AlignmentDB");
//for each word
for (int i = 0; i < numKmers; i++) {
+ if (m->control_pressed) { break; }
out << i << '\t';
}
int index = getMostProbableTaxonomy(queryKmers);
+
+ if (m->control_pressed) { return tax; }
//bootstrap - to set confidenceScore
int numToSelect = queryKmers.size() / 8;
map<int, int>::iterator itConvert;
for (int i = 0; i < iters; i++) {
+ if (m->control_pressed) { return "control"; }
+
vector<int> temp;
for (int j = 0; j < numToSelect; j++) {
}
//***************************************************************************************************************
-void Bellerophon::print(ostream& out, ostream& outAcc) {
+int Bellerophon::print(ostream& out, ostream& outAcc) {
try {
int above1 = 0;
out << "Name\tScore\tLeft\tRight\t" << endl;
//output prefenence structure to .chimeras file
for (int i = 0; i < pref.size(); i++) {
+
+ if (m->control_pressed) { return 0; }
+
out << pref[i].name << '\t' << setprecision(3) << pref[i].score[0] << '\t' << pref[i].leftParent[0] << '\t' << pref[i].rightParent[0] << endl;
//calc # of seqs with preference above 1.0
m->mothurOut("97.5%-tile:\t" + toString(pref[spot].score[0])); m->mothurOutEndLine();
spot = 0;
m->mothurOut("Maximum:\t" + toString(pref[spot].score[0])); m->mothurOutEndLine();
+
+ return 1;
}
catch(exception& e) {
filterSeqs->execute();
delete filterSeqs;
+ if (m->control_pressed) { return 0; }
+
//reset fastafile to filtered file
if (outputDir == "") { fastafile = getRootName(fastafile) + "filter.fasta"; }
else { fastafile = outputDir + getRootName(getSimpleName(fastafile)) + "filter.fasta"; }
}
distCalculator = new eachGapDist();
-cout << "fastafile = " << fastafile << endl;
+
//read in sequences
seqs = readSeqs(fastafile);
- cout << "here:"<< endl;
+
+ if (m->control_pressed) { return 0; }
+
if (unaligned) { m->mothurOut("Your sequences need to be aligned when you use the bellerophon method."); m->mothurOutEndLine(); return 1; }
int numSeqs = seqs.size();
int count = 0;
while (count < iters) {
+ if (m->control_pressed) { return 0; }
+
//create 2 vectors of sequences, 1 for left side and one for right side
vector<Sequence> left; vector<Sequence> right;
for (int i = 0; i < seqs.size(); i++) {
+
+ if (m->control_pressed) { return 0; }
+
//cout << "midpoint = " << midpoint << "\twindow = " << window << endl;
//cout << "whole = " << seqs[i]->getAligned().length() << endl;
//save left side
SparseMatrix* SparseRight = new SparseMatrix();
createSparseMatrix(0, left.size(), SparseLeft, left);
+
+ if (m->control_pressed) { delete SparseLeft; delete SparseRight; return 0; }
+
createSparseMatrix(0, right.size(), SparseRight, right);
+ if (m->control_pressed) { delete SparseLeft; delete SparseRight; return 0; }
+
vector<SeqMap> distMapRight;
vector<SeqMap> distMapLeft;
//cout << "left" << endl << endl;
for (MatData currentCell = SparseLeft->begin(); currentCell != SparseLeft->end(); currentCell++) {
distMapLeft[currentCell->row][currentCell->column] = currentCell->dist;
+ if (m->control_pressed) { delete SparseLeft; delete SparseRight; return 0; }
//cout << " i = " << currentCell->row << " j = " << currentCell->column << " dist = " << currentCell->dist << endl;
}
//cout << "right" << endl << endl;
for (MatData currentCell = SparseRight->begin(); currentCell != SparseRight->end(); currentCell++) {
distMapRight[currentCell->row][currentCell->column] = currentCell->dist;
+ if (m->control_pressed) { delete SparseLeft; delete SparseRight; return 0; }
//cout << " i = " << currentCell->row << " j = " << currentCell->column << " dist = " << currentCell->dist << endl;
}
for(int i=startSeq; i<endSeq; i++){
for(int j=0;j<i;j++){
+
+ if (m->control_pressed) { return 0; }
distCalculator->calcDist(s[i], s[j]);
float dist = distCalculator->getDist();
}
}
/***************************************************************************************************************/
-void Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right, int mid){
+int Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right, int mid){
try {
float dme = 0.0;
SeqMap currentRight = right[i]; // same as left but with distances on the right side.
for (int j = 0; j < i; j++) {
+
+ if (m->control_pressed) { return 0; }
itL = currentLeft.find(j);
itR = currentRight.find(j);
//cout << endl << "dme = " << dme << endl;
//recalculate prefernences based on dme
for (int i = 0; i < pref.size(); i++) {
+
+ if (m->control_pressed) { return 0; }
//cout << "unadjusted pref " << i << " = " << pref[i].score[1] << endl;
// gives the actual percentage of the dme this seq adds
pref[i].score[1] = pref[i].score[1] / dme;
//is this score bigger then the last score
for (int i = 0; i < pref.size(); i++) {
+ if (m->control_pressed) { return 0; }
+
//update biggest score
if (pref[i].score[1] > pref[i].score[0]) {
pref[i].score[0] = pref[i].score[1];
}
}
+
+ return 1;
}
catch(exception& e) {
~Bellerophon() {};
int getChimeras();
- void print(ostream&, ostream&);
-
- void setCons(string){};
- void setQuantiles(string) {};
-
+ int print(ostream&, ostream&);
private:
Dist* distCalculator;
string fastafile;
int iters;
- void generatePreferences(vector<SeqMap>, vector<SeqMap>, int);
+ int generatePreferences(vector<SeqMap>, vector<SeqMap>, int);
int createSparseMatrix(int, int, SparseMatrix*, vector<Sequence>);
};
while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+ if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
if(allLines == 1 || labels.count(list->getLabel()) == 1){
error = process(list);
list = input->getListVector();
}
-
+ if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
delete list;
}
+ if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
globaldata->gTreemap = tmap;
while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
-
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }
+
if(allLines == 1 || labels.count(order->getLabel()) == 1){
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
order = input->getSharedOrderVector();
}
+
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
}
}
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }
+
//run last line if you need to
if (needToRun == true) {
if (order != NULL) { delete order; }
}
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }
+
//reset groups parameter
globaldata->Groups.clear();
//assemble tree
t->assembleTree();
+
+ if (m->control_pressed) { return 1; }
//print newick file
t->print(*out);
//creates tree from similarity matrix and write out file
createTree(out[i], tempTree);
+ if (m->control_pressed) { delete tempTree; return 1; }
+
//save trees for consensus command.
trees[i].push_back(tempTree);
}
out << "For full window mapping info refer to " << mapInfo << endl << endl;
}
//***************************************************************************************************************
-void Ccode::print(ostream& out, ostream& outAcc) {
+int Ccode::print(ostream& out, ostream& outAcc) {
try {
ofstream out2;
//free memory
for (int i = 0; i < closest.size(); i++) { delete closest[i].seq; }
-
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "Ccode", "print");
//find closest matches to query
closest = findClosest(query, numWanted);
+ if (m->control_pressed) { return 0; }
+
//initialize spotMap
for (int i = 0; i < query->getAligned().length(); i++) { spotMap[i] = i; }
createFilter(temp, 0.5);
- for (int i = 0; i < temp.size(); i++) { runFilter(temp[i]); }
+ for (int i = 0; i < temp.size(); i++) {
+ if (m->control_pressed) { return 0; }
+ runFilter(temp[i]);
+ }
//update spotMap
map<int, int> newMap;
//trim sequences - this follows ccodes remove_extra_gaps
trimSequences(query);
-
+ if (m->control_pressed) { return 0; }
//windows are equivalent to words - ccode paper recommends windows are between 5% and 20% on alignment length().
//Our default will be 10% and we will warn if user tries to use a window above or below these recommendations
windows = findWindows();
-
+ if (m->control_pressed) { return 0; }
//remove sequences that are more than 20% different and less than 0.5% different - may want to allow user to specify this later
removeBadReferenceSeqs(closest);
-
+ if (m->control_pressed) { return 0; }
//find the averages for each querys references
getAverageRef(closest); //fills sumRef, averageRef, sumSquaredRef and refCombo.
getAverageQuery(closest, query); //fills sumQuery, averageQuery, sumSquaredQuery.
-
+ if (m->control_pressed) { return 0; }
//find the averages for each querys references
findVarianceRef(); //fills varRef and sdRef also sets minimum error rate to 0.001 to avoid divide by 0.
-
+ if (m->control_pressed) { return 0; }
//find the averages for the query
findVarianceQuery(); //fills varQuery and sdQuery also sets minimum error rate to 0.001 to avoid divide by 0.
+ if (m->control_pressed) { return 0; }
determineChimeras(); //fills anova, isChimericConfidence, isChimericTStudent and isChimericANOVA.
+ if (m->control_pressed) { return 0; }
return 0;
}
~Ccode();
int getChimeras(Sequence* query);
- void print(ostream&, ostream&);
+ int print(ostream&, ostream&);
void printHeader(ostream&);
private:
//for each sequence
for (int i = 0; i < seqs.size(); i++) {
+ if (m->control_pressed) { return filterString; }
+
string seqAligned = seqs[i]->getAligned();
for (int j = 0; j < seqAligned.length(); j++) {
//zero out spot where all sequences have blanks
int numColRemoved = 0;
for(int i = 0;i < seqs[0]->getAligned().length(); i++){
+
+ if (m->control_pressed) { return filterString; }
+
if(gaps[i] == seqs.size()) { filterString[i] = '0'; numColRemoved++; }
else if (((a[i] < threshold) && (t[i] < threshold) && (g[i] < threshold) && (c[i] < threshold))) { filterString[i] = '0'; numColRemoved++; }
//read in seqs and store in vector
while(!in.eof()){
+ if (m->control_pressed) { return container; }
+
Sequence* current = new Sequence(in); gobble(in);
if (count == 0) { length = current->getAligned().length(); count++; } //gets first seqs length
virtual void setCons(string){};
virtual void setQuantiles(string){};
- virtual void doPrep(){};
+ virtual int doPrep(){ return 0; }
virtual vector<Sequence*> readSeqs(string);
virtual vector< vector<float> > readQuantiles();
virtual void setMask(string);
virtual void printHeader(ostream&){};
virtual int getChimeras(Sequence*){ return 0; }
virtual int getChimeras(){ return 0; }
- virtual void print(ostream&, ostream&){};
+ virtual int print(ostream&, ostream&){ return 0; }
protected:
}
}
//***************************************************************************************************************
-void ChimeraCheckRDP::print(ostream& out, ostream& outAcc) {
+int ChimeraCheckRDP::print(ostream& out, ostream& outAcc) {
try {
m->mothurOut("Processing: " + querySeq->getName()); m->mothurOutEndLine();
makeSVGpic(IS); //zeros out negative results
}
}
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "ChimeraCheckRDP", "print");
}
}
//***************************************************************************************************************
-void ChimeraCheckRDP::doPrep() {
+int ChimeraCheckRDP::doPrep() {
try {
templateDB = new AlignmentDB(templateFileName, "kmer", kmerSize, 0.0,0.0,0.0,0.0);
m->mothurOutEndLine();
if (name != "") {
readName(name); //fills name map with names of seqs the user wants to have .svg for.
}
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "ChimeraCheckRDP", "doPrep");
~ChimeraCheckRDP();
int getChimeras(Sequence*);
- void print(ostream&, ostream&);
- void doPrep();
+ int print(ostream&, ostream&);
+ int doPrep();
private:
if (method == "bellerophon") {//run bellerophon separately since you need to read entire fastafile to run it
chimera->getChimeras();
+ if (m->control_pressed) { delete chimera; return 0; }
+
ofstream out;
openOutputFile(outputFileName, out);
out.close();
out2.close();
+ if (m->control_pressed) { remove(accnosFileName.c_str()); remove(outputFileName.c_str()); delete chimera; return 0; }
+
//delete accnos file if its blank
if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; }
//reads template
chimera->setTemplateFile(templatefile);
+ if (m->control_pressed) { delete chimera; return 0; }
+
if (method != "chimeracheck") {
if (chimera->getUnaligned()) {
m->mothurOut("Your template sequences are different lengths, please correct."); m->mothurOutEndLine();
//some methods need to do prep work before processing the chimeras
chimera->doPrep();
+ if (m->control_pressed) { delete chimera; return 0; }
+
templateSeqsLength = chimera->getLength();
ofstream outHeader;
driver(lines[0], outputFileName, fastafile, accnosFileName);
+ if (m->control_pressed) {
+ remove(outputFileName.c_str());
+ remove(tempHeader.c_str());
+ remove(accnosFileName.c_str());
+ for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
+ delete chimera;
+ return 0;
+ }
+
//delete accnos file if its blank
if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; }
remove(nonBlankAccnosFiles[h].c_str());
}
}else{ hasAccnos = false; }
+
+ if (m->control_pressed) {
+ remove(outputFileName.c_str());
+ remove(accnosFileName.c_str());
+ for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
+ delete chimera;
+ return 0;
+ }
}
driver(lines[0], outputFileName, fastafile, accnosFileName);
+ if (m->control_pressed) {
+ remove(outputFileName.c_str());
+ remove(tempHeader.c_str());
+ remove(accnosFileName.c_str());
+ for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
+ delete chimera;
+ return 0;
+ }
+
//delete accnos file if its blank
if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; }
#endif
if (hasAccnos) { m->mothurOut(accnosFileName); m->mothurOutEndLine(); }
m->mothurOutEndLine();
-
+ for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine();
for(int i=0;i<line->numSeqs;i++){
+ if (m->control_pressed) { return 1; }
+
Sequence* candidateSeq = new Sequence(inFASTA); gobble(inFASTA);
if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
}else{
//find chimeras
chimera->getChimeras(candidateSeq);
+
+ if (m->control_pressed) { delete candidateSeq; return 1; }
//print results
chimera->print(out, out2);
out2.close();
inFASTA.close();
- return 1;
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "ChimeraSeqsCommand", "driver");
/**************************************************************************************************/
-void ChimeraSeqsCommand::createProcesses(string outputFileName, string filename, string accnos) {
+int ChimeraSeqsCommand::createProcesses(string outputFileName, string filename, string accnos) {
try {
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
int process = 0;
int temp = processIDS[i];
wait(&temp);
}
+
+ return 0;
#endif
}
catch(exception& e) {
vector<linePair*> lines;
int driver(linePair*, string, string, string);
- void createProcesses(string, string, string);
+ int createProcesses(string, string, string);
void appendOutputFiles(string, string);
bool abort;
decalc = new DeCalculator();
}
//***************************************************************************************************************
-void ChimeraSlayer::doPrep() {
+int ChimeraSlayer::doPrep() {
try {
string kmerDBNameLeft;
if(!kmerFileTestLeft){
for (int i = 0; i < templateSeqs.size(); i++) {
+
+ if (m->control_pressed) { return 0; }
+
string leftFrag = templateSeqs[i]->getUnaligned();
leftFrag = leftFrag.substr(0, int(leftFrag.length() * 0.33));
if(!kmerFileTestRight){
for (int i = 0; i < templateSeqs.size(); i++) {
+ if (m->control_pressed) { return 0; }
+
string rightFrag = templateSeqs[i]->getUnaligned();
rightFrag = rightFrag.substr(int(rightFrag.length() * 0.66));
vector<Sequence*> tempQuerySeqs;
while(!in.eof()){
+ if (m->control_pressed) { for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i]; } return 0; }
+
Sequence* s = new Sequence(in);
gobble(in);
for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i]; }
+ if (m->control_pressed) { return 0; }
+
+
//run filter on template
- for (int i = 0; i < templateSeqs.size(); i++) { runFilter(templateSeqs[i]); }
+ for (int i = 0; i < templateSeqs.size(); i++) { if (m->control_pressed) { return 0; } runFilter(templateSeqs[i]); }
m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to filter."); m->mothurOutEndLine();
+
+ return 0;
}
catch(exception& e) {
out << "Name\tLeftParent\tRightParent\tDivQLAQRB\tPerIDQLAQRB\tBootStrapA\tDivQLBQRA\tPerIDQLBQRA\tBootStrapB\tFlag\tLeftWindow\tRightWindow\n";
}
//***************************************************************************************************************
-void ChimeraSlayer::print(ostream& out, ostream& outAcc) {
+int ChimeraSlayer::print(ostream& out, ostream& outAcc) {
try {
if (chimeraFlags == "yes") {
string chimeraFlag = "no";
out << endl;
}else { out << querySeq->getName() << "\tno" << endl; }
+ return 0;
+
}
catch(exception& e) {
m->errorOut(e, "ChimeraSlayer", "print");
maligner = new Maligner(templateSeqs, numWanted, match, misMatch, divR, minSim, minCov, searchMethod, databaseLeft, databaseRight);
slayer = new Slayer(window, increment, minSim, divR, iters, minSNP);
+ if (m->control_pressed) { return 0; }
+
string chimeraFlag = maligner->getResults(query, decalc);
+ if (m->control_pressed) { return 0; }
vector<results> Results = maligner->getOutput();
//found in testing realigning only made things worse
spotMap = decalc->getMaskMap();
}
+ if (m->control_pressed) { for (int k = 0; k < seqs.size(); k++) { delete seqs[k].seq; } return 0; }
+
//send to slayer
chimeraFlags = slayer->getResults(query, seqsForSlayer);
+ if (m->control_pressed) { return 0; }
chimeraResults = slayer->getOutput();
//free memory
~ChimeraSlayer();
int getChimeras(Sequence*);
- void print(ostream&, ostream&);
+ int print(ostream&, ostream&);
void printHeader(ostream&);
- void doPrep();
+ int doPrep();
private:
Sequence* querySeq;
m->mothurOutEndLine();
classify = new Bayesian(taxonomyFileName, templateFileName, search, kmerSize, cutoff, iters);
}
-
+
+ if (m->control_pressed) { delete classify; return 0; }
+
vector<string> outputNames;
for (int s = 0; s < fastaFileNames.size(); s++) {
#endif
//make taxonomy tree from new taxonomy file
PhyloTree taxaBrowser;
-
+
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete classify; return 0; }
+
ifstream in;
openInputFile(tempTaxonomyFile, in);
while(!in.eof()){
in >> name >> taxon; gobble(in);
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } remove(tempTaxonomyFile.c_str()); delete classify; return 0; }
+
if (namefile != "") {
itNames = nameMap.find(name);
in.close();
taxaBrowser.assignHeirarchyIDs(0);
+
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } remove(tempTaxonomyFile.c_str()); delete classify; return 0; }
taxaBrowser.binUnclassified();
remove(tempTaxonomyFile.c_str());
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete classify; return 0; }
+
+
//print summary file
ofstream outTaxTree;
openOutputFile(taxSummary, outTaxTree);
//get maxLevel from phylotree so you know how many 'unclassified's to add
int maxLevel = taxaBrowser.getMaxLevel();
- //read taxfile - this reading and rewriting is done to preserve the confidence sscores.
+ //read taxfile - this reading and rewriting is done to preserve the confidence scores.
while (!inTax.eof()) {
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } remove(unclass.c_str()); delete classify; return 0; }
+
inTax >> name >> taxon; gobble(inTax);
string newTax = addUnclassifieds(taxon, maxLevel);
string taxonomy;
for(int i=0;i<line->numSeqs;i++){
+ if (m->control_pressed) { return 0; }
Sequence* candidateSeq = new Sequence(inFASTA);
if (candidateSeq->getName() != "") {
taxonomy = classify->getTaxonomy(candidateSeq);
+
+ if (m->control_pressed) { delete candidateSeq; return 0; }
if (taxonomy != "bad seq") {
//output confidence scores or not
set<string> userLabels = labels;
if (m->control_pressed) {
- for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
delete input; globaldata->ginput = NULL;
delete read;
delete order; globaldata->gorder = NULL;
while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+
+ if (m->control_pressed) {
+ for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ delete input; globaldata->ginput = NULL;
+ delete read;
+ delete order; globaldata->gorder = NULL;
+ delete validCalculator;
+ globaldata->Groups.clear();
+ return 0;
+ }
+
if(allLines == 1 || labels.count(order->getLabel()) == 1){
-
+
+ m->mothurOut(order->getLabel()); m->mothurOutEndLine();
cCurve = new Collect(order, cDisplays);
- int error = cCurve->getCurve(freq);
+ cCurve->getCurve(freq);
delete cCurve;
- if (error == 1) {
- for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
- for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
- delete input; globaldata->ginput = NULL;
- delete read;
- delete order; globaldata->gorder = NULL;
- delete validCalculator;
- globaldata->Groups.clear();
- return 0;
- }
-
- m->mothurOut(order->getLabel()); m->mothurOutEndLine();
processedLabels.insert(order->getLabel());
userLabels.erase(order->getLabel());
delete order;
order = (input->getOrderVector(lastLabel));
+ m->mothurOut(order->getLabel()); m->mothurOutEndLine();
cCurve = new Collect(order, cDisplays);
- int error = cCurve->getCurve(freq);
+ cCurve->getCurve(freq);
delete cCurve;
- if (error == 1) {
- for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
- for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
- delete input; globaldata->ginput = NULL;
- delete read;
- delete order; globaldata->gorder = NULL;
- delete validCalculator;
- globaldata->Groups.clear();
- return 0;
- }
- m->mothurOut(order->getLabel()); m->mothurOutEndLine();
processedLabels.insert(order->getLabel());
userLabels.erase(order->getLabel());
order = (input->getOrderVector());
}
+
+ if (m->control_pressed) {
+ for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ delete input; globaldata->ginput = NULL;
+ delete read;
+ delete validCalculator;
+ globaldata->Groups.clear();
+ return 0;
+ }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
cCurve = new Collect(order, cDisplays);
- int error = cCurve->getCurve(freq);
+ cCurve->getCurve(freq);
delete cCurve;
- if (error == 1) {
- for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ if (m->control_pressed) {
for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
delete input; globaldata->ginput = NULL;
delete read;
delete order; globaldata->gorder = NULL;
delete validCalculator;
}
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
-
- if(allLines == 1 || labels.count(order->getLabel()) == 1){
-
- //create collectors curve
- cCurve = new Collect(order, cDisplays);
- int error = cCurve->getSharedCurve(freq);
- delete cCurve;
-
- if (error == 1) {
+ if (m->control_pressed) {
for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
- delete input; globaldata->ginput = NULL;
- delete read;
- delete order; globaldata->gorder = NULL;
- delete validCalculator;
+ delete order;
globaldata->Groups.clear();
return 0;
- }
+ }
+
+ if(allLines == 1 || labels.count(order->getLabel()) == 1){
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
+ //create collectors curve
+ cCurve = new Collect(order, cDisplays);
+ cCurve->getSharedCurve(freq);
+ delete cCurve;
+
processedLabels.insert(order->getLabel());
userLabels.erase(order->getLabel());
}
delete order;
order = input->getSharedOrderVector(lastLabel);
+ m->mothurOut(order->getLabel()); m->mothurOutEndLine();
//create collectors curve
cCurve = new Collect(order, cDisplays);
- int error = cCurve->getSharedCurve(freq);
+ cCurve->getSharedCurve(freq);
delete cCurve;
- if (error == 1) {
- for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
- for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
- delete input; globaldata->ginput = NULL;
- delete read;
- delete order; globaldata->gorder = NULL;
- delete validCalculator;
- globaldata->Groups.clear();
- return 0;
- }
-
-
- m->mothurOut(order->getLabel()); m->mothurOutEndLine();
processedLabels.insert(order->getLabel());
userLabels.erase(order->getLabel());
order = input->getSharedOrderVector();
}
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+ globaldata->Groups.clear();
+ return 0;
+ }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
if (needToRun == true) {
if (order != NULL) { delete order; }
order = input->getSharedOrderVector(lastLabel);
-
+
+ m->mothurOut(order->getLabel()); m->mothurOutEndLine();
cCurve = new Collect(order, cDisplays);
- int error = cCurve->getSharedCurve(freq);
+ cCurve->getSharedCurve(freq);
delete cCurve;
- if (error == 1) {
+ if (m->control_pressed) {
for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
- delete input; globaldata->ginput = NULL;
- delete read;
- delete order; globaldata->gorder = NULL;
- delete validCalculator;
+ delete order;
globaldata->Groups.clear();
return 0;
}
-
- m->mothurOut(order->getLabel()); m->mothurOutEndLine();
delete order;
}
}
//get the possible pairings
- getSets();
+ getSets();
+
+ if (m->control_pressed) { return 0; }
//open file for pairing not included in the tree
notIncluded = filename + ".cons.pairs";
buildConcensusTree(treeSet);
+ if (m->control_pressed) { delete consensusTree; return 0; }
+
consensusTree->assembleTree();
+ if (m->control_pressed) { delete consensusTree; return 0; }
+
//output species in order
out2 << "Species in Order: " << endl << endl;
for (int i = 0; i < treeSet.size(); i++) { out2 << i+1 << ". " << treeSet[i] << endl; }
//output sets included
out2 << endl << "Sets included in the consensus tree:" << endl << endl;
+ if (m->control_pressed) { delete consensusTree; return 0; }
+
vector<string> temp;
for (it2 = nodePairsInTree.begin(); it2 != nodePairsInTree.end(); it2++) {
+
+ if (m->control_pressed) { delete consensusTree; return 0; }
+
//only output pairs not leaves
if (it2->first.size() > 1) {
temp.clear();
//output sets not included
out2 << endl << "Sets NOT included in the consensus tree:" << endl << endl;
for (it2 = nodePairs.begin(); it2 != nodePairs.end(); it2++) {
+
+ if (m->control_pressed) { delete consensusTree; return 0; }
+
temp.clear();
//initialize temp to all "."
temp.resize(treeSet.size(), ".");
vector<string> leftChildSet;
vector<string> rightChildSet;
+ if (m->control_pressed) { return 1; }
+
//if you are at a leaf
if (nodeSet.size() == 1) {
//return the vector index of the leaf you are at
}
//**********************************************************************************************************************
-void ConcensusCommand::getSets() {
+int ConcensusCommand::getSets() {
try {
vector<string> temp;
treeSet.clear();
//for each non-leaf node get descendant info.
for (int j = numLeaves; j < numNodes; j++) {
+
+ if (m->control_pressed) { return 1; }
+
temp.clear();
//go through pcounts and pull out descendants
for (it = t[i]->tree[j].pcount.begin(); it != t[i]->tree[j].pcount.end(); it++) {
//you want the leaves in there but with insignifigant sightings value so it is added last
//for each leaf node get descendant info.
for (int j = 0; j < numLeaves; j++) {
+
+ if (m->control_pressed) { return 1; }
//only need the first one since leaves have no descendants but themselves
it = t[0]->tree[j].pcount.begin();
//set initial rating on pairs to sightings + subgroup sightings
while (nodePairsCopy.size() != 0) {
+ if (m->control_pressed) { return 1; }
vector<string> small = getSmallest(nodePairsCopy);
nodePairsCopy.erase(small);
}
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "ConcensusCommand", "getSets");
ofstream out, out2;
int numNodes, numLeaves, count; //count is the next available spot in the tree vector
- void getSets();
+ int getSets();
int getSubgroupRating(vector<string>);
vector<string> getSmallest(map< vector<string>, int>);
vector<string> getNextAvailableSet(vector<string>, vector<string>&);
Sequence* subject = new Sequence(seqs[j]->getName(), seqs[j]->getAligned());
+ if (m->control_pressed) { delete query; delete subject; return quan; }
+
map<int, int> trim;
map<int, int>::iterator it;
if(oldNameMapFName == "") { fastamap.readFastaFile(inFastaName); }
else { fastamap.readFastaFile(inFastaName, oldNameMapFName); }
+ if (m->control_pressed) { return 0; }
+
fastamap.printCondensedFasta(outFastaFile);
fastamap.printNamesFile(outNameFile);
+ if (m->control_pressed) { remove(outFastaFile.c_str()); remove(outNameFile.c_str()); return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
m->mothurOut(outFastaFile); m->mothurOutEndLine();
ifstream inFASTA;
driver(0, numSeqs, outputFile, cutoff);
#endif
+ if (m->control_pressed) { delete distCalculator; remove(outputFile.c_str()); return 0; }
if (output == "square") { convertMatrix(outputFile); }
+ if (m->control_pressed) { delete distCalculator; remove(outputFile.c_str()); return 0; }
+
delete distCalculator;
m->mothurOutEndLine();
outFile << name << '\t';
}
for(int j=0;j<i;j++){
+
+ if (m->control_pressed) { outFile.close(); return 0; }
+
distCalculator->calcDist(alignDB.get(i), alignDB.get(j));
double dist = distCalculator->getDist();
}
}
/**************************************************************************************************/
-void DistanceCommand::convertMatrix(string outputFile) {
+int DistanceCommand::convertMatrix(string outputFile) {
try{
//sort file by first column so the distances for each row are together
//openInputFile(outfile, in);
while(!in.eof()) {
+ if (m->control_pressed) { in.close(); remove(outfile.c_str()); out.close(); return 0; }
+
in >> first >> second >> dist; gobble(in);
if (first != currentRow) {
remove(outfile.c_str());
+ return 1;
+
}
catch(exception& e) {
m->errorOut(e, "DistanceCommand", "convertMatrix");
//void appendFiles(string, string);
void createProcesses(string);
int driver(/*Dist*, SequenceDB, */int, int, string, float);
- void convertMatrix(string);
+ int convertMatrix(string);
};
double DLibshuff::dCalculate(int x, int y){
+ double sum = 0;
+
minX = getMinX(x);
+
+ if (m->control_pressed) { return sum; }
+
minXY = getMinXY(x, y);
+ if (m->control_pressed) { return sum; }
+
vector<int> nx = calcN(minX);
+
+ if (m->control_pressed) { return sum; }
+
vector<int> nxy = calcN(minXY);
-
- double sum = 0;
+
+ if (m->control_pressed) { return sum; }
for(int i=0;i<numDXs;i++){
float h = (nx[i] - nxy[i]) / (float) groupSizes[x];
mout->mothurOutEndLine();
input = getCommand();
- mout->mothurOutEndLine();
+ mout->mothurOutEndLine();
+
+ if (mout->control_pressed) { input = "quit()"; }
//allow user to omit the () on the quit command
if (input == "quit") { input = "quit()"; }
options = parser.getOptionString();
if (commandName != "") {
-
+ mout->executing = true;
//executes valid command
Command* command = cFactory->getCommand(commandName, options);
quitCommandCalled = command->execute();
mout->control_pressed = 0;
-
+ mout->executing = false;
}else {
mout->mothurOut("Your input contains errors. Please try again.");
mout->mothurOutEndLine();
mout->mothurOut("mothur > " + input);
mout->mothurOutEndLine();
+ if (mout->control_pressed) { input = "quit()"; }
//allow user to omit the () on the quit command
if (input == "quit") { input = "quit()"; }
options = parser.getOptionString();
if (commandName != "") {
-
+ mout->executing = true;
//executes valid command
Command* command = cFactory->getCommand(commandName, options);
quitCommandCalled = command->execute();
mout->control_pressed = 0;
+ mout->executing = false;
}else {
mout->mothurOut("Invalid.");
mout->mothurOutEndLine();
mout->mothurOut("mothur > " + input);
mout->mothurOutEndLine();
+ if (mout->control_pressed) { input = "quit()"; }
//allow user to omit the () on the quit command
if (input == "quit") { input = "quit()"; }
options = parser.getOptionString();
if (commandName != "") {
-
+ mout->executing = true;
//executes valid command
Command* command = cFactory->getCommand(commandName, options);
quitCommandCalled = command->execute();
mout->control_pressed = 0;
+ mout->executing = false;
}else {
mout->mothurOut("Invalid.");
mout->mothurOutEndLine();
string temp;
while(!in.eof()){
+ if (m->control_pressed) { break; }
+
Sequence currSeq(in);
name = currSeq.getName();
map<string,string> oldNameMap;
string name, list;
while(!oldNameFile.eof()){
+ if (m->control_pressed) { break; }
+
oldNameFile >> name >> list;
oldNameMap[name] = list;
gobble(oldNameFile);
openInputFile(inFastaFile, inFASTA);
string sequence;
while(!inFASTA.eof()){
+ if (m->control_pressed) { break; }
+
Sequence currSeq(inFASTA);
name = currSeq.getName();
// two column file created with groupname and them list of identical sequence names
for (map<string,group>::iterator it = data.begin(); it != data.end(); it++) {
+ if (m->control_pressed) { break; }
outFile << it->second.groupname << '\t' << it->second.names << endl;
}
outFile.close();
openOutputFile(outFileName, out);
//creates a fasta file
for (map<string,group>::iterator it = data.begin(); it != data.end(); it++) {
+ if (m->control_pressed) { break; }
out << ">" << it->second.groupname << endl;
out << it->first << endl;
}
openInputFile(fastafileNames[i], in);
while(!in.eof()){ //read through and create the filter...
+
+ if (m->control_pressed) { in.close(); return 0; }
+
Sequence seq(in);
if (seq.getName() != "") {
if(trump != '*'){ F.doTrump(seq); }
while(!in.eof()){
+ if (m->control_pressed) { in.close(); outFASTA.close(); for(int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
Sequence seq(in);
if (seq.getName() != "") {
string align = seq.getAligned();
if(filter[i] == '1'){ filteredLength++; }
}
+ if (m->control_pressed) { for(int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
+
m->mothurOutEndLine();
m->mothurOut("Length of filtered alignment: " + toString(filteredLength)); m->mothurOutEndLine();
m->mothurOut("Number of columns removed: " + toString((alignmentLength-filteredLength))); m->mothurOutEndLine();
}
/***********************************************************************/
-void FormatColumnMatrix::read(NameAssignment* nameMap){
+int FormatColumnMatrix::read(NameAssignment* nameMap){
try {
string firstName, secondName;
while(fileHandle && lt == 1){ //let's assume it's a triangular matrix...
+ if (m->control_pressed) { out.close(); remove(tempOutFile.c_str()); fileHandle.close(); delete reading; return 0; }
+
fileHandle >> firstName >> secondName >> distance; // get the row and column names and distance
map<string,int>::iterator itA = nameMap->find(firstName);
system(command.c_str());
#endif
+ if (m->control_pressed) { remove(tempOutFile.c_str()); remove(outfile.c_str()); delete reading; return 0; }
//output to new file distance for each row and save positions in file where new row begins
ifstream in;
for(int k = 0; k < firstString.length(); k++) { in.putback(firstString[k]); }
while(!in.eof()) {
+
+ if (m->control_pressed) { in.close(); out.close(); remove(distFile.c_str()); remove(tempOutFile.c_str()); remove(outfile.c_str()); delete reading; return 0; }
+
in >> first >> second >> dist; gobble(in);
if (first != currentRow) {
in.close();
out.close();
+ if (m->control_pressed) { remove(distFile.c_str()); remove(tempOutFile.c_str()); remove(outfile.c_str()); delete reading; return 0; }
remove(tempOutFile.c_str());
remove(outfile.c_str());
reading->finish();
+
+ delete reading;
list->setLabel("0");
+
+ if (m->control_pressed) { remove(distFile.c_str()); return 0; }
+
+ return 1;
}
catch(exception& e) {
public:
FormatColumnMatrix(string);
~FormatColumnMatrix();
- void read(NameAssignment*);
+ int read(NameAssignment*);
private:
ifstream fileHandle;
FormatMatrix(){ m = MothurOut::getInstance(); }
virtual ~FormatMatrix() {}
- virtual void read(NameAssignment*){};
+ virtual int read(NameAssignment*){ return 1; }
void setCutoff(float c) { cutoff = c; }
ListVector* getListVector() { return list; }
}
/***********************************************************************/
//not using nameMap
-void FormatPhylipMatrix::read(NameAssignment* nameMap){
+int FormatPhylipMatrix::read(NameAssignment* nameMap){
try {
float distance;
//convert to square column matrix
for(int i=1;i<nseqs;i++){
+
fileHandle >> name;
list->set(i, name);
for(int j=0;j<i;j++){
+
+ if (m->control_pressed) { outTemp.close(); remove(tempFile.c_str()); fileHandle.close(); delete reading; return 0; }
+
fileHandle >> distance;
if (distance == -1) { distance = 1000000; }
system(command.c_str());
#endif
+ if (m->control_pressed) { remove(tempFile.c_str()); remove(outfile.c_str()); delete reading; return 0; }
//output to new file distance for each row and save positions in file where new row begins
ifstream in;
for(int k = 0; k < firstString.length(); k++) { in.putback(firstString[k]); }
while(!in.eof()) {
+ if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); remove(distFile.c_str()); remove(outfile.c_str()); delete reading; return 0; }
+
in >> first >> second >> dist; gobble(in);
if (first != currentRow) {
remove(tempFile.c_str());
remove(outfile.c_str());
+
+ if (m->control_pressed) { remove(distFile.c_str()); delete reading; return 0; }
+
}
else{ //square matrix convert directly to formatted row file
int index = nseqs;
list->set(i, name);
for(int j=0;j<nseqs;j++){
+ if (m->control_pressed) { fileHandle.close(); out.close(); remove(distFile.c_str()); delete reading; return 0; }
+
fileHandle >> distance;
if (distance == -1) { distance = 1000000; }
}
reading->finish();
delete reading;
-
- list->setLabel("0");
fileHandle.close();
out.close();
+ if (m->control_pressed) { remove(distFile.c_str()); return 0; }
+
+ list->setLabel("0");
+
+ return 1;
+
+
}
catch(exception& e) {
m->errorOut(e, "FormatPhylipMatrix", "read");
public:
FormatPhylipMatrix(string);
~FormatPhylipMatrix();
- void read(NameAssignment*);
+ int read(NameAssignment*);
private:
ifstream fileHandle;
string filename;
}
//read rest of matrix
- if (square == true) { readSquareMatrix(filehandle); }
- else { readLTMatrix(filehandle); }
+ if (square == true) { readSquareMatrix(filehandle); }
+ else { readLTMatrix(filehandle); }
- sortGroups(0, numSeqs-1);
+ filehandle.close();
+
+ if (!m->control_pressed) { sortGroups(0, numSeqs-1); }
}
catch(exception& e) {
}
}
/**************************************************************************/
-void FullMatrix::readSquareMatrix(ifstream& filehandle) {
+int FullMatrix::readSquareMatrix(ifstream& filehandle) {
try {
Progress* reading;
int count = 0;
string group, name;
-
+
for(int i=1;i<numSeqs;i++){
filehandle >> name;
if(group == "not found") { m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); }
for(int j=0;j<numSeqs;j++){
+ if (m->control_pressed) { delete reading; return 0; }
+
filehandle >> matrix[i][j];
count++;
reading->update(count);
}
}
+
+ if (m->control_pressed) { delete reading; return 0; }
+
reading->finish();
delete reading;
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "FullMatrix", "readSquareMatrix");
}
}
/**************************************************************************/
-void FullMatrix::readLTMatrix(ifstream& filehandle) {
+int FullMatrix::readLTMatrix(ifstream& filehandle) {
try {
Progress* reading;
reading = new Progress("Reading matrix: ", numSeqs * (numSeqs - 1) / 2);
if(group == "not found") { m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); }
for(int j=0;j<i;j++){
+ if (m->control_pressed) { delete reading; return 0; }
+
filehandle >> distance;
+
matrix[i][j] = distance; matrix[j][i] = distance;
count++;
reading->update(count);
}
}
-
+
+ if (m->control_pressed) { delete reading; return 0; }
+
reading->finish();
delete reading;
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "FullMatrix", "readLTMatrix");
private:
vector< vector<float> > matrix; //a 2D distance matrix of all the sequences and their distances to eachother.
- void readSquareMatrix(ifstream&);
- void readLTMatrix(ifstream&);
+ int readSquareMatrix(ifstream&);
+ int readLTMatrix(ifstream&);
vector<Names> index; // row in vector, sequence group. need to know this so when we sort it can be updated.
vector<int> sizes;
vector<string> groups;
in >> inputData;
}
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFile.c_str()); return 0; }
+
if (in.eof() != true) { in >> nextLabel; }
//read the rest of the groups info in
while ((nextLabel == holdLabel) && (in.eof() != true)) {
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFile.c_str()); return 0; }
+
in >> groupN >> num;
count++;
in.close();
out.close();
+ if (m->control_pressed) { remove(outputFile.c_str()); return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Name: "); m->mothurOutEndLine();
m->mothurOut(outputFile); m->mothurOutEndLine();
int numBins = 0;
int count = -1;
while(in.good()) {
+
+ if (m->control_pressed) { in.close(); return 0; }
+
if(count > numBins)
count = 0;
if(count == 0) {
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
set<string> processedLabels;
set<string> userLabels = labels;
-
+
+ if (m->control_pressed) {
+ delete read;
+ delete input;
+ delete list;
+ globaldata->gListVector = NULL;
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
if(allLines == 1 || labels.count(list->getLabel()) == 1){
process(list);
+
+ if (m->control_pressed) {
+ delete read;
+ delete input;
+ delete list;
+ globaldata->gListVector = NULL;
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
processedLabels.insert(list->getLabel());
userLabels.erase(list->getLabel());
list = input->getListVector(lastLabel);
process(list);
+
+ if (m->control_pressed) {
+ delete read;
+ delete input;
+ delete list;
+ globaldata->gListVector = NULL;
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
processedLabels.insert(list->getLabel());
userLabels.erase(list->getLabel());
if (list != NULL) { delete list; }
list = input->getListVector(lastLabel);
- process(list);
+ process(list);
+
+ if (m->control_pressed) {
+ delete read;
+ delete input;
+ delete list;
+ globaldata->gListVector = NULL;
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
delete list;
}
delete read;
+ delete input;
globaldata->gListVector = NULL;
m->mothurOutEndLine();
//for each bin in the list vector
for (int i = 0; i < list->getNumBins(); i++) {
+ if (m->control_pressed) { break; }
+
binnames = list->get(i);
out << i+1 << '\t' << binnames << endl;
}
}else{ nameMap = NULL; }
readMatrix->read(nameMap);
+
+ if (m->control_pressed) { delete readMatrix; delete groupMap; return 0; }
//get matrix
if (globaldata->gListVector != NULL) { delete globaldata->gListVector; }
// via the index of a sequence in the distance matrix
seqVec = vector<SeqMap>(globaldata->gListVector->size());
for (MatData currentCell = matrix->begin(); currentCell != matrix->end(); currentCell++) {
+ if (m->control_pressed) { delete readMatrix; delete groupMap; return 0; }
seqVec[currentCell->row][currentCell->column] = currentCell->dist;
}
delete matrix;
delete readMatrix;
+
+ if (m->control_pressed) { delete groupMap; return 0; }
}else {
//process file and set up indexes
if (format == "column") { formatMatrix = new FormatColumnMatrix(distFile); }
}else{ nameMap = NULL; }
formatMatrix->read(nameMap);
+
+ if (m->control_pressed) { delete formatMatrix; delete groupMap; return 0; }
//get matrix
if (globaldata->gListVector != NULL) { delete globaldata->gListVector; }
//openfile for getMap to use
openInputFile(distFile, inRow);
+
+ if (m->control_pressed) { inRow.close(); remove(distFile.c_str()); delete groupMap; return 0; }
}
+
//globaldata->gListVector bin 0 = first name read in distance matrix, globaldata->gListVector bin 1 = second name read in distance matrix
if (globaldata->gListVector != NULL) {
vector<string> names;
//read fastafile
fasta->readFastaFile(fastafile);
+
+ if (m->control_pressed) {
+ if (large) { inRow.close(); remove(distFile.c_str()); }
+ delete groupMap; delete fasta; return 0;
+ }
//if user gave a namesfile then use it
if (namefile != "") { readNamesFile(); }
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
set<string> processedLabels;
set<string> userLabels = labels;
+
+ if (m->control_pressed) {
+ if (large) { inRow.close(); remove(distFile.c_str()); }
+ delete groupMap; delete fasta; delete read; delete input; delete list; globaldata->gListVector = NULL; return 0;
+ }
while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
error = process(list);
if (error == 1) { return 0; } //there is an error in hte input files, abort command
+ if (m->control_pressed) {
+ if (large) { inRow.close(); remove(distFile.c_str()); }
+ if (groupfile != "") { delete groupMap; globaldata->gGroupmap = NULL; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ delete fasta; delete read; delete input; delete list; globaldata->gListVector = NULL; return 0;
+ }
+
processedLabels.insert(list->getLabel());
userLabels.erase(list->getLabel());
}
error = process(list);
if (error == 1) { return 0; } //there is an error in hte input files, abort command
+ if (m->control_pressed) {
+ if (large) { inRow.close(); remove(distFile.c_str()); }
+ if (groupfile != "") { delete groupMap; globaldata->gGroupmap = NULL; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ delete fasta; delete read; delete input; delete list; globaldata->gListVector = NULL; return 0;
+ }
+
processedLabels.insert(list->getLabel());
userLabels.erase(list->getLabel());
error = process(list);
delete list;
if (error == 1) { return 0; } //there is an error in hte input files, abort command
+
+ if (m->control_pressed) {
+ if (large) { inRow.close(); remove(distFile.c_str()); }
+ if (groupfile != "") { delete groupMap; globaldata->gGroupmap = NULL; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ delete fasta; delete read; delete input; delete list; globaldata->gListVector = NULL; return 0;
+ }
}
//close and remove formatted matrix file
delete groupMap; globaldata->gGroupmap = NULL;
}
+ if (m->control_pressed) { return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
SeqMap::iterator it;
SeqMap currMap;
for (size_t i=0; i < seqIndex.size(); i++) {
+ if (m->control_pressed) { return "control"; }
if (!large) { currMap = seqVec[seqIndex[i]]; }
else { currMap = getMap(seqIndex[i]); }
float min = 10000;
int minIndex;
for (size_t i=0; i < max_dist.size(); i++) {
+ if (m->control_pressed) { return "control"; }
if (max_dist[i] < min) {
min = max_dist[i];
minIndex = i;
for (int i = 0; i < processList->size(); i++) {
string groups;
int binsize;
+
+ if (m->control_pressed) { out.close(); newNamesOutput.close(); return 0; }
+
nameRep = findRep(i, groups, processList, binsize);
+ if (m->control_pressed) { out.close(); newNamesOutput.close(); return 0; }
+
//output to new names file
newNamesOutput << nameRep << '\t' << processList->get(i) << endl;
//**********************************************************************************************************************
-GetRAbundCommand::~GetRAbundCommand(){
- if (abort == false) { globaldata->gListVector = NULL; }
-}
+GetRAbundCommand::~GetRAbundCommand(){}
//**********************************************************************************************************************
set<string> processedLabels;
set<string> userLabels = labels;
+ if (m->control_pressed) { out.close(); remove(filename.c_str()); delete read; delete input; delete list; globaldata->gListVector = NULL; return 0; }
+
while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
if(allLines == 1 || labels.count(list->getLabel()) == 1){
rabund = new RAbundVector();
*rabund = (list->getRAbundVector());
+ if (m->control_pressed) { out.close(); remove(filename.c_str()); delete read; delete input; delete list; delete rabund; globaldata->gListVector = NULL; return 0; }
+
+
if(sorted) { rabund->print(out); }
else { rabund->nonSortedPrint(out); }
rabund = new RAbundVector();
*rabund = (list->getRAbundVector());
+ if (m->control_pressed) { out.close(); remove(filename.c_str()); delete read; delete input; delete list; delete rabund; globaldata->gListVector = NULL; return 0; }
+
if(sorted) { rabund->print(out); }
else { rabund->nonSortedPrint(out); }
rabund = new RAbundVector();
*rabund = (list->getRAbundVector());
+ if (m->control_pressed) { out.close(); remove(filename.c_str()); delete read; delete input; delete list; delete rabund; globaldata->gListVector = NULL; return 0; }
+
if(sorted) { rabund->print(out); }
else { rabund->nonSortedPrint(out); }
out.close();
+ delete read; delete input;
+ globaldata->gListVector = NULL;
+
return 0;
}
set<string> processedLabels;
set<string> userLabels = labels;
+ if (m->control_pressed) { out.close(); remove(filename.c_str()); delete read; delete input; delete order; globaldata->gorder = NULL; return 0; }
+
+
while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
if(allLines == 1 || labels.count(order->getLabel()) == 1){
*sabund = (order->getSAbundVector());
sabund->print(out);
delete sabund;
+
+ if (m->control_pressed) { out.close(); remove(filename.c_str()); delete read; delete input; delete order; globaldata->gorder = NULL; return 0; }
processedLabels.insert(order->getLabel());
userLabels.erase(order->getLabel());
*sabund = (order->getSAbundVector());
sabund->print(out);
delete sabund;
+
+ if (m->control_pressed) { out.close(); remove(filename.c_str()); delete read; delete input; delete order; globaldata->gorder = NULL; return 0; }
processedLabels.insert(order->getLabel());
userLabels.erase(order->getLabel());
*sabund = (order->getSAbundVector());
sabund->print(out);
delete sabund;
+
+ if (m->control_pressed) { out.close(); remove(filename.c_str()); delete read; delete input; delete order; globaldata->gorder = NULL; return 0; }
+
delete order;
}
globaldata->gorder = NULL;
+ delete read; delete input;
out.close();
//get names you want to keep
readAccnos();
+ if (m->control_pressed) { return 0; }
+
//read through the correct file and output lines you want to keep
if (fastafile != "") { readFasta(); }
else if (namefile != "") { readName(); }
else if (alignfile != "") { readAlign(); }
else if (listfile != "") { readList(); }
+ if (m->control_pressed) { return 0; }
+
if (outputNames.size() != 0) {
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
}
//**********************************************************************************************************************
-void GetSeqsCommand::readFasta(){
+int GetSeqsCommand::readFasta(){
try {
if (outputDir == "") { outputDir += hasPath(fastafile); }
string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + "pick" + getExtension(fastafile);
bool wroteSomething = false;
while(!in.eof()){
+
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; }
+
Sequence currSeq(in);
name = currSeq.getName();
m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();
remove(outputFileName.c_str());
}else { outputNames.push_back(outputFileName); }
+
+ return 0;
}
catch(exception& e) {
}
}
//**********************************************************************************************************************
-void GetSeqsCommand::readList(){
+int GetSeqsCommand::readList(){
try {
if (outputDir == "") { outputDir += hasPath(listfile); }
string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + "pick" + getExtension(listfile);
bool wroteSomething = false;
while(!in.eof()){
+
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; }
+
//read in list vector
ListVector list(in);
m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();
remove(outputFileName.c_str());
}else { outputNames.push_back(outputFileName); }
+
+ return 0;
}
catch(exception& e) {
}
}
//**********************************************************************************************************************
-void GetSeqsCommand::readName(){
+int GetSeqsCommand::readName(){
try {
if (outputDir == "") { outputDir += hasPath(namefile); }
string outputFileName = outputDir + getRootName(getSimpleName(namefile)) + "pick" + getExtension(namefile);
while(!in.eof()){
+
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; }
in >> firstCol;
in >> secondCol;
remove(outputFileName.c_str());
}else { outputNames.push_back(outputFileName); }
+ return 0;
+
}
catch(exception& e) {
m->errorOut(e, "GetSeqsCommand", "readName");
}
//**********************************************************************************************************************
-void GetSeqsCommand::readGroup(){
+int GetSeqsCommand::readGroup(){
try {
if (outputDir == "") { outputDir += hasPath(groupfile); }
string outputFileName = outputDir + getRootName(getSimpleName(groupfile)) + "pick" + getExtension(groupfile);
while(!in.eof()){
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; }
+
+
in >> name; //read from first column
in >> group; //read from second column
m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();
remove(outputFileName.c_str());
}else { outputNames.push_back(outputFileName); }
+
+ return 0;
}
catch(exception& e) {
//**********************************************************************************************************************
//alignreport file has a column header line then all other lines contain 16 columns. we just want the first column since that contains the name
-void GetSeqsCommand::readAlign(){
+int GetSeqsCommand::readAlign(){
try {
if (outputDir == "") { outputDir += hasPath(alignfile); }
string outputFileName = outputDir + getRootName(getSimpleName(alignfile)) + "pick.align.report";
out << endl;
while(!in.eof()){
+
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; }
+
in >> name; //read from first column
remove(outputFileName.c_str());
}else { outputNames.push_back(outputFileName); }
+ return 0;
+
}
catch(exception& e) {
m->errorOut(e, "GetSeqsCommand", "readAlign");
}
//**********************************************************************************************************************
-void GetSeqsCommand::readAccnos(){
+int GetSeqsCommand::readAccnos(){
try {
ifstream in;
gobble(in);
}
- in.close();
+ in.close();
+
+ return 0;
}
catch(exception& e) {
string accnosfile, fastafile, namefile, groupfile, alignfile, listfile, outputDir;
bool abort;
- void readFasta();
- void readName();
- void readGroup();
- void readAlign();
- void readAccnos();
- void readList();
+ int readFasta();
+ int readName();
+ int readGroup();
+ int readAlign();
+ int readAccnos();
+ int readList();
};
int error = groupMap->readMap();
if (error == 1) { delete groupMap; return 0; }
+ if (m->control_pressed) { delete groupMap; return 0; }
+
globaldata->gGroupmap = groupMap;
if (Groups.size() == 0) {
openInputFile(fastafile, inFasta);
while(!inFasta.eof()) {
+ if (m->control_pressed) { inFasta.close(); delete groupMap; return 0; }
+
Sequence seq(inFasta); gobble(inFasta);
if (seq.getName() != "") { seqs.push_back(seq); }
}
//as long as you are not at the end of the file or done wih the lines you want
while((!in.eof()) && ((allLines == 1) || (userLabels.size() != 0))) {
+ if (m->control_pressed) {
+ if (lastlist != NULL) { delete lastlist; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ delete groupMap; return 0;
+ }
+
list = new ListVector(in);
if(allLines == 1 || labels.count(list->getLabel()) == 1){
if (lastlist != NULL) { delete lastlist; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete groupMap; return 0; }
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
}
}
/***********************************************************/
-void GetSharedOTUCommand::process(ListVector* shared) {
+int GetSharedOTUCommand::process(ListVector* shared) {
try {
map<string, string> fastaMap;
//go through each bin, find out if shared
for (int i = 0; i < shared->getNumBins(); i++) {
+ if (m->control_pressed) { outNames.close(); remove(outputFileNames.c_str()); return 0; }
bool uniqueOTU = true;
outputNames.push_back(outputFileFasta);
for (int k = 0; k < seqs.size(); k++) {
+ if (m->control_pressed) { outFasta.close(); return 0; }
+
//if this is a sequence we want, output it
it = fastaMap.find(seqs[k].getName());
if (it != fastaMap.end()) {
outFasta.close();
}
-
+
+ return 0;
}
catch(exception& e) {
vector<Sequence> seqs;
vector<string> outputNames;
- void process(ListVector*);
+ int process(ListVector*);
};
//**********************************************************************************************************************
fileHandle >> seqName; //read from first column
fileHandle >> seqGroup; //read from second column
+ if (m->control_pressed) { fileHandle.close(); return 1; }
+
setNamesOfGroups(seqGroup);
it = groupmap.find(seqName);
}
/***********************************************************************/
-void HCluster::combineFile() {
+int HCluster::combineFile() {
try {
//int bufferSize = 64000; //512k - this should be a variable that the user can set to optimize code to their hardware
//char* inputBuffer;
in >> first >> second >> dist; gobble(in);
+ if (m->control_pressed) { in.close(); out.close(); remove(tempDistFile.c_str()); return 0; }
+
//while there are still values in mergedMin that are smaller than the distance read from file
while (count < mergedMin.size()) {
mergedMin.clear();
//rename tempfile to distfile
- int renameOK = remove(distfile.c_str());
- int ok = rename(tempDistFile.c_str(), distfile.c_str());
+ remove(distfile.c_str());
+ rename(tempDistFile.c_str(), distfile.c_str());
//cout << "remove = "<< renameOK << " rename = " << ok << endl;
//merge clustered rows averaging the distances
//sort merged values
sort(mergedMin.begin(), mergedMin.end(), compareSequenceDistance);
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "HCluster", "combineFile");
}
}
/***********************************************************************/
-void HCluster::processFile() {
+int HCluster::processFile() {
try {
string firstName, secondName;
float distance;
//get entry
while (!in.eof()) {
+ if (m->control_pressed) { in.close(); out.close(); remove(outTemp.c_str()); return 0; }
in >> firstName >> secondName >> distance; gobble(in);
remove(distfile.c_str());
rename(outTemp.c_str(), distfile.c_str());
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "HCluster", "processFile");
void updateMap();
vector<seqDist> getSeqsFNNN();
vector<seqDist> getSeqsAN();
- void combineFile();
- void processFile();
+ int combineFile();
+ int processFile();
//seqDist getNextDist(char*, int&, int);
RAbundVector* rabund;
read = new ReadCluster(distfile, cutoff);
read->setFormat(format);
read->read(globaldata->nameMap);
+
+ if (m->control_pressed) {
+ delete read;
+ sabundFile.close();
+ rabundFile.close();
+ listFile.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
distfile = read->getOutputFile();
list = read->getListVector();
}else {
list = new ListVector(globaldata->nameMap->getListVector());
}
-
+
+ if (m->control_pressed) {
+ sabundFile.close();
+ rabundFile.close();
+ listFile.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
m->mothurOut("It took " + toString(time(NULL) - estart) + " seconds to sort. "); m->mothurOutEndLine();
estart = time(NULL);
cluster = new HCluster(rabund, list, method, distfile, globaldata->nameMap, cutoff);
vector<seqDist> seqs; seqs.resize(1); // to start loop
+ if (m->control_pressed) {
+ delete cluster;
+ sabundFile.close();
+ rabundFile.close();
+ listFile.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
+
while (seqs.size() != 0){
seqs = cluster->getSeqs();
-
- for (int i = 0; i < seqs.size(); i++) { //-1 means skip me
+
+ if (m->control_pressed) {
+ delete cluster;
+ sabundFile.close();
+ rabundFile.close();
+ listFile.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+ for (int i = 0; i < seqs.size(); i++) { //-1 means skip me
+
if (seqs[i].seq1 != seqs[i].seq2) {
cluster->update(seqs[i].seq1, seqs[i].seq2, seqs[i].dist);
+ if (m->control_pressed) {
+ delete cluster;
+ sabundFile.close();
+ rabundFile.close();
+ listFile.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
+
float rndDist = roundDist(seqs[i].dist, precision);
if((previousDist <= 0.0000) && (seqs[i].dist != previousDist)){
}
}
+ if (m->control_pressed) {
+ delete cluster;
+ sabundFile.close();
+ rabundFile.close();
+ listFile.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
if(previousDist <= 0.0000){
printData("unique");
}
listFile.close();
delete cluster;
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
for(int i=0;i<rabund->size();i++){
float relAbund = rabund->get(i) / (float)rabund->getNumSeqs();
+ if (m->control_pressed) { return "control"; }
+
if (rabund->get(i) != 0) { //don't want log value of 0.
if (scaler == "log10") {
scaleRelAbund[i] = toHex(int(255 * log10(relAbund) / log10(maxRelAbund))) + "0000";
y = 70;
for (int i = 0; i < scaleRelAbund.size(); i++) {
+ if (m->control_pressed) { outsvg.close(); return "control"; }
outsvg << "<rect fill=\"#" + scaleRelAbund[i] + "\" stroke=\"#" + scaleRelAbund[i] + "\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"300\" height=\"5\"/>\n";
y += 5;
for(int i=0;i<lookup.size();i++){
scaleRelAbund[i].assign(lookup[i]->size(), "");
for(int j=0;j<lookup[i]->size();j++){
+ if (m->control_pressed) { return "control"; }
float relAbund = lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs();
if (lookup[i]->getAbundance(j) != 0) { //don't want log value of 0.
y = 70;
for (int i = 0; i < scaleRelAbund[0].size(); i++) {
for (int j = 0; j < scaleRelAbund.size(); j++) {
+ if (m->control_pressed) { outsvg.close(); return "control"; }
outsvg << "<rect fill=\"#" + scaleRelAbund[j][i] + "\" stroke=\"#" + scaleRelAbund[j][i] + "\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"300\" height=\"5\"/>\n";
x += 300;
scale = validParameter.validFile(parameters, "scale", false); if (scale == "not found") { scale = "log10"; }
- if (abort == false) {
- heatmap = new HeatMap(sorted, scale, outputDir);
- format = globaldata->getFormat();
- }
}
}
//**********************************************************************************************************************
HeatMapCommand::~HeatMapCommand(){
- if (abort == false) {
- delete read;
- delete heatmap;
- }
}
//**********************************************************************************************************************
try {
if (abort == true) { return 0; }
+
+ heatmap = new HeatMap(sorted, scale, outputDir);
+ format = globaldata->getFormat();
string lastLabel;
-
+
+ read = new ReadOTUFile(globaldata->inputFileName);
+ read->read(&*globaldata);
+ input = globaldata->ginput;
+
if (format == "sharedfile") {
//you have groups
- read = new ReadOTUFile(globaldata->inputFileName);
- read->read(&*globaldata);
-
- input = globaldata->ginput;
lookup = input->getSharedRAbundVectors();
lastLabel = lookup[0]->getLabel();
}else if ((format == "list") || (format == "rabund") || (format == "sabund")) {
//you are using just a list file and have only one group
- read = new ReadOTUFile(globaldata->inputFileName);
- read->read(&*globaldata);
-
rabund = globaldata->rabund;
lastLabel = rabund->getLabel();
- input = globaldata->ginput;
-
}
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
//as long as you are not at the end of the file or done wih the lines you want
while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+ if (m->control_pressed) {
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } }
+ globaldata->Groups.clear();
+ delete read; delete heatmap; return 0;
+ }
if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
lookup = input->getSharedRAbundVectors();
}
+
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } }
+ globaldata->Groups.clear();
+ delete read; delete heatmap; return 0;
+ }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
}
-
-
//reset groups parameter
globaldata->Groups.clear();
}else{
while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } }
+ delete rabund; delete read; delete heatmap; return 0;
+ }
if(allLines == 1 || labels.count(rabund->getLabel()) == 1){
rabund = input->getRAbundVector();
}
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } }
+ delete read; delete heatmap; return 0;
+ }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
globaldata->rabund = NULL;
delete input; globaldata->ginput = NULL;
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } }
+ delete read; delete heatmap; return 0;
+ }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
m->mothurOutEndLine();
+
+ delete read;
+ delete heatmap;
return 0;
}
vector<string> outputNames;
//make file for each calculator selected
- for (int m = 0; m < calcs.size(); m++) {
-
- string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + calcs[m]->getName() + ".heatmap.sim.svg";
+ for (int k = 0; k < calcs.size(); k++) {
+
+ if (m->control_pressed) { return outputNames; }
+
+ string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + calcs[k]->getName() + ".heatmap.sim.svg";
openOutputFile(filenamesvg, outsvg);
outputNames.push_back(filenamesvg);
//get sim for each comparison and save them so you can find the relative similairity
for(int i = 0; i < (lookup.size()-1); i++){
for(int j = (i+1); j < lookup.size(); j++){
-
+
+ if (m->control_pressed) { outsvg.close(); return outputNames; }
+
vector<SharedRAbundVector*> subset;
subset.push_back(lookup[i]); subset.push_back(lookup[j]);
//get similairity between groups
- data = calcs[m]->getValues(subset);
+ data = calcs[k]->getValues(subset);
sims.push_back(data[0]);
//save biggest similairity to set relative sim
//get sim for each comparison and save them so you can find the relative similairity
for(int i = 0; i < (dists.size()-1); i++){
for(int j = (i+1); j < dists.size(); j++){
+
+ if (m->control_pressed) { outsvg.close(); return filenamesvg; }
float sim = 1.0 - dists[i][j];
sims.push_back(sim);
delete heatmap;
delete validCalculator;
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
set<string> processedLabels;
set<string> userLabels = labels;
+ if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); return 0; }
+
//as long as you are not at the end of the file or done wih the lines you want
while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
-
+
+ if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); return 0; }
+
if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
lookup = input->getSharedRAbundVectors();
}
+
+ if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; globaldata->Groups.clear(); return 0; }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
}
}
+ if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; globaldata->Groups.clear(); return 0; }
+
//run last label if you need to
if (needToRun == true) {
for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
}
+ if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; globaldata->Groups.clear(); return 0; }
//reset groups parameter
globaldata->Groups.clear();
in >> name;
names.push_back(name);
- for(int j=0;j<numSeqs;j++) { in >> matrix[i][j]; }
+ if (m->control_pressed) { return 0; }
+
+ for(int j=0;j<numSeqs;j++) { in >> matrix[i][j]; }
gobble(in);
}
}else {
in >> name;
names.push_back(name);
+ if (m->control_pressed) { return 0; }
+
for(int j=0;j<i;j++){
in >> dist;
matrix[i][j] = dist; matrix[j][i] = dist;
while (!in.eof()) {
in >> first >> second >> dist; gobble(in);
+ if (m->control_pressed) { return 0; }
+
map<string, int>::iterator itA = nameMap->find(first);
map<string, int>::iterator itB = nameMap->find(second);
//use database to find closest seq
vector<int> closest = database->findClosestSequences(seq, num);
+
+ if (m->control_pressed) { return tax; }
vector<string> closestNames;
for (int i = 0; i < closest.size(); i++) {
int smallest = 100;
for (int i = 0; i < closest.size(); i++) {
+ if (m->control_pressed) { return "control"; }
string tax = taxonomy[closest[i]]; //we know its there since we checked in getTaxonomy
//start at the highest level all the closest seqs have
string common = "";
for (int i = (smallest-1); i >= 0; i--) {
+ if (m->control_pressed) { return "control"; }
string thistax = taxons[0][i];
int num = 0;
savedDXYValues = form->evaluateAll();
savedMinValues = form->getSavedMins();
+
+ if (m->control_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; return 0; }
pValueCounts.resize(numGroups);
for(int i=0;i<numGroups;i++){
pValueCounts[i].assign(numGroups, 0);
}
-
+
+ if (m->control_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; return 0; }
+
Progress* reading = new Progress();
for(int i=0;i<numGroups-1;i++) {
for(int j=i+1;j<numGroups;j++) {
+
+ if (m->control_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; }
+
reading->newLine(groupNames[i]+'-'+groupNames[j], iters);
int spoti = globaldata->gGroupmap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix
int spotj = globaldata->gGroupmap->groupIndex[groupNames[j]];
- for(int p=0;p<iters;p++) {
+ for(int p=0;p<iters;p++) {
+
+ if (m->control_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; }
+
form->randomizeGroups(spoti,spotj);
if(form->evaluatePair(spoti,spotj) >= savedDXYValues[spoti][spotj]) { pValueCounts[i][j]++; }
if(form->evaluatePair(spotj,spoti) >= savedDXYValues[spotj][spoti]) { pValueCounts[j][i]++; }
+
+ if (m->control_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; }
+
reading->update(p);
}
form->resetGroup(spoti);
form->resetGroup(spotj);
}
}
+
+ if (m->control_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; }
+
reading->finish();
delete reading;
m->mothurOutEndLine();
printSummaryFile();
printCoverageFile();
-
+
//clear out users groups
globaldata->Groups.clear();
delete form;
//delete globaldata's copy of the gmatrix to free up memory
delete globaldata->gMatrix; globaldata->gMatrix = NULL;
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
//**********************************************************************************************************************
-void LibShuffCommand::printCoverageFile() {
+int LibShuffCommand::printCoverageFile() {
try {
ofstream outCov;
int spotj = globaldata->gGroupmap->groupIndex[groupNames[j]];
for(int k=0;k<savedMinValues[spoti][spotj].size();k++){
+
+ if(m->control_pressed) { outCov.close(); return 0; }
+
if(allDistances[savedMinValues[spoti][spotj][k]].size() != 0){
allDistances[savedMinValues[spoti][spotj][k]][indices[i][j]]++;
}
}
for (int i=0;i<numGroups;i++){
for(int j=i+1;j<numGroups;j++){
+ if(m->control_pressed) { outCov.close(); return 0; }
outCov << '\t' << groupNames[i] << '-' << groupNames[j] << '\t';
outCov << groupNames[j] << '-' << groupNames[i];
}
}
for(int i=0;i<numGroups;i++){
for(int j=i+1;j<numGroups;j++){
+ if(m->control_pressed) { outCov.close(); return 0; }
+
outCov << it->second[indices[i][j]]/(float)lastRow[indices[i][j]] << '\t';
outCov << it->second[indices[j][i]]/(float)lastRow[indices[j][i]] << '\t';
}
outCov << endl;
}
outCov.close();
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "LibShuffCommand", "printCoverageFile");
//**********************************************************************************************************************
-void LibShuffCommand::printSummaryFile() {
+int LibShuffCommand::printSummaryFile() {
try {
ofstream outSum;
int precision = (int)log10(iters);
for(int i=0;i<numGroups;i++){
for(int j=i+1;j<numGroups;j++){
+ if(m->control_pressed) { outSum.close(); return 0; }
+
int spoti = globaldata->gGroupmap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix
int spotj = globaldata->gGroupmap->groupIndex[groupNames[j]];
}
outSum.close();
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "LibShuffCommand", "printSummaryFile");
vector<string> groupNames;
void setGroups();
- void printCoverageFile();
- void printSummaryFile();
+ int printCoverageFile();
+ int printSummaryFile();
GlobalData* globaldata;
FullMatrix* matrix;
else if (alignfile != "") { inputFileName = alignfile; readAlign(); }
else if (listfile != "") { inputFileName = listfile; readList(); }
+ if (m->control_pressed) { return 0; }
+
//sort in alphabetical order
sort(names.begin(), names.end());
//output to .accnos file
for (int i = 0; i < names.size(); i++) {
+
+ if (m->control_pressed) { out.close(); remove(outputFileName.c_str()); return 0; }
+
out << names[i] << endl;
}
out.close();
+ if (m->control_pressed) { remove(outputFileName.c_str()); return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Name: "); m->mothurOutEndLine();
m->mothurOut(outputFileName); m->mothurOutEndLine();
}
//**********************************************************************************************************************
-void ListSeqsCommand::readFasta(){
+int ListSeqsCommand::readFasta(){
try {
ifstream in;
string name;
while(!in.eof()){
+
+ if (m->control_pressed) { in.close(); return 0; }
+
Sequence currSeq(in);
name = currSeq.getName();
gobble(in);
}
- in.close();
+ in.close();
+
+ return 0;
}
catch(exception& e) {
}
}
//**********************************************************************************************************************
-void ListSeqsCommand::readList(){
+int ListSeqsCommand::readList(){
try {
ifstream in;
openInputFile(listfile, in);
for (int i = 0; i < list.getNumBins(); i++) {
string binnames = list.get(i);
+ if (m->control_pressed) { in.close(); return 0; }
+
while (binnames.find_first_of(',') != -1) {
string name = binnames.substr(0,binnames.find_first_of(','));
binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
}
in.close();
+ return 0;
+
}
catch(exception& e) {
m->errorOut(e, "ListSeqsCommand", "readList");
}
//**********************************************************************************************************************
-void ListSeqsCommand::readName(){
+int ListSeqsCommand::readName(){
try {
ifstream in;
string name, firstCol, secondCol;
while(!in.eof()){
+
+ if (m->control_pressed) { in.close(); return 0; }
in >> firstCol;
in >> secondCol;
gobble(in);
}
in.close();
+ return 0;
}
catch(exception& e) {
}
//**********************************************************************************************************************
-void ListSeqsCommand::readGroup(){
+int ListSeqsCommand::readGroup(){
try {
ifstream in;
string name, group;
while(!in.eof()){
-
+
+ if (m->control_pressed) { in.close(); return 0; }
+
in >> name; //read from first column
in >> group; //read from second column
gobble(in);
}
in.close();
+ return 0;
}
catch(exception& e) {
//**********************************************************************************************************************
//alignreport file has a column header line then all other lines contain 16 columns. we just want the first column since that contains the name
-void ListSeqsCommand::readAlign(){
+int ListSeqsCommand::readAlign(){
try {
ifstream in;
while(!in.eof()){
+
+ if (m->control_pressed) { in.close(); return 0; }
in >> name; //read from first column
gobble(in);
}
in.close();
+
+ return 0;
}
string fastafile, namefile, groupfile, alignfile, inputFileName, outputDir, listfile;
bool abort;
- void readFasta();
- void readName();
- void readGroup();
- void readAlign();
- void readList();
+ int readFasta();
+ int readName();
+ int readGroup();
+ int readAlign();
+ int readList();
};
refSeqs = getKmerSeqs(query, numWanted); //fills indexes
}else { m->mothurOut("not valid search."); exit(1); } //should never get here
+ if (m->control_pressed) { return chimera; }
+
refSeqs = minCoverageFilter(refSeqs);
if (refSeqs.size() < 2) {
//fills outputResults
chimera = chimeraMaligner(chimeraPenalty, decalc);
-
+
+ if (m->control_pressed) { return chimera; }
//free memory
delete query;
vector< vector<score_struct> > matrix = buildScoreMatrix(query->getAligned().length(), refSeqs.size()); //builds and initializes
+ if (m->control_pressed) { return chimera; }
+
fillScoreMatrix(matrix, refSeqs, chimeraPenalty);
vector<score_struct> path = extractHighestPath(matrix);
+ if (m->control_pressed) { return chimera; }
+
vector<trace_struct> trace = mapTraceRegionsToAlignment(path, refSeqs);
if (trace.size() > 1) { chimera = "yes"; }
percentIdenticalQueryChimera = computePercentID(queryInRange, chimeraSeq);
+ if (m->control_pressed) { return chimera; }
+
//save output results
for (int i = 0; i < trace.size(); i++) {
int regionStart = trace[i].col;
if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); return 0;}
numGroups = lookup.size();
+
+ if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); return 0; }
//as long as you are not at the end of the file or done wih the lines you want
while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+ if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }
+
if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
process(lookup);
lookup = input->getSharedRAbundVectors();
}
+ if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
}
}
+ if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }
+
//run last label if you need to
if (needToRun == true) {
for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
}
-
+ if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }
+
//reset groups parameter
globaldata->Groups.clear();
}
}
/***********************************************************/
-void MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
+int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
try {
EstOutput data;
//initialize simMatrix
simMatrix.clear();
simMatrix.resize(numGroups);
- for (int m = 0; m < simMatrix.size(); m++) {
+ for (int p = 0; p < simMatrix.size(); p++) {
for (int j = 0; j < simMatrix.size(); j++) {
- simMatrix[m].push_back(0.0);
+ simMatrix[p].push_back(0.0);
}
}
if (k != l) { //we dont need to similiarity of a groups to itself
//get estimated similarity between 2 groups
+ if (m->control_pressed) { return 0; }
+
subset.clear(); //clear out old pair of sharedrabunds
//add new pair of sharedrabunds
subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]);
}
-
+ return 0;
}
catch(exception& e) {
private:
void printSims(ostream&);
- void process(vector<SharedRAbundVector*>);
+ int process(vector<SharedRAbundVector*>);
GlobalData* globaldata;
ReadOTUFile* read;
openInputFile(fileNames[i], inputFile);
while(!inputFile.eof()){
+ if (m->control_pressed) { inputFile.close(); outputFile.close(); remove(outputFileName.c_str()); return 0; }
+
c = inputFile.get();
//-1 is eof char
if (int(c) != -1) { outputFile << c; }
outputFile.close();
+ if (m->control_pressed) { remove(outputFileName.c_str()); return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Name: "); m->mothurOutEndLine();
m->mothurOut(outputFileName); m->mothurOutEndLine();
list = new ListVector(nameMap->getListVector());
RAbundVector* rabund = new RAbundVector(list->getRAbundVector());
+ if (m->control_pressed) { delete nameMap; delete read; delete list; delete rabund; return 0; }
+
start = time(NULL);
oldList = *list;
openOutputFile(fileroot+ tag + ".rabund", rabundFile);
openOutputFile(fileroot+ tag + ".sabund", sabundFile);
+ if (m->control_pressed) {
+ delete nameMap; delete read; delete list; delete rabund;
+ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+ return 0;
+ }
+
if (!hclusterWanted) {
//get distmatrix and overlap
SparseMatrix* distMatrix = read->getDistMatrix();
else if(method == "average"){ cluster = new AverageLinkage(rabund, list, distMatrix, cutoff, method); }
cluster->setMapWanted(true);
+ if (m->control_pressed) {
+ delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster;
+ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+ return 0;
+ }
+
//cluster using cluster classes
while (distMatrix->getSmallDist() < cutoff && distMatrix->getNNodes() > 0){
cluster->update(cutoff);
+
+ if (m->control_pressed) {
+ delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster;
+ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+ return 0;
+ }
+
float dist = distMatrix->getSmallDist();
float rndDist = roundDist(dist, precision);
if (merge) {
map<string, int> seq2Bin = cluster->getSeqtoBin();
ListVector* temp = mergeOPFs(seq2Bin, rndPreviousDist);
+
+ if (m->control_pressed) {
+ delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster; delete temp;
+ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+ return 0;
+ }
+
temp->setLabel(toString(rndPreviousDist, precisionLength-1));
printData(temp);
delete temp;
if (merge) {
map<string, int> seq2Bin = cluster->getSeqtoBin();
ListVector* temp = mergeOPFs(seq2Bin, rndPreviousDist);
+
+ if (m->control_pressed) {
+ delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster; delete temp;
+ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+ return 0;
+ }
+
temp->setLabel(toString(rndPreviousDist, precisionLength-1));
printData(temp);
delete temp;
//sort the distance and overlap files
sortHclusterFiles(distFile, overlapFile);
+
+ if (m->control_pressed) {
+ delete nameMap; delete list; delete rabund;
+ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+ return 0;
+ }
//create cluster
hcluster = new HCluster(rabund, list, method, distFile, nameMap, cutoff);
vector<seqDist> seqs; seqs.resize(1); // to start loop
//ifstream inHcluster;
//openInputFile(distFile, inHcluster);
+
+ if (m->control_pressed) {
+ delete nameMap; delete list; delete rabund; delete hcluster;
+ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+ return 0;
+ }
while (seqs.size() != 0){
seqs = hcluster->getSeqs();
+ if (m->control_pressed) {
+ delete nameMap; delete list; delete rabund; delete hcluster;
+ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+ remove(distFile.c_str());
+ remove(overlapFile.c_str());
+ return 0;
+ }
+
for (int i = 0; i < seqs.size(); i++) { //-1 means skip me
if (seqs[i].seq1 != seqs[i].seq2) {
hcluster->update(seqs[i].seq1, seqs[i].seq2, seqs[i].dist);
+
+ if (m->control_pressed) {
+ delete nameMap; delete list; delete rabund; delete hcluster;
+ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+ remove(distFile.c_str());
+ remove(overlapFile.c_str());
+ return 0;
+ }
float rndDist = roundDist(seqs[i].dist, precision);
if (merge) {
map<string, int> seq2Bin = hcluster->getSeqtoBin();
ListVector* temp = mergeOPFs(seq2Bin, rndPreviousDist);
+
+ if (m->control_pressed) {
+ delete nameMap; delete list; delete rabund; delete hcluster; delete temp;
+ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+ remove(distFile.c_str());
+ remove(overlapFile.c_str());
+ return 0;
+ }
+
temp->setLabel(toString(rndPreviousDist, precisionLength-1));
printData(temp);
delete temp;
if (merge) {
map<string, int> seq2Bin = hcluster->getSeqtoBin();
ListVector* temp = mergeOPFs(seq2Bin, rndPreviousDist);
+
+ if (m->control_pressed) {
+ delete nameMap; delete list; delete rabund; delete hcluster; delete temp;
+ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+ remove(distFile.c_str());
+ remove(overlapFile.c_str());
+ return 0;
+ }
+
temp->setLabel(toString(rndPreviousDist, precisionLength-1));
printData(temp);
delete temp;
globaldata->setListFile(fileroot+ tag + ".list");
globaldata->setFormat("list");
+ if (m->control_pressed) {
+ delete nameMap;
+ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+ globaldata->setListFile("");
+ globaldata->setFormat("");
+ return 0;
+ }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
m->mothurOut(fileroot+ tag + ".list"); m->mothurOutEndLine();
}else { if (overlapMatrix.size() == 0) { done = true; } }
while (!done) {
+ if (m->control_pressed) {
+ if (hclusterWanted) { inOverlap.close(); }
+ return newList;
+ }
//get next overlap
seqDist overlapNode;
MothurOut* m = MothurOut::getInstance();
ctrlc_pressed = 1;
m->control_pressed = ctrlc_pressed;
+
+ if (m->executing) { //if mid command quit execution, else quit mothur
+ m->mothurOutEndLine(); m->mothurOut("quitting command..."); m->mothurOutEndLine();
+ }else{
+ m->mothurOut("quitting mothur"); m->mothurOutEndLine();
+ exit(1);
+ }
}
/***********************************************************************/
int main(int argc, char *argv[]){
void mothurOutJustToLog(string);
void errorOut(exception&, string, string);
int control_pressed;
+ bool executing;
private:
//get listvectors that correspond to labels requested, (or use smart distancing to get closest listvector)
vector<ListVector> lists = getListVectors();
+ if (m->control_pressed) { return 0; }
+
//determine which is little and which is big, putting little first
if (lists.size() == 2) {
//if big is first swap them
//map sequences to bin number in the "little" otu
map<string, int> littleBins;
for (int i = 0; i < lists[0].getNumBins(); i++) {
+
+ if (m->control_pressed) { return 0; }
+
string names = lists[0].get(i);
//parse bin
//go through each bin in "big" otu and output the bins in "little" otu which created it
for (int i = 0; i < lists[1].getNumBins(); i++) {
+ if (m->control_pressed) { out.close(); remove(outputFileName.c_str()); return 0; }
+
string names = lists[1].get(i);
//output column 1
out.close();
+ if (m->control_pressed) { remove(outputFileName.c_str()); return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Name: "); m->mothurOutEndLine();
m->mothurOut(outputFileName); m->mothurOutEndLine();
}
while ((list != NULL) && (userLabels.size() != 0)) {
+
+ if (m->control_pressed) { in.close(); delete list; return lists; }
//is this a listvector that we want?
if(labels.count(list->getLabel()) == 1){
}else { list = NULL; }
}
-
+ if (m->control_pressed) { in.close(); return lists; }
//output error messages about any remaining user labels
set<string>::iterator it;
}
}
+ if (m->control_pressed) { in.close(); return lists; }
+
//run last label if you need to
if (needToRun == true) {
if (list != NULL) { delete list; }
}
}
-
+ in.close();
return lists;
}
catch(exception& e) {
list = input->getListVector();
string lastLabel = list->getLabel();
+ if (m->control_pressed) {
+ delete input; delete list; delete groupMap;
+ for (i=0; i<groupMap->namesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close(); delete filehandles[groupMap->namesOfGroups[i]]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+
+ if (m->control_pressed) {
+ delete input; delete list; delete groupMap;
+ for (i=0; i<groupMap->namesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close(); delete filehandles[groupMap->namesOfGroups[i]]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
if(allLines == 1 || labels.count(list->getLabel()) == 1){
- parse(list);
m->mothurOut(list->getLabel()); m->mothurOutEndLine();
-
+ parse(list);
+
processedLabels.insert(list->getLabel());
userLabels.erase(list->getLabel());
}
delete list;
list = input->getListVector(lastLabel); //get new list vector to process
- parse(list);
m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+ parse(list);
processedLabels.insert(list->getLabel());
userLabels.erase(list->getLabel());
list = input->getListVector(); //get new list vector to process
}
+ if (m->control_pressed) {
+ delete input; delete groupMap;
+ for (i=0; i<groupMap->namesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close(); delete filehandles[groupMap->namesOfGroups[i]]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
}
+ if (m->control_pressed) {
+ delete input; delete groupMap;
+ for (i=0; i<groupMap->namesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close(); delete filehandles[groupMap->namesOfGroups[i]]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
//run last label if you need to
if (needToRun == true) {
if (list != NULL) { delete list; }
list = input->getListVector(lastLabel); //get new list vector to process
- parse(list);
m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+ parse(list);
delete list;
}
delete it3->second;
}
+
delete groupMap;
+ delete input;
+
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
}
}
/**********************************************************************************************************************/
-void ParseListCommand::parse(ListVector* thisList) {
+int ParseListCommand::parse(ListVector* thisList) {
try {
map<string, string> groupVector;
for (int i = 0; i < thisList->getNumBins(); i++) {
+ if (m->control_pressed) { return 0; }
map<string, string> groupBins;
string bin = list->get(i);
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
(*(filehandles[it3->first])) << thisList->getLabel() << '\t' << groupNumBins[it3->first] << '\t' << groupVector[it3->first] << endl; // label numBins listvector for that group
}
-
+
+ return 0;
}
catch(exception& e) {
void help();
private:
- void parse(ListVector*);
+ int parse(ListVector*);
ListVector* list;
GroupMap* groupMap;
}
for(int i=copyTree->getNumLeaves();i<copyTree->getNumNodes();i++){
+
+ if (m->control_pressed) { return data; }
+
int lc = copyTree->tree[i].getLChild();
int rc = copyTree->tree[i].getRChild();
// map<string,int>::iterator it;
for(int i=copyTree->getNumLeaves();i<copyTree->getNumNodes();i++){
+
+ if (m->control_pressed) { return data; }
+
int lc = copyTree->tree[i].getLChild();
int rc = copyTree->tree[i].getRChild();
Progress* reading;
reading = new Progress("Comparing to random:", iters);
+ if (m->control_pressed) {
+ delete reading; delete pars; delete util; delete output;
+ if (randomtree == "") { outSum.close(); }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ globaldata->Groups.clear();
+ return 0;
+ }
+
+
//get pscore for users tree
userData.resize(numComp,0); //data = AB, AC, BC, ABC.
randomData.resize(numComp,0); //data = AB, AC, BC, ABC.
//get pscores for users trees
for (int i = 0; i < T.size(); i++) {
userData = pars->getValues(T[i]); //data = AB, AC, BC, ABC.
+
+ if (m->control_pressed) {
+ delete reading; delete pars; delete util; delete output;
+ if (randomtree == "") { outSum.close(); }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ globaldata->Groups.clear();
+ return 0;
+ }
+
//output scores for each combination
for(int k = 0; k < numComp; k++) {
//get pscores for random trees
for (int j = 0; j < iters; j++) {
+
//create new tree with same num nodes and leaves as users
randT = new Tree();
//get pscore of random tree
randomData = pars->getValues(randT);
+
+ if (m->control_pressed) {
+ delete reading; delete pars; delete util; delete output; delete randT;
+ if (randomtree == "") { outSum.close(); }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ globaldata->Groups.clear();
+ return 0;
+ }
for(int r = 0; r < numComp; r++) {
//add trees pscore to map of scores
}else {
//get pscores for random trees
for (int j = 0; j < iters; j++) {
+
//create new tree with same num nodes and leaves as users
randT = new Tree();
//create random relationships between nodes
randT->assembleRandomTree();
+
+ if (m->control_pressed) {
+ delete reading; delete pars; delete util; delete output; delete randT;
+ globaldata->gTreemap = savetmap;
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ globaldata->Groups.clear();
+ return 0;
+ }
+
//get pscore of random tree
randomData = pars->getValues(randT);
+
+ if (m->control_pressed) {
+ delete reading; delete pars; delete util; delete output; delete randT;
+ globaldata->gTreemap = savetmap;
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ globaldata->Groups.clear();
+ return 0;
+ }
for(int r = 0; r < numComp; r++) {
//add trees pscore to map of scores
}
}
+ if (m->control_pressed) {
+ delete reading; delete pars; delete util; delete output;
+ if (randomtree == "") { outSum.close(); }
+ else { globaldata->gTreemap = savetmap; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ globaldata->Groups.clear();
+ return 0;
+ }
+
//finish progress bar
reading->finish();
delete reading;
//reset groups parameter
globaldata->Groups.clear();
+ if (m->control_pressed) {
+ delete pars; delete util; delete output;
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
}
}
/***********************************************************/
-void ParsimonyCommand::printUSummaryFile() {
+int ParsimonyCommand::printUSummaryFile() {
try {
//column headers
outSum << "Tree#" << '\t' << "Groups" << '\t' << "ParsScore" << '\t' << "ParsSig" << endl;
//print each line
for (int i = 0; i< T.size(); i++) {
for(int a = 0; a < numComp; a++) {
+ if (m->control_pressed) { outSum.close(); return 0; }
if (UScoreSig[a][i] > (1/(float)iters)) {
outSum << setprecision(6) << i+1 << '\t' << groupComb[a] << '\t' << userTreeScores[a][i] << setprecision(itersString.length()) << '\t' << UScoreSig[a][i] << endl;
cout << setprecision(6) << i+1 << '\t' << groupComb[a] << '\t' << userTreeScores[a][i] << setprecision(itersString.length()) << '\t' << UScoreSig[a][i] << endl;
}
outSum.close();
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "ParsimonyCommand", "printUSummaryFile");
vector<string> Groups, outputNames; //holds groups to be used
void printParsimonyFile();
- void printUSummaryFile();
+ int printUSummaryFile();
void getUserInput();
};
vector<string> names;
vector<vector<double> > D;
- //fbase = filename;
- //if(fbase.find_last_of(".")!=string::npos){
- // fbase.erase(fbase.find_last_of(".")+1);
- //}
- //else{
- // fbase += ".";
- //}
-
fbase = outputDir + getRootName(getSimpleName(filename));
read(filename, names, D);
+
+ if (m->control_pressed) { return 0; }
double offset = 0.0000;
vector<double> d;
vector<vector<double> > copy_G;
//int rank = D.size();
- cout << "\nProcessing...\n";
+ m->mothurOut("\nProcessing...\n");
for(int count=0;count<2;count++){
- recenter(offset, D, G);
- tred2(G, d, e);
- qtli(d, e, G);
+ recenter(offset, D, G); if (m->control_pressed) { return 0; }
+ tred2(G, d, e); if (m->control_pressed) { return 0; }
+ qtli(d, e, G); if (m->control_pressed) { return 0; }
offset = d[d.size()-1];
if(offset > 0.0) break;
}
+ if (m->control_pressed) { return 0; }
output(fbase, names, G, d);
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
/*********************************************************************************************************************************/
-void PCACommand::read_phylip(istream& f, int square_m, vector<string>& name_list, vector<vector<double> >& d){
+int PCACommand::read_phylip(istream& f, int square_m, vector<string>& name_list, vector<vector<double> >& d){
try {
// int count1=0;
// int count2=0;
f >> name_list[i];
// cout << i << "\t" << name_list[i] << endl;
for(int j=0;j<rank;j++) {
+ if (m->control_pressed) { return 0; }
+
f >> d[i][j];
if (d[i][j] == -0.0000)
d[i][j] = 0.0000;
f >> name_list[i];
d[i][i]=0.0000;
for(int j=0;j<i;j++){
+ if (m->control_pressed) { return 0; }
f >> d[i][j];
if (d[i][j] == -0.0000)
d[i][j] = 0.0000;
}
}
}
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "PCACommand", "read_phylip");
vector<string> outputNames;
void get_comment(istream&, char, char);
- void read_phylip(istream&, int, vector<string>&, vector<vector<double> >&);
+ int read_phylip(istream&, int, vector<string>&, vector<vector<double> >&);
void read(string, vector<string>&, vector<vector<double> >&);
double pythag(double, double);
void matrix_mult(vector<vector<double> >, vector<vector<double> >, vector<vector<double> >&);
//make it as long as the longest taxonomy in the file
TaxEqualizer* taxEqual = new TaxEqualizer(taxonomyFileName, cutoff);
+ if (m->control_pressed) { delete taxEqual; return 0; }
+
string equalizedTaxFile = taxEqual->getEqualizedTaxFile();
delete taxEqual;
bool done = false;
if (tree->get(leaves[0]).parent == -1) { m->mothurOut("Empty Tree"); m->mothurOutEndLine(); done = true; }
+ if (m->control_pressed) { delete tree; return 0; }
+
string fileroot = outputDir + getRootName(getSimpleName(taxonomyFileName));
ofstream outList;
string level = toString(count);
count++;
+ if (m->control_pressed) {
+ outRabund.close(); outSabund.close(); outList.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ delete tree; return 0;
+ }
+
//is this a level the user want output for
if(allLines == 1 || labels.count(level) == 1){
delete tree;
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
}
}
//***************************************************************************************************************
-void Pintail::doPrep() {
+int Pintail::doPrep() {
try {
mergedFilterString = "";
if (consfile == "") {
m->mothurOut("Calculating probability of conservation for your template sequences. This can take a while... I will output the frequency of the highest base in each position to a .freq file so that you can input them using the conservation parameter next time you run this command. Providing the .freq file will improve speed. "); cout.flush();
probabilityProfile = decalc->calcFreq(templateSeqs, outputDir + getSimpleName(templateFileName));
+ if (m->control_pressed) { return 0; }
m->mothurOut("Done."); m->mothurOutEndLine();
}else { probabilityProfile = readFreq(); m->mothurOut("Done."); }
m->mothurOutEndLine();
vector<Sequence*> tempQuerySeqs;
while(!in.eof()){
+ if (m->control_pressed) {
+ for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i]; }
+ return 0;
+ }
+
Sequence* s = new Sequence(in);
gobble(in);
reRead = true;
//mask templates
for (int i = 0; i < temp.size(); i++) {
+ if (m->control_pressed) {
+ for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i]; }
+ return 0;
+ }
decalc->runMask(temp[i]);
}
}
mergedFilterString = createFilter(temp, 0.5);
+ if (m->control_pressed) {
+ for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i]; }
+ return 0;
+ }
+
//reread template seqs
for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i]; }
}
reRead = true;
//mask templates
for (int i = 0; i < templateSeqs.size(); i++) {
+ if (m->control_pressed) { return 0; }
decalc->runMask(templateSeqs[i]);
}
}
if (filter) {
reRead = true;
for (int i = 0; i < templateSeqs.size(); i++) {
+ if (m->control_pressed) { return 0; }
runFilter(templateSeqs[i]);
}
}
quantilesMembers = decalc->getQuantiles(templateSeqs, windowSizesTemplate, window, probabilityProfile, increment, 0, templateSeqs.size());
}else { createProcessesQuan(); }
+ if (m->control_pressed) { return 0; }
ofstream out4, out5;
string noOutliers, outliers;
noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.filtered." + getSimpleName(getRootName(fastafile)) + "quan";
}
-
-
-
decalc->removeObviousOutliers(quantilesMembers, templateSeqs.size());
+ if (m->control_pressed) { return 0; }
+
openOutputFile(noOutliers, out5);
//adjust quantiles
for (int i = 0; i < quantilesMembers.size(); i++) {
//free memory
for (int i = 0; i < templateLines.size(); i++) { delete templateLines[i]; }
+ return 0;
+
}
catch(exception& e) {
m->errorOut(e, "Pintail", "doPrep");
}
}
//***************************************************************************************************************
-void Pintail::print(ostream& out, ostream& outAcc) {
+int Pintail::print(ostream& out, ostream& outAcc) {
try {
int index = ceil(deviation);
for (int m = 0; m < expectedDistance.size(); m++) { out << expectedDistance[m] << '\t'; }
out << endl;
+ return 0;
}
catch(exception& e) {
//find pairs has to be done before a mask
bestfit = findPairs(query);
+ if (m->control_pressed) { return 0; }
+
//if they mask
if (seqMask != "") {
decalc->runMask(query);
//find observed distance
obsDistance = decalc->calcObserved(query, bestfit, windowsForeachQuery, windowSizes);
+
+ if (m->control_pressed) { return 0; }
Qav = decalc->findQav(windowsForeachQuery, windowSizes, probabilityProfile);
+
+ if (m->control_pressed) { return 0; }
//find alpha
seqCoef = decalc->getCoef(obsDistance, Qav);
//calculating expected distance
expectedDistance = decalc->calcExpected(Qav, seqCoef);
+ if (m->control_pressed) { return 0; }
+
//finding de
DE = decalc->calcDE(obsDistance, expectedDistance);
+ if (m->control_pressed) { return 0; }
+
//find distance between query and closest match
it = trimmed.begin();
deviation = decalc->calcDist(query, bestfit, it->first, it->second);
~Pintail();
int getChimeras(Sequence*);
- void print(ostream&, ostream&);
+ int print(ostream&, ostream&);
void setCons(string c) { consfile = c; }
void setQuantiles(string q) { quanfile = q; }
Sequence* findPairs(Sequence*);
void createProcessesQuan();
- void doPrep();
+ int doPrep();
};
//reads fasta file and return number of seqs
int numSeqs = readFASTA(); //fills alignSeqs and makes all seqs active
+
+ if (m->control_pressed) { return 0; }
if (numSeqs == 0) { m->mothurOut("Error reading fasta file...please correct."); m->mothurOutEndLine(); return 0; }
if (diffs > length) { m->mothurOut("Error: diffs is greater than your sequence length."); m->mothurOutEndLine(); return 0; }
//try to merge it with all smaller seqs
for (int j = i+1; j < numSeqs; j++) {
+
+ if (m->control_pressed) { return 0; }
+
if (alignSeqs[j].active) { //this sequence has not been merged yet
//are you within "diff" bases
int mismatch = calcMisMatches(alignSeqs[i].seq.getAligned(), alignSeqs[j].seq.getAligned());
string newFastaFile = fileroot + "precluster" + getExtension(fastafile);
string newNamesFile = fileroot + "precluster.names";
+ if (m->control_pressed) { return 0; }
m->mothurOut("Total number of sequences before precluster was " + toString(alignSeqs.size()) + "."); m->mothurOutEndLine();
m->mothurOut("pre.cluster removed " + toString(count) + " sequences."); m->mothurOutEndLine();
printData(newFastaFile, newNamesFile);
+ if (m->control_pressed) { remove(newFastaFile.c_str()); remove(newNamesFile.c_str()); return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
m->mothurOut(newFastaFile); m->mothurOutEndLine();
length = 0;
while (!inFasta.eof()) {
-
+
+ if (m->control_pressed) { inFasta.close(); return 0; }
+
//inNames >> firstCol >> secondCol;
//nameString = secondCol;
Progress::Progress(string job, int end){
try {
+ m = MothurOut::getInstance();
+
m->mothurOut("********************#****#****#****#****#****#****#****#****#****#****#\n");
cout << setw(20) << left << job << setw(1) << marker;
m->mothurOutJustToLog(job);
nTicks = 0;
finalPos = end;
+
}
catch(exception& e) {
m->errorOut(e, "Progress", "Progress");
/***********************************************************************/
-void Rarefact::getCurve(int increment = 1, int nIters = 1000){
+int Rarefact::getCurve(int increment = 1, int nIters = 1000){
try {
RarefactionCurveData* rcd = new RarefactionCurveData();
for(int i=0;i<displays.size();i++){
for(int i=0;i<numSeqs;i++){
+ if (m->control_pressed) { delete lookup; delete rank; delete rcd; return 0; }
+
int binNumber = order->get(i);
int abundance = lookup->get(binNumber);
displays[i]->close();
}
delete rcd;
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "Rarefact", "getCurve");
/***********************************************************************/
-void Rarefact::getSharedCurve(int increment = 1, int nIters = 1000){
+int Rarefact::getSharedCurve(int increment = 1, int nIters = 1000){
try {
SharedRarefactionCurveData* rcd = new SharedRarefactionCurveData();
vector<SharedRAbundVector*> subset;
//send each group one at a time
for (int k = 0; k < lookup.size(); k++) {
+ if (m->control_pressed) { delete merge; delete rcd; return 0; }
+
subset.clear(); //clears out old pair of sharedrabunds
//add in new pair of sharedrabunds
subset.push_back(merge); subset.push_back(lookup[k]);
}
delete rcd;
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "Rarefact", "getSharedCurve");
lookup(shared), displays(disp) { globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); }
~Rarefact(){};
- void getCurve(int, int);
- void getSharedCurve(int, int);
+ int getCurve(int, int);
+ int getSharedCurve(int, int);
private:
GlobalData* globaldata;
if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); }
else { inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); }
+ if (m->control_pressed) { return 0; }
+
for (int p = 0; p < inputFileNames.size(); p++) {
string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p]));
globaldata->inputFileName = inputFileNames[p];
+ if (m->control_pressed) { return 0; }
+
if (inputFileNames.size() > 1) {
m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
}
//if the users entered no valid calculators don't execute command
- if (rDisplays.size() == 0) { return 0; }
+ if (rDisplays.size() == 0) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } delete validCalculator; return 0; }
read = new ReadOTUFile(globaldata->inputFileName);
read->read(&*globaldata);
set<string> processedLabels;
set<string> userLabels = labels;
+ if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } delete validCalculator; delete read; delete input; globaldata->ginput = NULL; delete order; globaldata->gorder = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
//as long as you are not at the end of the file or done wih the lines you want
while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+ if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } delete validCalculator; delete read; delete input; globaldata->ginput = NULL; delete order; globaldata->gorder = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
+
if(allLines == 1 || labels.count(order->getLabel()) == 1){
+ m->mothurOut(order->getLabel()); m->mothurOutEndLine();
rCurve = new Rarefact(order, rDisplays);
rCurve->getCurve(freq, nIters);
delete rCurve;
- m->mothurOut(order->getLabel()); m->mothurOutEndLine();
processedLabels.insert(order->getLabel());
userLabels.erase(order->getLabel());
}
delete order;
order = (input->getOrderVector(lastLabel));
+ m->mothurOut(order->getLabel()); m->mothurOutEndLine();
rCurve = new Rarefact(order, rDisplays);
rCurve->getCurve(freq, nIters);
delete rCurve;
- m->mothurOut(order->getLabel()); m->mothurOutEndLine();
processedLabels.insert(order->getLabel());
userLabels.erase(order->getLabel());
order = (input->getOrderVector());
}
+ if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } delete validCalculator; delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
}
}
+ if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } delete validCalculator; delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
//run last label if you need to
if (needToRun == true) {
if (order != NULL) { delete order; }
order = (input->getOrderVector(lastLabel));
+ m->mothurOut(order->getLabel()); m->mothurOutEndLine();
rCurve = new Rarefact(order, rDisplays);
rCurve->getCurve(freq, nIters);
delete rCurve;
- m->mothurOut(order->getLabel()); m->mothurOutEndLine();
delete order;
}
}
-
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
input = globaldata->ginput;
lookup = input->getSharedRAbundVectors();
string lastLabel = lookup[0]->getLabel();
+
+ if (m->control_pressed) {
+ globaldata->Groups.clear();
+ for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ return 0;
+ }
+
if (lookup.size() < 2) {
m->mothurOut("I cannot run the command without at least 2 valid groups.");
//as long as you are not at the end of the file or done wih the lines you want
while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+ if (m->control_pressed) {
+ globaldata->Groups.clear();
+ for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ return 0;
+ }
if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
-
+ m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
rCurve = new Rarefact(lookup, rDisplays);
rCurve->getSharedCurve(freq, nIters);
delete rCurve;
- m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
processedLabels.insert(lookup[0]->getLabel());
userLabels.erase(lookup[0]->getLabel());
}
lookup = input->getSharedRAbundVectors();
}
+ if (m->control_pressed) {
+ globaldata->Groups.clear();
+ for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
}
}
+ if (m->control_pressed) {
+ globaldata->Groups.clear();
+ for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
//run last label if you need to
if (needToRun == true) {
for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }
//reset groups parameter
globaldata->Groups.clear();
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
//assumptions about the blast file:
//1. if duplicate lines occur the first line is always best and is chosen
//2. blast scores are grouped together, ie. a a .... score, a b .... score, a c ....score...
-void ReadBlast::read(NameAssignment* nameMap) {
+int ReadBlast::read(NameAssignment* nameMap) {
try {
//if the user has not given a names file read names from blastfile
if (nameMap->size() == 0) { readNames(nameMap); }
int nseqs = nameMap->size();
+
+ if (m->control_pressed) { return 0; }
ifstream fileHandle;
openInputFile(blastfile, fileHandle);
openOutputFile(overlapFile, outOverlap);
openOutputFile(distFile, outDist);
}
-
+
+ if (m->control_pressed) {
+ fileHandle.close();
+ if (!hclusterWanted) { delete matrix; }
+ else { outOverlap.close(); remove(overlapFile.c_str()); outDist.close(); remove(distFile.c_str()); }
+ return 0;
+ }
+
Progress* reading = new Progress("Reading blast: ", nseqs * nseqs);
//this is used to quickly find if we already have a distance for this combo
//read file
while(!fileHandle.eof()){
+
+ if (m->control_pressed) {
+ fileHandle.close();
+ if (!hclusterWanted) { delete matrix; }
+ else { outOverlap.close(); remove(overlapFile.c_str()); outDist.close(); remove(distFile.c_str()); }
+ delete reading;
+ return 0;
+ }
//read in line from file
fileHandle >> firstName >> secondName >> percentId >> numBases >> mismatch >> gap >> startQuery >> endQuery >> startRef >> endRef >> eScore >> score;
thisRowsBlastScores.clear();
dists.clear();
+ if (m->control_pressed) {
+ fileHandle.close();
+ if (!hclusterWanted) { delete matrix; }
+ else { outOverlap.close(); remove(overlapFile.c_str()); outDist.close(); remove(distFile.c_str()); }
+ delete reading;
+ return 0;
+ }
+
if (!hclusterWanted) {
sort(overlap.begin(), overlap.end(), compareOverlap);
}else {
outOverlap.close();
}
+ if (m->control_pressed) {
+ fileHandle.close();
+ if (!hclusterWanted) { delete matrix; }
+ else { remove(overlapFile.c_str()); remove(distFile.c_str()); }
+ delete reading;
+ return 0;
+ }
+
reading->finish();
delete reading;
fileHandle.close();
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "ReadBlast", "read");
}
}
/*********************************************************************************************/
-void ReadBlast::readNames(NameAssignment* nameMap) {
+int ReadBlast::readNames(NameAssignment* nameMap) {
try {
m->mothurOut("Reading names... "); cout.flush();
nameMap->push_back(prevName);
while (!in.eof()) {
+ if (m->control_pressed) { in.close(); return 0; }
//read line
in >> name;
//openOutputFile(outNames, out);
//nameMap->print(out);
//out.close();
+ if (m->control_pressed) { return 0; }
m->mothurOut(toString(num) + " names read."); m->mothurOutEndLine();
+ return 0;
+
}
catch(exception& e) {
m->errorOut(e, "ReadBlast", "readNames");
ReadBlast(string, float, float, int, bool, bool); //blastfile, cutoff, penalty, length of overlap, min or max bsr, hclusterWanted
~ReadBlast() {}
- void read(NameAssignment*);
+ int read(NameAssignment*);
SparseMatrix* getDistMatrix() { return matrix; }
vector<seqDist> getOverlapMatrix() { return overlap; }
string getOverlapFile() { return overlapFile; }
vector<seqDist> overlap;
MothurOut* m;
- void readNames(NameAssignment*);
+ int readNames(NameAssignment*);
};
/*******************************************************************************************/
/***********************************************************************/
-void ReadCluster::read(NameAssignment* nameMap){
+int ReadCluster::read(NameAssignment* nameMap){
try {
if (format == "phylip") { convertPhylip2Column(nameMap); }
else { list = new ListVector(nameMap->getListVector()); }
+ if (m->control_pressed) { return 0; }
+
OutPutFile = sortFile(distFile);
+
+ return 0;
}
catch(exception& e) {
}
/***********************************************************************/
-void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
+int ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
try {
//convert phylip file to column file
map<int, string> rowToName;
list->set(i, name);
for(int j=0;j<i;j++){
+
+ if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+
in >> distance;
if (distance == -1) { distance = 1000000; }
if(nameMap->count(name)==0){ m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); }
for(int j=0;j<i;j++){
+
+ if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+
in >> distance;
if (distance == -1) { distance = 1000000; }
if(nameMap == NULL){
list->set(i, name);
for(int j=0;j<nseqs;j++){
+ if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+
in >> distance;
if (distance == -1) { distance = 1000000; }
if(nameMap->count(name)==0){ m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); }
for(int j=0;j<nseqs;j++){
+ if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+
in >> distance;
if (distance == -1) { distance = 1000000; }
float dist;
while (in2) {
+ if (m->control_pressed) { in2.close(); out2.close(); remove(tempFile.c_str()); remove(outputFile.c_str()); return 0; }
+
in2 >> first >> second >> dist;
out2 << rowToName[first] << '\t' << rowToName[second] << '\t' << dist << endl;
gobble(in2);
remove(tempFile.c_str());
distFile = outputFile;
+
+ if (m->control_pressed) { remove(outputFile.c_str()); }
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "ReadCluster", "convertPhylip2Column");
public:
ReadCluster(string, float);
~ReadCluster();
- void read(NameAssignment*);
+ int read(NameAssignment*);
string getOutputFile() { return OutPutFile; }
void setFormat(string f) { format = f; }
ListVector* getListVector() { return list; }
float cutoff;
MothurOut* m;
- void convertPhylip2Column(NameAssignment*);
+ int convertPhylip2Column(NameAssignment*);
};
/******************************************************/
\r
/***********************************************************************/\r
\r
-void ReadColumnMatrix::read(NameAssignment* nameMap){\r
+int ReadColumnMatrix::read(NameAssignment* nameMap){\r
try { \r
\r
string firstName, secondName;\r
//need to see if this is a square or a triangular matrix...\r
\r
while(fileHandle && lt == 1){ //let's assume it's a triangular matrix...\r
+\r
\r
fileHandle >> firstName >> secondName >> distance; // get the row and column names and distance\r
+ \r
+ if (m->control_pressed) { fileHandle.close(); delete reading; return 0; }\r
\r
map<string,int>::iterator itA = nameMap->find(firstName);\r
map<string,int>::iterator itB = nameMap->find(secondName);\r
\r
while(fileHandle){\r
fileHandle >> firstName >> secondName >> distance;\r
+ \r
+ if (m->control_pressed) { fileHandle.close(); delete reading; return 0; }\r
\r
map<string,int>::iterator itA = nameMap->find(firstName);\r
map<string,int>::iterator itB = nameMap->find(secondName);\r
gobble(fileHandle);\r
}\r
}\r
-\r
+ \r
+ if (m->control_pressed) { fileHandle.close(); delete reading; return 0; }\r
+ \r
reading->finish();\r
fileHandle.close();\r
\r
list->setLabel("0");\r
+ \r
+ return 1;\r
\r
}\r
catch(exception& e) {\r
public:
ReadColumnMatrix(string);
~ReadColumnMatrix();
- void read(NameAssignment*);
+ int read(NameAssignment*);
private:
ifstream fileHandle;
string distFile;
size_t numDists = 0;
vector<string> outputNames;
-
+cout << format << endl;
if (format == "matrix") {
ifstream in;
openInputFile(distFileName, in);
matrix = new FullMatrix(in); //reads the matrix file
in.close();
+ if (m->control_pressed) { delete groupMap; delete matrix; return 0; }
+
//if files don't match...
if (matrix->getNumSeqs() < groupMap->getNumSeqs()) {
m->mothurOut("Your distance file contains " + toString(matrix->getNumSeqs()) + " sequences, and your group file contains " + toString(groupMap->getNumSeqs()) + " sequences."); m->mothurOutEndLine();
openOutputFile(newGroupFile, outGroups);
for (int i = 0; i < matrix->getNumSeqs(); i++) {
+ if (m->control_pressed) { delete groupMap; delete matrix; outGroups.close(); remove(newGroupFile.c_str()); return 0; }
+
Names temp = matrix->getRowInfo(i);
outGroups << temp.seqName << '\t' << temp.groupName << endl;
}
groupMap = new GroupMap(groupfile);
groupMap->readMap();
+ if (m->control_pressed) { delete groupMap; delete matrix; remove(newGroupFile.c_str()); return 0; }
+
globaldata->gGroupmap = groupMap;
}
} else {
read->read(nameMap);
//to prevent memory leak
-
+
+ if (m->control_pressed) { return 0; }
+
if (globaldata->gListVector != NULL) { delete globaldata->gListVector; }
globaldata->gListVector = read->getListVector();
if (globaldata->gSparseMatrix != NULL) { delete globaldata->gSparseMatrix; }
globaldata->gSparseMatrix = read->getMatrix();
numDists = globaldata->gSparseMatrix->getNNodes();
- //cout << "matrix contains " << numDists << " distances." << endl;
-
- /* int lines = cutoff / (1.0/precision);
- vector<float> dist_cutoff(lines+1,0);
- for (int i = 0; i <= lines;i++) {
- dist_cutoff[i] = (i + 0.5) / precision;
- }
- vector<int> dist_count(lines+1,0);
- list<PCell>::iterator currentCell;
- SparseMatrix* smatrix = globaldata->gSparseMatrix;
- for (currentCell = smatrix->begin(); currentCell != smatrix->end(); currentCell++) {
- for (int i = 0; i <= lines;i++) {
- if (currentCell->dist < dist_cutoff[i]) {
- dist_count[i]++;
- break;
- }
- }
- }
-*/
- // string dist_string = "Dist:";
- // string count_string = "Count: ";
- //for (int i = 0; i <= lines;i++) {
- //dist_string = dist_string.append("\t").append(toString(dist_cutoff[i]));
- // count_string = count_string.append("\t").append(toString(dist_count[i]));
- // }
- //m->mothurOut(dist_string); m->mothurOutEndLine(); m->mothurOut(count_string); m->mothurOutEndLine();
}
+ if (m->control_pressed) { return 0; }
+
if (outputNames.size() != 0) {
m->mothurOutEndLine();
m->mothurOut("Output File Name: "); m->mothurOutEndLine();
public:
ReadMatrix(){ D = new SparseMatrix(); m = MothurOut::getInstance(); }
virtual ~ReadMatrix() {}
- virtual void read(NameAssignment*){};
- virtual void read(GlobalData* globaldata){};
+ virtual int read(NameAssignment*){ return 1; }
+
void setCutoff(float c) { cutoff = c; }
SparseMatrix* getMatrix() { return D; }
ListVector* getListVector() { return list; }
/***********************************************************************/
-void ReadPhylipMatrix::read(NameAssignment* nameMap){
+int ReadPhylipMatrix::read(NameAssignment* nameMap){
try {
float distance;
int index = 0;
for(int i=1;i<nseqs;i++){
+ if (m->control_pressed) { fileHandle.close(); delete reading; return 0; }
+
fileHandle >> name;
matrixNames.push_back(name);
+
//there's A LOT of repeated code throughout this method...
if(nameMap == NULL){
list->set(i, name);
for(int j=0;j<i;j++){
+
+ if (m->control_pressed) { delete reading; fileHandle.close(); return 0; }
+
fileHandle >> distance;
+
if (distance == -1) { distance = 1000000; }
for(int j=0;j<i;j++){
fileHandle >> distance;
+
+ if (m->control_pressed) { delete reading; fileHandle.close(); return 0; }
if (distance == -1) { distance = 1000000; }
for(int i=1;i<nseqs;i++){
fileHandle >> name;
matrixNames.push_back(name);
+
+
if(nameMap == NULL){
list->set(i, name);
for(int j=0;j<nseqs;j++){
fileHandle >> distance;
-
+
+ if (m->control_pressed) { fileHandle.close(); delete reading; return 0; }
+
if (distance == -1) { distance = 1000000; }
if(distance < cutoff && j < i){
for(int j=0;j<nseqs;j++){
fileHandle >> distance;
-
+
+ if (m->control_pressed) { fileHandle.close(); delete reading; return 0; }
+
if (distance == -1) { distance = 1000000; }
if(distance < cutoff && j < i){
}
}
}
+
+ if (m->control_pressed) { fileHandle.close(); delete reading; return 0; }
+
reading->finish();
delete reading;
m->mothurOut("missed something\t" + toString(nameMap->size())); m->mothurOutEndLine();
}
} */
+
+ return 1;
}
catch(exception& e) {
public:
ReadPhylipMatrix(string);
~ReadPhylipMatrix();
- void read(NameAssignment*);
+ int read(NameAssignment*);
private:
ifstream fileHandle;
string distFile;
int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) {
try {
+
+ if (m->control_pressed) { return -1; }
+
int c = readNodeChar(f);
if(c == '('){
//assemble users trees
for (int i = 0; i < T.size(); i++) {
+ if (m->control_pressed) {
+ for (int i = 0; i < T.size(); i++) { delete T[i]; }
+ globaldata->gTree.clear();
+ delete globaldata->gTreemap;
+ return 0;
+ }
+
T[i]->assembleTree();
}
count++;
}
+ if (m->control_pressed) {
+ for (int i = 0; i < T.size(); i++) { delete T[i]; }
+ globaldata->gTree.clear();
+ delete globaldata->gTreemap;
+ return 0;
+ }
+
//then you did not find it so report it
if (count == globaldata->Treenames.size()) {
//if it is in your namefile then don't remove
//get names you want to keep
readAccnos();
+ if (m->control_pressed) { return 0; }
+
//read through the correct file and output lines you want to keep
if (fastafile != "") { readFasta(); }
else if (namefile != "") { readName(); }
else if (alignfile != "") { readAlign(); }
else if (listfile != "") { readList(); }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
if (outputNames.size() != 0) {
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
}
//**********************************************************************************************************************
-void RemoveSeqsCommand::readFasta(){
+int RemoveSeqsCommand::readFasta(){
try {
if (outputDir == "") { outputDir += hasPath(fastafile); }
string outputFileName = getRootName(fastafile) + "pick" + getExtension(fastafile);
bool wroteSomething = false;
while(!in.eof()){
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; }
+
Sequence currSeq(in);
name = currSeq.getName();
m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();
remove(outputFileName.c_str());
}else { outputNames.push_back(outputFileName); }
-
+
+ return 0;
+
}
catch(exception& e) {
m->errorOut(e, "RemoveSeqsCommand", "readFasta");
}
}
//**********************************************************************************************************************
-void RemoveSeqsCommand::readList(){
+int RemoveSeqsCommand::readList(){
try {
if (outputDir == "") { outputDir += hasPath(listfile); }
string outputFileName = getRootName(listfile) + "pick" + getExtension(listfile);
//for each bin
for (int i = 0; i < list.getNumBins(); i++) {
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; }
//parse out names that are in accnos file
string binnames = list.get(i);
m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();
remove(outputFileName.c_str());
}else { outputNames.push_back(outputFileName); }
+
+ return 0;
}
catch(exception& e) {
}
}
//**********************************************************************************************************************
-void RemoveSeqsCommand::readName(){
+int RemoveSeqsCommand::readName(){
try {
if (outputDir == "") { outputDir += hasPath(namefile); }
string outputFileName = getRootName(namefile) + "pick" + getExtension(namefile);
bool wroteSomething = false;
while(!in.eof()){
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); if (dups) { out2.close(); remove(outputFileName2.c_str()); } return 0; }
in >> firstCol;
in >> secondCol;
remove(outputFileName.c_str());
}else { outputNames.push_back(outputFileName); }
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "RemoveSeqsCommand", "readName");
}
//**********************************************************************************************************************
-void RemoveSeqsCommand::readGroup(){
+int RemoveSeqsCommand::readGroup(){
try {
if (outputDir == "") { outputDir += hasPath(groupfile); }
string outputFileName = getRootName(groupfile) + "pick" + getExtension(groupfile);
bool wroteSomething = false;
while(!in.eof()){
-
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; }
+
in >> name; //read from first column
in >> group; //read from second column
m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();
remove(outputFileName.c_str());
}else { outputNames.push_back(outputFileName); }
-
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "RemoveSeqsCommand", "readGroup");
//**********************************************************************************************************************
//alignreport file has a column header line then all other lines contain 16 columns. we just want the first column since that contains the name
-void RemoveSeqsCommand::readAlign(){
+int RemoveSeqsCommand::readAlign(){
try {
if (outputDir == "") { outputDir += hasPath(alignfile); }
string outputFileName = getRootName(getRootName(alignfile)) + "pick.align.report";
out << endl;
while(!in.eof()){
-
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; }
+
in >> name; //read from first column
//if this name is in the accnos file
remove(outputFileName.c_str());
}else { outputNames.push_back(outputFileName); }
+ return 0;
+
}
catch(exception& e) {
m->errorOut(e, "RemoveSeqsCommand", "readAlign");
bool abort, dups;
vector<string> outputNames;
- void readFasta();
- void readName();
- void readGroup();
- void readAlign();
+ int readFasta();
+ int readName();
+ int readGroup();
+ int readAlign();
void readAccnos();
- void readList();
+ int readList();
};
openOutputFile(reverseFile, outFASTA);
while(!inFASTA.eof()){
+ if (m->control_pressed) { inFASTA.close(); outFASTA.close(); remove(reverseFile.c_str()); return 0; }
+
Sequence currSeq(inFASTA); gobble(inFASTA);
if (currSeq.getName() != "") {
currSeq.reverseComplement();
inFASTA.close();
outFASTA.close();
+ if (m->control_pressed) { remove(reverseFile.c_str()); return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Name: "); m->mothurOutEndLine();
m->mothurOut(reverseFile); m->mothurOutEndLine();
ofstream badSeqOut; openOutputFile(badSeqFile, badSeqOut);
while(!inFASTA.eof()){
+ if (m->control_pressed) { goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+
Sequence currSeq(inFASTA);
if (currSeq.getName() != "") {
bool goodSeq = 1; // innocent until proven guilty
}
}
gobble(inFASTA);
- }
- if(namefile != "" && groupfile != "") { screenNameGroupFile(badSeqNames); } // this screens both names and groups
- else if(namefile != "") { screenNameGroupFile(badSeqNames); }
- else if(groupfile != "") { screenGroupFile(badSeqNames); } // this screens just the groups
+ }
+
+ if(namefile != "" && groupfile != "") {
+ screenNameGroupFile(badSeqNames);
+ if (m->control_pressed) { goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+ }else if(namefile != "") {
+ screenNameGroupFile(badSeqNames);
+ if (m->control_pressed) { goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+ }else if(groupfile != "") { screenGroupFile(badSeqNames); } // this screens just the group
+
+ if (m->control_pressed) { goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+
if(alignreport != "") { screenAlignReport(badSeqNames); }
goodSeqOut.close();
badSeqOut.close();
inFASTA.close();
+
+ if (m->control_pressed) { remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
m->mothurOut(goodSeqFile); m->mothurOutEndLine();
m->mothurOut(badSeqFile); m->mothurOutEndLine();
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
m->mothurOutEndLine();
//***************************************************************************************************************
-void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
+int ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
ifstream inputNames;
openInputFile(namefile, inputNames);
string goodNameFile = outputDir + getRootName(getSimpleName(namefile)) + "good" + getExtension(namefile);
string badNameFile = outputDir + getRootName(getSimpleName(namefile)) + "bad" + getExtension(namefile);
+ outputNames.push_back(goodNameFile); outputNames.push_back(badNameFile);
+
ofstream goodNameOut; openOutputFile(goodNameFile, goodNameOut);
ofstream badNameOut; openOutputFile(badNameFile, badNameOut);
while(!inputNames.eof()){
+ if (m->control_pressed) { goodNameOut.close(); badNameOut.close(); inputNames.close(); remove(goodNameFile.c_str()); remove(badNameFile.c_str()); return 0; }
+
inputNames >> seqName >> seqList;
it = badSeqNames.find(seqName);
string goodGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "good" + getExtension(groupfile);
string badGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "bad" + getExtension(groupfile);
+ outputNames.push_back(goodGroupFile); outputNames.push_back(badGroupFile);
+
ofstream goodGroupOut; openOutputFile(goodGroupFile, goodGroupOut);
ofstream badGroupOut; openOutputFile(badGroupFile, badGroupOut);
while(!inputGroups.eof()){
+ if (m->control_pressed) { goodGroupOut.close(); badGroupOut.close(); inputGroups.close(); remove(goodNameFile.c_str()); remove(badNameFile.c_str()); remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); return 0; }
+
inputGroups >> seqName >> group;
it = badSeqGroups.find(seqName);
}
}
}
+
+ return 0;
+
}
//***************************************************************************************************************
-void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
+int ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
ifstream inputGroups;
openInputFile(groupfile, inputGroups);
string goodGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "good" + getExtension(groupfile);
string badGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "bad" + getExtension(groupfile);
+ outputNames.push_back(goodGroupFile); outputNames.push_back(badGroupFile);
+
ofstream goodGroupOut; openOutputFile(goodGroupFile, goodGroupOut);
ofstream badGroupOut; openOutputFile(badGroupFile, badGroupOut);
while(!inputGroups.eof()){
+ if (m->control_pressed) { goodGroupOut.close(); badGroupOut.close(); inputGroups.close(); remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); return 0; }
+
inputGroups >> seqName >> group;
it = badSeqNames.find(seqName);
gobble(inputGroups);
}
+ if (m->control_pressed) { goodGroupOut.close(); badGroupOut.close(); inputGroups.close(); remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); return 0; }
+
//we were unable to remove some of the bad sequences
if (badSeqNames.size() != 0) {
for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {
goodGroupOut.close();
badGroupOut.close();
+ if (m->control_pressed) { remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); }
+
+
+ return 0;
+
}
//***************************************************************************************************************
-void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
+int ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
ifstream inputAlignReport;
openInputFile(alignreport, inputAlignReport);
string goodAlignReportFile = outputDir + getRootName(getSimpleName(alignreport)) + "good" + getExtension(alignreport);
string badAlignReportFile = outputDir + getRootName(getSimpleName(alignreport)) + "bad" + getExtension(alignreport);
+ outputNames.push_back(goodAlignReportFile); outputNames.push_back(badAlignReportFile);
+
ofstream goodAlignReportOut; openOutputFile(goodAlignReportFile, goodAlignReportOut);
ofstream badAlignReportOut; openOutputFile(badAlignReportFile, badAlignReportOut);
}
while(!inputAlignReport.eof()){
+ if (m->control_pressed) { goodAlignReportOut.close(); badAlignReportOut.close(); inputAlignReport.close(); remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; }
+
inputAlignReport >> seqName;
it = badSeqNames.find(seqName);
string line;
gobble(inputAlignReport);
}
+ if (m->control_pressed) { goodAlignReportOut.close(); badAlignReportOut.close(); inputAlignReport.close(); remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; }
+
//we were unable to remove some of the bad sequences
if (badSeqNames.size() != 0) {
for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {
inputAlignReport.close();
goodAlignReportOut.close();
badAlignReportOut.close();
+
+ if (m->control_pressed) { remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; }
+
+ return 0;
+
}
void help();
private:
- void screenNameGroupFile(set<string>);
- void screenGroupFile(set<string>);
- void screenAlignReport(set<string>);
+ int screenNameGroupFile(set<string>);
+ int screenGroupFile(set<string>);
+ int screenAlignReport(set<string>);
bool abort;
string fastafile, namefile, groupfile, alignreport, outputDir;
int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength;
+ vector<string> outputNames;
};
#endif
while(!in.eof()){
+ if (m->control_pressed) { in.close(); out.close(); remove(outfile.c_str()); return 0; }
Sequence seq(in); gobble(in);
if (seq.getName() != "") {
in.close();
out.close();
+ if (m->control_pressed) { remove(outfile.c_str()); return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Name: "); m->mothurOutEndLine();
m->mothurOut(outfile); m->mothurOutEndLine();
outSummary << "seqname\tstart\tend\tnbases\tambigs\tpolymer" << endl;
while(!inFASTA.eof()){
+ if (m->control_pressed) { inFASTA.close(); outSummary.close(); remove(summaryFile.c_str()); return 0; }
+
Sequence current(inFASTA);
if (current.getName() != "") {
startPosition.push_back(current.getStartPos());
if (startPosition[0] == -1) { startPosition[0] = 0; }
if (endPosition[0] == -1) { endPosition[0] = 0; }
+ if (m->control_pressed) { outSummary.close(); remove(summaryFile.c_str()); return 0; }
+
m->mothurOutEndLine();
m->mothurOut("\t\tStart\tEnd\tNBases\tAmbigs\tPolymer"); m->mothurOutEndLine();
m->mothurOut("Minimum:\t" + toString(startPosition[0]) + "\t" + toString(endPosition[0]) + "\t" + toString(seqLength[0]) + "\t" + toString(ambigBases[0]) + "\t" + toString(longHomoPolymer[0])); m->mothurOutEndLine();
outSummary.close();
+ if (m->control_pressed) { remove(summaryFile.c_str()); return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Name: "); m->mothurOutEndLine();
m->mothurOut(summaryFile); m->mothurOutEndLine();
//clears file before we start to write to it below
for (int i=0; i<groups.size(); i++) {
remove((fileroot + groups[i] + ".rabund").c_str());
+ outputNames.push_back((fileroot + groups[i] + ".rabund"));
}
}
string lastLabel = SharedList->getLabel();
vector<SharedRAbundVector*> lookup;
+ if (m->control_pressed) {
+ delete input; delete SharedList; globaldata->ginput = NULL; globaldata->gSharedList = NULL;
+ for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
+ out.close(); remove(filename.c_str());
+ for (int i=0; i<groups.size(); i++) { remove((fileroot + groups[i] + ".rabund").c_str()); }
+ return 1;
+ }
+
if ((globaldata->Groups.size() == 0) && (SharedList->getNumSeqs() != groupMap->getNumSeqs())) { //if the user has not specified any groups and their files don't match exit with error
m->mothurOut("Your group file contains " + toString(groupMap->getNumSeqs()) + " sequences and list file contains " + toString(SharedList->getNumSeqs()) + " sequences. Please correct."); m->mothurOutEndLine();
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
delete it3->second;
}
+ delete input;
+ globaldata->ginput = NULL;
delete SharedList;
globaldata->gSharedList = NULL;
set<string> userLabels = globaldata->labels;
while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+ if (m->control_pressed) {
+ delete input; delete SharedList; globaldata->ginput = NULL; globaldata->gSharedList = NULL;
+ for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
+ out.close(); remove(filename.c_str());
+ for (int i=0; i<groups.size(); i++) { remove((fileroot + groups[i] + ".rabund").c_str()); }
+ return 1;
+ }
if(globaldata->allLines == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
-
+
lookup = SharedList->getSharedRAbundVector();
+ m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
if (pickedGroups) { //check for otus with no seqs in them
eliminateZeroOTUS(lookup);
}
- m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
+
+ if (m->control_pressed) {
+ delete input; delete SharedList; globaldata->ginput = NULL; globaldata->gSharedList = NULL;
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
+ out.close(); remove(filename.c_str());
+ for (int i=0; i<groups.size(); i++) { remove((fileroot + groups[i] + ".rabund").c_str()); }
+ return 1;
+ }
printSharedData(lookup); //prints info to the .shared file
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
SharedList = input->getSharedListVector(lastLabel); //get new list vector to process
lookup = SharedList->getSharedRAbundVector();
+ m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
if (pickedGroups) { //check for otus with no seqs in them
eliminateZeroOTUS(lookup);
}
- m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
+
+
+ if (m->control_pressed) {
+ delete input; delete SharedList; globaldata->ginput = NULL; globaldata->gSharedList = NULL;
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
+ out.close(); remove(filename.c_str());
+ for (int i=0; i<groups.size(); i++) { remove((fileroot + groups[i] + ".rabund").c_str()); }
+ return 1;
+ }
printSharedData(lookup); //prints info to the .shared file
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
SharedList = input->getSharedListVector(lastLabel); //get new list vector to process
lookup = SharedList->getSharedRAbundVector();
+ m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
if (pickedGroups) { //check for otus with no seqs in them
eliminateZeroOTUS(lookup);
}
- m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
+
+ if (m->control_pressed) {
+ delete input; globaldata->ginput = NULL;
+ for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
+ out.close(); remove(filename.c_str());
+ for (int i=0; i<groups.size(); i++) { remove((fileroot + groups[i] + ".rabund").c_str()); }
+ return 1;
+ }
printSharedData(lookup); //prints info to the .shared file
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
globaldata->setListFile("");
globaldata->setGroupFile("");
globaldata->setSharedFile(filename);
-
+
+ if (m->control_pressed) {
+ delete input; globaldata->ginput = NULL;
+ remove(filename.c_str());
+ for (int i=0; i<groups.size(); i++) { remove((fileroot + groups[i] + ".rabund").c_str()); }
+ return 1;
+ }
+
+ m->mothurOutEndLine();
+ m->mothurOut("Output File Names: "); m->mothurOutEndLine();
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
+ m->mothurOut(filename); m->mothurOutEndLine();
+ m->mothurOutEndLine();
return 0;
}
}
}
//**********************************************************************************************************************
-void SharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
+int SharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
try {
vector<SharedRAbundVector*> newLookup;
//for each bin
for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
+ if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; }
//look at each sharedRabund and make sure they are not all zero
bool allZero = true;
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
-
+
+ return 0;
}
catch(exception& e) {
}
}
//**********************************************************************************************************************
-void SharedCommand::createMisMatchFile() {
+int SharedCommand::createMisMatchFile() {
try {
ofstream outMisMatch;
string outputMisMatchName = outputDir + getRootName(getSimpleName(globaldata->inputFileName));
//go through list and if group returns "not found" output it
for (int i = 0; i < SharedList->getNumBins(); i++) {
+ if (m->control_pressed) { outMisMatch.close(); remove(outputMisMatchName.c_str()); return 0; }
string names = SharedList->get(i);
//go through listfile and get names
for (int i = 0; i < SharedList->getNumBins(); i++) {
+ if (m->control_pressed) { return 0; }
+
string names = SharedList->get(i);
//loop through names in seqNames and if they aren't in namesIn list output them
for (int i = 0; i < seqNames.size(); i++) {
+ if (m->control_pressed) { outMisMatch.close(); remove(outputMisMatchName.c_str()); return 0; }
itMatch = namesInList.find(seqNames[i]);
}
outMisMatch.close();
}
-
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "SharedCommand", "createMisMatchFile");
private:
void printSharedData(vector<SharedRAbundVector*>);
- void createMisMatchFile();
+ int createMisMatchFile();
bool isValidGroup(string, vector<string>);
- void eliminateZeroOTUS(vector<SharedRAbundVector*>&);
+ int eliminateZeroOTUS(vector<SharedRAbundVector*>&);
GlobalData* globaldata;
ReadOTUFile* read;
SharedListVector* SharedList;
InputData* input;
GroupMap* groupMap;
- vector<string> groups;
+ vector<string> groups, outputNames;
ofstream out;
string filename, fileroot, outputDir;
bool firsttime, pickedGroups;
for (int i = 0; i < refSeqs.size(); i++) {
for (int j = i+1; j < refSeqs.size(); j++) {
+
+ if (m->control_pressed) { return "no"; }
//make copies of query and each parent because runBellerophon removes gaps and messes them up
Sequence* q = new Sequence(query->getName(), query->getAligned());
map<int, int> spots; //map from spot in original sequence to spot in filtered sequence for query and both parents
vector<data_struct> divs = runBellerophon(q, leftParent, rightParent, spots);
+ if (m->control_pressed) {
+ delete q;
+ delete leftParent;
+ delete rightParent;
+ return "no";
+ }
+
vector<data_struct> selectedDivs;
for (int k = 0; k < divs.size(); k++) {
vector<snps> snpsLeft = getSNPS(divs[k].parentA.getAligned(), divs[k].querySeq.getAligned(), divs[k].parentB.getAligned(), divs[k].winLStart, divs[k].winLEnd);
vector<snps> snpsRight = getSNPS(divs[k].parentA.getAligned(), divs[k].querySeq.getAligned(), divs[k].parentB.getAligned(), divs[k].winRStart, divs[k].winREnd);
+ if (m->control_pressed) {
+ delete q;
+ delete leftParent;
+ delete rightParent;
+ return "no";
+ }
+
int numSNPSLeft = snpsLeft.size();
int numSNPSRight = snpsRight.size();
float BS_A, BS_B;
bootstrapSNPS(snpsLeft, snpsRight, BS_A, BS_B);
+
+ if (m->control_pressed) {
+ delete q;
+ delete leftParent;
+ delete rightParent;
+ return "no";
+ }
divs[k].bsa = BS_A;
divs[k].bsb = BS_B;
for (int i = windowSize-1; i <= (length - windowSize); i += windowStep) {
+ if (m->control_pressed) { return data; }
+
int breakpoint = i;
int leftLength = breakpoint + 1;
int rightLength = length - leftLength;
}
}
/***********************************************************************/
-void Slayer::bootstrapSNPS(vector<snps> left, vector<snps> right, float& BSA, float& BSB) {
+int Slayer::bootstrapSNPS(vector<snps> left, vector<snps> right, float& BSA, float& BSB) {
try {
srand((unsigned)time( NULL ));
for (int i = 0; i < iters; i++) {
//random sampling with replacement.
+ if (m->control_pressed) { return 0; }
+
vector<snps> selectedLeft;
for (int j = 0; j < numLeft; j++) {
BSA = ((float) count_A / (float) iters) * 100;
BSB = ((float) count_B / (float) iters) * 100;
//cout << "bsa = " << BSA << " bsb = " << BSB << endl;
+
+ return 0;
}
catch(exception& e) {
vector<data_struct> runBellerophon(Sequence*, Sequence*, Sequence*, map<int, int>&);
vector<snps> getSNPS(string, string, string, int, int);
- void bootstrapSNPS(vector<snps>, vector<snps>, float&, float&);
+ int bootstrapSNPS(vector<snps>, vector<snps>, float&, float&);
float snpQA(vector<snps>);
float snpQB(vector<snps>);
float snpAB(vector<snps>);
double SLibshuff::sCalculate(int x, int y){
try{
+ double sum = 0.0,t=0.0;
+
minX = getMinX(x);
+
+ if (m->control_pressed) { return sum; }
+
minXY = getMinXY(x,y);
+
+ if (m->control_pressed) { return sum; }
sort(minX.begin(), minX.end());
+
+ if (m->control_pressed) { return sum; }
+
sort(minXY.begin(), minXY.end());
+
+ if (m->control_pressed) { return sum; }
- double sum = 0.0,t=0.0;
int ix=0,iy=0;
while( (ix < groupSizes[x]) && (iy < groupSizes[x]) ) {
double h = (ix-iy)/double(groupSizes[x]);
if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); }
else { inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); }
+ if (m->control_pressed) { return 0; }
+
for (int p = 0; p < inputFileNames.size(); p++) {
string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p])) + "summary";
set<string> processedLabels;
set<string> userLabels = labels;
+ if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0; }
+
while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+ if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0; }
+
if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
outputFileHandle << sabund->getLabel();
for(int i=0;i<sumCalculators.size();i++){
vector<double> data = sumCalculators[i]->getValues(sabund);
+
+ if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0; }
+
outputFileHandle << '\t';
sumCalculators[i]->print(outputFileHandle);
}
outputFileHandle << sabund->getLabel();
for(int i=0;i<sumCalculators.size();i++){
vector<double> data = sumCalculators[i]->getValues(sabund);
+
+ if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0; }
+
outputFileHandle << '\t';
sumCalculators[i]->print(outputFileHandle);
}
sabund = input->getSAbundVector();
}
+ if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete input; globaldata->ginput = NULL; return 0; }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
outputFileHandle << sabund->getLabel();
for(int i=0;i<sumCalculators.size();i++){
vector<double> data = sumCalculators[i]->getValues(sabund);
+
+ if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0; }
+
outputFileHandle << '\t';
sumCalculators[i]->print(outputFileHandle);
}
outputFileHandle.close();
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete input; globaldata->ginput = NULL; return 0; }
+
+
delete input; globaldata->ginput = NULL;
delete read;
delete validCalculator;
globaldata->sabund = NULL;
+ for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
}
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
remove(outAllFileName.c_str());
outputNames.pop_back();
}
-
+
+ if (m->control_pressed) {
+ if (mult) { outAll.close(); remove(outAllFileName.c_str()); }
+ outputFileHandle.close(); remove(outputFileName.c_str());
+ delete input; globaldata->ginput = NULL;
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
+ globaldata->Groups.clear();
+ return 0;
+ }
+
+
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
set<string> processedLabels;
set<string> userLabels = labels;
//as long as you are not at the end of the file or done wih the lines you want
while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+ if (m->control_pressed) {
+ if (mult) { outAll.close(); remove(outAllFileName.c_str()); }
+ outputFileHandle.close(); remove(outputFileName.c_str());
+ delete input; globaldata->ginput = NULL;
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
+ globaldata->Groups.clear();
+ return 0;
+ }
+
if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
lookup = input->getSharedRAbundVectors();
}
+ if (m->control_pressed) {
+ if (mult) { outAll.close(); remove(outAllFileName.c_str()); }
+ outputFileHandle.close(); remove(outputFileName.c_str());
+ delete input; globaldata->ginput = NULL;
+ for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
+ globaldata->Groups.clear();
+ return 0;
+ }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
}
-
+
//reset groups parameter
globaldata->Groups.clear();
if (mult == true) { outAll.close(); }
for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
-
delete input; globaldata->ginput = NULL;
+ if (m->control_pressed) {
+ remove(outAllFileName.c_str());
+ remove(outputFileName.c_str());
+ return 0;
+ }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
}
/***********************************************************/
-void SummarySharedCommand::process(vector<SharedRAbundVector*> thisLookup) {
+int SummarySharedCommand::process(vector<SharedRAbundVector*> thisLookup) {
try {
//loop through calculators and add to file all for all calcs that can do mutiple groups
if (mult == true) {
for(int i=0;i<sumCalculators.size();i++){
if (sumCalculators[i]->getMultiple() == true) {
sumCalculators[i]->getValues(thisLookup);
+
+ if (m->control_pressed) { return 1; }
+
outAll << '\t';
sumCalculators[i]->print(outAll);
}
for(int i=0;i<sumCalculators.size();i++) {
sumCalculators[i]->getValues(subset); //saves the calculator outputs
+
+ if (m->control_pressed) { return 1; }
+
outputFileHandle << '\t';
sumCalculators[i]->print(outputFileHandle);
}
}
n++;
}
-
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "SummarySharedCommand", "process");
vector<SharedRAbundVector*> lookup;
string outputFileName, format, outAllFileName, outputDir;
ofstream outputFileHandle, outAll;
- void process(vector<SharedRAbundVector*>);
+ int process(vector<SharedRAbundVector*>);
};
openInputFile(tfile, inTax);
highestLevel = getHighestLevel(inTax);
-
- //if the user has specified a cutoff and it's smaller than the highest level
- if ((cutoff != -1) && (cutoff < highestLevel)) {
- highestLevel = cutoff;
- }else if (cutoff > highestLevel) {
- m->mothurOut("The highest level taxonomy you have is " + toString(highestLevel) + " and your cutoff is " + toString(cutoff) + ". I will set the cutoff to " + toString(highestLevel));
- m->mothurOutEndLine();
- }
-
- inTax.close();
- ifstream in;
- openInputFile(tfile, in);
-
- ofstream out;
- equalizedFile = getRootName(tfile) + "equalized.taxonomy";
- openOutputFile(equalizedFile, out);
- string name, tax;
- while (in) {
- in >> name >> tax; gobble(in);
+ if (!m->control_pressed) {
- if (containsConfidence) { removeConfidences(tax); }
+ //if the user has specified a cutoff and it's smaller than the highest level
+ if ((cutoff != -1) && (cutoff < highestLevel)) {
+ highestLevel = cutoff;
+ }else if (cutoff > highestLevel) {
+ m->mothurOut("The highest level taxonomy you have is " + toString(highestLevel) + " and your cutoff is " + toString(cutoff) + ". I will set the cutoff to " + toString(highestLevel));
+ m->mothurOutEndLine();
+ }
- //is this a taxonomy that needs to be extended?
- if (seqLevels[name] < highestLevel) {
- extendTaxonomy(name, tax, highestLevel);
- }else if (seqLevels[name] > highestLevel) { //this can happen if the user enters a cutoff
- truncateTaxonomy(name, tax, highestLevel);
+ inTax.close();
+ ifstream in;
+ openInputFile(tfile, in);
+
+ ofstream out;
+ equalizedFile = getRootName(tfile) + "equalized.taxonomy";
+ openOutputFile(equalizedFile, out);
+
+
+ string name, tax;
+ while (in) {
+
+ if (m->control_pressed) { break; }
+
+ in >> name >> tax; gobble(in);
+
+ if (containsConfidence) { removeConfidences(tax); }
+
+ //is this a taxonomy that needs to be extended?
+ if (seqLevels[name] < highestLevel) {
+ extendTaxonomy(name, tax, highestLevel);
+ }else if (seqLevels[name] > highestLevel) { //this can happen if the user enters a cutoff
+ truncateTaxonomy(name, tax, highestLevel);
+ }
+
+ out << name << '\t' << tax << endl;
}
- out << name << '\t' << tax << endl;
- }
+ in.close();
+ out.close();
+
+ if (m->control_pressed) { remove(equalizedFile.c_str()); }
+ }else { inTax.close(); }
- in.close();
- out.close();
-
}
catch(exception& e) {
m->errorOut(e, "TaxEqualizer", "TaxEqualizer");
}
}
/*****************************************************************/
-void Tree::assembleTree() {
+int Tree::assembleTree() {
try {
//if user has given a names file we want to include that info in the pgroups and pcount info.
//build the pGroups in non leaf nodes to be used in the parsimony calcs.
for (int i = numLeaves; i < numNodes; i++) {
+ if (m->control_pressed) { return 1; }
+
tree[i].pGroups = (mergeGroups(i));
tree[i].pcount = (mergeGcounts(i));
}
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "Tree", "assembleTree");
int findRoot(); //return index of root node
//this function takes the leaf info and populates the non leaf nodes
- void assembleTree();
+ int assembleTree();
vector<Node> tree; //the first n nodes are the leaves, where n is the number of sequences.
//**********************************************************************************************************************
TreeGroupCommand::~TreeGroupCommand(){
+ globaldata->Groups.clear();
if (abort == false) {
if (format == "sharedfile") { delete read; delete input; globaldata->ginput = NULL; }
//used in tree constructor
globaldata->runParse = false;
+ //clear globaldatas old tree names if any
+ globaldata->Treenames.clear();
+
+ //fills globaldatas tree names
+ globaldata->Treenames = globaldata->Groups;
+
+ //create treemap class from groupmap for tree class to use
+ tmap = new TreeMap();
+ tmap->makeSim(globaldata->gGroupmap);
+ globaldata->gTreemap = tmap;
+
+ if (m->control_pressed) { return 0; }
+
//create tree file
makeSimsShared();
+
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
}else{
//read in dist file
filename = globaldata->inputFileName;
//make treemap
tmap = new TreeMap();
+
+ if (m->control_pressed) { return 0; }
+
tmap->makeSim(list);
globaldata->gTreemap = tmap;
//used in tree constructor
globaldata->runParse = false;
+ if (m->control_pressed) { return 0; }
+
makeSimsDist();
+
+ if (m->control_pressed) { return 0; }
//create a new filename
outputFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "tre";
outputNames.push_back(outputFile);
createTree();
+
+ if (m->control_pressed) { return 0; }
+
m->mothurOut("Tree complete. "); m->mothurOutEndLine();
+
}
//reset groups parameter
}
//**********************************************************************************************************************
-void TreeGroupCommand::createTree(){
+int TreeGroupCommand::createTree(){
try {
//create tree
t = new Tree();
//there are numGroups - 1 merges to do
for (int i = 0; i < (numGroups - 1); i++) {
float largest = -1000.0;
-
+
+ if (m->control_pressed) { delete t; return 1; }
+
int row, column;
//find largest value in sims matrix by searching lower triangle
for (int j = 1; j < simMatrix.size(); j++) {
//assemble tree
t->assembleTree();
+ if (m->control_pressed) { delete t; return 1; }
+
//print newick file
t->createNewickFile(outputFile);
//delete tree
delete t;
+
+ if (m->control_pressed) { remove(outputFile.c_str()); outputNames.pop_back(); return 1; }
+
+ return 0;
}
catch(exception& e) {
}
}
/***********************************************************/
-void TreeGroupCommand::makeSimsDist() {
+int TreeGroupCommand::makeSimsDist() {
try {
numGroups = list->size();
//initialize simMatrix
simMatrix.clear();
simMatrix.resize(numGroups);
- for (int m = 0; m < simMatrix.size(); m++) {
+ for (int k = 0; k < simMatrix.size(); k++) {
for (int j = 0; j < simMatrix.size(); j++) {
- simMatrix[m].push_back(0.0);
+ simMatrix[k].push_back(0.0);
}
}
for(MatData currentCell = matrix->begin(); currentCell != matrix->end(); currentCell++){
//similairity = -(distance-1)
simMatrix[currentCell->row][currentCell->column] = -(currentCell->dist -1.0);
- simMatrix[currentCell->column][currentCell->row] = -(currentCell->dist -1.0);
+ simMatrix[currentCell->column][currentCell->row] = -(currentCell->dist -1.0);
+
+ if (m->control_pressed) { return 1; }
+
}
-
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "TreeGroupCommand", "makeSimsDist");
}
/***********************************************************/
-void TreeGroupCommand::makeSimsShared() {
+int TreeGroupCommand::makeSimsShared() {
try {
-
- //clear globaldatas old tree names if any
- globaldata->Treenames.clear();
-
- //fills globaldatas tree names
- globaldata->Treenames = globaldata->Groups;
-
- //create treemap class from groupmap for tree class to use
- tmap = new TreeMap();
- tmap->makeSim(globaldata->gGroupmap);
- globaldata->gTreemap = tmap;
-
set<string> processedLabels;
set<string> userLabels = labels;
//as long as you are not at the end of the file or done wih the lines you want
while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+ if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for(int i = 0 ; i < treeCalculators.size(); i++) { delete treeCalculators[i]; } return 1; }
if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
lookup = input->getSharedRAbundVectors();
}
+ if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for(int i = 0 ; i < treeCalculators.size(); i++) { delete treeCalculators[i]; } return 1; }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
}
for(int i = 0 ; i < treeCalculators.size(); i++) { delete treeCalculators[i]; }
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "TreeGroupCommand", "makeSimsShared");
}
/***********************************************************/
-void TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
+int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
try{
EstOutput data;
vector<SharedRAbundVector*> subset;
//initialize simMatrix
simMatrix.clear();
simMatrix.resize(numGroups);
- for (int m = 0; m < simMatrix.size(); m++) {
+ for (int k = 0; k < simMatrix.size(); k++) {
for (int j = 0; j < simMatrix.size(); j++) {
- simMatrix[m].push_back(0.0);
+ simMatrix[k].push_back(0.0);
}
}
subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]);
data = treeCalculators[i]->getValues(subset); //saves the calculator outputs
+
+ if (m->control_pressed) { return 1; }
+
//save values in similarity matrix
simMatrix[k][l] = data[0];
simMatrix[l][k] = data[0];
}
}
}
-
+
+ if (m->control_pressed) { return 1; }
//creates tree from similarity matrix and write out file
createTree();
+
+ if (m->control_pressed) { return 1; }
}
+
+ return 0;
}
catch(exception& e) {
void help();
private:
- void createTree();
+ int createTree();
void printSims(ostream&);
- void makeSimsShared();
- void makeSimsDist();
+ int makeSimsShared();
+ int makeSimsDist();
GlobalData* globaldata;
ReadOTUFile* read;
vector<string> Estimators, Groups, outputNames; //holds estimators to be used
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
- void process(vector<SharedRAbundVector*>);
+ int process(vector<SharedRAbundVector*>);
if (abort == true) { return 0; }
- vector<string> outputNames;
-
numFPrimers = 0; //this needs to be initialized
numRPrimers = 0;
bool success;
while(!inFASTA.eof()){
+
+ if (m->control_pressed) {
+ inFASTA.close();
+ outFASTA.close();
+ scrapFASTA.close();
+ outGroups.close();
+ if(qFileName != "") { qFile.close(); }
+ for(int i=0;i<fastaFileNames.size();i++){
+ fastaFileNames[i]->close();
+ delete fastaFileNames[i];
+ }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
+
Sequence currSeq(inFASTA);
string origSeq = currSeq.getUnaligned();
inFASTA.close();
}
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
if(allFiles){
outFASTAVec.push_back(new ofstream((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta").c_str(), ios::ate));
+ outputNames.push_back((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta"));
}
}
}
bool flip, allFiles, qtrim;
int numFPrimers, numRPrimers, maxAmbig, maxHomoP, minLength, maxLength, qThreshold, qAverage;
- vector<string> forPrimer, revPrimer;
+ vector<string> forPrimer, revPrimer, outputNames;
map<string, int> barcodes;
vector<string> groupVector;
};
//get pscores for users trees
for (int i = 0; i < T.size(); i++) {
+ if (m->control_pressed) {
+ outSum.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
counter = 0;
if (random) {
outputNames.push_back(outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted");
}
+
//get unweighted for users tree
rscoreFreq.resize(numComp);
rCumul.resize(numComp);
userData = unweighted->getValues(T[i]); //userData[0] = unweightedscore
+ if (m->control_pressed) {
+ if (random) { delete output; }
+ outSum.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
//output scores for each combination
for(int k = 0; k < numComp; k++) {
//saves users score
validScores[userData[k]] = userData[k];
}
- //get unweighted scores for random trees
+ //get unweighted scores for random trees - if random is false iters = 0
for (int j = 0; j < iters; j++) {
//we need a different getValues because when we swap the labels we only want to swap those in each pairwise comparison
randomData = unweighted->getValues(T[i], "", "");
+
+ if (m->control_pressed) {
+ if (random) { delete output; }
+ outSum.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
for(int k = 0; k < numComp; k++) {
//add trees unweighted score to map of scores
if (random) { UWScoreSig[a].push_back(rCumul[a][userData[a]]); }
else { UWScoreSig[a].push_back(0.0); }
}
-
+
+
+ if (m->control_pressed) {
+ if (random) { delete output; }
+ outSum.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
//print output files
printUWSummaryFile(i);
if (random) { printUnweightedFile(); delete output; }
UWScoreSig.clear();
}
- //reset groups parameter
- globaldata->Groups.clear();
+
outSum.close();
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
public:
UnifracUnweightedCommand(string);
- ~UnifracUnweightedCommand() { delete unweighted; delete util; }
+ ~UnifracUnweightedCommand() { globaldata->Groups.clear(); if (abort == false) { delete unweighted; delete util; } }
int execute();
void help();
//get weighted scores for users trees
for (int i = 0; i < T.size(); i++) {
+
+ if (m->control_pressed) {
+ delete randT;
+ if (random) { delete reading; }
+ outSum.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
counter = 0;
rScores.resize(numComp); //data[0] = weightedscore AB, data[1] = weightedscore AC...
uScores.resize(numComp); //data[0] = weightedscore AB, data[1] = weightedscore AC...
userData = weighted->getValues(T[i]); //userData[0] = weightedscore
+ if (m->control_pressed) {
+ delete randT;
+ if (random) { delete reading; delete output; }
+ outSum.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
+
//save users score
for (int s=0; s<numComp; s++) {
//add users score to vector of user scores
//create a random tree with same topology as T[i], but different labels
randT->assembleRandomUnifracTree(globaldata->Groups[r], globaldata->Groups[l]);
+
+ if (m->control_pressed) {
+ delete randT;
+ if (random) { delete reading; delete output; }
+ outSum.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
+
//get wscore of random tree
randomData = weighted->getValues(randT, globaldata->Groups[r], globaldata->Groups[l]);
+ if (m->control_pressed) {
+ delete randT;
+ if (random) { delete reading; delete output; }
+ outSum.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
//save scores
rScores[count].push_back(randomData[0]);
count++;
validScores.clear();
}
+
+ if (m->control_pressed) {
+ delete randT;
+ if (random) { delete reading; }
+ outSum.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
//finish progress bar
if (random) { reading->finish(); delete reading; }
delete randT;
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
groups.push_back(globaldata->Groups[a]); groups.push_back(globaldata->Groups[l]);
for(int i=0;i<t->getNumNodes();i++){
+ if (m->control_pressed) { return data; }
copyIpcount = t->tree[i].pcount;
for (it = copyIpcount.begin(); it != copyIpcount.end();) {
copyIpcount.clear();
for(int i=0;i<t->getNumNodes();i++){
+
+ if (m->control_pressed) { return data; }
copyIpcount = t->tree[i].pcount;
for (it = copyIpcount.begin(); it != copyIpcount.end();) {
//swap labels in the groups you want to compare
copyTree->assembleRandomUnifracTree(groups[0], groups[1]);
+ if (m->control_pressed) { delete copyTree; return data; }
+
//copyTree->createNewickFile("random"+groupA+toString(count));
for(int i=0;i<copyTree->getNumNodes();i++){
-
+
+ if (m->control_pressed) { delete copyTree; return data; }
+
/**********************************************************************/
//This section adds in all lengths that are non leaf
copyIpcount = copyTree->tree[i].pcount;
//swap labels in all the groups you want to compare
copyTree->assembleRandomUnifracTree(groups);
+
+ if (m->control_pressed) { delete copyTree; return data; }
for(int i=0;i<copyTree->getNumNodes();i++){
+ if (m->control_pressed) { delete copyTree; return data; }
copyIpcount = copyTree->tree[i].pcount;
for (it = copyIpcount.begin(); it != copyIpcount.end();) {
string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg";
outputNames.push_back(filenamesvg);
openOutputFile(filenamesvg, outsvg);
+
+ if (m->control_pressed) { outsvg.close(); return outputNames; }
vector<double> data = vCalcs[i]->getValues(sabund);
string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
outputNames.push_back(filenamesvg);
openOutputFile(filenamesvg, outsvg);
-
+
+ if (m->control_pressed) { outsvg.close(); return outputNames; }
+
//in essence you want to run it like a single
if (vCalcs[i]->getName() == "sharedsobs") {
singleCalc = new Sobs();
outputNames.push_back(filenamesvg);
openOutputFile(filenamesvg, outsvg);
+ if (m->control_pressed) { outsvg.close(); return outputNames; }
+
//get estimates for sharedAB
vector<double> shared = vCalcs[i]->getValues(subset);
outputNames.push_back(filenamesvg);
openOutputFile(filenamesvg, outsvg);
+ if (m->control_pressed) { outsvg.close(); return outputNames; }
+
if (vCalcs[i]->getName() == "sharedace") {
singleCalc = new Ace(10);
outputNames.push_back(filenamesvg);
openOutputFile(filenamesvg, outsvg);
-
+ if (m->control_pressed) { outsvg.close(); return outputNames; }
+
//in essence you want to run it like a single
if (vCalcs[i]->getName() == "sharedsobs") {
singleCalc = new Sobs();
delete read;
delete venn;
globaldata->sabund = NULL;
+ delete validCalculator;
}
}
//as long as you are not at the end of the file or done wih the lines you want
while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+
+ if (m->control_pressed) {
+ for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; }
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ globaldata->Groups.clear();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
}
vector<string> outfilenames = venn->getPic(lookup, vennCalculators);
- for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); }
+ for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } }
}
if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor
}
vector<string> outfilenames = venn->getPic(lookup, vennCalculators);
- for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); }
+ for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } }
//restore real lastlabel to save below
lookup[0]->setLabel(saveLabel);
lookup = input->getSharedRAbundVectors();
}
+ if (m->control_pressed) {
+ for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; }
+ globaldata->Groups.clear();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor
}
vector<string> outfilenames = venn->getPic(lookup, vennCalculators);
- for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); }
+ for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } }
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
}
//reset groups parameter
globaldata->Groups.clear();
+ if (m->control_pressed) {
+ for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
+
}else{
while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+
+ if (m->control_pressed) {
+ for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; }
+ delete sabund;
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
vector<string> outfilenames = venn->getPic(sabund, vennCalculators);
- for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); }
+ for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } }
processedLabels.insert(sabund->getLabel());
m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
vector<string> outfilenames = venn->getPic(sabund, vennCalculators);
- for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); }
+ for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } }
processedLabels.insert(sabund->getLabel());
sabund = input->getSAbundVector();
}
+ if (m->control_pressed) {
+ for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
vector<string> outfilenames = venn->getPic(sabund, vennCalculators);
- for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); }
+ for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } }
delete sabund;
}
+ if (m->control_pressed) {
+ for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
}
for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; }
/********************************************************/
//calculate a D value for each group combo
for(int v=0;v<t->getNumLeaves();v++){
+
+ if (m->control_pressed) { return data; }
+
int index = v;
double sum = 0.0000;
//calculate weighted score for each of the group comb i.e. with groups A,B,C = AB, AC, BC.
for (int b=0; b<numGroups; b++) {
for (int l = b+1; l < numGroups; l++) {
+
+ if (m->control_pressed) { return data; }
+
//calculate a u value for each combo
double u;
//does this node have descendants from group b-1
/********************************************************/
//calculate a D value for the group combo
for(int v=0;v<t->getNumLeaves();v++){
+ if (m->control_pressed) { return data; }
+
int index = v;
double sum = 0.0000;
//calculate u for the group comb
for(int i=0;i<t->getNumNodes();i++){
+
+ if (m->control_pressed) { return data; }
+
double u;
//does this node have descendants from groupA
it = t->tree[i].pcount.find(groupA);