Skip to content

Commit

Permalink
Adds removechimeras to chimera.ccode
Browse files Browse the repository at this point in the history
  • Loading branch information
mothur-westcott committed Oct 28, 2021
1 parent cee65a2 commit e206fe8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
47 changes: 45 additions & 2 deletions source/commands/chimeraccodecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "chimeraccodecommand.h"
#include "ccode.h"
#include "removeseqscommand.h"

//**********************************************************************************************************************
vector<string> ChimeraCcodeCommand::setParameters(){
Expand All @@ -19,6 +20,7 @@ vector<string> ChimeraCcodeCommand::setParameters(){
CommandParameter pwindow("window", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pwindow);
CommandParameter pnumwanted("numwanted", "Number", "", "20", "", "", "","",false,false); parameters.push_back(pnumwanted);
CommandParameter pmask("mask", "String", "", "", "", "", "","",false,false); parameters.push_back(pmask);
CommandParameter premovechimeras("removechimeras", "Boolean", "", "t", "", "", "","fasta",false,false); parameters.push_back(premovechimeras);
CommandParameter pseed("seed", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pseed);
CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
Expand All @@ -29,6 +31,7 @@ vector<string> ChimeraCcodeCommand::setParameters(){
outputTypes["chimera"] = tempOutNames;
outputTypes["mapinfo"] = tempOutNames;
outputTypes["accnos"] = tempOutNames;
outputTypes["fasta"] = tempOutNames;

vector<string> myArray;
for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
Expand All @@ -52,6 +55,7 @@ string ChimeraCcodeCommand::getHelpString(){
helpString += "The mask parameter allows you to specify a file containing one sequence you wish to use as a mask for the your sequences. \n";
helpString += "The window parameter allows you to specify the window size for searching for chimeras. \n";
helpString += "The numwanted parameter allows you to specify how many sequences you would each query sequence compared with.\n";
helpString += "The removechimeras parameter allows you to indicate you would like to automatically remove the sequences that are flagged as chimeric. Default=t.\n";
helpString += "The chimera.ccode command should be in the following format: \n";
helpString += "chimera.ccode(fasta=yourFastaFile, reference=yourTemplate) \n";
helpString += "Example: chimera.ccode(fasta=AD.align, reference=core_set_aligned.imputed.fasta) \n";
Expand All @@ -68,8 +72,9 @@ string ChimeraCcodeCommand::getOutputPattern(string type) {
try {
string pattern = "";

if (type == "chimera") { pattern = "[filename],[tag],ccode.chimeras-[filename],ccode.chimeras"; }
else if (type == "accnos") { pattern = "[filename],[tag],ccode.accnos-[filename],ccode.accnos"; }
if (type == "chimera") { pattern = "[filename],[tag],ccode.chimeras-[filename],ccode.chimeras"; }
else if (type == "accnos") { pattern = "[filename],[tag],ccode.accnos-[filename],ccode.accnos"; }
else if (type == "fasta") { pattern = "[filename],ccode.fasta-[filename],[tag],ccode.fasta"; }
else if (type == "mapinfo") { pattern = "[filename],mapinfo"; }
else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->setControl_pressed(true); }

Expand Down Expand Up @@ -121,6 +126,9 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) : Command() {
temp = validParameter.valid(parameters, "numwanted"); if (temp == "not found") { temp = "20"; }
util.mothurConvert(temp, numwanted);

temp = validParameter.valid(parameters, "removechimeras"); if (temp == "not found") { temp = "t"; }
removeChimeras = util.isTrue(temp);

//this has to go after save so that if the user sets save=t and provides no reference we abort
templatefile = validParameter.validFile(parameters, "reference");
if (templatefile == "not found") { m->mothurOut("[ERROR]: The reference parameter is a required, aborting.\n"); abort = true;
Expand Down Expand Up @@ -172,13 +180,48 @@ int ChimeraCcodeCommand::execute(){

m->mothurOut("\nIt took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences.\n");

if (removeChimeras) {
if (!util.isBlank(accnosFileName)) {
m->mothurOut("\nRemoving chimeras from your input files:\n");

string inputString = "fasta=" + fastafile + ", accnos=" + accnosFileName;

m->mothurOut("/******************************************/\n");
m->mothurOut("Running command: remove.seqs(" + inputString + ")\n");
current->setMothurCalling(true);

Command* removeCommand = new RemoveSeqsCommand(inputString);
removeCommand->execute();

map<string, vector<string> > filenames = removeCommand->getOutputFiles();

delete removeCommand;
current->setMothurCalling(false);
m->mothurOut("/******************************************/\n");

map<string, string> variables;
variables["[filename]"] = outputdir + util.getRootName(util.getSimpleName(fastafile));
string currentName = getOutputFileName("fasta", variables);

util.renameFile(filenames["fasta"][0], currentName);
util.mothurRemove(filenames["fasta"][0]);

outputNames.push_back(currentName); outputTypes["fasta"].push_back(currentName);
}else { m->mothurOut("\nNo chimeras found, skipping remove.seqs.\n"); }
}

//set accnos file as new current accnosfile
string currentName = "";
itTypes = outputTypes.find("accnos");
if (itTypes != outputTypes.end()) {
if ((itTypes->second).size() != 0) { currentName = (itTypes->second)[0]; current->setAccnosFile(currentName); }
}

itTypes = outputTypes.find("fasta");
if (itTypes != outputTypes.end()) {
if ((itTypes->second).size() != 0) { currentName = (itTypes->second)[0]; current->setFastaFile(currentName); }
}

m->mothurOut("\nOutput File Names: \n");
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
m->mothurOutEndLine();
Expand Down
2 changes: 1 addition & 1 deletion source/commands/chimeraccodecommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ChimeraCcodeCommand : public Command {


private:
bool abort, filter, save;
bool abort, filter, save, removeChimeras;
string fastafile, templatefile, maskfile;
int window, numwanted, numSeqs, templateSeqsLength;
vector<string> outputNames;
Expand Down
5 changes: 1 addition & 4 deletions source/commands/chimeraperseuscommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ int ChimeraPerseusCommand::execute(){
current->setMothurCalling(false);
groups = cparser.getNamesOfGroups();
group2Files = cparser.getFiles();

}

if (m->getControl_pressed()) { return 0; }
Expand All @@ -414,8 +413,7 @@ int ChimeraPerseusCommand::execute(){
CountTable newCount; newCount.readTable(countfile, true, false);

if (!util.isBlank(countlist)) {
ifstream in2;
util.openInputFile(countlist, in2);
ifstream in2; util.openInputFile(countlist, in2);

string name, group;
while (!in2.eof()) {
Expand Down Expand Up @@ -485,7 +483,6 @@ int ChimeraPerseusCommand::execute(){

delete removeCommand;
current->setMothurCalling(false);

m->mothurOut("/******************************************/\n");

if (countfile != "") {
Expand Down

0 comments on commit e206fe8

Please sign in to comment.