else {
//valid paramters for this command
- string AlignArray[] = {"taxonomy","cutoff","label","outputdir","inputdir"};
+ string AlignArray[] = {"taxonomy","cutoff","label","name","outputdir","inputdir"};
vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
OptionParser parser(option);
//if the user has not given a path then, add inputdir. else leave path alone.
if (path == "") { parameters["taxonomy"] = inputDir + it->second; }
}
+
+ it = parameters.find("name");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = 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; }
+ }
}
taxonomyFileName = validParameter.validFile(parameters, "taxonomy", true);
abort = true;
}else if (taxonomyFileName == "not open") { abort = true; }
+ namefile = validParameter.validFile(parameters, "name", true);
+ if (namefile == "not open") { abort = true; }
+ else if (namefile == "not found") { namefile = ""; }
+ else { readNamesFile(); }
+
//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 = "";
//reads in taxonomy file and makes all the taxonomies the same length
//by appending the last taxon to a given taxonomy as many times as needed to
//make it as long as the longest taxonomy in the file
- TaxEqualizer* taxEqual = new TaxEqualizer(taxonomyFileName, cutoff);
+ TaxEqualizer* taxEqual = new TaxEqualizer(taxonomyFileName, cutoff, outputDir);
+
+ if (m->control_pressed) { delete taxEqual; return 0; }
string equalizedTaxFile = taxEqual->getEqualizedTaxFile();
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){
//make the names compatable with listvector
string name = "";
- for (int i = 0; i < names.size(); i++) { name += names[i] + ","; }
+ for (int i = 0; i < names.size(); i++) {
+ if (namefile != "") {
+ map<string, string>::iterator itNames = namemap.find(names[i]); //make sure this name is in namefile
+
+ if (itNames != namemap.end()) { name += namemap[names[i]] + ","; } //you found it in namefile
+ else { m->mothurOut(names[i] + " is not in your namefile, please correct."); m->mothurOutEndLine(); exit(1); }
+
+ }else{ name += names[i] + ","; }
+ }
name = name.substr(0, name.length()-1); //rip off extra ','
//add bin to list vector
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(); }
exit(1);
}
}
+/*****************************************************************/
+int PhylotypeCommand::readNamesFile() {
+ try {
+
+ ifstream in;
+ openInputFile(namefile, in);
+
+ string first, second;
+ map<string, string>::iterator itNames;
+
+ while(!in.eof()) {
+ in >> first >> second; gobble(in);
+
+ itNames = namemap.find(first);
+ if (itNames == namemap.end()) {
+ namemap[first] = second;
+ }else { m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); namemap.clear(); namefile = ""; return 1; }
+ }
+ in.close();
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "PhylotypeCommand", "readNamesFile");
+ exit(1);
+ }
+}
+
/**********************************************************************************************************************/