]> git.donarmstrong.com Git - mothur.git/blob - chimeraseqscommand.cpp
899d6ef33a5ec05ffe12ea24891c9680b33d0733
[mothur.git] / chimeraseqscommand.cpp
1 /*
2  *  chimeraseqscommand.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 6/29/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "chimeraseqscommand.h"
11 #include "bellerophon.h"
12 #include "pintail.h"
13
14 //***************************************************************************************************************
15
16 ChimeraSeqsCommand::ChimeraSeqsCommand(string option){
17         try {
18                 abort = false;
19                 
20                 //allow user to run help
21                 if(option == "help") { help(); abort = true; }
22                 
23                 else {
24                         //valid paramters for this command
25                         string Array[] =  {"fasta", "filter", "correction", "processors", "method", "window", "increment", "template", "conservation", "quantile", "mask" };
26                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
27                         
28                         OptionParser parser(option);
29                         map<string,string> parameters = parser.getParameters();
30                         
31                         ValidParameters validParameter;
32                         
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;  }
36                         }
37                         
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;  }     
42                         
43                         templatefile = validParameter.validFile(parameters, "template", true);
44                         if (templatefile == "not open") { abort = true; }
45                         else if (templatefile == "not found") { templatefile = "";  }   
46                         
47                         consfile = validParameter.validFile(parameters, "conservation", true);
48                         if (consfile == "not open") { abort = true; }
49                         else if (consfile == "not found") { consfile = "";  }   
50                         
51                         quanfile = validParameter.validFile(parameters, "quantile", true);
52                         if (quanfile == "not open") { abort = true; }
53                         else if (quanfile == "not found") { quanfile = "";  }
54                                 
55                         maskfile = validParameter.validFile(parameters, "mask", false);
56                         if (maskfile == "not found") { maskfile = "";  }        
57                         else if (maskfile != "default")  { 
58                                 ifstream in;
59                                 int     ableToOpen = openInputFile(maskfile, in);
60                                 if (ableToOpen == 1) { abort = true; }
61                                 in.close();
62                         }
63                 
64
65                         
66
67                         string temp;
68                         temp = validParameter.validFile(parameters, "filter", false);                   if (temp == "not found") { temp = "F"; }
69                         filter = isTrue(temp);
70                         
71                         temp = validParameter.validFile(parameters, "correction", false);               if (temp == "not found") { temp = "T"; }
72                         correction = isTrue(temp);
73                         
74                         temp = validParameter.validFile(parameters, "processors", false);               if (temp == "not found") { temp = "1"; }
75                         convert(temp, processors);
76                         
77                         temp = validParameter.validFile(parameters, "window", false);                   if (temp == "not found") { temp = "0"; }
78                         convert(temp, window);
79                                         
80                         temp = validParameter.validFile(parameters, "increment", false);                        if (temp == "not found") { temp = "25"; }
81                         convert(temp, increment);
82                                 
83                         method = validParameter.validFile(parameters, "method", false);         if (method == "not found") { method = "pintail"; }
84                         
85                         if ((method == "pintail") && (templatefile == "")) { mothurOut("You must provide a template file with the pintail method."); mothurOutEndLine(); abort = true;  }
86                         
87
88                 }
89         }
90         catch(exception& e) {
91                 errorOut(e, "ChimeraSeqsCommand", "ChimeraSeqsCommand");
92                 exit(1);
93         }
94 }
95 //**********************************************************************************************************************
96
97 void ChimeraSeqsCommand::help(){
98         try {
99                 mothurOut("chimera.seqs ASSUMES that your sequences are ALIGNED.\n");
100                 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");
101                 mothurOut("The chimera.seqs command parameters are fasta, filter, correction, processors, mask, method, window, increment, template, conservation and quantile.\n");
102                 mothurOut("The filter parameter allows you to specify if you would like to apply a 50% soft filter this only applies when the method is bellerphon.  The default is false. \n");
103                 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. This only applies when the method is bellerphon.\n");
104                 mothurOut("The processors parameter allows you to specify how many processors you would like to use.  The default is 1. \n");
105                 mothurOut("The method parameter allows you to specify the method for finding chimeric sequences.  The default is pintail. Options include..... \n");
106                 mothurOut("The mask parameter allows you to specify a file containing one sequence you wish to use as a mask for the pintail and mallard method.  The default is no mask.  If you enter mask=default, then the mask is 236627 EU009184.1 Shigella dysenteriae str. FBD013. \n");
107                 mothurOut("The window parameter allows you to specify the window size for searching for chimeras.  The default is 300 is method is pintail unless the sequence length is less than 300, and 1/4 sequence length for bellerphon.\n");
108                 mothurOut("The increment parameter allows you to specify how far you move each window while finding chimeric sequences.  The default is 25.\n");
109                 mothurOut("The template parameter allows you to enter a template file containing known non-chimeric sequences for use by the pintail algorythm. It is a required parameter if using pintail.\n");
110                 mothurOut("The conservation parameter allows you to enter a frequency file containing the highest bases frequency at each place in the alignment for use by the pintail algorythm. It is not required, but will speed up the pintail method.\n");
111                 mothurOut("The quantile parameter allows you to enter a file containing quantiles for a template files sequences for use by the pintail algorythm. It is not required, but will speed up the pintail method.\n");
112                 mothurOut("If you have run chimera.seqs using pintail a .quan and .freq file will be created if you have not provided them for use in future command executions.");
113                 mothurOut("The chimera.seqs command should be in the following format: \n");
114                 mothurOut("chimera.seqs(fasta=yourFastaFile, filter=yourFilter, correction=yourCorrection, processors=yourProcessors, method=bellerophon) \n");
115                 mothurOut("Example: chimera.seqs(fasta=AD.align, filter=True, correction=true, processors=2, method=yourMethod) \n");
116                 mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n");        
117         }
118         catch(exception& e) {
119                 errorOut(e, "ChimeraSeqsCommand", "help");
120                 exit(1);
121         }
122 }
123
124 //***************************************************************************************************************
125
126 ChimeraSeqsCommand::~ChimeraSeqsCommand(){      /*      do nothing      */      }
127
128 //***************************************************************************************************************
129
130 int ChimeraSeqsCommand::execute(){
131         try{
132                 
133                 if (abort == true) { return 0; }
134                 
135                 if (method == "bellerophon")    {               chimera = new Bellerophon(fastafile);                   }
136                 else if (method == "pintail")   {               chimera = new Pintail(fastafile, templatefile); 
137                         //saves time to avoid generating it
138                         if (consfile != "")                     {               chimera->setCons(consfile);                                             }
139                         else                                            {               chimera->setCons("");                                                   }
140                         
141                         //saves time to avoid generating it
142                         if (quanfile != "")                     {               chimera->setQuantiles(quanfile);                                }
143                         else                                            {               chimera->setQuantiles("");                                              }
144                         
145                         if (maskfile == "default") { mothurOut("I am using the default 236627 EU009184.1 Shigella dysenteriae str. FBD013."); mothurOutEndLine();  }
146                         chimera->setMask(maskfile);
147                                                 
148                 }else { mothurOut("Not a valid method."); mothurOutEndLine(); return 0;         }
149                 
150                 //set user options
151                 chimera->setFilter(filter);
152                 chimera->setCorrection(correction);
153                 chimera->setProcessors(processors);
154                 chimera->setWindow(window);
155                 chimera->setIncrement(increment);
156                                 
157                 //find chimeras
158                 chimera->getChimeras();
159                 
160                 string outputFileName = getRootName(fastafile) + method + maskfile + ".chimeras";
161                 ofstream out;
162                 openOutputFile(outputFileName, out);
163                 
164                 //print results
165                 chimera->print(out);
166                 
167                 out.close();
168                 
169                 delete chimera;
170                 
171                 return 0;
172                 
173         }
174         catch(exception& e) {
175                 errorOut(e, "ChimeraSeqsCommand", "execute");
176                 exit(1);
177         }
178 }
179 /**************************************************************************************************/
180