2 * chimeraseqscommand.cpp
5 * Created by Sarah Westcott on 6/29/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "chimeraseqscommand.h"
11 #include "bellerophon.h"
14 //***************************************************************************************************************
16 ChimeraSeqsCommand::ChimeraSeqsCommand(string option){
20 //allow user to run help
21 if(option == "help") { help(); abort = true; }
24 //valid paramters for this command
25 string Array[] = {"fasta", "filter", "correction", "processors", "method", "window", "increment", "template", "conservation" };
26 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
28 OptionParser parser(option);
29 map<string,string> parameters = parser.getParameters();
31 ValidParameters validParameter;
33 //check to make sure all parameters are valid for command
34 for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
35 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
38 //check for required parameters
39 fastafile = validParameter.validFile(parameters, "fasta", true);
40 if (fastafile == "not open") { abort = true; }
41 else if (fastafile == "not found") { fastafile = ""; mothurOut("fasta is a required parameter for the chimera.seqs command."); mothurOutEndLine(); abort = true; }
43 templatefile = validParameter.validFile(parameters, "template", true);
44 if (templatefile == "not open") { abort = true; }
45 else if (templatefile == "not found") { templatefile = ""; }
47 consfile = validParameter.validFile(parameters, "conservation", true);
48 if (consfile == "not open") { abort = true; }
49 else if (consfile == "not found") { consfile = ""; }
53 temp = validParameter.validFile(parameters, "filter", false); if (temp == "not found") { temp = "T"; }
54 filter = isTrue(temp);
56 temp = validParameter.validFile(parameters, "correction", false); if (temp == "not found") { temp = "T"; }
57 correction = isTrue(temp);
59 temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; }
60 convert(temp, processors);
62 temp = validParameter.validFile(parameters, "window", false); if (temp == "not found") { temp = "0"; }
63 convert(temp, window);
65 temp = validParameter.validFile(parameters, "increment", false); if (temp == "not found") { temp = "25"; }
66 convert(temp, increment);
68 method = validParameter.validFile(parameters, "method", false); if (method == "not found") { method = "pintail"; }
70 if ((method == "pintail") && (templatefile == "") && (consfile == "")) { mothurOut("You must provide a template or conservation file with the pintail method."); mothurOutEndLine(); abort = true; }
76 errorOut(e, "ChimeraSeqsCommand", "ChimeraSeqsCommand");
80 //**********************************************************************************************************************
82 void ChimeraSeqsCommand::help(){
84 mothurOut("The chimera.seqs command reads a fastafile and creates a sorted priority score list of potentially chimeric sequences (ideally, the sequences should already be aligned).\n");
85 mothurOut("The chimera.seqs command parameters are fasta, filter, correction, processors and method. fasta is required.\n");
86 mothurOut("The filter parameter allows you to specify if you would like to apply a 50% soft filter. The default is false. \n");
87 mothurOut("The correction parameter allows you to put more emphasis on the distance between highly similar sequences and less emphasis on the differences between remote homologs. The default is true. \n");
88 mothurOut("The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n");
89 mothurOut("The method parameter allows you to specify the method for finding chimeric sequences. The default is pintail. \n");
90 mothurOut("The chimera.seqs command should be in the following format: \n");
91 mothurOut("chimera.seqs(fasta=yourFastaFile, filter=yourFilter, correction=yourCorrection, processors=yourProcessors, method=bellerophon) \n");
92 mothurOut("Example: chimera.seqs(fasta=AD.align, filter=True, correction=true, processors=2, method=yourMethod) \n");
93 mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n");
96 errorOut(e, "ChimeraSeqsCommand", "help");
101 //***************************************************************************************************************
103 ChimeraSeqsCommand::~ChimeraSeqsCommand(){ /* do nothing */ }
105 //***************************************************************************************************************
107 int ChimeraSeqsCommand::execute(){
110 if (abort == true) { return 0; }
112 if (method == "bellerophon") { chimera = new Bellerophon(fastafile); }
113 else if (method == "pintail") { chimera = new Pintail(fastafile, templatefile);
114 if (consfile != "") { chimera->setCons(consfile); }
115 else { chimera->setCons(""); }
116 }else { mothurOut("Not a valid method."); mothurOutEndLine(); return 0; }
119 chimera->setFilter(filter);
120 chimera->setCorrection(correction);
121 chimera->setProcessors(processors);
122 chimera->setWindow(window);
123 chimera->setIncrement(increment);
126 chimera->getChimeras();
128 string outputFileName = getRootName(fastafile) + method + ".chimeras";
130 openOutputFile(outputFileName, out);
142 catch(exception& e) {
143 errorOut(e, "ChimeraSeqsCommand", "execute");
147 /**************************************************************************************************/