From: westcott Date: Wed, 22 Dec 2010 19:03:19 +0000 (+0000) Subject: chimera.slayer fix X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=8af930b692ff87d1b7031fdd5c9a0b88cdd61245 chimera.slayer fix --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 9cd6afa..6f1e88d 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -136,6 +136,8 @@ A7D215C911996C6E00F13F13 /* clearcutcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clearcutcommand.cpp; sourceTree = ""; }; A7D216061199C47F00F13F13 /* catchallcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = catchallcommand.h; sourceTree = ""; }; A7D216071199C47F00F13F13 /* catchallcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = catchallcommand.cpp; sourceTree = ""; }; + A7D9006D12C2544A00D8F543 /* corraxescommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = corraxescommand.h; sourceTree = ""; }; + A7D9006E12C2544A00D8F543 /* corraxescommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = corraxescommand.cpp; sourceTree = ""; }; A7DA1FEC113FECD400BF472F /* ace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ace.cpp; sourceTree = ""; }; A7DA1FED113FECD400BF472F /* ace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ace.h; sourceTree = ""; }; A7DA1FEE113FECD400BF472F /* aligncommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = aligncommand.cpp; sourceTree = ""; }; @@ -872,6 +874,8 @@ A7DA2031113FECD400BF472F /* consensuscommand.cpp */, A71FF438129BDC35004397E6 /* consensusseqscommand.h */, A71FF439129BDC35004397E6 /* consensusseqscommand.cpp */, + A7D9006D12C2544A00D8F543 /* corraxescommand.h */, + A7D9006E12C2544A00D8F543 /* corraxescommand.cpp */, A7118EE511CFCAC000CFDE03 /* degapseqscommand.h */, A7118EE611CFCAC000CFDE03 /* degapseqscommand.cpp */, A7DA203B113FECD400BF472F /* deconvolutecommand.h */, diff --git a/corraxescommand.cpp b/corraxescommand.cpp new file mode 100644 index 0000000..322b7f9 --- /dev/null +++ b/corraxescommand.cpp @@ -0,0 +1,596 @@ +/* + * corraxescommand.cpp + * Mothur + * + * Created by westcott on 12/22/10. + * Copyright 2010 Schloss Lab. All rights reserved. + * + */ + +#include "corraxescommand.h" + +//********************************************************************************************************************** +vector CorrAxesCommand::getValidParameters(){ + try { + string Array[] = {"axes","shared","relabund","numaxes","label","groups","method","metastats","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector CorrAxesCommand::getRequiredParameters(){ + try { + string Array[] = {"axes"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +CorrAxesCommand::CorrAxesCommand(){ + try { + abort = true; + //initialize outputTypes + vector tempOutNames; + outputTypes["corr.axes"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "CorrAxesCommand"); + exit(1); + } +} + +//********************************************************************************************************************** +vector CorrAxesCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** +CorrAxesCommand::CorrAxesCommand(string option) { + try { + abort = false; + globaldata = GlobalData::getInstance(); + + //allow user to run help + if(option == "help") { help(); abort = true; } + + else { + //valid paramters for this command + string Array[] = {"axes","shared","relabund","numaxes","label","groups","method","metastats","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + + OptionParser parser(option); + map parameters = parser.getParameters(); + + ValidParameters validParameter; + map::iterator it; + + //check to make sure all parameters are valid for command + for (it = parameters.begin(); it != parameters.end(); it++) { + if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } + } + + vector tempOutNames; + outputTypes["corr.axes"] = tempOutNames; + + //if the user changes the input directory command factory will send this info to us in the output parameter + string inputDir = validParameter.validFile(parameters, "inputdir", false); + if (inputDir == "not found"){ inputDir = ""; } + else { + string path; + it = parameters.find("axes"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["axes"] = inputDir + it->second; } + } + + it = parameters.find("shared"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["shared"] = inputDir + it->second; } + } + + it = parameters.find("relabund"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["relabund"] = inputDir + it->second; } + } + } + + + //check for required parameters + axesfile = validParameter.validFile(parameters, "axes", true); + if (axesfile == "not open") { abort = true; } + else if (axesfile == "not found") { axesfile = ""; m->mothurOut("axes is a required parameter for the corr.axes command."); m->mothurOutEndLine(); abort = true; } + + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { abort = true; } + else if (sharedfile == "not found") { sharedfile = ""; } + else { inputFileName = sharedfile; } + + relabundfile = validParameter.validFile(parameters, "relabund", true); + if (relabundfile == "not open") { abort = true; } + else if (relabundfile == "not found") { relabundfile = ""; } + else { inputFileName = relabundfile; } + + groups = validParameter.validFile(parameters, "groups", false); + if (groups == "not found") { groups = ""; pickedGroups = false; } + else { + pickedGroups = true; + m->splitAtDash(groups, Groups); + } + globaldata->Groups = Groups; + + outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(inputFileName); } + + label = validParameter.validFile(parameters, "label", false); + if (label == "not found") { label = ""; m->mothurOut("You did not provide a label, I will use the first label in your inputfile."); m->mothurOutEndLine(); label=""; } + + if ((relabundfile == "") && (sharedfile == "")) { m->mothurOut("You must provide either a shared or relabund file."); m->mothurOutEndLine(); abort = true; } + + if ((relabundfile != "") && (sharedfile != "")) { m->mothurOut("You may not use both a shared and relabund file."); m->mothurOutEndLine(); abort = true; } + + string temp; + temp = validParameter.validFile(parameters, "numaxes", false); if (temp == "not found"){ temp = "3"; } + convert(temp, numaxes); + + method = validParameter.validFile(parameters, "method", false); if (method == "not found"){ method = "pearson"; } + + if ((method != "pearson") && (method != "spearman") && (method != "kendall")) { m->mothurOut(method + " is not a valid method. Valid methods are pearson, spearman, and kendall."); m->mothurOutEndLine(); abort = true; } + + } + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "CorrAxesCommand"); + exit(1); + } +} +//********************************************************************************************************************** + +void CorrAxesCommand::help(){ + try { + + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "help"); + exit(1); + } +} + +//********************************************************************************************************************** + +CorrAxesCommand::~CorrAxesCommand(){} + +//********************************************************************************************************************** + +int CorrAxesCommand::execute(){ + try { + + if (abort == true) { return 0; } + + /*************************************************************************************/ + // use smart distancing to get right sharedRabund and convert to relabund if needed // + /************************************************************************************/ + if (sharedfile != "") { + getShared(); + if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (lookup[0] == NULL) { m->mothurOut("[ERROR] reading shared file."); m->mothurOutEndLine(); return 0; } + + //fills lookupFloat with relative abundance values from lookup + convertToRelabund(); + + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + }else { + getSharedFloat(); + if (m->control_pressed) { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } return 0; } + if (lookupFloat[0] == NULL) { m->mothurOut("[ERROR] reading relabund file."); m->mothurOutEndLine(); return 0; } + + if (pickedGroups) { eliminateZeroOTUS(lookupFloat); } + } + + if (m->control_pressed) { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } return 0; } + + //this is for a sanity check to make sure the axes file and shared file match + for (int i = 0; i < lookupFloat.size(); i++) { names.insert(lookupFloat[i]->getGroup()); } + + /*************************************************************************************/ + // read axes file and check for file mismatches with shared or relabund file // + /************************************************************************************/ + + //read axes file + map > axes = readAxes(); + + if (m->control_pressed) { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } return 0; } + + //sanity check, the read only adds groups that are in the shared or relabund file, but we want to make sure the axes file isn't missing anyone + if (axes.size() != lookupFloat.size()) { + map >::iterator it; + for (int i = 0; i < lookupFloat.size(); i++) { + it = axes.find(lookupFloat[i]->getGroup()); + if (it == axes.end()) { m->mothurOut(lookupFloat[i]->getGroup() + " is in your shared of relabund file but not in your axes file, please correct."); m->mothurOutEndLine(); } + } + m->control_pressed = true; + } + + if (m->control_pressed) { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } return 0; } + + string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + "corr.axes"; + outputNames.push_back(outputFileName); outputTypes["corr.axes"].push_back(outputFileName); + ofstream out; + m->openOutputFile(outputFileName, out); + + if (method == "pearson") { calcPearson(axes, out); } + //else if (method == "spearman") { calcSpearman(axes, out); } + //else if (method == "kendall") { calcKendal(axes, out); } + //else { m->mothurOut("[ERROR]: Invalid method."); m->mothurOutEndLine(); } + + out.close(); + for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } + + if (m->control_pressed) { return 0; } + + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } + m->mothurOutEndLine(); + + return 0; + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "execute"); + exit(1); + } +} +//********************************************************************************************************************** +int CorrAxesCommand::calcPearson(map >& axes, ofstream& out) { + try { + + //find average of each axis - X + vector averageAxes; averageAxes.resize(numaxes, 0.0); + for (map >::iterator it = axes.begin(); it != axes.end(); it++) { + vector temp = it->second; + for (int i = 0; i < temp.size(); i++) { + averageAxes[i] += temp[i]; + } + } + + for (int i = 0; i < averageAxes.size(); i++) { averageAxes[i] = averageAxes[i] / (float) axes.size(); } + + //for each otu + for (int i = 0; i < lookupFloat[0]->getNumBins(); i++) { + + //find the averages this otu - Y + float sumOtu = 0.0; + for (int j = 0; j < lookupFloat.size(); j++) { + sumOtu += lookupFloat[j]->getAbundance(i); + } + float Ybar = sumOtu / (float) lookupFloat.size(); + + //find the average + } + + return 0; + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "calcPearson"); + exit(1); + } +} +//********************************************************************************************************************** +int CorrAxesCommand::getShared(){ + try { + InputData* input = new InputData(sharedfile, "sharedfile"); + lookup = input->getSharedRAbundVectors(); + string lastLabel = lookup[0]->getLabel(); + + if (label == "") { label = lastLabel; delete input; return 0; } + + //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. + set labels; labels.insert(label); + set processedLabels; + set userLabels = labels; + + //as long as you are not at the end of the file or done wih the lines you want + while((lookup[0] != NULL) && (userLabels.size() != 0)) { + if (m->control_pressed) { delete input; return 0; } + + if(labels.count(lookup[0]->getLabel()) == 1){ + processedLabels.insert(lookup[0]->getLabel()); + userLabels.erase(lookup[0]->getLabel()); + break; + } + + if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup[0]->getLabel(); + + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(lastLabel); + + processedLabels.insert(lookup[0]->getLabel()); + userLabels.erase(lookup[0]->getLabel()); + + //restore real lastlabel to save below + lookup[0]->setLabel(saveLabel); + break; + } + + lastLabel = lookup[0]->getLabel(); + + //get next line to process + //prevent memory leak + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + lookup = input->getSharedRAbundVectors(); + } + + + if (m->control_pressed) { delete input; return 0; } + + //output error messages about any remaining user labels + set::iterator it; + bool needToRun = false; + for (it = userLabels.begin(); it != userLabels.end(); it++) { + m->mothurOut("Your file does not include the label " + *it); + if (processedLabels.count(lastLabel) != 1) { + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); + needToRun = true; + }else { + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); + } + } + + //run last label if you need to + if (needToRun == true) { + for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + lookup = input->getSharedRAbundVectors(lastLabel); + } + + delete input; + return 0; + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "getShared"); + exit(1); + } +} +//********************************************************************************************************************** +int CorrAxesCommand::getSharedFloat(){ + try { + InputData* input = new InputData(relabundfile, "relabund"); + lookupFloat = input->getSharedRAbundFloatVectors(); + string lastLabel = lookupFloat[0]->getLabel(); + + if (label == "") { label = lastLabel; delete input; return 0; } + + //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. + set labels; labels.insert(label); + set processedLabels; + set userLabels = labels; + + //as long as you are not at the end of the file or done wih the lines you want + while((lookupFloat[0] != NULL) && (userLabels.size() != 0)) { + + if (m->control_pressed) { delete input; return 0; } + + if(labels.count(lookupFloat[0]->getLabel()) == 1){ + processedLabels.insert(lookupFloat[0]->getLabel()); + userLabels.erase(lookupFloat[0]->getLabel()); + break; + } + + if ((m->anyLabelsToProcess(lookupFloat[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookupFloat[0]->getLabel(); + + for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } + lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); + + processedLabels.insert(lookupFloat[0]->getLabel()); + userLabels.erase(lookupFloat[0]->getLabel()); + + //restore real lastlabel to save below + lookupFloat[0]->setLabel(saveLabel); + break; + } + + lastLabel = lookupFloat[0]->getLabel(); + + //get next line to process + //prevent memory leak + for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } + lookupFloat = input->getSharedRAbundFloatVectors(); + } + + + if (m->control_pressed) { delete input; return 0; } + + //output error messages about any remaining user labels + set::iterator it; + bool needToRun = false; + for (it = userLabels.begin(); it != userLabels.end(); it++) { + m->mothurOut("Your file does not include the label " + *it); + if (processedLabels.count(lastLabel) != 1) { + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); + needToRun = true; + }else { + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); + } + } + + //run last label if you need to + if (needToRun == true) { + for (int i = 0; i < lookupFloat.size(); i++) { if (lookupFloat[i] != NULL) { delete lookupFloat[i]; } } + lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); + } + + delete input; + return 0; + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "getSharedFloat"); + exit(1); + } +} +/*****************************************************************/ +int CorrAxesCommand::convertToRelabund(){ + try { + + vector newLookup; + for (int i = 0; i < lookup.size(); i++) { + SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); + temp->setLabel(lookup[i]->getLabel()); + temp->setGroup(lookup[i]->getGroup()); + newLookup.push_back(temp); + } + + for (int i = 0; i < lookup.size(); i++) { + + for (int j = 0; j < lookup[i]->getNumBins(); j++) { + + if (m->control_pressed) { return 0; } + + int abund = lookup[i]->getAbundance(j); + + float relabund = abund / (float) lookup[i]->getNumSeqs(); + + newLookup[i]->push_back(relabund, lookup[i]->getGroup()); + } + } + + if (pickedGroups) { eliminateZeroOTUS(newLookup); } + + lookupFloat = newLookup; + + return 0; + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "convertToRelabund"); + exit(1); + } +} +//********************************************************************************************************************** +int CorrAxesCommand::eliminateZeroOTUS(vector& thislookup) { + try { + + vector newLookup; + for (int i = 0; i < thislookup.size(); i++) { + SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); + temp->setLabel(thislookup[i]->getLabel()); + temp->setGroup(thislookup[i]->getGroup()); + newLookup.push_back(temp); + } + + //for each bin + for (int i = 0; i < thislookup[0]->getNumBins(); i++) { + if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } + + //look at each sharedRabund and make sure they are not all zero + bool allZero = true; + for (int j = 0; j < thislookup.size(); j++) { + if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; } + } + + //if they are not all zero add this bin + if (!allZero) { + for (int j = 0; j < thislookup.size(); j++) { + newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); + } + } + } + + for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; } + + thislookup = newLookup; + + return 0; + + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "eliminateZeroOTUS"); + exit(1); + } +} +/*****************************************************************/ +map > CorrAxesCommand::readAxes(){ + try { + map > axes; + + ifstream in; + m->openInputFile(axesfile, in); + + string headerLine = m->getline(in); m->gobble(in); + + //count the number of axis you are reading + bool done = false; + int count = 0; + while (!done) { + int pos = headerLine.find("axis"); + if (pos != string::npos) { + count++; + headerLine = headerLine.substr(pos+4); + }else { done = true; } + } + cout << "count = " << count << endl; + + while (!in.eof()) { + + if (m->control_pressed) { in.close(); return axes; } + + string group = ""; + in >> group; m->gobble(in); + + vector thisGroupsAxes; + for (int i = 0; i < count; i++) { + float temp = 0.0; + in >> temp; + + //only save the axis we want + if (i < numaxes) { thisGroupsAxes.push_back(temp); } + } + + //save group if its one the user selected + if (names.count(group) != 0) { + map >::iterator it = axes.find(group); + + if (it == axes.end()) { + axes[group] = thisGroupsAxes; + }else { + m->mothurOut(group + " is already in your axes file, using first definition."); m->mothurOutEndLine(); + } + } + + m->gobble(in); + } + in.close(); + + return axes; + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "convertToRelabund"); + exit(1); + } +} +/*****************************************************************/ + + + + + + diff --git a/corraxescommand.h b/corraxescommand.h new file mode 100644 index 0000000..507399c --- /dev/null +++ b/corraxescommand.h @@ -0,0 +1,54 @@ +#ifndef CORRAXESCOMMAND_H +#define CORRAXESCOMMAND_H + +/* + * corraxescommand.h + * Mothur + * + * Created by westcott on 12/22/10. + * Copyright 2010 Schloss Lab. All rights reserved. + * + */ + +#include "command.hpp" +#include "sharedrabundvector.h" +#include "sharedrabundfloatvector.h" +#include "inputdata.h" + +class CorrAxesCommand : public Command { +public: + CorrAxesCommand(string); + CorrAxesCommand(); + ~CorrAxesCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } + int execute(); + void help(); + +private: + GlobalData* globaldata; + string axesfile, sharedfile, relabundfile, groups, label, inputFileName, outputDir, method; + bool abort, pickedGroups; + int numaxes; + set names; + + vector outputNames, Groups; + map > outputTypes; + vector lookup; + vector lookupFloat; + + int getShared(); + int getSharedFloat(); + int convertToRelabund(); + int eliminateZeroOTUS(vector&); + map > readAxes(); + int calcPearson(map >&, ofstream&); + +}; + + +#endif + + diff --git a/decalc.cpp b/decalc.cpp index a5a0ec0..9c84429 100644 --- a/decalc.cpp +++ b/decalc.cpp @@ -947,28 +947,35 @@ map DeCalculator::trimSeqs(Sequence* query, vector topMatch //save this spot if it is the farthest if (pos < rearPos) { rearPos = pos; } - - //check to make sure that is not whole seq - if ((rearPos - frontPos - 1) <= 0) { m->mothurOut("Error, when I trim your sequences, the entire sequence is trimmed."); m->mothurOutEndLine(); exit(1); } -//cout << query->getName() << " front = " << frontPos << " rear = " << rearPos << endl; - //trim query - string newAligned = query->getAligned(); - newAligned = newAligned.substr(frontPos, (rearPos-frontPos+1)); - query->setAligned(newAligned); - - //trim topMatches - for (int i = 0; i < topMatches.size(); i++) { - newAligned = topMatches[i]->getAligned(); - newAligned = newAligned.substr(frontPos, (rearPos-frontPos+1)); - topMatches[i]->setAligned(newAligned); - } map trimmedPos; - - for (int i = 0; i < newAligned.length(); i++) { - trimmedPos[i] = i+frontPos; + //check to make sure that is not whole seq + if ((rearPos - frontPos - 1) <= 0) { + m->mothurOut("[ERROR]: when I trim your sequences, the entire sequence is trimmed."); m->mothurOutEndLine(); + query->setAligned(""); + //trim topMatches + for (int i = 0; i < topMatches.size(); i++) { + topMatches[i]->setAligned(""); + } + + }else { + + //trim query + string newAligned = query->getAligned(); + newAligned = newAligned.substr(frontPos, (rearPos-frontPos+1)); + query->setAligned(newAligned); + + //trim topMatches + for (int i = 0; i < topMatches.size(); i++) { + newAligned = topMatches[i]->getAligned(); + newAligned = newAligned.substr(frontPos, (rearPos-frontPos+1)); + topMatches[i]->setAligned(newAligned); + } + + for (int i = 0; i < newAligned.length(); i++) { + trimmedPos[i] = i+frontPos; + } } - return trimmedPos; } catch(exception& e) { diff --git a/maligner.cpp b/maligner.cpp index 1d52589..5f522a6 100644 --- a/maligner.cpp +++ b/maligner.cpp @@ -71,6 +71,9 @@ string Maligner::chimeraMaligner(int chimeraPenalty, DeCalculator* decalc) { //trims seqs to first non gap char in all seqs and last non gap char in all seqs spotMap = decalc->trimSeqs(query, refSeqs); + + //you trimmed the whole sequence, skip + if (query->getAligned() == "") { return "no"; } vector temp = refSeqs; temp.push_back(query); diff --git a/mothur b/mothur index 537b967..3ee5a5a 100755 Binary files a/mothur and b/mothur differ