A751032B128AC93F00ABB831 /* removegroupscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = removegroupscommand.cpp; sourceTree = "<group>"; };
A75103D6128AE34100ABB831 /* getgroupscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getgroupscommand.h; sourceTree = "<group>"; };
A75103D7128AE34100ABB831 /* getgroupscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getgroupscommand.cpp; sourceTree = "<group>"; };
+ A7510407128AFCC100ABB831 /* getotuscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getotuscommand.h; sourceTree = "<group>"; };
+ A7510408128AFCC100ABB831 /* getotuscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getotuscommand.cpp; sourceTree = "<group>"; };
A7639F8D1175DF35008F5578 /* makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = makefile; sourceTree = "<group>"; };
A7653CB112789EFD009D6C09 /* subsamplecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = subsamplecommand.h; sourceTree = "<group>"; };
A7653CB212789EFD009D6C09 /* subsamplecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = subsamplecommand.cpp; sourceTree = "<group>"; };
A76AAD03117F322B003D8DA1 /* phylosummary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = phylosummary.cpp; sourceTree = "<group>"; };
A76C4A1011876BAF0009460B /* setlogfilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = setlogfilecommand.h; sourceTree = SOURCE_ROOT; };
A76C4A1111876BAF0009460B /* setlogfilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = setlogfilecommand.cpp; sourceTree = SOURCE_ROOT; };
+ A76D1451128D6A03005D4DFE /* removeotuscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = removeotuscommand.h; sourceTree = "<group>"; };
+ A76D1452128D6A03005D4DFE /* removeotuscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = removeotuscommand.cpp; sourceTree = "<group>"; };
A77D787B126F387700F351BD /* pairwiseseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pairwiseseqscommand.h; sourceTree = "<group>"; };
A77D787C126F387700F351BD /* pairwiseseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pairwiseseqscommand.cpp; sourceTree = "<group>"; };
A780E6CB11E7745D00BB5718 /* endiannessmacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = endiannessmacros.h; sourceTree = "<group>"; };
A76714DE126DE45A003F359A /* deuniqueseqscommand.cpp */,
A7DA2050113FECD400BF472F /* filterseqscommand.h */,
A7DA204F113FECD400BF472F /* filterseqscommand.cpp */,
- A75103D6128AE34100ABB831 /* getgroupscommand.h */,
- A75103D7128AE34100ABB831 /* getgroupscommand.cpp */,
A7DA205B113FECD400BF472F /* getgroupcommand.h */,
A7DA205A113FECD400BF472F /* getgroupcommand.cpp */,
+ A75103D6128AE34100ABB831 /* getgroupscommand.h */,
+ A75103D7128AE34100ABB831 /* getgroupscommand.cpp */,
A7DA205D113FECD400BF472F /* getlabelcommand.h */,
A7DA205C113FECD400BF472F /* getlabelcommand.cpp */,
A787A24F124CB46C0076EB84 /* getlineagecommand.h */,
A787A250124CB46C0076EB84 /* getlineagecommand.cpp */,
A7DA205F113FECD400BF472F /* getlistcountcommand.h */,
A7DA205E113FECD400BF472F /* getlistcountcommand.cpp */,
+ A7510407128AFCC100ABB831 /* getotuscommand.h */,
+ A7510408128AFCC100ABB831 /* getotuscommand.cpp */,
A7DA2061113FECD400BF472F /* getoturepcommand.h */,
A7DA2060113FECD400BF472F /* getoturepcommand.cpp */,
A7DA2063113FECD400BF472F /* getrabundcommand.h */,
A751032B128AC93F00ABB831 /* removegroupscommand.cpp */,
A787A28E124CE1470076EB84 /* removelineagecommand.h */,
A787A28F124CE1470076EB84 /* removelineagecommand.cpp */,
+ A76D1451128D6A03005D4DFE /* removeotuscommand.h */,
+ A76D1452128D6A03005D4DFE /* removeotuscommand.cpp */,
A7DA20F3113FECD400BF472F /* removeseqscommand.h */,
A7DA20F2113FECD400BF472F /* removeseqscommand.cpp */,
A7DA20F5113FECD400BF472F /* reversecommand.h */,
#include "subsamplecommand.h"
#include "removegroupscommand.h"
#include "getgroupscommand.h"
-
+#include "getotuscommand.h"
+#include "removeotuscommand.h"
/*******************************************************/
commands["sub.sample"] = "sub.sample";
commands["remove.groups"] = "remove.groups";
commands["get.groups"] = "get.groups";
+ commands["get.otus"] = "get.otus";
+ commands["remove.otus"] = "remove.otus";
commands["pairwise.seqs"] = "MPIEnabled";
commands["pipeline.pds"] = "MPIEnabled";
commands["classify.seqs"] = "MPIEnabled";
else if(commandName == "remove.lineage") { command = new RemoveLineageCommand(optionString); }
else if(commandName == "get.groups") { command = new GetGroupsCommand(optionString); }
else if(commandName == "remove.groups") { command = new RemoveGroupsCommand(optionString); }
+ else if(commandName == "get.otus") { command = new GetOtusCommand(optionString); }
+ else if(commandName == "remove.otus") { command = new RemoveOtusCommand(optionString); }
else if(commandName == "fastq.info") { command = new ParseFastaQCommand(optionString); }
else if(commandName == "pipeline.pds") { command = new PipelineCommand(optionString); }
else if(commandName == "deunique.seqs") { command = new DeUniqueSeqsCommand(optionString); }
else if(commandName == "get.groups") { pipecommand = new GetGroupsCommand(optionString); }
else if(commandName == "remove.lineage") { pipecommand = new RemoveLineageCommand(optionString); }
else if(commandName == "remove.groups") { pipecommand = new RemoveGroupsCommand(optionString); }
+ else if(commandName == "get.otus") { pipecommand = new GetOtusCommand(optionString); }
+ else if(commandName == "remove.otus") { pipecommand = new RemoveOtusCommand(optionString); }
else if(commandName == "fastq.info") { pipecommand = new ParseFastaQCommand(optionString); }
else if(commandName == "deunique.seqs") { pipecommand = new DeUniqueSeqsCommand(optionString); }
else if(commandName == "pairwise.seqs") { pipecommand = new PairwiseSeqsCommand(optionString); }
else if(commandName == "remove.lineage") { shellcommand = new RemoveLineageCommand(); }
else if(commandName == "get.groups") { shellcommand = new GetGroupsCommand(); }
else if(commandName == "remove.groups") { shellcommand = new RemoveGroupsCommand(); }
+ else if(commandName == "get.otus") { shellcommand = new GetOtusCommand(); }
+ else if(commandName == "remove.otus") { shellcommand = new RemoveOtusCommand(); }
else if(commandName == "fastq.info") { shellcommand = new ParseFastaQCommand(); }
else if(commandName == "deunique.seqs") { shellcommand = new DeUniqueSeqsCommand(); }
else if(commandName == "pairwise.seqs") { shellcommand = new PairwiseSeqsCommand(); }
--- /dev/null
+/*
+ * getotuscommand.cpp
+ * Mothur
+ *
+ * Created by westcott on 11/10/10.
+ * Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "getotuscommand.h"
+#include "inputdata.h"
+#include "sharedutilities.h"
+
+
+//**********************************************************************************************************************
+vector<string> GetOtusCommand::getValidParameters(){
+ try {
+ string Array[] = { "group", "accnos","label", "groups","list","outputdir","inputdir" };
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetOtusCommand", "getValidParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+GetOtusCommand::GetOtusCommand(){
+ try {
+ abort = true;
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["group"] = tempOutNames;
+ outputTypes["list"] = tempOutNames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetOtusCommand", "GetOtusCommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> GetOtusCommand::getRequiredParameters(){
+ try {
+ string Array[] = {"group","label", "list"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetOtusCommand", "getRequiredParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> GetOtusCommand::getRequiredFiles(){
+ try {
+ vector<string> myArray;
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetOtusCommand", "getRequiredFiles");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+GetOtusCommand::GetOtusCommand(string option) {
+ try {
+ abort = false;
+
+ //allow user to run help
+ if(option == "help") { help(); abort = true; }
+
+ else {
+ //valid paramters for this command
+ string Array[] = { "group", "accnos","label", "groups", "list","outputdir","inputdir" };
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
+ map<string,string>::iterator it;
+
+ //check to make sure all parameters are valid for command
+ for (it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ }
+
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["group"] = tempOutNames;
+ outputTypes["list"] = tempOutNames;
+
+
+ //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 = ""; }
+
+ //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);
+ if (inputDir == "not found"){ inputDir = ""; }
+ else {
+ string path;
+ it = parameters.find("accnos");
+ //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["accnos"] = inputDir + it->second; }
+ }
+
+ it = parameters.find("list");
+ //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["list"] = 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; }
+ }
+ }
+
+
+ //check for required parameters
+ accnosfile = validParameter.validFile(parameters, "accnos", true);
+ if (accnosfile == "not open") { abort = true; }
+ else if (accnosfile == "not found") { accnosfile = ""; }
+
+ groupfile = validParameter.validFile(parameters, "group", true);
+ if (groupfile == "not open") { abort = true; }
+ else if (groupfile == "not found") { groupfile = ""; m->mothurOut("You must provide a group file."); m->mothurOutEndLine(); abort = true; }
+
+ listfile = validParameter.validFile(parameters, "list", true);
+ if (listfile == "not open") { abort = true; }
+ else if (listfile == "not found") { listfile = ""; m->mothurOut("You must provide a list file."); m->mothurOutEndLine(); abort = true; }
+
+ groups = validParameter.validFile(parameters, "groups", false);
+ if (groups == "not found") { groups = ""; }
+ else {
+ m->splitAtDash(groups, Groups);
+ }
+
+ label = validParameter.validFile(parameters, "label", false);
+ if (label == "not found") { label = ""; m->mothurOut("You must provide a label to process."); m->mothurOutEndLine(); abort = true; }
+
+ if ((accnosfile == "") && (Groups.size() == 0)) { m->mothurOut("You must provide an accnos file or specify groups using the groups parameter."); m->mothurOutEndLine(); abort = true; }
+ }
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetOtusCommand", "GetOtusCommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+void GetOtusCommand::help(){
+ try {
+ m->mothurOut("The get.otus command selects otus containing sequences from a specfic group or set of groups.\n");
+ m->mothurOut("It outputs a new list file containing the otus containing sequences from in the those specified groups.\n");
+ m->mothurOut("The get.otus command parameters are accnos, group, list, label and groups. The group, list and label parameters are required.\n");
+ m->mothurOut("You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n");
+ m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like. You can separate group names with dashes.\n");
+ m->mothurOut("The label parameter allows you to specify which distance you want to process.\n");
+ m->mothurOut("The get.otus command should be in the following format: get.otus(accnos=yourAccnos, list=yourListFile, group=yourGroupFile, label=yourLabel).\n");
+ m->mothurOut("Example get.otus(accnos=amazon.accnos, list=amazon.fn.list, group=amazon.groups, label=0.03).\n");
+ m->mothurOut("or get.otus(groups=pasture, list=amazon.fn.list, amazon.groups, label=0.03).\n");
+ m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n");
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetOtusCommand", "help");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+
+int GetOtusCommand::execute(){
+ try {
+
+ if (abort == true) { return 0; }
+
+ groupMap = new GroupMap(groupfile);
+ groupMap->readMap();
+
+ //get groups you want to remove
+ if (accnosfile != "") { readAccnos(); }
+
+ //make sure groups are valid
+ //takes care of user setting groupNames that are invalid or setting groups=all
+ SharedUtil* util = new SharedUtil();
+ util->setGroups(Groups, groupMap->namesOfGroups);
+ delete util;
+
+ if (m->control_pressed) { delete groupMap; return 0; }
+
+ //read through the list file keeping any otus that contain any sequence from the groups selected
+ readListGroup();
+
+ 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();
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
+ m->mothurOutEndLine();
+ }
+
+ return 0;
+ }
+
+ catch(exception& e) {
+ m->errorOut(e, "GetOtusCommand", "execute");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+int GetOtusCommand::readListGroup(){
+ try {
+ string thisOutputDir = outputDir;
+ if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
+ string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick." + label + m->getExtension(listfile);
+
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+
+ string GroupOutputDir = outputDir;
+ if (outputDir == "") { GroupOutputDir += m->hasPath(groupfile); }
+ string outputGroupFileName = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick." + label + m->getExtension(groupfile);
+
+ ofstream outGroup;
+ m->openOutputFile(outputGroupFileName, outGroup);
+
+ InputData* input = new InputData(listfile, "list");
+ ListVector* list = input->getListVector();
+ string lastLabel = list->getLabel();
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> labels; labels.insert(label);
+ set<string> processedLabels;
+ set<string> userLabels = labels;
+
+ bool wroteSomething = false;
+
+ //as long as you are not at the end of the file or done wih the lines you want
+ while((list != NULL) && (userLabels.size() != 0)) {
+
+ if (m->control_pressed) { delete list; delete input; out.close(); outGroup.close(); remove(outputFileName.c_str()); remove(outputGroupFileName.c_str());return 0; }
+
+ if(labels.count(list->getLabel()) == 1){
+ processList(list, groupMap, out, outGroup, wroteSomething);
+
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+ }
+
+ if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+ string saveLabel = list->getLabel();
+
+ delete list;
+
+ list = input->getListVector(lastLabel);
+
+ processList(list, groupMap, out, outGroup, wroteSomething);
+
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+
+ //restore real lastlabel to save below
+ list->setLabel(saveLabel);
+ }
+
+ lastLabel = list->getLabel();
+
+ delete list; list = NULL;
+
+ //get next line to process
+ list = input->getListVector();
+ }
+
+
+ if (m->control_pressed) { if (list != NULL) { delete list; } delete input; out.close(); outGroup.close(); remove(outputFileName.c_str()); remove(outputGroupFileName.c_str()); return 0; }
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ m->mothurOut("Your file does not include the label " + *it);
+ if (processedLabels.count(lastLabel) != 1) {
+ m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
+ needToRun = true;
+ }else {
+ m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
+ }
+ }
+
+ //run last label if you need to
+ if (needToRun == true) {
+ if (list != NULL) { delete list; }
+
+ list = input->getListVector(lastLabel);
+
+ processList(list, groupMap, out, outGroup, wroteSomething);
+
+ delete list; list = NULL;
+ }
+
+ out.close();
+ outGroup.close();
+
+ if (wroteSomething == false) { m->mothurOut("At distance " + label + " your file does NOT contain any otus containing sequences from the groups you wish to get."); m->mothurOutEndLine(); }
+ outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
+ outputTypes["group"].push_back(outputGroupFileName); outputNames.push_back(outputGroupFileName);
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetOtusCommand", "readList");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+int GetOtusCommand::processList(ListVector*& list, GroupMap*& groupMap, ofstream& out, ofstream& outGroup, bool& wroteSomething){
+ try {
+
+ //make a new list vector
+ ListVector newList;
+ newList.setLabel(list->getLabel());
+
+ int numOtus = 0;
+ //for each bin
+ for (int i = 0; i < list->getNumBins(); i++) {
+ if (m->control_pressed) { return 0; }
+
+ //parse out names that are in accnos file
+ string binnames = list->get(i);
+
+ bool keepBin = false;
+ string groupFileOutput = "";
+
+ //parse names
+ string individual = "";
+ int length = binnames.length();
+ for(int j=0;j<length;j++){
+ if(binnames[j] == ','){
+ string group = groupMap->getGroup(individual);
+ if (group == "not found") { m->mothurOut("[ERROR]: " + individual + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
+
+ if (m->inUsersGroups(group, Groups)) { keepBin = true; }
+ groupFileOutput += individual + "\t" + group + "\n";
+ individual = "";
+
+ }
+ else{ individual += binnames[j]; }
+ }
+
+ string group = groupMap->getGroup(individual);
+ if (group == "not found") { m->mothurOut("[ERROR]: " + individual + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
+
+ if (m->inUsersGroups(group, Groups)) { keepBin = true; }
+ groupFileOutput += individual + "\t" + group + "\n";
+
+ //if there are sequences from the groups we want in this bin add to new list, output to groupfile
+ if (keepBin) {
+ newList.push_back(binnames);
+ outGroup << groupFileOutput;
+ numOtus++;
+ }
+ }
+
+ //print new listvector
+ if (newList.getNumBins() != 0) {
+ wroteSomething = true;
+ newList.print(out);
+ }
+
+ m->mothurOut(newList.getLabel() + " - selected " + toString(numOtus) + " of the " + toString(list->getNumBins()) + " OTUs."); m->mothurOutEndLine();
+
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetOtusCommand", "processList");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+void GetOtusCommand::readAccnos(){
+ try {
+ Groups.clear();
+
+ ifstream in;
+ m->openInputFile(accnosfile, in);
+ string name;
+
+ while(!in.eof()){
+ in >> name;
+
+ Groups.push_back(name);
+
+ m->gobble(in);
+ }
+ in.close();
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetOtusCommand", "readAccnos");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+
--- /dev/null
+#ifndef GETOTUSCOMMAND_H
+#define GETOTUSCOMMAND_H
+
+/*
+ * getotuscommand.h
+ * Mothur
+ *
+ * Created by westcott on 11/10/10.
+ * Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+
+
+#include "command.hpp"
+#include "groupmap.h"
+#include "listvector.hpp"
+
+class GetOtusCommand : public Command {
+
+public:
+
+ GetOtusCommand(string);
+ GetOtusCommand();
+ ~GetOtusCommand(){}
+ vector<string> getRequiredParameters();
+ vector<string> getValidParameters();
+ vector<string> getRequiredFiles();
+ map<string, vector<string> > getOutputFiles() { return outputTypes; }
+ int execute();
+ void help();
+
+private:
+ string accnosfile, groupfile, listfile, outputDir, groups, label;
+ bool abort;
+ vector<string> outputNames, Groups;
+ map<string, vector<string> > outputTypes;
+ GroupMap* groupMap;
+
+ void readAccnos();
+ int readListGroup();
+ int processList(ListVector*&, GroupMap*&, ofstream&, ofstream&, bool&);
+
+};
+
+#endif
+
+
+
//**********************************************************************************************************************
vector<string> MakeGroupCommand::getValidParameters(){
try {
- string Array[] = {"fasta", "groups","outputdir","inputdir"};
+ string Array[] = {"fasta", "output","groups","outputdir","inputdir"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
return myArray;
}
else {
//valid paramters for this command
- string AlignArray[] = {"fasta","groups","outputdir","inputdir"};
+ string AlignArray[] = {"fasta","groups","output","outputdir","inputdir"};
vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
OptionParser parser(option);
//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);
if (inputDir == "not found"){ inputDir = ""; }
-
- filename = outputDir;
fastaFileName = validParameter.validFile(parameters, "fasta", false);
if (fastaFileName == "not found") { m->mothurOut("fasta is a required parameter for the make.group command."); 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 = ""; }
+ output = validParameter.validFile(parameters, "output", false);
+ if (output == "not found") { output = ""; }
+ else{ filename = output; }
+
groups = validParameter.validFile(parameters, "groups", false);
if (groups == "not found") { m->mothurOut("groups is a required parameter for the make.group command."); m->mothurOutEndLine(); abort = true; }
else { m->splitAtDash(groups, groupsNames); }
if (groupsNames.size() != fastaFileNames.size()) { m->mothurOut("You do not have the same number of valid fastfile files as groups. This could be because we could not open a fastafile."); m->mothurOutEndLine(); abort = true; }
}
-
+ cout << "here" << endl;
}
catch(exception& e) {
m->errorOut(e, "MakeGroupCommand", "MakeGroupCommand");
void MakeGroupCommand::help(){
try {
m->mothurOut("The make.group command reads a fasta file or series of fasta files and creates a groupfile.\n");
- m->mothurOut("The make.group command parameters are fasta and groups, both are required.\n");
+ m->mothurOut("The make.group command parameters are fasta, groups and output. Fasta and group are required.\n");
+ m->mothurOut("The output parameter allows you to specify the name of groupfile created. \n");
m->mothurOut("The make.group command should be in the following format: \n");
- m->mothurOut("make.group(fasta=yourFastaFiles, groups=yourGroups. \n");
+ m->mothurOut("make.group(fasta=yourFastaFiles, groups=yourGroups). \n");
m->mothurOut("Example make.group(fasta=seqs1.fasta-seq2.fasta-seqs3.fasta, groups=A-B-C)\n");
m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFiles).\n\n");
}
int MakeGroupCommand::execute(){
try {
- if (abort == true) { return 0; }
+ if (abort == true) { return 0; }
if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[0]); }
-
+
filename = outputDir + filename;
ofstream out;
private:
- string fastaFileName, groups, outputDir, filename;
+ string fastaFileName, groups, outputDir, filename, output;
vector<string> fastaFileNames;
vector<string> groupsNames, outputNames;
map<string, vector<string> > outputTypes;
int *nr, *nc, *ldtabl, *work;
int nrow=2, ncol=2, ldtable=2;
- int workspace=(row*sizeof(double *)+size*sizeof(double *));
+ int workspace = 2*(row*col*sizeof(double *));
double *expect, *prc, *emin,*prt,*pre;
double e=0, prc1=0, emin1=0, prt1=0, pre1=0;
+
+ prt = (double *) malloc(size*sizeof(double *));
+ prc = (double *) malloc(size*sizeof(double *));
nr = &nrow;
nc = &ncol;
double data[] = {f11, f12, f21, f22};
int *nr, *nc, *ldtabl, *work;
- int nrow=2, ncol=2, ldtable=2, workspace=10000000; // I added two zeros for larger data sets
+ int nrow=2, ncol=2, ldtable=2, workspace=INT_MAX; // I added two zeros for larger data sets
double *expect, *prc, *emin,*prt,*pre;
double e=0, prc1=0, emin1=0, prt1=0, pre1=0;
}
//go through users set and make them floats
- for(it = userLabels.begin(); it != userLabels.end(); ++it) {
+ for(it = userLabels.begin(); it != userLabels.end();) {
float temp;
if ((*it != "unique") && (convertTestFloat(*it, temp) == true)){
convert(*it, temp);
orderFloat.push_back(temp);
userMap[*it] = temp;
+ it++;
}else if (*it == "unique") {
orderFloat.push_back(-1.0);
userMap["unique"] = -1.0;
+ it++;
}else {
- if (errorOff == "") { cout << *it << " is not a valid label." << endl; }
- userLabels.erase(*it);
- it--;
+ if (errorOff == "") { mothurOut(*it + " is not a valid label."); mothurOutEndLine(); }
+ userLabels.erase(it++);
}
}
if (orderFloat[i] < labelFloat) {
smaller = true;
if (orderFloat[i] == -1) {
- if (errorOff == "") { cout << "Your file does not include the label unique." << endl; }
+ if (errorOff == "") { mothurOut("Your file does not include the label unique."); mothurOutEndLine(); }
userLabels.erase("unique");
}
else {
- if (errorOff == "") { cout << "Your file does not include the label " << endl; }
+ if (errorOff == "") { mothurOut("Your file does not include the label "); mothurOutEndLine(); }
string s = "";
for (it2 = userMap.begin(); it2!= userMap.end(); it2++) {
if (it2->second == orderFloat[i]) {
break;
}
}
- if (errorOff == "") {cout << s << ". I will use the next smallest distance. " << endl; }
+ if (errorOff == "") {mothurOut( s + ". I will use the next smallest distance. "); mothurOutEndLine(); }
}
//since they are sorted once you find a bigger one stop looking
}else { break; }
--- /dev/null
+/*
+ * removeotuscommand.cpp
+ * Mothur
+ *
+ * Created by westcott on 11/12/10.
+ * Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "removeotuscommand.h"
+#include "inputdata.h"
+#include "sharedutilities.h"
+
+
+//**********************************************************************************************************************
+vector<string> RemoveOtusCommand::getValidParameters(){
+ try {
+ string Array[] = { "group", "accnos","label", "groups","list","outputdir","inputdir" };
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RemoveOtusCommand", "getValidParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+RemoveOtusCommand::RemoveOtusCommand(){
+ try {
+ abort = true;
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["group"] = tempOutNames;
+ outputTypes["list"] = tempOutNames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RemoveOtusCommand", "RemoveOtusCommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> RemoveOtusCommand::getRequiredParameters(){
+ try {
+ string Array[] = {"group","label", "list"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RemoveOtusCommand", "getRequiredParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> RemoveOtusCommand::getRequiredFiles(){
+ try {
+ vector<string> myArray;
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RemoveOtusCommand", "getRequiredFiles");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+RemoveOtusCommand::RemoveOtusCommand(string option) {
+ try {
+ abort = false;
+
+ //allow user to run help
+ if(option == "help") { help(); abort = true; }
+
+ else {
+ //valid paramters for this command
+ string Array[] = { "group", "accnos","label", "groups", "list","outputdir","inputdir" };
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
+ map<string,string>::iterator it;
+
+ //check to make sure all parameters are valid for command
+ for (it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ }
+
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["group"] = tempOutNames;
+ outputTypes["list"] = tempOutNames;
+
+
+ //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 = ""; }
+
+ //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);
+ if (inputDir == "not found"){ inputDir = ""; }
+ else {
+ string path;
+ it = parameters.find("accnos");
+ //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["accnos"] = inputDir + it->second; }
+ }
+
+ it = parameters.find("list");
+ //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["list"] = 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; }
+ }
+ }
+
+
+ //check for required parameters
+ accnosfile = validParameter.validFile(parameters, "accnos", true);
+ if (accnosfile == "not open") { abort = true; }
+ else if (accnosfile == "not found") { accnosfile = ""; }
+
+ groupfile = validParameter.validFile(parameters, "group", true);
+ if (groupfile == "not open") { abort = true; }
+ else if (groupfile == "not found") { groupfile = ""; m->mothurOut("You must provide a group file."); m->mothurOutEndLine(); abort = true; }
+
+ listfile = validParameter.validFile(parameters, "list", true);
+ if (listfile == "not open") { abort = true; }
+ else if (listfile == "not found") { listfile = ""; m->mothurOut("You must provide a list file."); m->mothurOutEndLine(); abort = true; }
+
+ groups = validParameter.validFile(parameters, "groups", false);
+ if (groups == "not found") { groups = ""; }
+ else {
+ m->splitAtDash(groups, Groups);
+ }
+
+ label = validParameter.validFile(parameters, "label", false);
+ if (label == "not found") { label = ""; m->mothurOut("You must provide a label to process."); m->mothurOutEndLine(); abort = true; }
+
+ if ((accnosfile == "") && (Groups.size() == 0)) { m->mothurOut("You must provide an accnos file or specify groups using the groups parameter."); m->mothurOutEndLine(); abort = true; }
+ }
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RemoveOtusCommand", "RemoveOtusCommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+void RemoveOtusCommand::help(){
+ try {
+ m->mothurOut("The remove.otus command removes otus containing sequences from a specfic group or set of groups.\n");
+ m->mothurOut("It outputs a new list file containing the otus containing sequences NOT from in the those specified groups.\n");
+ m->mothurOut("The remove.otus command parameters are accnos, group, list, label and groups. The group, list and label parameters are required.\n");
+ m->mothurOut("You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n");
+ m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like. You can separate group names with dashes.\n");
+ m->mothurOut("The label parameter allows you to specify which distance you want to process.\n");
+ m->mothurOut("The remove.otus command should be in the following format: remove.otus(accnos=yourAccnos, list=yourListFile, group=yourGroupFile, label=yourLabel).\n");
+ m->mothurOut("Example remove.otus(accnos=amazon.accnos, list=amazon.fn.list, group=amazon.groups, label=0.03).\n");
+ m->mothurOut("or remove.otus(groups=pasture, list=amazon.fn.list, amazon.groups, label=0.03).\n");
+ m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n");
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RemoveOtusCommand", "help");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+
+int RemoveOtusCommand::execute(){
+ try {
+
+ if (abort == true) { return 0; }
+
+ groupMap = new GroupMap(groupfile);
+ groupMap->readMap();
+
+ //get groups you want to remove
+ if (accnosfile != "") { readAccnos(); }
+
+ //make sure groups are valid
+ //takes care of user setting groupNames that are invalid or setting groups=all
+ SharedUtil* util = new SharedUtil();
+ util->setGroups(Groups, groupMap->namesOfGroups);
+ delete util;
+
+ if (m->control_pressed) { delete groupMap; return 0; }
+
+ //read through the list file keeping any otus that contain any sequence from the groups selected
+ readListGroup();
+
+ 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();
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
+ m->mothurOutEndLine();
+ }
+
+ return 0;
+ }
+
+ catch(exception& e) {
+ m->errorOut(e, "RemoveOtusCommand", "execute");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+int RemoveOtusCommand::readListGroup(){
+ try {
+ string thisOutputDir = outputDir;
+ if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
+ string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick." + label + m->getExtension(listfile);
+
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+
+ string GroupOutputDir = outputDir;
+ if (outputDir == "") { GroupOutputDir += m->hasPath(groupfile); }
+ string outputGroupFileName = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick." + label + m->getExtension(groupfile);
+
+ ofstream outGroup;
+ m->openOutputFile(outputGroupFileName, outGroup);
+
+ InputData* input = new InputData(listfile, "list");
+ ListVector* list = input->getListVector();
+ string lastLabel = list->getLabel();
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> labels; labels.insert(label);
+ set<string> processedLabels;
+ set<string> userLabels = labels;
+
+ bool wroteSomething = false;
+
+ //as long as you are not at the end of the file or done wih the lines you want
+ while((list != NULL) && (userLabels.size() != 0)) {
+
+ if (m->control_pressed) { delete list; delete input; out.close(); outGroup.close(); remove(outputFileName.c_str()); remove(outputGroupFileName.c_str());return 0; }
+
+ if(labels.count(list->getLabel()) == 1){
+ processList(list, groupMap, out, outGroup, wroteSomething);
+
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+ }
+
+ if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+ string saveLabel = list->getLabel();
+
+ delete list;
+
+ list = input->getListVector(lastLabel);
+
+ processList(list, groupMap, out, outGroup, wroteSomething);
+
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+
+ //restore real lastlabel to save below
+ list->setLabel(saveLabel);
+ }
+
+ lastLabel = list->getLabel();
+
+ delete list; list = NULL;
+
+ //get next line to process
+ list = input->getListVector();
+ }
+
+
+ if (m->control_pressed) { if (list != NULL) { delete list; } delete input; out.close(); outGroup.close(); remove(outputFileName.c_str()); remove(outputGroupFileName.c_str()); return 0; }
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ m->mothurOut("Your file does not include the label " + *it);
+ if (processedLabels.count(lastLabel) != 1) {
+ m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
+ needToRun = true;
+ }else {
+ m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
+ }
+ }
+
+ //run last label if you need to
+ if (needToRun == true) {
+ if (list != NULL) { delete list; }
+
+ list = input->getListVector(lastLabel);
+
+ processList(list, groupMap, out, outGroup, wroteSomething);
+
+ delete list; list = NULL;
+ }
+
+ out.close();
+ outGroup.close();
+
+ if (wroteSomething == false) { m->mothurOut("At distance " + label + " your file ONLY contains otus containing sequences from the groups you wish to remove."); m->mothurOutEndLine(); }
+ outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
+ outputTypes["group"].push_back(outputGroupFileName); outputNames.push_back(outputGroupFileName);
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RemoveOtusCommand", "readList");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+int RemoveOtusCommand::processList(ListVector*& list, GroupMap*& groupMap, ofstream& out, ofstream& outGroup, bool& wroteSomething){
+ try {
+
+ //make a new list vector
+ ListVector newList;
+ newList.setLabel(list->getLabel());
+
+ int numOtus = 0;
+ //for each bin
+ for (int i = 0; i < list->getNumBins(); i++) {
+ if (m->control_pressed) { return 0; }
+
+ //parse out names that are in accnos file
+ string binnames = list->get(i);
+
+ bool removeBin = false;
+ string groupFileOutput = "";
+
+ //parse names
+ string individual = "";
+ int length = binnames.length();
+ for(int j=0;j<length;j++){
+ if(binnames[j] == ','){
+ string group = groupMap->getGroup(individual);
+ if (group == "not found") { m->mothurOut("[ERROR]: " + individual + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
+
+ if (m->inUsersGroups(group, Groups)) { removeBin = true; break; }
+ groupFileOutput += individual + "\t" + group + "\n";
+ individual = "";
+
+ }
+ else{ individual += binnames[j]; }
+ }
+
+ if (!removeBin) {
+ //get last name
+ string group = groupMap->getGroup(individual);
+ if (group == "not found") { m->mothurOut("[ERROR]: " + individual + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
+
+ if (m->inUsersGroups(group, Groups)) { removeBin = true; }
+ groupFileOutput += individual + "\t" + group + "\n";
+
+ //if there are no sequences from the groups we want to remove in this bin add to new list, output to groupfile
+ newList.push_back(binnames);
+ outGroup << groupFileOutput;
+ numOtus++;
+ }
+ }
+
+ //print new listvector
+ if (newList.getNumBins() != 0) {
+ wroteSomething = true;
+ newList.print(out);
+ }
+
+ m->mothurOut(newList.getLabel() + " - removed " + toString(numOtus) + " of the " + toString(list->getNumBins()) + " OTUs."); m->mothurOutEndLine();
+
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RemoveOtusCommand", "processList");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+void RemoveOtusCommand::readAccnos(){
+ try {
+ Groups.clear();
+
+ ifstream in;
+ m->openInputFile(accnosfile, in);
+ string name;
+
+ while(!in.eof()){
+ in >> name;
+
+ Groups.push_back(name);
+
+ m->gobble(in);
+ }
+ in.close();
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RemoveOtusCommand", "readAccnos");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+
+
--- /dev/null
+#ifndef REMOVEOTUSCOMMAND_H
+#define REMOVEOTUSCOMMAND_H
+
+/*
+ * removeotuscommand.h
+ * Mothur
+ *
+ * Created by westcott on 11/12/10.
+ * Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+
+
+#include "command.hpp"
+#include "groupmap.h"
+#include "listvector.hpp"
+
+class RemoveOtusCommand : public Command {
+
+public:
+
+ RemoveOtusCommand(string);
+ RemoveOtusCommand();
+ ~RemoveOtusCommand(){}
+ vector<string> getRequiredParameters();
+ vector<string> getValidParameters();
+ vector<string> getRequiredFiles();
+ map<string, vector<string> > getOutputFiles() { return outputTypes; }
+ int execute();
+ void help();
+
+private:
+ string accnosfile, groupfile, listfile, outputDir, groups, label;
+ bool abort;
+ vector<string> outputNames, Groups;
+ map<string, vector<string> > outputTypes;
+ GroupMap* groupMap;
+
+ void readAccnos();
+ int readListGroup();
+ int processList(ListVector*&, GroupMap*&, ofstream&, ofstream&, bool&);
+
+};
+
+#endif
+
+
+
+
outputTypes["unweighted"] = tempOutNames;
outputTypes["uwsummary"] = tempOutNames;
outputTypes["phylip"] = tempOutNames;
+ outputTypes["column"] = tempOutNames;
}
catch(exception& e) {
m->errorOut(e, "UnifracUnweightedCommand", "UnifracUnweightedCommand");
outputTypes["unweighted"] = tempOutNames;
outputTypes["uwsummary"] = tempOutNames;
outputTypes["phylip"] = tempOutNames;
+ outputTypes["column"] = tempOutNames;
if (globaldata->gTree.size() == 0) {//no trees were read
m->mothurOut("You must execute the read.tree command, before you may execute the unifrac.unweighted command."); m->mothurOutEndLine(); abort = true; }
itersString = validParameter.validFile(parameters, "iters", false); if (itersString == "not found") { itersString = "1000"; }
convert(itersString, iters);
- string temp = validParameter.validFile(parameters, "distance", false); if (temp == "not found") { temp = "false"; }
- phylip = m->isTrue(temp);
+ string temp = validParameter.validFile(parameters, "distance", false);
+ if (temp == "not found") { phylip = false; outputForm = ""; }
+ else{
+ if ((temp == "lt") || (temp == "column") || (temp == "square")) { phylip = true; outputForm = temp; }
+ else { m->mothurOut("Options for distance are: lt, square, or column. Using lt."); m->mothurOutEndLine(); phylip = true; outputForm = "lt"; }
+ }
temp = validParameter.validFile(parameters, "random", false); if (temp == "not found") { temp = "f"; }
random = m->isTrue(temp);
m->mothurOut("The unifrac.unweighted command parameters are groups, iters, distance, processors and random. No parameters are required.\n");
m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 1 valid group.\n");
m->mothurOut("The group names are separated by dashes. The iters parameter allows you to specify how many random trees you would like compared to your tree.\n");
- m->mothurOut("The distance parameter allows you to create a distance file from the results. The default is false.\n");
+ m->mothurOut("The distance parameter allows you to create a distance file from the results. The default is false. You may set distance to lt, square or column.\n");
m->mothurOut("The random parameter allows you to shut off the comparison to random trees. The default is false, meaning compare don't your trees with randomly generated trees.\n");
m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n");
m->mothurOut("The unifrac.unweighted command should be in the following format: unifrac.unweighted(groups=yourGroups, iters=yourIters).\n");
/***********************************************************/
void UnifracUnweightedCommand::createPhylipFile(int i) {
try {
- string phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted.dist";
- outputNames.push_back(phylipFileName); outputTypes["phylip"].push_back(phylipFileName);
+ string phylipFileName;
+ if ((outputForm == "lt") || (outputForm == "square")) {
+ phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted.phylip.dist";
+ outputNames.push_back(phylipFileName); outputTypes["phylip"].push_back(phylipFileName);
+ }else { //column
+ phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted.column.dist";
+ outputNames.push_back(phylipFileName); outputTypes["column"].push_back(phylipFileName);
+ }
ofstream out;
m->openOutputFile(phylipFileName, out);
-
- //output numSeqs
- out << globaldata->Groups.size() << endl;
-
+
+ if ((outputForm == "lt") || (outputForm == "square")) {
+ //output numSeqs
+ out << globaldata->Groups.size() << endl;
+ }
+
//make matrix with scores in it
vector< vector<float> > dists; dists.resize(globaldata->Groups.size());
for (int i = 0; i < globaldata->Groups.size(); i++) {
if (name.length() < 10) { //pad with spaces to make compatible
while (name.length() < 10) { name += " "; }
}
- out << name << '\t';
- //output distances
- for (int l = 0; l < r; l++) { out << dists[r][l] << '\t'; }
- out << endl;
+ if (outputForm == "lt") {
+ out << name << '\t';
+
+ //output distances
+ for (int l = 0; l < r; l++) { out << dists[r][l] << '\t'; }
+ out << endl;
+ }else if (outputForm == "square") {
+ out << name << '\t';
+
+ //output distances
+ for (int l = 0; l < globaldata->Groups.size(); l++) { out << dists[r][l] << '\t'; }
+ out << endl;
+ }else{
+ //output distances
+ for (int l = 0; l < r; l++) {
+ string otherName = globaldata->Groups[l];
+ if (otherName.length() < 10) { //pad with spaces to make compatible
+ while (otherName.length() < 10) { otherName += " "; }
+ }
+
+ out << name << '\t' << otherName << dists[r][l] << endl;
+ }
+ }
}
out.close();
}
vector< map<float, float> > rCumul; //map <unweighted score, cumulative percentage of number of random trees with that score or higher.> -vector entry for each combination.
bool abort, phylip, random;
- string groups, itersString, outputDir;
+ string groups, itersString, outputDir, outputForm;
vector<string> Groups, outputNames; //holds groups to be used
map<string, vector<string> > outputTypes;
outputTypes["weighted"] = tempOutNames;
outputTypes["wsummary"] = tempOutNames;
outputTypes["phylip"] = tempOutNames;
+ outputTypes["column"] = tempOutNames;
}
catch(exception& e) {
m->errorOut(e, "UnifracWeightedCommand", "UnifracWeightedCommand");
outputTypes["weighted"] = tempOutNames;
outputTypes["wsummary"] = tempOutNames;
outputTypes["phylip"] = tempOutNames;
+ outputTypes["column"] = tempOutNames;
if (globaldata->gTree.size() == 0) {//no trees were read
m->mothurOut("You must execute the read.tree command, before you may execute the unifrac.weighted command."); m->mothurOutEndLine(); abort = true; }
itersString = validParameter.validFile(parameters, "iters", false); if (itersString == "not found") { itersString = "1000"; }
convert(itersString, iters);
- string temp = validParameter.validFile(parameters, "distance", false); if (temp == "not found") { temp = "false"; }
- phylip = m->isTrue(temp);
-
+ string temp = validParameter.validFile(parameters, "distance", false);
+ if (temp == "not found") { phylip = false; outputForm = ""; }
+ else{
+ if ((temp == "lt") || (temp == "column") || (temp == "square")) { phylip = true; outputForm = temp; }
+ else { m->mothurOut("Options for distance are: lt, square, or column. Using lt."); m->mothurOutEndLine(); phylip = true; outputForm = "lt"; }
+ }
+
temp = validParameter.validFile(parameters, "random", false); if (temp == "not found") { temp = "F"; }
random = m->isTrue(temp);
//for each tree
for (int i = 0; i < T.size(); i++) {
- string phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted.dist";
- outputNames.push_back(phylipFileName);
- outputTypes["phylip"].push_back(phylipFileName);
+ string phylipFileName;
+ if ((outputForm == "lt") || (outputForm == "square")) {
+ phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted.phylip.dist";
+ outputNames.push_back(phylipFileName); outputTypes["phylip"].push_back(phylipFileName);
+ }else { //column
+ phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted.column.dist";
+ outputNames.push_back(phylipFileName); outputTypes["column"].push_back(phylipFileName);
+ }
+
ofstream out;
m->openOutputFile(phylipFileName, out);
- //output numSeqs
- out << globaldata->Groups.size() << endl;
-
+ if ((outputForm == "lt") || (outputForm == "square")) {
+ //output numSeqs
+ out << globaldata->Groups.size() << endl;
+ }
+
//make matrix with scores in it
vector< vector<float> > dists; dists.resize(globaldata->Groups.size());
for (int i = 0; i < globaldata->Groups.size(); i++) {
if (name.length() < 10) { //pad with spaces to make compatible
while (name.length() < 10) { name += " "; }
}
- out << name << '\t';
- //output distances
- for (int l = 0; l < r; l++) { out << dists[r][l] << '\t'; }
- out << endl;
+ if (outputForm == "lt") {
+ out << name << '\t';
+
+ //output distances
+ for (int l = 0; l < r; l++) { out << dists[r][l] << '\t'; }
+ out << endl;
+ }else if (outputForm == "square") {
+ out << name << '\t';
+
+ //output distances
+ for (int l = 0; l < globaldata->Groups.size(); l++) { out << dists[r][l] << '\t'; }
+ out << endl;
+ }else{
+ //output distances
+ for (int l = 0; l < r; l++) {
+ string otherName = globaldata->Groups[l];
+ if (otherName.length() < 10) { //pad with spaces to make compatible
+ while (otherName.length() < 10) { otherName += " "; }
+ }
+
+ out << name << '\t' << otherName << dists[r][l] << endl;
+ }
+ }
}
out.close();
}
map<float, float> validScores; //map contains scores from random
bool abort, phylip, random;
- string groups, itersString;
+ string groups, itersString, outputForm;
vector<string> Groups, outputNames; //holds groups to be used
map<string, vector<string> > outputTypes;
int processors;