From 79ca496859f48f1c38803c0f7c603faac348fe4c Mon Sep 17 00:00:00 2001 From: SarahsWork Date: Wed, 3 Apr 2013 14:56:23 -0400 Subject: [PATCH] added name, group and count files to chop.seqs. added intelligent warnings for when you use a group file instead of design file - common bug report. --- chopseqscommand.cpp | 156 ++++++++++++++++++++++++++++++++++++++++---- chopseqscommand.h | 4 +- counttable.cpp | 56 +++++++++++++++- groupmap.cpp | 4 ++ readtree.cpp | 14 ++-- tree.cpp | 17 +++-- tree.h | 2 +- 7 files changed, 225 insertions(+), 28 deletions(-) diff --git a/chopseqscommand.cpp b/chopseqscommand.cpp index 80dd856..96d7ae6 100644 --- a/chopseqscommand.cpp +++ b/chopseqscommand.cpp @@ -9,11 +9,15 @@ #include "chopseqscommand.h" #include "sequence.hpp" +#include "removeseqscommand.h" //********************************************************************************************************************** vector ChopSeqsCommand::setParameters(){ try { CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","group",false,false,true); parameters.push_back(pgroup); CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); CommandParameter pnumbases("numbases", "Number", "", "0", "", "", "","",false,true,true); parameters.push_back(pnumbases); CommandParameter pcountgaps("countgaps", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pcountgaps); @@ -36,8 +40,9 @@ string ChopSeqsCommand::getHelpString(){ try { string helpString = ""; helpString += "The chop.seqs command reads a fasta file and outputs a .chop.fasta containing the trimmed sequences. Note: If a sequence is completely 'chopped', an accnos file will be created with the names of the sequences removed. \n"; - helpString += "The chop.seqs command parameters are fasta, numbases, countgaps and keep. fasta is required unless you have a valid current fasta file. numbases is required.\n"; + helpString += "The chop.seqs command parameters are fasta, name, group, count, numbases, countgaps and keep. fasta is required unless you have a valid current fasta file. numbases is required.\n"; helpString += "The chop.seqs command should be in the following format: chop.seqs(fasta=yourFasta, numbases=yourNum, keep=yourKeep).\n"; + helpString += "If you provide a name, group or count file any sequences removed from the fasta file will also be removed from those files.\n"; helpString += "The numbases parameter allows you to specify the number of bases you want to keep.\n"; helpString += "The keep parameter allows you to specify whether you want to keep the front or the back of your sequence, default=front.\n"; helpString += "The countgaps parameter allows you to specify whether you want to count gaps as bases, default=false.\n"; @@ -58,7 +63,10 @@ string ChopSeqsCommand::getOutputPattern(string type) { try { string pattern = ""; - if (type == "fasta") { pattern = "[filename],chop.fasta"; } + if (type == "fasta") { pattern = "[filename],chop.fasta"; } + else if (type == "name") { pattern = "[filename],chop.names"; } + else if (type == "group") { pattern = "[filename],chop.groups"; } + else if (type == "count") { pattern = "[filename],chop.count_table"; } else if (type == "accnos") { pattern = "[filename],chop.accnos"; } else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } @@ -77,6 +85,9 @@ ChopSeqsCommand::ChopSeqsCommand(){ vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["accnos"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["count"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "ChopSeqsCommand", "ChopSeqsCommand"); @@ -110,6 +121,9 @@ ChopSeqsCommand::ChopSeqsCommand(string option) { vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["accnos"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["count"] = tempOutNames; //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); @@ -123,6 +137,30 @@ ChopSeqsCommand::ChopSeqsCommand(string option) { //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } + + it = parameters.find("name"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["name"] = inputDir + it->second; } + } + + it = parameters.find("group"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["group"] = inputDir + it->second; } + } + + it = parameters.find("count"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["count"] = inputDir + it->second; } + } } //check for required parameters @@ -134,8 +172,31 @@ ChopSeqsCommand::ChopSeqsCommand(string option) { else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } }else { m->setFastaFile(fastafile); } + namefile = validParameter.validFile(parameters, "name", true); + if (namefile == "not open") { namefile = ""; abort = true; } + else if (namefile == "not found") { namefile = ""; } + else { m->setNameFile(namefile); } + + groupfile = validParameter.validFile(parameters, "group", true); + if (groupfile == "not open") { groupfile = ""; abort = true; } + else if (groupfile == "not found") { groupfile = ""; } + else { m->setGroupFile(groupfile); } + + countfile = validParameter.validFile(parameters, "count", true); + if (countfile == "not open") { countfile = ""; abort = true; } + else if (countfile == "not found") { countfile = ""; } + else { m->setCountTableFile(countfile); } + + if ((namefile != "") && (countfile != "")) { + m->mothurOut("[ERROR]: you may only use one of the following: name or count."); m->mothurOutEndLine(); abort = true; + } + + if ((groupfile != "") && (countfile != "")) { + m->mothurOut("[ERROR]: you may only use one of the following: group or count."); m->mothurOutEndLine(); abort=true; + } + //if the user changes the output directory command factory will send this info to us in the output parameter - outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(fastafile); } + outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } string temp = validParameter.validFile(parameters, "numbases", false); if (temp == "not found") { temp = "0"; } m->mothurConvert(temp, numbases); @@ -168,9 +229,12 @@ int ChopSeqsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - map variables; - variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + map variables; + string thisOutputDir = outputDir; + if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); string outputFileName = getOutputFileName("fasta", variables); + outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); string outputFileNameAccnos = getOutputFileName("accnos", variables); vector positions; @@ -198,29 +262,95 @@ int ChopSeqsCommand::execute(){ if (m->control_pressed) { return 0; } - m->mothurOutEndLine(); - m->mothurOut("Output File Names: "); m->mothurOutEndLine(); - m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); - - if (wroteAccnos) { m->mothurOut(outputFileNameAccnos); m->mothurOutEndLine(); outputNames.push_back(outputFileNameAccnos); outputTypes["accnos"].push_back(outputFileNameAccnos); } + if (wroteAccnos) { + outputNames.push_back(outputFileNameAccnos); outputTypes["accnos"].push_back(outputFileNameAccnos); + + //use remove.seqs to create new name, group and count file + if ((countfile != "") || (namefile != "") || (groupfile != "")) { + string inputString = "accnos=" + outputFileNameAccnos; + + if (countfile != "") { inputString += ", count=" + countfile; } + else{ + if (namefile != "") { inputString += ", name=" + namefile; } + if (groupfile != "") { inputString += ", group=" + groupfile; } + } + + m->mothurOut("/******************************************/"); m->mothurOutEndLine(); + m->mothurOut("Running command: remove.seqs(" + inputString + ")"); m->mothurOutEndLine(); + m->mothurCalling = true; + + Command* removeCommand = new RemoveSeqsCommand(inputString); + removeCommand->execute(); + + map > filenames = removeCommand->getOutputFiles(); + + delete removeCommand; + m->mothurCalling = false; + m->mothurOut("/******************************************/"); m->mothurOutEndLine(); + + if (groupfile != "") { + thisOutputDir = outputDir; + if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + string outGroup = getOutputFileName("group", variables); + m->renameFile(filenames["group"][0], outGroup); + outputNames.push_back(outGroup); outputTypes["group"].push_back(outGroup); + } + + if (namefile != "") { + thisOutputDir = outputDir; + if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile)); + string outName = getOutputFileName("name", variables); + m->renameFile(filenames["name"][0], outName); + outputNames.push_back(outName); outputTypes["name"].push_back(outName); + } + + if (countfile != "") { + thisOutputDir = outputDir; + if (outputDir == "") { thisOutputDir += m->hasPath(countfile); } + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); + string outCount = getOutputFileName("count", variables); + m->renameFile(filenames["count"][0], outCount); + outputNames.push_back(outCount); outputTypes["count"].push_back(outCount); + } + } + } else { m->mothurRemove(outputFileNameAccnos); } - m->mothurOutEndLine(); - //set fasta file as new current fastafile string current = ""; itTypes = outputTypes.find("fasta"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); } } - + if (wroteAccnos) { //set accnos file as new current accnosfile itTypes = outputTypes.find("accnos"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setAccnosFile(current); } } + + itTypes = outputTypes.find("name"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); } + } + + itTypes = outputTypes.find("group"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); } + } + + itTypes = outputTypes.find("count"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setCountTableFile(current); } + } } + 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(); return 0; } diff --git a/chopseqscommand.h b/chopseqscommand.h index c9a4962..a9cfc10 100644 --- a/chopseqscommand.h +++ b/chopseqscommand.h @@ -27,7 +27,7 @@ class ChopSeqsCommand : public Command { string getCommandCategory() { return "Sequence Processing"; } string getHelpString(); - string getOutputPattern(string); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Chops.seqs"; } string getDescription() { return "trim sequence length"; } @@ -41,7 +41,7 @@ class ChopSeqsCommand : public Command { linePair(unsigned long long i, unsigned long long j) : start(i), end(j) {} }; - string fastafile, outputDir, keep; + string fastafile, outputDir, keep, namefile, groupfile, countfile; bool abort, countGaps, Short; int numbases, processors; vector outputNames; diff --git a/counttable.cpp b/counttable.cpp index c16bf92..48b52d9 100644 --- a/counttable.cpp +++ b/counttable.cpp @@ -40,7 +40,13 @@ int CountTable::createTable(set& n, map& g, set& if (itGroup != g.end()) { groupCounts[indexGroupMap[itGroup->second]] = 1; totalGroups[indexGroupMap[itGroup->second]]++; - }else { m->mothurOut("[ERROR]: Your group file does not contain " + seqName + ". Please correct."); m->mothurOutEndLine(); } + }else { + //look for it in names of groups to see if the user accidently used the wrong file + if (m->inUsersGroups(seqName, groups)) { + m->mothurOut("[WARNING]: Your group or design file contains a group named " + seqName + ". Perhaps you are used a group file instead of a design file? A common cause of this is using a tree file that relates your groups (created by the tree.shared command) with a group file that assigns sequences to a group."); m->mothurOutEndLine(); + } + m->mothurOut("[ERROR]: Your group file does not contain " + seqName + ". Please correct."); m->mothurOutEndLine(); + } map::iterator it2 = indexNameMap.find(seqName); if (it2 == indexNameMap.end()) { @@ -360,6 +366,10 @@ vector CountTable::getGroupCounts(string seqName) { if (hasGroups) { map::iterator it = indexNameMap.find(seqName); if (it == indexNameMap.end()) { + //look for it in names of groups to see if the user accidently used the wrong file + if (m->inUsersGroups(seqName, groups)) { + m->mothurOut("[WARNING]: Your group or design file contains a group named " + seqName + ". Perhaps you are used a group file instead of a design file? A common cause of this is using a tree file that relates your groups (created by the tree.shared command) with a group file that assigns sequences to a group."); m->mothurOutEndLine(); + } m->mothurOut("[ERROR]: " + seqName + " is not in your count table. Please correct.\n"); m->control_pressed = true; }else { temp = counts[it->second]; @@ -404,6 +414,10 @@ int CountTable::getGroupCount(string seqName, string groupName) { }else { map::iterator it2 = indexNameMap.find(seqName); if (it2 == indexNameMap.end()) { + //look for it in names of groups to see if the user accidently used the wrong file + if (m->inUsersGroups(seqName, groups)) { + m->mothurOut("[WARNING]: Your group or design file contains a group named " + seqName + ". Perhaps you are used a group file instead of a design file? A common cause of this is using a tree file that relates your groups (created by the tree.shared command) with a group file that assigns sequences to a group."); m->mothurOutEndLine(); + } m->mothurOut("[ERROR]: seq " + seqName + " is not in your count table. Please correct.\n"); m->control_pressed = true; }else { return counts[it2->second][it->second]; @@ -429,6 +443,10 @@ int CountTable::setAbund(string seqName, string groupName, int num) { }else { map::iterator it2 = indexNameMap.find(seqName); if (it2 == indexNameMap.end()) { + //look for it in names of groups to see if the user accidently used the wrong file + if (m->inUsersGroups(seqName, groups)) { + m->mothurOut("[WARNING]: Your group or design file contains a group named " + seqName + ". Perhaps you are used a group file instead of a design file? A common cause of this is using a tree file that relates your groups (created by the tree.shared command) with a group file that assigns sequences to a group."); m->mothurOutEndLine(); + } m->mothurOut("[ERROR]: " + seqName + " is not in your count table. Please correct.\n"); m->control_pressed = true; }else { int oldCount = counts[it2->second][it->second]; @@ -576,6 +594,12 @@ int CountTable::renameSeq(string oldSeqName, string newSeqName) { map::iterator it = indexNameMap.find(oldSeqName); if (it == indexNameMap.end()) { + if (hasGroupInfo()) { + //look for it in names of groups to see if the user accidently used the wrong file + if (m->inUsersGroups(oldSeqName, groups)) { + m->mothurOut("[WARNING]: Your group or design file contains a group named " + oldSeqName + ". Perhaps you are used a group file instead of a design file? A common cause of this is using a tree file that relates your groups (created by the tree.shared command) with a group file that assigns sequences to a group."); m->mothurOutEndLine(); + } + } m->mothurOut("[ERROR]: " + oldSeqName + " is not in your count table. Please correct.\n"); m->control_pressed = true; }else { int index = it->second; @@ -598,6 +622,12 @@ int CountTable::getNumSeqs(string seqName) { map::iterator it = indexNameMap.find(seqName); if (it == indexNameMap.end()) { + if (hasGroupInfo()) { + //look for it in names of groups to see if the user accidently used the wrong file + if (m->inUsersGroups(seqName, groups)) { + m->mothurOut("[WARNING]: Your group or design file contains a group named " + seqName + ". Perhaps you are used a group file instead of a design file? A common cause of this is using a tree file that relates your groups (created by the tree.shared command) with a group file that assigns sequences to a group."); m->mothurOutEndLine(); + } + } m->mothurOut("[ERROR]: " + seqName + " is not in your count table. Please correct.\n"); m->control_pressed = true; }else { return totals[it->second]; @@ -617,6 +647,12 @@ int CountTable::get(string seqName) { map::iterator it = indexNameMap.find(seqName); if (it == indexNameMap.end()) { + if (hasGroupInfo()) { + //look for it in names of groups to see if the user accidently used the wrong file + if (m->inUsersGroups(seqName, groups)) { + m->mothurOut("[WARNING]: Your group or design file contains a group named " + seqName + ". Perhaps you are used a group file instead of a design file? A common cause of this is using a tree file that relates your groups (created by the tree.shared command) with a group file that assigns sequences to a group."); m->mothurOutEndLine(); + } + } m->mothurOut("[ERROR]: " + seqName + " is not in your count table. Please correct.\n"); m->control_pressed = true; }else { return it->second; } @@ -663,6 +699,12 @@ int CountTable::remove(string seqName) { total -= thisTotal; indexNameMap.erase(it); }else { + if (hasGroupInfo()) { + //look for it in names of groups to see if the user accidently used the wrong file + if (m->inUsersGroups(seqName, groups)) { + m->mothurOut("[WARNING]: Your group or design file contains a group named " + seqName + ". Perhaps you are used a group file instead of a design file? A common cause of this is using a tree file that relates your groups (created by the tree.shared command) with a group file that assigns sequences to a group."); m->mothurOutEndLine(); + } + } m->mothurOut("[ERROR]: Your count table contains does not include " + seqName + ", cannot remove."); m->mothurOutEndLine(); m->control_pressed = true; } @@ -799,10 +841,22 @@ int CountTable::mergeCounts(string seq1, string seq2) { try { map::iterator it = indexNameMap.find(seq1); if (it == indexNameMap.end()) { + if (hasGroupInfo()) { + //look for it in names of groups to see if the user accidently used the wrong file + if (m->inUsersGroups(seq1, groups)) { + m->mothurOut("[WARNING]: Your group or design file contains a group named " + seq1 + ". Perhaps you are used a group file instead of a design file? A common cause of this is using a tree file that relates your groups (created by the tree.shared command) with a group file that assigns sequences to a group."); m->mothurOutEndLine(); + } + } m->mothurOut("[ERROR]: " + seq1 + " is not in your count table. Please correct.\n"); m->control_pressed = true; }else { map::iterator it2 = indexNameMap.find(seq2); if (it2 == indexNameMap.end()) { + if (hasGroupInfo()) { + //look for it in names of groups to see if the user accidently used the wrong file + if (m->inUsersGroups(seq2, groups)) { + m->mothurOut("[WARNING]: Your group or design file contains a group named " + seq2 + ". Perhaps you are used a group file instead of a design file? A common cause of this is using a tree file that relates your groups (created by the tree.shared command) with a group file that assigns sequences to a group."); m->mothurOutEndLine(); + } + } m->mothurOut("[ERROR]: " + seq2 + " is not in your count table. Please correct.\n"); m->control_pressed = true; }else { //merge data diff --git a/groupmap.cpp b/groupmap.cpp index e5d8427..8e2139d 100644 --- a/groupmap.cpp +++ b/groupmap.cpp @@ -317,6 +317,10 @@ string GroupMap::getGroup(string sequenceName) { if (it != groupmap.end()) { //sequence name was in group file return it->second; }else { + //look for it in names of groups to see if the user accidently used the wrong file + if (m->inUsersGroups(sequenceName, namesOfGroups)) { + m->mothurOut("[WARNING]: Your group or design file contains a group named " + sequenceName + ". Perhaps you are used a group file instead of a design file? A common cause of this is using a tree file that relates your groups (created by the tree.shared command) with a group file that assigns sequences to a group."); m->mothurOutEndLine(); + } return "not found"; } } diff --git a/readtree.cpp b/readtree.cpp index 4c9def8..b9c38e9 100644 --- a/readtree.cpp +++ b/readtree.cpp @@ -115,8 +115,10 @@ int ReadNewickTree::read(CountTable* ct) { //if you are not a nexus file if ((c = filehandle.peek()) != '#') { - while((c = filehandle.peek()) != EOF) { + while((c = filehandle.peek()) != EOF) { + if (m->control_pressed) { filehandle.close(); return 0; } while ((c = filehandle.peek()) != EOF) { + if (m->control_pressed) { filehandle.close(); return 0; } // get past comments if(c == '[') { comment = 1; @@ -146,9 +148,11 @@ int ReadNewickTree::read(CountTable* ct) { Tree* temp = new Tree(ct); delete temp; nexusTranslation(ct); //reads file through the translation and updates treemap - while((c = filehandle.peek()) != EOF) { + while((c = filehandle.peek()) != EOF) { + if (m->control_pressed) { filehandle.close(); return 0; } // get past comments - while ((c = filehandle.peek()) != EOF) { + while ((c = filehandle.peek()) != EOF) { + if (m->control_pressed) { filehandle.close(); return 0; } if(holder == "[" || holder == "[!"){ comment = 1; } @@ -242,7 +246,7 @@ int ReadNewickTree::readTreeString(CountTable* ct) { n = numLeaves; //number of leaves / sequences, we want node 1 to start where the leaves left off lc = readNewickInt(filehandle, n, T, ct); - if (lc == -1) { m->mothurOut("error with lc"); m->mothurOutEndLine(); return -1; } //reports an error in reading + if (lc == -1) { m->mothurOut("error with lc"); m->mothurOutEndLine(); m->control_pressed = true; return -1; } //reports an error in reading if(filehandle.peek()==','){ readSpecialChar(filehandle,',',"comma"); @@ -254,7 +258,7 @@ int ReadNewickTree::readTreeString(CountTable* ct) { if(rooted != 1){ rc = readNewickInt(filehandle, n, T, ct); - if (rc == -1) { m->mothurOut("error with rc"); m->mothurOutEndLine(); return -1; } //reports an error in reading + if (rc == -1) { m->mothurOut("error with rc"); m->mothurOutEndLine(); m->control_pressed = true; return -1; } //reports an error in reading if(filehandle.peek() == ')'){ readSpecialChar(filehandle,')',"right parenthesis"); } diff --git a/tree.cpp b/tree.cpp index 6b799f4..7458934 100644 --- a/tree.cpp +++ b/tree.cpp @@ -1233,7 +1233,7 @@ void Tree::printTree() { /*****************************************************************/ //this code is a mess and should be rethought...-slw -void Tree::parseTreeFile() { +int Tree::parseTreeFile() { //only takes names from the first tree and assumes that all trees use the same names. try { @@ -1246,8 +1246,10 @@ void Tree::parseTreeFile() { //ifyou are not a nexus file if((c = filehandle.peek()) != '#') { - while((c = filehandle.peek()) != ';') { + while((c = filehandle.peek()) != ';') { + if (m->control_pressed) { filehandle.close(); return 0; } while ((c = filehandle.peek()) != ';') { + if (m->control_pressed) { filehandle.close(); return 0; } // get past comments if(c == '[') { comment = 1; @@ -1267,7 +1269,8 @@ void Tree::parseTreeFile() { string holder = ""; // get past comments - while(holder != "translate" && holder != "Translate"){ + while(holder != "translate" && holder != "Translate"){ + if (m->control_pressed) { filehandle.close(); return 0; } if(holder == "[" || holder == "[!"){ comment = 1; } @@ -1296,7 +1299,8 @@ void Tree::parseTreeFile() { string number, name, h; h = ""; // so it enters the loop the first time - while((h != ";") && (number != ";")) { + while((h != ";") && (number != ";")) { + if (m->control_pressed) { filehandle.close(); return 0; } filehandle >> number; filehandle >> name; @@ -1309,7 +1313,7 @@ void Tree::parseTreeFile() { } } filehandle.close(); - + return 0; //for (int i = 0; i < globaldata->Treenames.size(); i++) { //cout << globaldata->Treenames[i] << endl; } //cout << globaldata->Treenames.size() << endl; @@ -1327,7 +1331,8 @@ int Tree::readTreeString(ifstream& filehandle) { int c; string name; //, k - while((c = filehandle.peek()) != ';') { + while((c = filehandle.peek()) != ';') { + if (m->control_pressed) { return 0; } //k = c; //cout << " at beginning of while " << k << endl; if(c == ')') { diff --git a/tree.h b/tree.h index 88e49c0..c8e8478 100644 --- a/tree.h +++ b/tree.h @@ -69,7 +69,7 @@ private: //void randomLabels(string, string); void printBranch(int, ostream&, map); //recursively print out tree void printBranch(int, ostream&, string); - void parseTreeFile(); //parses through tree file to find names of nodes and number of them + int parseTreeFile(); //parses through tree file to find names of nodes and number of them //this is required in case user has sequences in the names file that are //not included in the tree. //only takes names from the first tree in the tree file and assumes that all trees use the same names. -- 2.39.2