]> git.donarmstrong.com Git - mothur.git/blob - chimeraseqscommand.cpp
fixed bug with aligner in database class, worked on chimeras
[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", true);
56                         if (maskfile == "not open") { abort = true; }
57                         else if (maskfile == "not found") { maskfile = "";  }   
58
59                         
60
61                         string temp;
62                         temp = validParameter.validFile(parameters, "filter", false);                   if (temp == "not found") { temp = "T"; }
63                         filter = isTrue(temp);
64                         
65                         temp = validParameter.validFile(parameters, "correction", false);               if (temp == "not found") { temp = "T"; }
66                         correction = isTrue(temp);
67                         
68                         temp = validParameter.validFile(parameters, "processors", false);               if (temp == "not found") { temp = "1"; }
69                         convert(temp, processors);
70                         
71                         temp = validParameter.validFile(parameters, "window", false);                   if (temp == "not found") { temp = "0"; }
72                         convert(temp, window);
73                                         
74                         temp = validParameter.validFile(parameters, "increment", false);                        if (temp == "not found") { temp = "25"; }
75                         convert(temp, increment);
76                                 
77                         method = validParameter.validFile(parameters, "method", false);         if (method == "not found") { method = "pintail"; }
78                         
79                         if ((method == "pintail") && (templatefile == "")) { mothurOut("You must provide a template file with the pintail method."); mothurOutEndLine(); abort = true;  }
80                         
81
82                 }
83         }
84         catch(exception& e) {
85                 errorOut(e, "ChimeraSeqsCommand", "ChimeraSeqsCommand");
86                 exit(1);
87         }
88 }
89 //**********************************************************************************************************************
90
91 void ChimeraSeqsCommand::help(){
92         try {
93                 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");
94                 mothurOut("The chimera.seqs command parameters are fasta, filter, correction, processors, mask and method.  fasta is required.\n");
95                 mothurOut("The filter parameter allows you to specify if you would like to apply a 50% soft filter.  The default is false. \n");
96                 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");
97                 mothurOut("The processors parameter allows you to specify how many processors you would like to use.  The default is 1. \n");
98                 mothurOut("The method parameter allows you to specify the method for finding chimeric sequences.  The default is pintail. \n");
99                 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 236627 EU009184.1 Shigella dysenteriae str. FBD013. \n");
100                 mothurOut("The chimera.seqs command should be in the following format: \n");
101                 mothurOut("chimera.seqs(fasta=yourFastaFile, filter=yourFilter, correction=yourCorrection, processors=yourProcessors, method=bellerophon) \n");
102                 mothurOut("Example: chimera.seqs(fasta=AD.align, filter=True, correction=true, processors=2, method=yourMethod) \n");
103                 mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n");        
104         }
105         catch(exception& e) {
106                 errorOut(e, "ChimeraSeqsCommand", "help");
107                 exit(1);
108         }
109 }
110
111 //***************************************************************************************************************
112
113 ChimeraSeqsCommand::~ChimeraSeqsCommand(){      /*      do nothing      */      }
114
115 //***************************************************************************************************************
116
117 int ChimeraSeqsCommand::execute(){
118         try{
119                 
120                 if (abort == true) { return 0; }
121                 
122                 if (method == "bellerophon")    {               chimera = new Bellerophon(fastafile);                   }
123                 else if (method == "pintail")   {               chimera = new Pintail(fastafile, templatefile); 
124                         //saves time to avoid generating it
125                         if (consfile != "")                     {               chimera->setCons(consfile);                                             }
126                         else                                            {               chimera->setCons("");                                                   }
127                         
128                         //saves time to avoid generating it
129                         if (quanfile != "")                     {               chimera->setQuantiles(quanfile);                                }
130                         else                                            {               chimera->setQuantiles("");                                              }
131                         
132                         if (maskfile == "") { mothurOut("You have not provided a mask, so I am using the default 236627 EU009184.1 Shigella dysenteriae str. FBD013."); mothurOutEndLine();  }
133                         chimera->setMask(maskfile);
134                                                 
135                 }else { mothurOut("Not a valid method."); mothurOutEndLine(); return 0;         }
136                 
137                 //set user options
138                 chimera->setFilter(filter);
139                 chimera->setCorrection(correction);
140                 chimera->setProcessors(processors);
141                 chimera->setWindow(window);
142                 chimera->setIncrement(increment);
143                                 
144                 //find chimeras
145                 chimera->getChimeras();
146                 
147                 string outputFileName = getRootName(fastafile) + method + ".chimeras";
148                 ofstream out;
149                 openOutputFile(outputFileName, out);
150                 
151                 //print results
152                 chimera->print(out);
153                 
154                 out.close();
155                 
156                 delete chimera;
157                 
158                 return 0;
159                 
160         }
161         catch(exception& e) {
162                 errorOut(e, "ChimeraSeqsCommand", "execute");
163                 exit(1);
164         }
165 }
166 /**************************************************************************************************/
167