X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=getlineagecommand.cpp;fp=getlineagecommand.cpp;h=ec5ef61233d7cfa24ef1b9b9d7debf355a5820ba;hb=499f4ac6e321f9f03d4c3aa25c3b6880892c8b83;hp=862aef7a0da6dde200bc387209bdd73d730015f5;hpb=a935b75dd890da5ae7f09e5e6179f90ab2955348;p=mothur.git diff --git a/getlineagecommand.cpp b/getlineagecommand.cpp index 862aef7..ec5ef61 100644 --- a/getlineagecommand.cpp +++ b/getlineagecommand.cpp @@ -75,7 +75,7 @@ string GetLineageCommand::getOutputPattern(string type) { else if (type == "name") { pattern = "[filename],pick,[extension]"; } else if (type == "group") { pattern = "[filename],pick,[extension]"; } else if (type == "count") { pattern = "[filename],pick,[extension]"; } - else if (type == "list") { pattern = "[filename],pick,[extension]-[filename],[distance],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],[distance],pick,[extension]"; } else if (type == "shared") { pattern = "[filename],[distance],pick,[extension]"; } else if (type == "alignreport") { pattern = "[filename],pick.align.report"; } else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } @@ -537,18 +537,13 @@ int GetLineageCommand::readList(){ map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); variables["[extension]"] = m->getExtension(listfile); - string outputFileName = getOutputFileName("list", variables); - ofstream out; - m->openOutputFile(outputFileName, out); - + ifstream in; m->openInputFile(listfile, in); bool wroteSomething = false; while(!in.eof()){ - - if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; } //read in list vector ListVector list(in); @@ -556,6 +551,18 @@ int GetLineageCommand::readList(){ //make a new list vector ListVector newList; newList.setLabel(list.getLabel()); + + variables["[distance]"] = list.getLabel(); + string outputFileName = getOutputFileName("list", variables); + + ofstream out; + m->openOutputFile(outputFileName, out); + outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); + + if (m->control_pressed) { in.close(); out.close(); return 0; } + + vector binLabels = list.getLabels(); + vector newBinLabels; //for each bin for (int i = 0; i < list.getNumBins(); i++) { @@ -576,23 +583,26 @@ int GetLineageCommand::readList(){ //if there are names in this bin add to new list if (newNames != "") { newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma - newList.push_back(newNames); + newList.push_back(newNames); + newBinLabels.push_back(binLabels[i]); } } //print new listvector if (newList.getNumBins() != 0) { wroteSomething = true; + newList.setLabels(newBinLabels); + newList.printHeaders(out); newList.print(out); } m->gobble(in); + out.close(); } in.close(); - out.close(); + if (wroteSomething == false) { m->mothurOut("Your file contains does not contain any sequences from " + taxons + "."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); outputTypes["list"].push_back(outputFileName); return 0; @@ -615,6 +625,8 @@ int GetLineageCommand::readConsList(){ bool wroteSomething = false; string snumBins = toString(list->getNumBins()); + vector binLabels = list->getLabels(); + vector newBinLabels; for (int i = 0; i < list->getNumBins(); i++) { if (m->control_pressed) { delete list; return 0;} @@ -631,6 +643,7 @@ int GetLineageCommand::readConsList(){ if (names.count(m->getSimpleLabel(otuLabel)) != 0) { selectedCount++; newList.push_back(list->get(i)); + newBinLabels.push_back(binLabels[i]); } } @@ -648,6 +661,8 @@ int GetLineageCommand::readConsList(){ //print new listvector if (newList.getNumBins() != 0) { wroteSomething = true; + newList.setLabels(newBinLabels); + newList.printHeaders(out); newList.print(out); } out.close(); @@ -767,9 +782,9 @@ int GetLineageCommand::readShared(){ if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } return 0; } //is this otu on the list - if (names.count(m->getSimpleLabel(m->currentBinLabels[i])) != 0) { + if (names.count(m->getSimpleLabel(m->currentSharedBinLabels[i])) != 0) { numSelected++; wroteSomething = true; - newLabels.push_back(m->currentBinLabels[i]); + newLabels.push_back(m->currentSharedBinLabels[i]); for (int j = 0; j < newLookup.size(); j++) { //add this OTU to the new lookup newLookup[j]->push_back(lookup[j]->getAbundance(i), lookup[j]->getGroup()); } @@ -789,7 +804,7 @@ int GetLineageCommand::readShared(){ for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } - m->currentBinLabels = newLabels; + m->currentSharedBinLabels = newLabels; newLookup[0]->printHeaders(out);