2 * consensusseqscommand.cpp
5 * Created by westcott on 11/23/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "consensusseqscommand.h"
11 #include "sequence.hpp"
12 #include "inputdata.h"
14 //**********************************************************************************************************************
15 vector<string> ConsensusSeqsCommand::setParameters(){
17 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta);
18 CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname);
19 CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(plist);
20 CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
21 CommandParameter pcutoff("cutoff", "Number", "", "100", "", "", "",false,false); parameters.push_back(pcutoff);
22 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
23 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
25 vector<string> myArray;
26 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
30 m->errorOut(e, "ConsensusSeqsCommand", "setParameters");
34 //**********************************************************************************************************************
35 string ConsensusSeqsCommand::getHelpString(){
37 string helpString = "";
38 helpString += "The consensus.seqs command can be used in 2 ways: create a consensus sequence from a fastafile, or with a listfile create a consensus sequence for each otu. Sequences must be aligned.\n";
39 helpString += "The consensus.seqs command parameters are fasta, list, name, cutoff and label.\n";
40 helpString += "The fasta parameter allows you to enter the fasta file containing your sequences, and is required, unless you have a valid current fasta file. \n";
41 helpString += "The list parameter allows you to enter a your list file. \n";
42 helpString += "The name parameter allows you to enter a names file associated with the fasta file. \n";
43 helpString += "The label parameter allows you to select what distance levels you would like output files for, and are separated by dashes.\n";
44 helpString += "The cutoff parameter allows you set a percentage of sequences that support the base. For example: cutoff=97 would only return a sequence that only showed ambiguities for bases that were not supported by at least 97% of sequences.\n";
45 helpString += "The consensus.seqs command should be in the following format: \n";
46 helpString += "consensus.seqs(fasta=yourFastaFile, list=yourListFile) \n";
47 helpString += "Example: consensus.seqs(fasta=abrecovery.align, list=abrecovery.fn.list) \n";
48 helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n";
52 m->errorOut(e, "ConsensusSeqsCommand", "getHelpString");
57 //**********************************************************************************************************************
58 ConsensusSeqsCommand::ConsensusSeqsCommand(){
60 abort = true; calledHelp = true;
62 vector<string> tempOutNames;
63 outputTypes["fasta"] = tempOutNames;
64 outputTypes["name"] = tempOutNames;
65 outputTypes["summary"] = tempOutNames;
68 m->errorOut(e, "ConsensusSeqsCommand", "ConsensusSeqsCommand");
72 //***************************************************************************************************************
73 ConsensusSeqsCommand::ConsensusSeqsCommand(string option) {
75 abort = false; calledHelp = false;
78 //allow user to run help
79 if(option == "help") { help(); abort = true; calledHelp = true; }
80 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
84 vector<string> myArray = setParameters();
86 OptionParser parser(option);
87 map<string,string> parameters = parser.getParameters();
89 ValidParameters validParameter;
90 map<string,string>::iterator it;
92 //check to make sure all parameters are valid for command
93 for (it = parameters.begin(); it != parameters.end(); it++) {
94 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
97 //initialize outputTypes
98 vector<string> tempOutNames;
99 outputTypes["fasta"] = tempOutNames;
100 outputTypes["name"] = tempOutNames;
101 outputTypes["summary"] = tempOutNames;
104 //if the user changes the input directory command factory will send this info to us in the output parameter
105 string inputDir = validParameter.validFile(parameters, "inputdir", false);
106 if (inputDir == "not found"){ inputDir = ""; }
109 it = parameters.find("fasta");
110 //user has given a template file
111 if(it != parameters.end()){
112 path = m->hasPath(it->second);
113 //if the user has not given a path then, add inputdir. else leave path alone.
114 if (path == "") { parameters["fasta"] = inputDir + it->second; }
117 it = parameters.find("name");
118 //user has given a template file
119 if(it != parameters.end()){
120 path = m->hasPath(it->second);
121 //if the user has not given a path then, add inputdir. else leave path alone.
122 if (path == "") { parameters["name"] = inputDir + it->second; }
125 it = parameters.find("list");
126 //user has given a template file
127 if(it != parameters.end()){
128 path = m->hasPath(it->second);
129 //if the user has not given a path then, add inputdir. else leave path alone.
130 if (path == "") { parameters["list"] = inputDir + it->second; }
135 //check for parameters
136 fastafile = validParameter.validFile(parameters, "fasta", true);
137 if (fastafile == "not open") { abort = true; }
138 else if (fastafile == "not found") {
139 fastafile = m->getFastaFile();
140 if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); }
141 else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; }
142 }else { m->setFastaFile(fastafile); }
144 namefile = validParameter.validFile(parameters, "name", true);
145 if (namefile == "not open") { namefile = ""; abort = true; }
146 else if (namefile == "not found") { namefile = ""; }
147 else { m->setNameFile(namefile); }
149 listfile = validParameter.validFile(parameters, "list", true);
150 if (listfile == "not open") { abort = true; }
151 else if (listfile == "not found") { listfile = ""; }
152 else { m->setListFile(listfile); }
154 label = validParameter.validFile(parameters, "label", false);
155 if (label == "not found") { label = ""; }
157 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
158 else { allLines = 1; }
161 string temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "100"; }
162 m->mothurConvert(temp, cutoff);
164 //if the user changes the output directory command factory will send this info to us in the output parameter
165 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(fastafile); }
168 vector<string> files; files.push_back(fastafile);
169 parser.getNameFile(files);
173 catch(exception& e) {
174 m->errorOut(e, "ConsensusSeqsCommand", "ConsensusSeqsCommand");
178 //***************************************************************************************************************
180 int ConsensusSeqsCommand::execute(){
183 if (abort == true) { if (calledHelp) { return 0; } return 2; }
187 if (m->control_pressed) { return 0; }
189 if (namefile != "") { readNames(); }
191 if (m->control_pressed) { return 0; }
194 if (listfile == "") {
197 string outputSummaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "cons.summary";
198 m->openOutputFile(outputSummaryFile, outSummary);
199 outSummary.setf(ios::fixed, ios::floatfield); outSummary.setf(ios::showpoint);
200 outputNames.push_back(outputSummaryFile); outputTypes["summary"].push_back(outputSummaryFile);
202 outSummary << "PositioninAlignment\tA\tT\tG\tC\tGap\tNumberofSeqs\tConsensusBase" << endl;
205 string outputFastaFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "cons.fasta";
206 m->openOutputFile(outputFastaFile, outFasta);
207 outputNames.push_back(outputFastaFile); outputTypes["fasta"].push_back(outputFastaFile);
211 for (map<string, string>::iterator it = nameMap.begin(); it != nameMap.end(); it++) {
213 if (m->control_pressed) { outSummary.close(); outFasta.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
215 string seq = fastaMap[it->second];
218 if (seqLength == 0) { seqLength = seq.length(); }
219 else if (seqLength != seq.length()) { m->mothurOut("[ERROR]: sequence are not the same length, please correct."); m->mothurOutEndLine(); m->control_pressed = true; }
223 vector< vector<float> > percentages; percentages.resize(5);
224 for (int j = 0; j < percentages.size(); j++) { percentages[j].resize(seqLength, 0.0); }
228 for (int j = 0; j < seqLength; j++) {
230 if (m->control_pressed) { outSummary.close(); outFasta.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
232 vector<int> counts; counts.resize(5, 0); //A,T,G,C,Gap
235 for (int i = 0; i < seqs.size(); i++) {
237 if (seqs[i][j] == '.') { numDots++; }
239 char base = toupper(seqs[i][j]);
240 if (base == 'A') { counts[0]++; }
241 else if (base == 'T') { counts[1]++; }
242 else if (base == 'G') { counts[2]++; }
243 else if (base == 'C') { counts[3]++; }
244 else { counts[4]++; }
248 if (numDots != seqs.size()) { conBase = getBase(counts, seqs.size()); }
252 percentages[0][j] = counts[0] / (float) seqs.size();
253 percentages[1][j] = counts[1] / (float) seqs.size();
254 percentages[2][j] = counts[2] / (float) seqs.size();
255 percentages[3][j] = counts[3] / (float) seqs.size();
256 percentages[4][j] = counts[4] / (float) seqs.size();
260 for (int j = 0; j < seqLength; j++) {
261 outSummary << (j+1) << '\t' << percentages[0][j] << '\t'<< percentages[1][j] << '\t'<< percentages[2][j] << '\t' << percentages[3][j] << '\t' << percentages[4][j] << '\t' << seqs.size() << '\t' << consSeq[j] << endl;
265 outFasta << ">conseq" << endl << consSeq << endl;
267 outSummary.close(); outFasta.close();
273 InputData* input = new InputData(listfile, "list");
274 ListVector* list = input->getListVector();
276 string lastLabel = list->getLabel();
277 set<string> processedLabels;
278 set<string> userLabels = labels;
280 //as long as you are not at the end of the file or done wih the lines you want
281 while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
283 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete list; delete input; return 0; }
285 if(allLines == 1 || labels.count(list->getLabel()) == 1){
287 m->mothurOut(list->getLabel()); m->mothurOutEndLine();
291 processedLabels.insert(list->getLabel());
292 userLabels.erase(list->getLabel());
295 if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
296 string saveLabel = list->getLabel();
300 list = input->getListVector(lastLabel);
301 m->mothurOut(list->getLabel()); m->mothurOutEndLine();
305 processedLabels.insert(list->getLabel());
306 userLabels.erase(list->getLabel());
308 //restore real lastlabel to save below
309 list->setLabel(saveLabel);
312 lastLabel = list->getLabel();
314 delete list; list = NULL;
316 //get next line to process
317 list = input->getListVector();
321 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } if (list != NULL) { delete list; } delete input; return 0; }
323 //output error messages about any remaining user labels
324 set<string>::iterator it;
325 bool needToRun = false;
326 for (it = userLabels.begin(); it != userLabels.end(); it++) {
327 m->mothurOut("Your file does not include the label " + *it);
328 if (processedLabels.count(lastLabel) != 1) {
329 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
332 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
336 //run last label if you need to
337 if (needToRun == true) {
338 if (list != NULL) { delete list; }
340 list = input->getListVector(lastLabel);
342 m->mothurOut(list->getLabel()); m->mothurOutEndLine();
346 delete list; list = NULL;
349 if (list != NULL) { delete list; }
353 m->mothurOutEndLine();
354 m->mothurOut("Output File Name: "); m->mothurOutEndLine();
355 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
356 m->mothurOutEndLine();
362 catch(exception& e) {
363 m->errorOut(e, "ConsensusSeqsCommand", "execute");
367 //***************************************************************************************************************
369 int ConsensusSeqsCommand::processList(ListVector*& list){
373 string outputSummaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + ".cons.summary";
374 m->openOutputFile(outputSummaryFile, outSummary);
375 outSummary.setf(ios::fixed, ios::floatfield); outSummary.setf(ios::showpoint);
376 outputNames.push_back(outputSummaryFile); outputTypes["summary"].push_back(outputSummaryFile);
379 string outputNameFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + ".cons.names";
380 m->openOutputFile(outputNameFile, outName);
381 outputNames.push_back(outputNameFile); outputTypes["name"].push_back(outputNameFile);
384 string outputFastaFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + ".cons.fasta";
385 m->openOutputFile(outputFastaFile, outFasta);
386 outputNames.push_back(outputFastaFile); outputTypes["fasta"].push_back(outputFastaFile);
388 outSummary << "OTU#\tPositioninAlignment\tA\tT\tG\tC\tGap\tNumberofSeqs\tConsensusBase" << endl;
390 for (int i = 0; i < list->getNumBins(); i++) {
392 if (m->control_pressed) { outSummary.close(); outName.close(); outFasta.close(); return 0; }
394 string bin = list->get(i);
397 string consSeq = getConsSeq(bin, outSummary, newName, i);
399 outFasta << ">seq" << (i+1) << endl << consSeq << endl;
400 outName << "seq" << (i+1) << '\t' << "seq" << (i+1) << "," << newName << endl;
403 outSummary.close(); outName.close(); outFasta.close();
408 catch(exception& e) {
409 m->errorOut(e, "ConsensusSeqsCommand", "processList");
414 //***************************************************************************************************************
415 //made this smart enough to owrk with unique or non unique list file
416 string ConsensusSeqsCommand::getConsSeq(string bin, ofstream& outSummary, string& name, int binNumber){
422 //the whole bin is the second column if no names file, otherwise build it
424 if (namefile != "") { name = ""; }
426 vector<string> binNames;
427 m->splitAtComma(bin, binNames);
429 //get sequence strings for each name in the bin
432 set<string> addedAlready;
434 for (int i = 0; i < binNames.size(); i++) {
436 map<string, string>::iterator it;
438 it = nameMap.find(binNames[i]);
439 if (it == nameMap.end()) {
440 if (namefile == "") { m->mothurOut("[ERROR]: " + binNames[i] + " is not in your fasta file, please correct."); m->mothurOutEndLine(); error = true; }
441 else { m->mothurOut("[ERROR]: " + binNames[i] + " is not in your fasta or name file, please correct."); m->mothurOutEndLine(); error = true; }
445 //add sequence string to seqs vector to process below
446 string seq = fastaMap[it->second];
449 if (seqLength == 0) { seqLength = seq.length(); }
450 else if (seqLength != seq.length()) { m->mothurOut("[ERROR]: sequence are not the same length, please correct."); m->mothurOutEndLine(); error = true; break; }
452 if (namefile != "") {
453 //did we add this line from name file already?
454 if (addedAlready.count(it->second) == 0) {
455 name += "," + nameFileMap[it->second];
456 addedAlready.insert(it->second);
463 if (error) { m->control_pressed = true; return consSeq; }
465 if (namefile != "") { name = name.substr(1); }
467 vector< vector<float> > percentages; percentages.resize(5);
468 for (int j = 0; j < percentages.size(); j++) { percentages[j].resize(seqLength, 0.0); }
471 for (int j = 0; j < seqLength; j++) {
473 if (m->control_pressed) { return consSeq; }
475 vector<int> counts; counts.resize(5, 0); //A,T,G,C,Gap
478 for (int i = 0; i < seqs.size(); i++) {
480 if (seqs[i][j] == '.') { numDots++; }
482 char base = toupper(seqs[i][j]);
483 if (base == 'A') { counts[0]++; }
484 else if (base == 'T') { counts[1]++; }
485 else if (base == 'G') { counts[2]++; }
486 else if (base == 'C') { counts[3]++; }
487 else { counts[4]++; }
491 if (numDots != seqs.size()) { conBase = getBase(counts, seqs.size()); }
495 percentages[0][j] = counts[0] / (float) seqs.size();
496 percentages[1][j] = counts[1] / (float) seqs.size();
497 percentages[2][j] = counts[2] / (float) seqs.size();
498 percentages[3][j] = counts[3] / (float) seqs.size();
499 percentages[4][j] = counts[4] / (float) seqs.size();
503 for (int j = 0; j < seqLength; j++) {
504 outSummary << (binNumber + 1) << '\t' << (j+1) << '\t' << percentages[0][j] << '\t'<< percentages[1][j] << '\t'<< percentages[2][j] << '\t' << percentages[3][j] << '\t' << percentages[4][j] << '\t' << seqs.size() << '\t' << consSeq[j] << endl;
510 catch(exception& e) {
511 m->errorOut(e, "ConsensusSeqsCommand", "getConsSeq");
515 //***************************************************************************************************************
517 char ConsensusSeqsCommand::getBase(vector<int> counts, int size){ //A,T,G,C,Gap
524 * Y = T C (pyrimidine)
527 * S = G C (strong bonds)
528 * W = A T (weak bonds)
529 * B = G T C (all but A)
530 * D = G A T (all but C)
531 * H = A C T (all but G)
532 * V = G C A (all but T)
533 * N = A G C T (any) */
537 //zero out counts that don't make the cutoff
538 float percentage = (100.0 - cutoff) / 100.0;
539 int zeroCutoff = percentage * size;
541 for (int i = 0; i < counts.size(); i++) {
542 if (counts[i] < zeroCutoff) { counts[i] = 0; }
546 if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'n'; }
548 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'N'; }
550 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'v'; }
552 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'V'; }
554 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'h'; }
556 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'H'; }
558 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 'd'; }
560 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'D'; }
562 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'b'; }
564 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'B'; }
565 //W = A T (weak bonds)
566 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 'w'; }
567 //W = A T (weak bonds) no gap
568 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'W'; }
569 //S = G C (strong bonds)
570 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 's'; }
571 //S = G C (strong bonds) no gap
572 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'S'; }
574 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'm'; }
575 //M = A C (amino) no gap
576 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'M'; }
578 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 'k'; }
579 //K = G T (keto) no gap
580 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'K'; }
581 //Y = T C (pyrimidine)
582 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'y'; }
583 //Y = T C (pyrimidine) no gap
584 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'Y'; }
586 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 'r'; }
587 //R = G A (purine) no gap
588 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'R'; }
590 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 'a'; }
592 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'A'; }
594 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 't'; }
596 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'T'; }
598 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 'g'; }
600 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'G'; }
602 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'c'; }
604 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'C'; }
606 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = '-'; }
607 //cutoff removed all counts
608 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'N'; }
609 else{ m->mothurOut("[ERROR]: cannot find consensus base."); m->mothurOutEndLine(); }
614 catch(exception& e) {
615 m->errorOut(e, "ConsensusSeqsCommand", "getBase");
620 //***************************************************************************************************************
622 int ConsensusSeqsCommand::readFasta(){
626 m->openInputFile(fastafile, in);
630 if (m->control_pressed) { break; }
632 Sequence seq(in); m->gobble(in);
633 string name = seq.getName();
636 fastaMap[name] = seq.getAligned();
637 nameMap[name] = name; //set nameMap incase no names file
638 nameFileMap[name] = name;
647 catch(exception& e) {
648 m->errorOut(e, "ConsensusSeqsCommand", "readFasta");
652 //***************************************************************************************************************
654 int ConsensusSeqsCommand::readNames(){
658 m->openInputFile(namefile, in);
660 string thisname, repnames;
661 map<string, string>::iterator it;
667 if (m->control_pressed) { break; }
669 in >> thisname; m->gobble(in); //read from first column
670 in >> repnames; //read from second column
672 it = nameMap.find(thisname);
673 if (it != nameMap.end()) { //then this sequence was in the fastafile
675 vector<string> splitRepNames;
676 m->splitAtComma(repnames, splitRepNames);
678 nameFileMap[thisname] = repnames; //for later when outputting the new namesFile if the list file is unique
679 for (int i = 0; i < splitRepNames.size(); i++) { nameMap[splitRepNames[i]] = thisname; }
681 }else{ m->mothurOut("[ERROR]: " + thisname + " is not in the fasta file, please correct."); m->mothurOutEndLine(); error = true; }
688 if (error) { m->control_pressed = true; }
693 catch(exception& e) {
694 m->errorOut(e, "ConsensusSeqsCommand", "readNames");
699 //***************************************************************************************************************