2 * chimeraperseuscommand.cpp
5 * Created by westcott on 10/26/11.
6 * Copyright 2011 Schloss Lab. All rights reserved.
10 #include "chimeraperseuscommand.h"
11 #include "deconvolutecommand.h"
12 #include "sequence.hpp"
13 #include "counttable.h"
14 #include "sequencecountparser.h"
15 //**********************************************************************************************************************
16 vector<string> ChimeraPerseusCommand::setParameters(){
18 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","chimera-accnos",false,true,true); parameters.push_back(pfasta);
19 CommandParameter pname("name", "InputTypes", "", "", "NameCount", "NameCount", "none","",false,false,true); parameters.push_back(pname);
20 CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "NameCount", "none","",false,false,true); parameters.push_back(pcount);
21 CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup);
22 CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors);
23 CommandParameter pdups("dereplicate", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pdups);
25 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
26 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
27 CommandParameter pcutoff("cutoff", "Number", "", "0.5", "", "", "","",false,false); parameters.push_back(pcutoff);
28 CommandParameter palpha("alpha", "Number", "", "-5.54", "", "", "","",false,false); parameters.push_back(palpha);
29 CommandParameter pbeta("beta", "Number", "", "0.33", "", "", "","",false,false); parameters.push_back(pbeta);
31 vector<string> myArray;
32 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
36 m->errorOut(e, "ChimeraPerseusCommand", "setParameters");
40 //**********************************************************************************************************************
41 string ChimeraPerseusCommand::getHelpString(){
43 string helpString = "";
44 helpString += "The chimera.perseus command reads a fastafile and namefile or countfile and outputs potentially chimeric sequences.\n";
45 helpString += "The chimera.perseus command parameters are fasta, name, group, cutoff, processors, dereplicate, alpha and beta.\n";
46 helpString += "The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required, unless you have a valid current fasta file. \n";
47 helpString += "The name parameter allows you to provide a name file associated with your fasta file.\n";
48 helpString += "The count parameter allows you to provide a count file associated with your fasta file. A count or name file is required. \n";
49 helpString += "You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amazon.fasta \n";
50 helpString += "The group parameter allows you to provide a group file. When checking sequences, only sequences from the same group as the query sequence will be used as the reference. \n";
51 helpString += "The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n";
52 helpString += "If the dereplicate parameter is false, then if one group finds the seqeunce to be chimeric, then all groups find it to be chimeric, default=f.\n";
53 helpString += "The alpha parameter .... The default is -5.54. \n";
54 helpString += "The beta parameter .... The default is 0.33. \n";
55 helpString += "The cutoff parameter .... The default is 0.50. \n";
56 helpString += "The chimera.perseus command should be in the following format: \n";
57 helpString += "chimera.perseus(fasta=yourFastaFile, name=yourNameFile) \n";
58 helpString += "Example: chimera.perseus(fasta=AD.align, name=AD.names) \n";
59 helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n";
63 m->errorOut(e, "ChimeraPerseusCommand", "getHelpString");
67 //**********************************************************************************************************************
68 string ChimeraPerseusCommand::getOutputPattern(string type) {
72 if (type == "chimera") { pattern = "[filename],perseus.chimeras"; }
73 else if (type == "accnos") { pattern = "[filename],perseus.accnos"; }
74 else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
79 m->errorOut(e, "ChimeraPerseusCommand", "getOutputPattern");
83 //**********************************************************************************************************************
84 ChimeraPerseusCommand::ChimeraPerseusCommand(){
86 abort = true; calledHelp = true;
88 vector<string> tempOutNames;
89 outputTypes["chimera"] = tempOutNames;
90 outputTypes["accnos"] = tempOutNames;
93 m->errorOut(e, "ChimeraPerseusCommand", "ChimeraPerseusCommand");
97 //***************************************************************************************************************
98 ChimeraPerseusCommand::ChimeraPerseusCommand(string option) {
100 abort = false; calledHelp = false;
104 //allow user to run help
105 if(option == "help") { help(); abort = true; calledHelp = true; }
106 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
109 vector<string> myArray = setParameters();
111 OptionParser parser(option);
112 map<string,string> parameters = parser.getParameters();
114 ValidParameters validParameter("chimera.perseus");
115 map<string,string>::iterator it;
117 //check to make sure all parameters are valid for command
118 for (it = parameters.begin(); it != parameters.end(); it++) {
119 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
122 vector<string> tempOutNames;
123 outputTypes["chimera"] = tempOutNames;
124 outputTypes["accnos"] = tempOutNames;
126 //if the user changes the input directory command factory will send this info to us in the output parameter
127 string inputDir = validParameter.validFile(parameters, "inputdir", false);
128 if (inputDir == "not found"){ inputDir = ""; }
130 //check for required parameters
131 fastafile = validParameter.validFile(parameters, "fasta", false);
132 if (fastafile == "not found") {
133 //if there is a current fasta file, use it
134 string filename = m->getFastaFile();
135 if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); }
136 else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; }
138 m->splitAtDash(fastafile, fastaFileNames);
140 //go through files and make sure they are good, if not, then disregard them
141 for (int i = 0; i < fastaFileNames.size(); i++) {
144 if (fastaFileNames[i] == "current") {
145 fastaFileNames[i] = m->getFastaFile();
146 if (fastaFileNames[i] != "") { m->mothurOut("Using " + fastaFileNames[i] + " as input file for the fasta parameter where you had given current."); m->mothurOutEndLine(); }
148 m->mothurOut("You have no current fastafile, ignoring current."); m->mothurOutEndLine(); ignore=true;
149 //erase from file list
150 fastaFileNames.erase(fastaFileNames.begin()+i);
157 if (inputDir != "") {
158 string path = m->hasPath(fastaFileNames[i]);
159 //if the user has not given a path then, add inputdir. else leave path alone.
160 if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; }
166 ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror");
168 //if you can't open it, try default location
169 if (ableToOpen == 1) {
170 if (m->getDefaultPath() != "") { //default path is set
171 string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]);
172 m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
174 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
176 fastaFileNames[i] = tryPath;
180 if (ableToOpen == 1) {
181 if (m->getOutputDir() != "") { //default path is set
182 string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]);
183 m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine();
185 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
187 fastaFileNames[i] = tryPath;
193 if (ableToOpen == 1) {
194 m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine();
195 //erase from file list
196 fastaFileNames.erase(fastaFileNames.begin()+i);
199 m->setFastaFile(fastaFileNames[i]);
204 //make sure there is at least one valid file left
205 if (fastaFileNames.size() == 0) { m->mothurOut("[ERROR]: no valid files."); m->mothurOutEndLine(); abort = true; }
209 //check for required parameters
210 namefile = validParameter.validFile(parameters, "name", false);
211 if (namefile == "not found") { namefile = ""; }
213 m->splitAtDash(namefile, nameFileNames);
215 //go through files and make sure they are good, if not, then disregard them
216 for (int i = 0; i < nameFileNames.size(); i++) {
219 if (nameFileNames[i] == "current") {
220 nameFileNames[i] = m->getNameFile();
221 if (nameFileNames[i] != "") { m->mothurOut("Using " + nameFileNames[i] + " as input file for the name parameter where you had given current."); m->mothurOutEndLine(); }
223 m->mothurOut("You have no current namefile, ignoring current."); m->mothurOutEndLine(); ignore=true;
224 //erase from file list
225 nameFileNames.erase(nameFileNames.begin()+i);
232 if (inputDir != "") {
233 string path = m->hasPath(nameFileNames[i]);
234 //if the user has not given a path then, add inputdir. else leave path alone.
235 if (path == "") { nameFileNames[i] = inputDir + nameFileNames[i]; }
241 ableToOpen = m->openInputFile(nameFileNames[i], in, "noerror");
243 //if you can't open it, try default location
244 if (ableToOpen == 1) {
245 if (m->getDefaultPath() != "") { //default path is set
246 string tryPath = m->getDefaultPath() + m->getSimpleName(nameFileNames[i]);
247 m->mothurOut("Unable to open " + nameFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
249 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
251 nameFileNames[i] = tryPath;
255 if (ableToOpen == 1) {
256 if (m->getOutputDir() != "") { //default path is set
257 string tryPath = m->getOutputDir() + m->getSimpleName(nameFileNames[i]);
258 m->mothurOut("Unable to open " + nameFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine();
260 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
262 nameFileNames[i] = tryPath;
268 if (ableToOpen == 1) {
269 m->mothurOut("Unable to open " + nameFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine();
270 //erase from file list
271 nameFileNames.erase(nameFileNames.begin()+i);
274 m->setNameFile(nameFileNames[i]);
280 if (nameFileNames.size() != 0) { hasName = true; }
282 //check for required parameters
283 vector<string> countfileNames;
284 countfile = validParameter.validFile(parameters, "count", false);
285 if (countfile == "not found") {
288 m->splitAtDash(countfile, countfileNames);
290 //go through files and make sure they are good, if not, then disregard them
291 for (int i = 0; i < countfileNames.size(); i++) {
294 if (countfileNames[i] == "current") {
295 countfileNames[i] = m->getCountTableFile();
296 if (countfileNames[i] != "") { m->mothurOut("Using " + countfileNames[i] + " as input file for the count parameter where you had given current."); m->mothurOutEndLine(); }
298 m->mothurOut("You have no current count file, ignoring current."); m->mothurOutEndLine(); ignore=true;
299 //erase from file list
300 countfileNames.erase(countfileNames.begin()+i);
307 if (inputDir != "") {
308 string path = m->hasPath(countfileNames[i]);
309 //if the user has not given a path then, add inputdir. else leave path alone.
310 if (path == "") { countfileNames[i] = inputDir + countfileNames[i]; }
316 ableToOpen = m->openInputFile(countfileNames[i], in, "noerror");
318 //if you can't open it, try default location
319 if (ableToOpen == 1) {
320 if (m->getDefaultPath() != "") { //default path is set
321 string tryPath = m->getDefaultPath() + m->getSimpleName(countfileNames[i]);
322 m->mothurOut("Unable to open " + countfileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
324 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
326 countfileNames[i] = tryPath;
330 if (ableToOpen == 1) {
331 if (m->getOutputDir() != "") { //default path is set
332 string tryPath = m->getOutputDir() + m->getSimpleName(countfileNames[i]);
333 m->mothurOut("Unable to open " + countfileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine();
335 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
337 countfileNames[i] = tryPath;
343 if (ableToOpen == 1) {
344 m->mothurOut("Unable to open " + countfileNames[i] + ". It will be disregarded."); m->mothurOutEndLine();
345 //erase from file list
346 countfileNames.erase(countfileNames.begin()+i);
349 m->setCountTableFile(countfileNames[i]);
355 if (countfileNames.size() != 0) { hasCount = true; }
357 //make sure there is at least one valid file left
358 if (hasName && hasCount) { m->mothurOut("[ERROR]: You must enter ONLY ONE of the following: count or name."); m->mothurOutEndLine(); abort = true; }
360 if (!hasName && !hasCount) {
361 //if there is a current name file, use it, else look for current count file
362 string filename = m->getNameFile();
363 if (filename != "") { hasName = true; nameFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the name parameter."); m->mothurOutEndLine(); }
365 filename = m->getCountTableFile();
366 if (filename != "") { hasCount = true; countfileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the count parameter."); m->mothurOutEndLine(); }
367 else { m->mothurOut("[ERROR]: You must provide a count or name file."); m->mothurOutEndLine(); abort = true; }
370 if (!hasName && hasCount) { nameFileNames = countfileNames; }
372 if (nameFileNames.size() != fastaFileNames.size()) { m->mothurOut("[ERROR]: The number of name or count files does not match the number of fastafiles, please correct."); m->mothurOutEndLine(); abort=true; }
374 bool hasGroup = true;
375 groupfile = validParameter.validFile(parameters, "group", false);
376 if (groupfile == "not found") { groupfile = ""; hasGroup = false; }
378 m->splitAtDash(groupfile, groupFileNames);
380 //go through files and make sure they are good, if not, then disregard them
381 for (int i = 0; i < groupFileNames.size(); i++) {
384 if (groupFileNames[i] == "current") {
385 groupFileNames[i] = m->getGroupFile();
386 if (groupFileNames[i] != "") { m->mothurOut("Using " + groupFileNames[i] + " as input file for the group parameter where you had given current."); m->mothurOutEndLine(); }
388 m->mothurOut("You have no current namefile, ignoring current."); m->mothurOutEndLine(); ignore=true;
389 //erase from file list
390 groupFileNames.erase(groupFileNames.begin()+i);
397 if (inputDir != "") {
398 string path = m->hasPath(groupFileNames[i]);
399 //if the user has not given a path then, add inputdir. else leave path alone.
400 if (path == "") { groupFileNames[i] = inputDir + groupFileNames[i]; }
406 ableToOpen = m->openInputFile(groupFileNames[i], in, "noerror");
408 //if you can't open it, try default location
409 if (ableToOpen == 1) {
410 if (m->getDefaultPath() != "") { //default path is set
411 string tryPath = m->getDefaultPath() + m->getSimpleName(groupFileNames[i]);
412 m->mothurOut("Unable to open " + groupFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
414 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
416 groupFileNames[i] = tryPath;
420 if (ableToOpen == 1) {
421 if (m->getOutputDir() != "") { //default path is set
422 string tryPath = m->getOutputDir() + m->getSimpleName(groupFileNames[i]);
423 m->mothurOut("Unable to open " + groupFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine();
425 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
427 groupFileNames[i] = tryPath;
433 if (ableToOpen == 1) {
434 m->mothurOut("Unable to open " + groupFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine();
435 //erase from file list
436 groupFileNames.erase(groupFileNames.begin()+i);
439 m->setGroupFile(groupFileNames[i]);
444 //make sure there is at least one valid file left
445 if (groupFileNames.size() == 0) { m->mothurOut("[ERROR]: no valid group files."); m->mothurOutEndLine(); abort = true; }
448 if (hasGroup && (groupFileNames.size() != fastaFileNames.size())) { m->mothurOut("[ERROR]: The number of groupfiles does not match the number of fastafiles, please correct."); m->mothurOutEndLine(); abort=true; }
450 if (hasGroup && hasCount) { m->mothurOut("[ERROR]: You must enter ONLY ONE of the following: count or group."); m->mothurOutEndLine(); abort = true; }
452 //if the user changes the output directory command factory will send this info to us in the output parameter
453 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
455 string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); }
456 m->setProcessors(temp);
457 m->mothurConvert(temp, processors);
459 temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found"){ temp = "0.50"; }
460 m->mothurConvert(temp, cutoff);
462 temp = validParameter.validFile(parameters, "alpha", false); if (temp == "not found"){ temp = "-5.54"; }
463 m->mothurConvert(temp, alpha);
465 temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found"){ temp = "0.33"; }
466 m->mothurConvert(temp, beta);
468 temp = validParameter.validFile(parameters, "dereplicate", false);
469 if (temp == "not found") {
470 if (groupfile != "") { temp = "false"; }
471 else { temp = "true"; }
473 dups = m->isTrue(temp);
476 catch(exception& e) {
477 m->errorOut(e, "ChimeraPerseusCommand", "ChimeraPerseusCommand");
481 //***************************************************************************************************************
483 int ChimeraPerseusCommand::execute(){
485 if (abort == true) { if (calledHelp) { return 0; } return 2; }
489 for (int s = 0; s < fastaFileNames.size(); s++) {
491 m->mothurOut("Checking sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine();
493 int start = time(NULL);
494 if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it
495 map<string, string> variables;
496 variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s]));
497 string outputFileName = getOutputFileName("chimera", variables);
498 string accnosFileName = getOutputFileName("accnos", variables);
500 //string newFasta = m->getRootName(fastaFileNames[s]) + "temp";
502 //you provided a groupfile
503 string groupFile = "";
504 if (groupFileNames.size() != 0) { groupFile = groupFileNames[s]; }
506 string nameFile = "";
507 if (nameFileNames.size() != 0) { //you provided a namefile and we don't need to create one
508 nameFile = nameFileNames[s];
509 }else { nameFile = getNamesFile(fastaFileNames[s]); }
511 if (m->control_pressed) { for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } return 0; }
517 CountTable* ct = new CountTable();
518 ct->readTable(nameFile);
520 if (ct->hasGroupInfo()) {
521 cparser = new SequenceCountParser(fastaFileNames[s], *ct);
523 vector<string> groups = cparser->getNamesOfGroups();
525 if (m->control_pressed) { delete ct; delete cparser; for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } return 0; }
528 ofstream out, out1, out2;
529 m->openOutputFile(outputFileName, out); out.close();
530 m->openOutputFile(accnosFileName, out1); out1.close();
532 if(processors == 1) { numSeqs = driverGroups(outputFileName, accnosFileName, 0, groups.size(), groups); }
533 else { numSeqs = createProcessesGroups(outputFileName, accnosFileName, groups, groupFile, fastaFileNames[s], nameFile); }
535 if (m->control_pressed) { delete ct; delete cparser; for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } return 0; }
536 map<string, string> uniqueNames = cparser->getAllSeqsMap();
538 numChimeras = deconvoluteResults(uniqueNames, outputFileName, accnosFileName);
542 m->mothurOut("The number of sequences checked may be larger than the number of unique sequences because some sequences are found in several samples."); m->mothurOutEndLine();
544 if (m->control_pressed) { delete ct; for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } return 0; }
547 if (processors != 1) { m->mothurOut("Your count file does not contain group information, mothur can only use 1 processor, continuing."); m->mothurOutEndLine(); processors = 1; }
549 //read sequences and store sorted by frequency
550 vector<seqData> sequences = readFiles(fastaFileNames[s], ct);
552 if (m->control_pressed) { delete ct; for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } return 0; }
554 numSeqs = driver(outputFileName, sequences, accnosFileName, numChimeras);
558 if (groupFile != "") {
559 //Parse sequences by group
560 parser = new SequenceParser(groupFile, fastaFileNames[s], nameFile);
561 vector<string> groups = parser->getNamesOfGroups();
563 if (m->control_pressed) { delete parser; for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } return 0; }
566 ofstream out, out1, out2;
567 m->openOutputFile(outputFileName, out); out.close();
568 m->openOutputFile(accnosFileName, out1); out1.close();
570 if(processors == 1) { numSeqs = driverGroups(outputFileName, accnosFileName, 0, groups.size(), groups); }
571 else { numSeqs = createProcessesGroups(outputFileName, accnosFileName, groups, groupFile, fastaFileNames[s], nameFile); }
573 if (m->control_pressed) { delete parser; for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } return 0; }
574 map<string, string> uniqueNames = parser->getAllSeqsMap();
576 numChimeras = deconvoluteResults(uniqueNames, outputFileName, accnosFileName);
580 m->mothurOut("The number of sequences checked may be larger than the number of unique sequences because some sequences are found in several samples."); m->mothurOutEndLine();
582 if (m->control_pressed) { for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } return 0; }
584 if (processors != 1) { m->mothurOut("Without a groupfile, mothur can only use 1 processor, continuing."); m->mothurOutEndLine(); processors = 1; }
586 //read sequences and store sorted by frequency
587 vector<seqData> sequences = readFiles(fastaFileNames[s], nameFile);
589 if (m->control_pressed) { for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } return 0; }
591 numSeqs = driver(outputFileName, sequences, accnosFileName, numChimeras);
595 if (m->control_pressed) { for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } return 0; }
597 m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences. " + toString(numChimeras) + " chimeras were found."); m->mothurOutEndLine();
598 outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName);
599 outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName);
602 //set accnos file as new current accnosfile
604 itTypes = outputTypes.find("accnos");
605 if (itTypes != outputTypes.end()) {
606 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setAccnosFile(current); }
609 m->mothurOutEndLine();
610 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
611 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
612 m->mothurOutEndLine();
617 catch(exception& e) {
618 m->errorOut(e, "ChimeraPerseusCommand", "execute");
622 //**********************************************************************************************************************
623 string ChimeraPerseusCommand::getNamesFile(string& inputFile){
625 string nameFile = "";
627 m->mothurOutEndLine(); m->mothurOut("No namesfile given, running unique.seqs command to generate one."); m->mothurOutEndLine(); m->mothurOutEndLine();
629 //use unique.seqs to create new name and fastafile
630 string inputString = "fasta=" + inputFile;
631 m->mothurOut("/******************************************/"); m->mothurOutEndLine();
632 m->mothurOut("Running command: unique.seqs(" + inputString + ")"); m->mothurOutEndLine();
633 m->mothurCalling = true;
635 Command* uniqueCommand = new DeconvoluteCommand(inputString);
636 uniqueCommand->execute();
638 map<string, vector<string> > filenames = uniqueCommand->getOutputFiles();
640 delete uniqueCommand;
641 m->mothurCalling = false;
642 m->mothurOut("/******************************************/"); m->mothurOutEndLine();
644 nameFile = filenames["name"][0];
645 inputFile = filenames["fasta"][0];
649 catch(exception& e) {
650 m->errorOut(e, "ChimeraPerseusCommand", "getNamesFile");
654 //**********************************************************************************************************************
655 int ChimeraPerseusCommand::driverGroups(string outputFName, string accnos, int start, int end, vector<string> groups){
661 for (int i = start; i < end; i++) {
663 m->mothurOutEndLine(); m->mothurOut("Checking sequences from group " + groups[i] + "..."); m->mothurOutEndLine();
665 int start = time(NULL); if (m->control_pressed) { return 0; }
667 vector<seqData> sequences = loadSequences(groups[i]);
669 if (m->control_pressed) { return 0; }
671 int numSeqs = driver((outputFName + groups[i]), sequences, (accnos+groups[i]), numChimeras);
672 totalSeqs += numSeqs;
674 if (m->control_pressed) { return 0; }
677 m->appendFiles((outputFName+groups[i]), outputFName); m->mothurRemove((outputFName+groups[i]));
678 m->appendFiles((accnos+groups[i]), accnos); m->mothurRemove((accnos+groups[i]));
680 m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences from group " + groups[i] + "."); m->mothurOutEndLine();
686 catch(exception& e) {
687 m->errorOut(e, "ChimeraPerseusCommand", "driverGroups");
691 //**********************************************************************************************************************
692 vector<seqData> ChimeraPerseusCommand::loadSequences(string group){
696 vector<seqData> sequences;
698 vector<Sequence> thisGroupsSeqs = cparser->getSeqs(group);
699 map<string, int> counts = cparser->getCountTable(group);
700 map<string, int>::iterator it;
702 for (int i = 0; i < thisGroupsSeqs.size(); i++) {
704 if (m->control_pressed) { return sequences; }
706 it = counts.find(thisGroupsSeqs[i].getName());
707 if (it == counts.end()) { error = true; m->mothurOut("[ERROR]: " + thisGroupsSeqs[i].getName() + " is in your fasta file and not in your count file, please correct."); m->mothurOutEndLine(); }
709 thisGroupsSeqs[i].setAligned(removeNs(thisGroupsSeqs[i].getUnaligned()));
710 sequences.push_back(seqData(thisGroupsSeqs[i].getName(), thisGroupsSeqs[i].getUnaligned(), it->second));
711 if (thisGroupsSeqs[i].getUnaligned().length() > alignLength) { alignLength = thisGroupsSeqs[i].getUnaligned().length(); }
715 vector<Sequence> thisGroupsSeqs = parser->getSeqs(group);
716 map<string, string> nameMap = parser->getNameMap(group);
717 map<string, string>::iterator it;
719 for (int i = 0; i < thisGroupsSeqs.size(); i++) {
721 if (m->control_pressed) { return sequences; }
723 it = nameMap.find(thisGroupsSeqs[i].getName());
724 if (it == nameMap.end()) { error = true; m->mothurOut("[ERROR]: " + thisGroupsSeqs[i].getName() + " is in your fasta file and not in your namefile, please correct."); m->mothurOutEndLine(); }
726 int num = m->getNumNames(it->second);
727 thisGroupsSeqs[i].setAligned(removeNs(thisGroupsSeqs[i].getUnaligned()));
728 sequences.push_back(seqData(thisGroupsSeqs[i].getName(), thisGroupsSeqs[i].getUnaligned(), num));
729 if (thisGroupsSeqs[i].getUnaligned().length() > alignLength) { alignLength = thisGroupsSeqs[i].getUnaligned().length(); }
735 if (error) { m->control_pressed = true; }
737 sort(sequences.rbegin(), sequences.rend());
741 catch(exception& e) {
742 m->errorOut(e, "ChimeraPerseusCommand", "loadSequences");
747 //**********************************************************************************************************************
748 vector<seqData> ChimeraPerseusCommand::readFiles(string inputFile, string name){
750 map<string, int>::iterator it;
751 map<string, int> nameMap = m->readNames(name);
753 //read fasta file and create sequenceData structure - checking for file mismatches
754 vector<seqData> sequences;
757 m->openInputFile(inputFile, in);
762 if (m->control_pressed) { in.close(); return sequences; }
764 Sequence temp(in); m->gobble(in);
766 it = nameMap.find(temp.getName());
767 if (it == nameMap.end()) { error = true; m->mothurOut("[ERROR]: " + temp.getName() + " is in your fasta file and not in your namefile, please correct."); m->mothurOutEndLine(); }
769 temp.setAligned(removeNs(temp.getUnaligned()));
770 sequences.push_back(seqData(temp.getName(), temp.getUnaligned(), it->second));
771 if (temp.getUnaligned().length() > alignLength) { alignLength = temp.getUnaligned().length(); }
776 if (error) { m->control_pressed = true; }
779 sort(sequences.rbegin(), sequences.rend());
783 catch(exception& e) {
784 m->errorOut(e, "ChimeraPerseusCommand", "readFiles");
788 //**********************************************************************************************************************
789 string ChimeraPerseusCommand::removeNs(string seq){
792 for (int i = 0; i < seq.length(); i++) {
793 if (seq[i] != 'N') { newSeq += seq[i]; }
797 catch(exception& e) {
798 m->errorOut(e, "ChimeraPerseusCommand", "removeNs");
802 //**********************************************************************************************************************
803 vector<seqData> ChimeraPerseusCommand::readFiles(string inputFile, CountTable* ct){
805 //read fasta file and create sequenceData structure - checking for file mismatches
806 vector<seqData> sequences;
808 m->openInputFile(inputFile, in);
812 Sequence temp(in); m->gobble(in);
814 int count = ct->getNumSeqs(temp.getName());
815 if (m->control_pressed) { break; }
817 temp.setAligned(removeNs(temp.getUnaligned()));
818 sequences.push_back(seqData(temp.getName(), temp.getUnaligned(), count));
819 if (temp.getUnaligned().length() > alignLength) { alignLength = temp.getUnaligned().length(); }
825 sort(sequences.rbegin(), sequences.rend());
829 catch(exception& e) {
830 m->errorOut(e, "ChimeraPerseusCommand", "getNamesFile");
834 //**********************************************************************************************************************
835 int ChimeraPerseusCommand::driver(string chimeraFileName, vector<seqData>& sequences, string accnosFileName, int& numChimeras){
838 vector<vector<double> > correctModel(4); //could be an option in the future to input own model matrix
839 for(int i=0;i<4;i++){ correctModel[i].resize(4); }
841 correctModel[0][0] = 0.000000; //AA
842 correctModel[1][0] = 11.619259; //CA
843 correctModel[2][0] = 11.694004; //TA
844 correctModel[3][0] = 7.748623; //GA
846 correctModel[1][1] = 0.000000; //CC
847 correctModel[2][1] = 7.619657; //TC
848 correctModel[3][1] = 12.852562; //GC
850 correctModel[2][2] = 0.000000; //TT
851 correctModel[3][2] = 10.964048; //TG
853 correctModel[3][3] = 0.000000; //GG
855 for(int i=0;i<4;i++){
856 for(int j=0;j<i;j++){
857 correctModel[j][i] = correctModel[i][j];
861 int numSeqs = sequences.size();
862 //int alignLength = sequences[0].sequence.size();
864 ofstream chimeraFile;
866 m->openOutputFile(chimeraFileName, chimeraFile);
867 m->openOutputFile(accnosFileName, accnosFile);
870 vector<vector<double> > binMatrix = myPerseus.binomial(alignLength);
872 chimeraFile << "SequenceIndex\tName\tDiffsToBestMatch\tBestMatchIndex\tBestMatchName\tDiffstToChimera\tIndexofLeftParent\tIndexOfRightParent\tNameOfLeftParent\tNameOfRightParent\tDistanceToBestMatch\tcIndex\t(cIndex - singleDist)\tloonIndex\tMismatchesToChimera\tMismatchToTrimera\tChimeraBreakPoint\tLogisticProbability\tTypeOfSequence\n";
874 vector<bool> chimeras(numSeqs, 0);
876 for(int i=0;i<numSeqs;i++){
877 if (m->control_pressed) { chimeraFile.close(); m->mothurRemove(chimeraFileName); accnosFile.close(); m->mothurRemove(accnosFileName); return 0; }
879 vector<bool> restricted = chimeras;
881 vector<vector<int> > leftDiffs(numSeqs);
882 vector<vector<int> > leftMaps(numSeqs);
883 vector<vector<int> > rightDiffs(numSeqs);
884 vector<vector<int> > rightMaps(numSeqs);
886 vector<int> singleLeft, bestLeft;
887 vector<int> singleRight, bestRight;
889 int bestSingleIndex, bestSingleDiff;
890 vector<pwAlign> alignments(numSeqs);
892 int comparisons = myPerseus.getAlignments(i, sequences, alignments, leftDiffs, leftMaps, rightDiffs, rightMaps, bestSingleIndex, bestSingleDiff, restricted);
893 if (m->control_pressed) { chimeraFile.close(); m->mothurRemove(chimeraFileName); accnosFile.close(); m->mothurRemove(accnosFileName); return 0; }
895 int minMismatchToChimera, leftParentBi, rightParentBi, breakPointBi;
897 string dummyA, dummyB;
899 if (sequences[i].sequence.size() < 3) {
900 chimeraFile << i << '\t' << sequences[i].seqName << "\t0\t0\tNull\t0\t0\t0\tNull\tNull\t0.0\t0.0\t0.0\t0\t0\t0\t0.0\t0.0\tgood" << endl;
901 }else if(comparisons >= 2){
902 minMismatchToChimera = myPerseus.getChimera(sequences, leftDiffs, rightDiffs, leftParentBi, rightParentBi, breakPointBi, singleLeft, bestLeft, singleRight, bestRight, restricted);
903 if (m->control_pressed) { chimeraFile.close(); m->mothurRemove(chimeraFileName); accnosFile.close(); m->mothurRemove(accnosFileName); return 0; }
905 int minMismatchToTrimera = numeric_limits<int>::max();
906 int leftParentTri, middleParentTri, rightParentTri, breakPointTriA, breakPointTriB;
908 if(minMismatchToChimera >= 3 && comparisons >= 3){
909 minMismatchToTrimera = myPerseus.getTrimera(sequences, leftDiffs, leftParentTri, middleParentTri, rightParentTri, breakPointTriA, breakPointTriB, singleLeft, bestLeft, singleRight, bestRight, restricted);
910 if (m->control_pressed) { chimeraFile.close(); m->mothurRemove(chimeraFileName); accnosFile.close(); m->mothurRemove(accnosFileName); return 0; }
913 double singleDist = myPerseus.modeledPairwiseAlignSeqs(sequences[i].sequence, sequences[bestSingleIndex].sequence, dummyA, dummyB, correctModel);
915 if (m->control_pressed) { chimeraFile.close(); m->mothurRemove(chimeraFileName); accnosFile.close(); m->mothurRemove(accnosFileName); return 0; }
918 string chimeraRefSeq;
920 if(minMismatchToChimera - minMismatchToTrimera >= 3){
922 chimeraRefSeq = myPerseus.stitchTrimera(alignments, leftParentTri, middleParentTri, rightParentTri, breakPointTriA, breakPointTriB, leftMaps, rightMaps);
926 chimeraRefSeq = myPerseus.stitchBimera(alignments, leftParentBi, rightParentBi, breakPointBi, leftMaps, rightMaps);
929 if (m->control_pressed) { chimeraFile.close(); m->mothurRemove(chimeraFileName); accnosFile.close(); m->mothurRemove(accnosFileName); return 0; }
931 double chimeraDist = myPerseus.modeledPairwiseAlignSeqs(sequences[i].sequence, chimeraRefSeq, dummyA, dummyB, correctModel);
933 if (m->control_pressed) { chimeraFile.close(); m->mothurRemove(chimeraFileName); accnosFile.close(); m->mothurRemove(accnosFileName); return 0; }
935 double cIndex = chimeraDist;//modeledPairwiseAlignSeqs(sequences[i].sequence, chimeraRefSeq);
936 double loonIndex = myPerseus.calcLoonIndex(sequences[i].sequence, sequences[leftParentBi].sequence, sequences[rightParentBi].sequence, breakPointBi, binMatrix);
938 if (m->control_pressed) { chimeraFile.close(); m->mothurRemove(chimeraFileName); accnosFile.close(); m->mothurRemove(accnosFileName); return 0; }
940 chimeraFile << i << '\t' << sequences[i].seqName << '\t' << bestSingleDiff << '\t' << bestSingleIndex << '\t' << sequences[bestSingleIndex].seqName << '\t';
941 chimeraFile << minMismatchToChimera << '\t' << leftParentBi << '\t' << rightParentBi << '\t' << sequences[leftParentBi].seqName << '\t' << sequences[rightParentBi].seqName << '\t';
942 chimeraFile << singleDist << '\t' << cIndex << '\t' << (cIndex - singleDist) << '\t' << loonIndex << '\t';
943 chimeraFile << minMismatchToChimera << '\t' << minMismatchToTrimera << '\t' << breakPointBi << '\t';
945 double probability = myPerseus.classifyChimera(singleDist, cIndex, loonIndex, alpha, beta);
947 chimeraFile << probability << '\t';
949 if(probability > cutoff){
950 chimeraFile << type << endl;
951 accnosFile << sequences[i].seqName << endl;
956 chimeraFile << "good" << endl;
961 chimeraFile << i << '\t' << sequences[i].seqName << "\t0\t0\tNull\t0\t0\t0\tNull\tNull\t0.0\t0.0\t0.0\t0\t0\t0\t0.0\t0.0\tgood" << endl;
965 if((i+1) % 100 == 0){ m->mothurOut("Processing sequence: " + toString(i+1) + "\n"); }
968 if((numSeqs) % 100 != 0){ m->mothurOut("Processing sequence: " + toString(numSeqs) + "\n"); }
975 catch(exception& e) {
976 m->errorOut(e, "ChimeraPerseusCommand", "driver");
980 /**************************************************************************************************/
981 int ChimeraPerseusCommand::createProcessesGroups(string outputFName, string accnos, vector<string> groups, string group, string fasta, string name) {
984 vector<int> processIDS;
989 if (groups.size() < processors) { processors = groups.size(); }
991 //divide the groups between the processors
992 vector<linePair> lines;
993 int numGroupsPerProcessor = groups.size() / processors;
994 for (int i = 0; i < processors; i++) {
995 int startIndex = i * numGroupsPerProcessor;
996 int endIndex = (i+1) * numGroupsPerProcessor;
997 if(i == (processors - 1)){ endIndex = groups.size(); }
998 lines.push_back(linePair(startIndex, endIndex));
1001 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
1003 //loop through and create all the processes you want
1004 while (process != processors) {
1008 processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
1010 }else if (pid == 0){
1011 num = driverGroups(outputFName + toString(getpid()) + ".temp", accnos + toString(getpid()) + ".temp", lines[process].start, lines[process].end, groups);
1013 //pass numSeqs to parent
1015 string tempFile = outputFName + toString(getpid()) + ".num.temp";
1016 m->openOutputFile(tempFile, out);
1022 m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
1023 for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
1029 num = driverGroups(outputFName, accnos, lines[0].start, lines[0].end, groups);
1031 //force parent to wait until all the processes are done
1032 for (int i=0;i<processIDS.size();i++) {
1033 int temp = processIDS[i];
1037 for (int i = 0; i < processIDS.size(); i++) {
1039 string tempFile = outputFName + toString(processIDS[i]) + ".num.temp";
1040 m->openInputFile(tempFile, in);
1041 if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; }
1042 in.close(); m->mothurRemove(tempFile);
1046 //////////////////////////////////////////////////////////////////////////////////////////////////////
1047 //Windows version shared memory, so be careful when passing variables through the preClusterData struct.
1048 //Above fork() will clone, so memory is separate, but that's not the case with windows,
1049 //////////////////////////////////////////////////////////////////////////////////////////////////////
1051 vector<perseusData*> pDataArray;
1052 DWORD dwThreadIdArray[processors-1];
1053 HANDLE hThreadArray[processors-1];
1055 //Create processor worker threads.
1056 for( int i=1; i<processors; i++ ){
1057 // Allocate memory for thread data.
1058 string extension = toString(i) + ".temp";
1060 perseusData* tempPerseus = new perseusData(hasName, hasCount, alpha, beta, cutoff, outputFName+extension, fasta, name, group, accnos+extension, groups, m, lines[i].start, lines[i].end, i);
1062 pDataArray.push_back(tempPerseus);
1063 processIDS.push_back(i);
1065 //MyPerseusThreadFunction is in header. It must be global or static to work with the threads.
1066 //default security attributes, thread function name, argument to thread function, use default creation flags, returns the thread identifier
1067 hThreadArray[i-1] = CreateThread(NULL, 0, MyPerseusThreadFunction, pDataArray[i-1], 0, &dwThreadIdArray[i-1]);
1071 //using the main process as a worker saves time and memory
1072 num = driverGroups(outputFName, accnos, lines[0].start, lines[0].end, groups);
1074 //Wait until all threads have terminated.
1075 WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE);
1077 //Close all thread handles and free memory allocations.
1078 for(int i=0; i < pDataArray.size(); i++){
1079 num += pDataArray[i]->count;
1080 CloseHandle(hThreadArray[i]);
1081 delete pDataArray[i];
1086 //append output files
1087 for(int i=0;i<processIDS.size();i++){
1088 m->appendFiles((outputFName + toString(processIDS[i]) + ".temp"), outputFName);
1089 m->mothurRemove((outputFName + toString(processIDS[i]) + ".temp"));
1091 m->appendFiles((accnos + toString(processIDS[i]) + ".temp"), accnos);
1092 m->mothurRemove((accnos + toString(processIDS[i]) + ".temp"));
1098 catch(exception& e) {
1099 m->errorOut(e, "ChimeraPerseusCommand", "createProcessesGroups");
1103 //**********************************************************************************************************************
1104 int ChimeraPerseusCommand::deconvoluteResults(map<string, string>& uniqueNames, string outputFileName, string accnosFileName){
1106 map<string, string>::iterator itUnique;
1111 m->openInputFile(accnosFileName, in2);
1114 m->openOutputFile(accnosFileName+".temp", out2);
1117 set<string> namesInFile; //this is so if a sequence is found to be chimera in several samples we dont write it to the results file more than once
1118 set<string>::iterator itNames;
1119 set<string> chimerasInFile;
1120 set<string>::iterator itChimeras;
1123 while (!in2.eof()) {
1124 if (m->control_pressed) { in2.close(); out2.close(); m->mothurRemove(outputFileName); m->mothurRemove((accnosFileName+".temp")); return 0; }
1126 in2 >> name; m->gobble(in2);
1129 itUnique = uniqueNames.find(name);
1131 if (itUnique == uniqueNames.end()) { m->mothurOut("[ERROR]: trouble parsing accnos results. Cannot find "+ name + "."); m->mothurOutEndLine(); m->control_pressed = true; }
1133 itChimeras = chimerasInFile.find((itUnique->second));
1135 if (itChimeras == chimerasInFile.end()) {
1136 out2 << itUnique->second << endl;
1137 chimerasInFile.insert((itUnique->second));
1145 m->mothurRemove(accnosFileName);
1146 rename((accnosFileName+".temp").c_str(), accnosFileName.c_str());
1150 m->openInputFile(outputFileName, in);
1153 m->openOutputFile(outputFileName+".temp", out); out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint);
1155 int DiffsToBestMatch, BestMatchIndex, DiffstToChimera, IndexofLeftParent, IndexOfRightParent;
1156 float temp1,temp2, temp3, temp4, temp5, temp6, temp7, temp8;
1157 string index, BestMatchName, parent1, parent2, flag;
1159 namesInFile.clear();
1160 //assumptions - in file each read will always look like
1162 SequenceIndex Name DiffsToBestMatch BestMatchIndex BestMatchName DiffstToChimera IndexofLeftParent IndexOfRightParent NameOfLeftParent NameOfRightParent DistanceToBestMatch cIndex (cIndex - singleDist) loonIndex MismatchesToChimera MismatchToTrimera ChimeraBreakPoint LogisticProbability TypeOfSequence
1163 0 F01QG4L02JVBQY 0 0 Null 0 0 0 Null Null 0.0 0.0 0.0 0.0 0 0 0 0.0 0.0 good
1164 1 F01QG4L02ICTC6 0 0 Null 0 0 0 Null Null 0.0 0.0 0.0 0.0 0 0 0 0.0 0.0 good
1165 2 F01QG4L02JZOEC 48 0 F01QG4L02JVBQY 47 0 0 F01QG4L02JVBQY F01QG4L02JVBQY 2.0449 2.03545 -0.00944493 0 47 2147483647 138 0 good
1166 3 F01QG4L02G7JEC 42 0 F01QG4L02JVBQY 40 1 0 F01QG4L02ICTC6 F01QG4L02JVBQY 1.87477 1.81113 -0.0636404 5.80145 40 2147483647 25 0 good
1169 //get and print headers
1170 BestMatchName = m->getline(in); m->gobble(in);
1171 out << BestMatchName << endl;
1175 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove((outputFileName+".temp")); return 0; }
1178 in >> index; m->gobble(in);
1180 if (index != "SequenceIndex") { //if you are not a header line, there will be a header line for each group if group file is given
1181 in >> name; m->gobble(in);
1182 in >> DiffsToBestMatch; m->gobble(in);
1183 in >> BestMatchIndex; m->gobble(in);
1184 in >> BestMatchName; m->gobble(in);
1185 in >> DiffstToChimera; m->gobble(in);
1186 in >> IndexofLeftParent; m->gobble(in);
1187 in >> IndexOfRightParent; m->gobble(in);
1188 in >> parent1; m->gobble(in);
1189 in >> parent2; m->gobble(in);
1190 in >> temp1 >> temp2 >> temp3 >> temp4 >> temp5 >> temp6 >> temp7 >> temp8 >> flag; m->gobble(in);
1193 itUnique = uniqueNames.find(name);
1195 if (itUnique == uniqueNames.end()) { m->mothurOut("[ERROR]: trouble parsing chimera results. Cannot find "+ name + "."); m->mothurOutEndLine(); m->control_pressed = true; }
1197 name = itUnique->second;
1198 //is this name already in the file
1199 itNames = namesInFile.find((name));
1201 if (itNames == namesInFile.end()) { //no not in file
1202 if (flag == "good") { //are you really a no??
1203 //is this sequence really not chimeric??
1204 itChimeras = chimerasInFile.find(name);
1206 //then you really are a no so print, otherwise skip
1207 if (itChimeras == chimerasInFile.end()) { print = true; }
1208 }else{ print = true; }
1213 out << index << '\t' << name << '\t' << DiffsToBestMatch << '\t' << BestMatchIndex << '\t';
1214 namesInFile.insert(name);
1216 if (BestMatchName != "Null") {
1217 itUnique = uniqueNames.find(BestMatchName);
1218 if (itUnique == uniqueNames.end()) { m->mothurOut("[ERROR]: trouble parsing chimera results. Cannot find BestMatchName "+ BestMatchName + "."); m->mothurOutEndLine(); m->control_pressed = true; }
1219 else { out << itUnique->second << '\t'; }
1220 }else { out << "Null" << '\t'; }
1222 out << DiffstToChimera << '\t' << IndexofLeftParent << '\t' << IndexOfRightParent << '\t';
1224 if (parent1 != "Null") {
1225 itUnique = uniqueNames.find(parent1);
1226 if (itUnique == uniqueNames.end()) { m->mothurOut("[ERROR]: trouble parsing chimera results. Cannot find parent1 "+ parent1 + "."); m->mothurOutEndLine(); m->control_pressed = true; }
1227 else { out << itUnique->second << '\t'; }
1228 }else { out << "Null" << '\t'; }
1230 if (parent1 != "Null") {
1231 itUnique = uniqueNames.find(parent2);
1232 if (itUnique == uniqueNames.end()) { m->mothurOut("[ERROR]: trouble parsing chimera results. Cannot find parent2 "+ parent2 + "."); m->mothurOutEndLine(); m->control_pressed = true; }
1233 else { out << itUnique->second << '\t'; }
1234 }else { out << "Null" << '\t'; }
1236 out << temp1 << '\t' << temp2 << '\t' << temp3 << '\t' << temp4 << '\t' << temp5 << '\t' << temp6 << '\t' << temp7 << '\t' << temp8 << '\t' << flag << endl;
1238 }else { index = m->getline(in); m->gobble(in); }
1243 m->mothurRemove(outputFileName);
1244 rename((outputFileName+".temp").c_str(), outputFileName.c_str());
1248 catch(exception& e) {
1249 m->errorOut(e, "ChimeraPerseusCommand", "deconvoluteResults");
1253 //**********************************************************************************************************************