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; }
144 namefile = validParameter.validFile(parameters, "name", true);
145 if (namefile == "not open") { abort = true; }
146 else if (namefile == "not found") { namefile = ""; }
148 listfile = validParameter.validFile(parameters, "list", true);
149 if (listfile == "not open") { abort = true; }
150 else if (listfile == "not found") { listfile = ""; }
152 label = validParameter.validFile(parameters, "label", false);
153 if (label == "not found") { label = ""; }
155 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
156 else { allLines = 1; }
159 string temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "100"; }
160 convert(temp, cutoff);
162 //if the user changes the output directory command factory will send this info to us in the output parameter
163 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(fastafile); }
167 catch(exception& e) {
168 m->errorOut(e, "ConsensusSeqsCommand", "ConsensusSeqsCommand");
172 //***************************************************************************************************************
174 int ConsensusSeqsCommand::execute(){
177 if (abort == true) { if (calledHelp) { return 0; } return 2; }
181 if (m->control_pressed) { return 0; }
183 if (namefile != "") { readNames(); }
185 if (m->control_pressed) { return 0; }
188 if (listfile == "") {
191 string outputSummaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "cons.summary";
192 m->openOutputFile(outputSummaryFile, outSummary);
193 outSummary.setf(ios::fixed, ios::floatfield); outSummary.setf(ios::showpoint);
194 outputNames.push_back(outputSummaryFile); outputTypes["summary"].push_back(outputSummaryFile);
196 outSummary << "PositioninAlignment\tA\tT\tG\tC\tGap\tNumberofSeqs\tConsensusBase" << endl;
199 string outputFastaFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "cons.fasta";
200 m->openOutputFile(outputFastaFile, outFasta);
201 outputNames.push_back(outputFastaFile); outputTypes["fasta"].push_back(outputFastaFile);
205 for (map<string, string>::iterator it = nameMap.begin(); it != nameMap.end(); it++) {
207 if (m->control_pressed) { outSummary.close(); outFasta.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
209 string seq = fastaMap[it->second];
212 if (seqLength == 0) { seqLength = seq.length(); }
213 else if (seqLength != seq.length()) { m->mothurOut("[ERROR]: sequence are not the same length, please correct."); m->mothurOutEndLine(); m->control_pressed = true; }
217 vector< vector<float> > percentages; percentages.resize(5);
218 for (int j = 0; j < percentages.size(); j++) { percentages[j].resize(seqLength, 0.0); }
222 for (int j = 0; j < seqLength; j++) {
224 if (m->control_pressed) { outSummary.close(); outFasta.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
226 vector<int> counts; counts.resize(5, 0); //A,T,G,C,Gap
229 for (int i = 0; i < seqs.size(); i++) {
231 if (seqs[i][j] == '.') { numDots++; }
233 char base = toupper(seqs[i][j]);
234 if (base == 'A') { counts[0]++; }
235 else if (base == 'T') { counts[1]++; }
236 else if (base == 'G') { counts[2]++; }
237 else if (base == 'C') { counts[3]++; }
238 else { counts[4]++; }
242 if (numDots != seqs.size()) { conBase = getBase(counts, seqs.size()); }
246 percentages[0][j] = counts[0] / (float) seqs.size();
247 percentages[1][j] = counts[1] / (float) seqs.size();
248 percentages[2][j] = counts[2] / (float) seqs.size();
249 percentages[3][j] = counts[3] / (float) seqs.size();
250 percentages[4][j] = counts[4] / (float) seqs.size();
254 for (int j = 0; j < seqLength; j++) {
255 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;
259 outFasta << ">conseq" << endl << consSeq << endl;
261 outSummary.close(); outFasta.close();
267 InputData* input = new InputData(listfile, "list");
268 ListVector* list = input->getListVector();
270 string lastLabel = list->getLabel();
271 set<string> processedLabels;
272 set<string> userLabels = labels;
274 //as long as you are not at the end of the file or done wih the lines you want
275 while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
277 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete list; delete input; return 0; }
279 if(allLines == 1 || labels.count(list->getLabel()) == 1){
281 m->mothurOut(list->getLabel()); m->mothurOutEndLine();
285 processedLabels.insert(list->getLabel());
286 userLabels.erase(list->getLabel());
289 if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
290 string saveLabel = list->getLabel();
294 list = input->getListVector(lastLabel);
295 m->mothurOut(list->getLabel()); m->mothurOutEndLine();
299 processedLabels.insert(list->getLabel());
300 userLabels.erase(list->getLabel());
302 //restore real lastlabel to save below
303 list->setLabel(saveLabel);
306 lastLabel = list->getLabel();
308 delete list; list = NULL;
310 //get next line to process
311 list = input->getListVector();
315 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } if (list != NULL) { delete list; } delete input; return 0; }
317 //output error messages about any remaining user labels
318 set<string>::iterator it;
319 bool needToRun = false;
320 for (it = userLabels.begin(); it != userLabels.end(); it++) {
321 m->mothurOut("Your file does not include the label " + *it);
322 if (processedLabels.count(lastLabel) != 1) {
323 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
326 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
330 //run last label if you need to
331 if (needToRun == true) {
332 if (list != NULL) { delete list; }
334 list = input->getListVector(lastLabel);
336 m->mothurOut(list->getLabel()); m->mothurOutEndLine();
340 delete list; list = NULL;
343 if (list != NULL) { delete list; }
347 m->mothurOutEndLine();
348 m->mothurOut("Output File Name: "); m->mothurOutEndLine();
349 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
350 m->mothurOutEndLine();
356 catch(exception& e) {
357 m->errorOut(e, "ConsensusSeqsCommand", "execute");
361 //***************************************************************************************************************
363 int ConsensusSeqsCommand::processList(ListVector*& list){
367 string outputSummaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + ".cons.summary";
368 m->openOutputFile(outputSummaryFile, outSummary);
369 outSummary.setf(ios::fixed, ios::floatfield); outSummary.setf(ios::showpoint);
370 outputNames.push_back(outputSummaryFile); outputTypes["summary"].push_back(outputSummaryFile);
373 string outputNameFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + ".cons.names";
374 m->openOutputFile(outputNameFile, outName);
375 outputNames.push_back(outputNameFile); outputTypes["name"].push_back(outputNameFile);
378 string outputFastaFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + ".cons.fasta";
379 m->openOutputFile(outputFastaFile, outFasta);
380 outputNames.push_back(outputFastaFile); outputTypes["fasta"].push_back(outputFastaFile);
382 outSummary << "OTU#\tPositioninAlignment\tA\tT\tG\tC\tGap\tNumberofSeqs\tConsensusBase" << endl;
384 for (int i = 0; i < list->getNumBins(); i++) {
386 if (m->control_pressed) { outSummary.close(); outName.close(); outFasta.close(); return 0; }
388 string bin = list->get(i);
391 string consSeq = getConsSeq(bin, outSummary, newName, i);
393 outFasta << ">seq" << (i+1) << endl << consSeq << endl;
394 outName << "seq" << (i+1) << '\t' << "seq" << (i+1) << "," << newName << endl;
397 outSummary.close(); outName.close(); outFasta.close();
402 catch(exception& e) {
403 m->errorOut(e, "ConsensusSeqsCommand", "processList");
408 //***************************************************************************************************************
409 //made this smart enough to owrk with unique or non unique list file
410 string ConsensusSeqsCommand::getConsSeq(string bin, ofstream& outSummary, string& name, int binNumber){
416 //the whole bin is the second column if no names file, otherwise build it
418 if (namefile != "") { name = ""; }
420 vector<string> binNames;
421 m->splitAtComma(bin, binNames);
423 //get sequence strings for each name in the bin
426 set<string> addedAlready;
428 for (int i = 0; i < binNames.size(); i++) {
430 map<string, string>::iterator it;
432 it = nameMap.find(binNames[i]);
433 if (it == nameMap.end()) {
434 if (namefile == "") { m->mothurOut("[ERROR]: " + binNames[i] + " is not in your fasta file, please correct."); m->mothurOutEndLine(); error = true; }
435 else { m->mothurOut("[ERROR]: " + binNames[i] + " is not in your fasta or name file, please correct."); m->mothurOutEndLine(); error = true; }
439 //add sequence string to seqs vector to process below
440 string seq = fastaMap[it->second];
443 if (seqLength == 0) { seqLength = seq.length(); }
444 else if (seqLength != seq.length()) { m->mothurOut("[ERROR]: sequence are not the same length, please correct."); m->mothurOutEndLine(); error = true; break; }
446 if (namefile != "") {
447 //did we add this line from name file already?
448 if (addedAlready.count(it->second) == 0) {
449 name += "," + nameFileMap[it->second];
450 addedAlready.insert(it->second);
457 if (error) { m->control_pressed = true; return consSeq; }
459 if (namefile != "") { name = name.substr(1); }
461 vector< vector<float> > percentages; percentages.resize(5);
462 for (int j = 0; j < percentages.size(); j++) { percentages[j].resize(seqLength, 0.0); }
465 for (int j = 0; j < seqLength; j++) {
467 if (m->control_pressed) { return consSeq; }
469 vector<int> counts; counts.resize(5, 0); //A,T,G,C,Gap
472 for (int i = 0; i < seqs.size(); i++) {
474 if (seqs[i][j] == '.') { numDots++; }
476 char base = toupper(seqs[i][j]);
477 if (base == 'A') { counts[0]++; }
478 else if (base == 'T') { counts[1]++; }
479 else if (base == 'G') { counts[2]++; }
480 else if (base == 'C') { counts[3]++; }
481 else { counts[4]++; }
485 if (numDots != seqs.size()) { conBase = getBase(counts, seqs.size()); }
489 percentages[0][j] = counts[0] / (float) seqs.size();
490 percentages[1][j] = counts[1] / (float) seqs.size();
491 percentages[2][j] = counts[2] / (float) seqs.size();
492 percentages[3][j] = counts[3] / (float) seqs.size();
493 percentages[4][j] = counts[4] / (float) seqs.size();
497 for (int j = 0; j < seqLength; j++) {
498 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;
504 catch(exception& e) {
505 m->errorOut(e, "ConsensusSeqsCommand", "getConsSeq");
509 //***************************************************************************************************************
511 char ConsensusSeqsCommand::getBase(vector<int> counts, int size){ //A,T,G,C,Gap
518 * Y = T C (pyrimidine)
521 * S = G C (strong bonds)
522 * W = A T (weak bonds)
523 * B = G T C (all but A)
524 * D = G A T (all but C)
525 * H = A C T (all but G)
526 * V = G C A (all but T)
527 * N = A G C T (any) */
531 //zero out counts that don't make the cutoff
532 float percentage = (100.0 - cutoff) / 100.0;
533 int zeroCutoff = percentage * size;
535 for (int i = 0; i < counts.size(); i++) {
536 if (counts[i] < zeroCutoff) { counts[i] = 0; }
540 if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'n'; }
542 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'N'; }
544 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'v'; }
546 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'V'; }
548 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'h'; }
550 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'H'; }
552 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 'd'; }
554 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'D'; }
556 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'b'; }
558 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'B'; }
559 //W = A T (weak bonds)
560 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 'w'; }
561 //W = A T (weak bonds) no gap
562 else if ((counts[0] != 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'W'; }
563 //S = G C (strong bonds)
564 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 's'; }
565 //S = G C (strong bonds) no gap
566 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'S'; }
568 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'm'; }
569 //M = A C (amino) no gap
570 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'M'; }
572 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 'k'; }
573 //K = G T (keto) no gap
574 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'K'; }
575 //Y = T C (pyrimidine)
576 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'y'; }
577 //Y = T C (pyrimidine) no gap
578 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'Y'; }
580 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 'r'; }
581 //R = G A (purine) no gap
582 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'R'; }
584 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 'a'; }
586 else if ((counts[0] != 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'A'; }
588 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 't'; }
590 else if ((counts[0] == 0) && (counts[1] != 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'T'; }
592 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = 'g'; }
594 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] != 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'G'; }
596 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] != 0)) { conBase = 'c'; }
598 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] != 0) && (counts[4] == 0)) { conBase = 'C'; }
600 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] != 0)) { conBase = '-'; }
601 //cutoff removed all counts
602 else if ((counts[0] == 0) && (counts[1] == 0) && (counts[2] == 0) && (counts[3] == 0) && (counts[4] == 0)) { conBase = 'N'; }
603 else{ m->mothurOut("[ERROR]: cannot find consensus base."); m->mothurOutEndLine(); }
608 catch(exception& e) {
609 m->errorOut(e, "ConsensusSeqsCommand", "getBase");
614 //***************************************************************************************************************
616 int ConsensusSeqsCommand::readFasta(){
620 m->openInputFile(fastafile, in);
624 if (m->control_pressed) { break; }
626 Sequence seq(in); m->gobble(in);
627 string name = seq.getName();
630 fastaMap[name] = seq.getAligned();
631 nameMap[name] = name; //set nameMap incase no names file
632 nameFileMap[name] = name;
641 catch(exception& e) {
642 m->errorOut(e, "ConsensusSeqsCommand", "readFasta");
646 //***************************************************************************************************************
648 int ConsensusSeqsCommand::readNames(){
652 m->openInputFile(namefile, in);
654 string thisname, repnames;
655 map<string, string>::iterator it;
661 if (m->control_pressed) { break; }
663 in >> thisname; m->gobble(in); //read from first column
664 in >> repnames; //read from second column
666 it = nameMap.find(thisname);
667 if (it != nameMap.end()) { //then this sequence was in the fastafile
669 vector<string> splitRepNames;
670 m->splitAtComma(repnames, splitRepNames);
672 nameFileMap[thisname] = repnames; //for later when outputting the new namesFile if the list file is unique
673 for (int i = 0; i < splitRepNames.size(); i++) { nameMap[splitRepNames[i]] = thisname; }
675 }else{ m->mothurOut("[ERROR]: " + thisname + " is not in the fasta file, please correct."); m->mothurOutEndLine(); error = true; }
682 if (error) { m->control_pressed = true; }
687 catch(exception& e) {
688 m->errorOut(e, "ConsensusSeqsCommand", "readNames");
693 //***************************************************************************************************************