5 * Created by westcott on 5/10/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "chopseqscommand.h"
11 #include "sequence.hpp"
12 #include "removeseqscommand.h"
14 //**********************************************************************************************************************
15 vector<string> ChopSeqsCommand::setParameters(){
17 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta);
18 CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","name",false,false,true); parameters.push_back(pname);
19 CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","count",false,false,true); parameters.push_back(pcount);
20 CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","group",false,false,true); parameters.push_back(pgroup);
21 CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors);
22 CommandParameter pnumbases("numbases", "Number", "", "0", "", "", "","",false,true,true); parameters.push_back(pnumbases);
23 CommandParameter pcountgaps("countgaps", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pcountgaps);
24 CommandParameter pshort("short", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pshort);
25 CommandParameter pkeep("keep", "Multiple", "front-back", "front", "", "", "","",false,false); parameters.push_back(pkeep);
26 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
27 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
29 vector<string> myArray;
30 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
34 m->errorOut(e, "ChopSeqsCommand", "setParameters");
38 //**********************************************************************************************************************
39 string ChopSeqsCommand::getHelpString(){
41 string helpString = "";
42 helpString += "The chop.seqs command reads a fasta file and outputs a .chop.fasta containing the trimmed sequences. Note: If a sequence is completely 'chopped', an accnos file will be created with the names of the sequences removed. \n";
43 helpString += "The chop.seqs command parameters are fasta, name, group, count, numbases, countgaps and keep. fasta is required unless you have a valid current fasta file. numbases is required.\n";
44 helpString += "The chop.seqs command should be in the following format: chop.seqs(fasta=yourFasta, numbases=yourNum, keep=yourKeep).\n";
45 helpString += "If you provide a name, group or count file any sequences removed from the fasta file will also be removed from those files.\n";
46 helpString += "The numbases parameter allows you to specify the number of bases you want to keep.\n";
47 helpString += "The keep parameter allows you to specify whether you want to keep the front or the back of your sequence, default=front.\n";
48 helpString += "The countgaps parameter allows you to specify whether you want to count gaps as bases, default=false.\n";
49 helpString += "The short parameter allows you to specify you want to keep sequences that are too short to chop, default=false.\n";
50 helpString += "The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n";
51 helpString += "For example, if you ran chop.seqs with numbases=200 and short=t, if a sequence had 100 bases mothur would keep the sequence rather than eliminate it.\n";
52 helpString += "Example chop.seqs(fasta=amazon.fasta, numbases=200, keep=front).\n";
53 helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n";
57 m->errorOut(e, "ChopSeqsCommand", "getHelpString");
61 //**********************************************************************************************************************
62 string ChopSeqsCommand::getOutputPattern(string type) {
66 if (type == "fasta") { pattern = "[filename],chop.fasta"; }
67 else if (type == "name") { pattern = "[filename],chop.names"; }
68 else if (type == "group") { pattern = "[filename],chop.groups"; }
69 else if (type == "count") { pattern = "[filename],chop.count_table"; }
70 else if (type == "accnos") { pattern = "[filename],chop.accnos"; }
71 else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
76 m->errorOut(e, "ChopSeqsCommand", "getOutputPattern");
80 //**********************************************************************************************************************
81 ChopSeqsCommand::ChopSeqsCommand(){
83 abort = true; calledHelp = true;
85 vector<string> tempOutNames;
86 outputTypes["fasta"] = tempOutNames;
87 outputTypes["accnos"] = tempOutNames;
88 outputTypes["name"] = tempOutNames;
89 outputTypes["group"] = tempOutNames;
90 outputTypes["count"] = tempOutNames;
93 m->errorOut(e, "ChopSeqsCommand", "ChopSeqsCommand");
97 //**********************************************************************************************************************
98 ChopSeqsCommand::ChopSeqsCommand(string option) {
100 abort = false; calledHelp = false;
102 //allow user to run help
103 if(option == "help") { help(); abort = true; calledHelp = true; }
104 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
107 vector<string> myArray = setParameters();
109 OptionParser parser(option);
110 map<string,string> parameters = parser.getParameters();
112 ValidParameters validParameter;
113 map<string,string>::iterator it;
115 //check to make sure all parameters are valid for command
116 for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
117 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
120 //initialize outputTypes
121 vector<string> tempOutNames;
122 outputTypes["fasta"] = tempOutNames;
123 outputTypes["accnos"] = tempOutNames;
124 outputTypes["name"] = tempOutNames;
125 outputTypes["group"] = tempOutNames;
126 outputTypes["count"] = tempOutNames;
128 //if the user changes the input directory command factory will send this info to us in the output parameter
129 string inputDir = validParameter.validFile(parameters, "inputdir", false);
130 if (inputDir == "not found"){ inputDir = ""; }
133 it = parameters.find("fasta");
134 //user has given a template file
135 if(it != parameters.end()){
136 path = m->hasPath(it->second);
137 //if the user has not given a path then, add inputdir. else leave path alone.
138 if (path == "") { parameters["fasta"] = inputDir + it->second; }
141 it = parameters.find("name");
142 //user has given a template file
143 if(it != parameters.end()){
144 path = m->hasPath(it->second);
145 //if the user has not given a path then, add inputdir. else leave path alone.
146 if (path == "") { parameters["name"] = inputDir + it->second; }
149 it = parameters.find("group");
150 //user has given a template file
151 if(it != parameters.end()){
152 path = m->hasPath(it->second);
153 //if the user has not given a path then, add inputdir. else leave path alone.
154 if (path == "") { parameters["group"] = inputDir + it->second; }
157 it = parameters.find("count");
158 //user has given a template file
159 if(it != parameters.end()){
160 path = m->hasPath(it->second);
161 //if the user has not given a path then, add inputdir. else leave path alone.
162 if (path == "") { parameters["count"] = inputDir + it->second; }
166 //check for required parameters
167 fastafile = validParameter.validFile(parameters, "fasta", true);
168 if (fastafile == "not open") { abort = true; }
169 else if (fastafile == "not found") { //if there is a current fasta file, use it
170 fastafile = m->getFastaFile();
171 if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); }
172 else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; }
173 }else { m->setFastaFile(fastafile); }
175 namefile = validParameter.validFile(parameters, "name", true);
176 if (namefile == "not open") { namefile = ""; abort = true; }
177 else if (namefile == "not found") { namefile = ""; }
178 else { m->setNameFile(namefile); }
180 groupfile = validParameter.validFile(parameters, "group", true);
181 if (groupfile == "not open") { groupfile = ""; abort = true; }
182 else if (groupfile == "not found") { groupfile = ""; }
183 else { m->setGroupFile(groupfile); }
185 countfile = validParameter.validFile(parameters, "count", true);
186 if (countfile == "not open") { countfile = ""; abort = true; }
187 else if (countfile == "not found") { countfile = ""; }
188 else { m->setCountTableFile(countfile); }
190 if ((namefile != "") && (countfile != "")) {
191 m->mothurOut("[ERROR]: you may only use one of the following: name or count."); m->mothurOutEndLine(); abort = true;
194 if ((groupfile != "") && (countfile != "")) {
195 m->mothurOut("[ERROR]: you may only use one of the following: group or count."); m->mothurOutEndLine(); abort=true;
198 //if the user changes the output directory command factory will send this info to us in the output parameter
199 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
201 string temp = validParameter.validFile(parameters, "numbases", false); if (temp == "not found") { temp = "0"; }
202 m->mothurConvert(temp, numbases);
204 temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); }
205 m->setProcessors(temp);
206 m->mothurConvert(temp, processors);
208 temp = validParameter.validFile(parameters, "countgaps", false); if (temp == "not found") { temp = "f"; }
209 countGaps = m->isTrue(temp);
211 temp = validParameter.validFile(parameters, "short", false); if (temp == "not found") { temp = "f"; }
212 Short = m->isTrue(temp);
214 keep = validParameter.validFile(parameters, "keep", false); if (keep == "not found") { keep = "front"; }
216 if (numbases == 0) { m->mothurOut("You must provide the number of bases you want to keep for the chops.seqs command."); m->mothurOutEndLine(); abort = true; }
220 catch(exception& e) {
221 m->errorOut(e, "ChopSeqsCommand", "ChopSeqsCommand");
225 //**********************************************************************************************************************
227 int ChopSeqsCommand::execute(){
230 if (abort == true) { if (calledHelp) { return 0; } return 2; }
232 map<string, string> variables;
233 string thisOutputDir = outputDir;
234 if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); }
235 variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile));
236 string outputFileName = getOutputFileName("fasta", variables);
237 outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName);
238 string outputFileNameAccnos = getOutputFileName("accnos", variables);
240 vector<unsigned long long> positions;
241 vector<linePair> lines;
242 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
243 positions = m->divideFile(fastafile, processors);
244 for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); }
247 positions = m->setFilePosFasta(fastafile, numSeqs);
248 if (positions.size() < processors) { processors = positions.size(); }
250 //figure out how many sequences you have to process
251 int numSeqsPerProcessor = numSeqs / processors;
252 for (int i = 0; i < processors; i++) {
253 int startIndex = i * numSeqsPerProcessor;
254 if(i == (processors - 1)){ numSeqsPerProcessor = numSeqs - i * numSeqsPerProcessor; }
255 lines.push_back(linePair(positions[startIndex], numSeqsPerProcessor));
259 bool wroteAccnos = false;
260 if(processors == 1) { wroteAccnos = driver(lines[0], fastafile, outputFileName, outputFileNameAccnos); }
261 else { wroteAccnos = createProcesses(lines, fastafile, outputFileName, outputFileNameAccnos); }
263 if (m->control_pressed) { return 0; }
266 outputNames.push_back(outputFileNameAccnos); outputTypes["accnos"].push_back(outputFileNameAccnos);
268 //use remove.seqs to create new name, group and count file
269 if ((countfile != "") || (namefile != "") || (groupfile != "")) {
270 string inputString = "accnos=" + outputFileNameAccnos;
272 if (countfile != "") { inputString += ", count=" + countfile; }
274 if (namefile != "") { inputString += ", name=" + namefile; }
275 if (groupfile != "") { inputString += ", group=" + groupfile; }
278 m->mothurOut("/******************************************/"); m->mothurOutEndLine();
279 m->mothurOut("Running command: remove.seqs(" + inputString + ")"); m->mothurOutEndLine();
280 m->mothurCalling = true;
282 Command* removeCommand = new RemoveSeqsCommand(inputString);
283 removeCommand->execute();
285 map<string, vector<string> > filenames = removeCommand->getOutputFiles();
287 delete removeCommand;
288 m->mothurCalling = false;
289 m->mothurOut("/******************************************/"); m->mothurOutEndLine();
291 if (groupfile != "") {
292 thisOutputDir = outputDir;
293 if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); }
294 variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile));
295 string outGroup = getOutputFileName("group", variables);
296 m->renameFile(filenames["group"][0], outGroup);
297 outputNames.push_back(outGroup); outputTypes["group"].push_back(outGroup);
300 if (namefile != "") {
301 thisOutputDir = outputDir;
302 if (outputDir == "") { thisOutputDir += m->hasPath(namefile); }
303 variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile));
304 string outName = getOutputFileName("name", variables);
305 m->renameFile(filenames["name"][0], outName);
306 outputNames.push_back(outName); outputTypes["name"].push_back(outName);
309 if (countfile != "") {
310 thisOutputDir = outputDir;
311 if (outputDir == "") { thisOutputDir += m->hasPath(countfile); }
312 variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile));
313 string outCount = getOutputFileName("count", variables);
314 m->renameFile(filenames["count"][0], outCount);
315 outputNames.push_back(outCount); outputTypes["count"].push_back(outCount);
319 else { m->mothurRemove(outputFileNameAccnos); }
321 //set fasta file as new current fastafile
323 itTypes = outputTypes.find("fasta");
324 if (itTypes != outputTypes.end()) {
325 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
328 if (wroteAccnos) { //set accnos file as new current accnosfile
329 itTypes = outputTypes.find("accnos");
330 if (itTypes != outputTypes.end()) {
331 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setAccnosFile(current); }
334 itTypes = outputTypes.find("name");
335 if (itTypes != outputTypes.end()) {
336 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
339 itTypes = outputTypes.find("group");
340 if (itTypes != outputTypes.end()) {
341 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
344 itTypes = outputTypes.find("count");
345 if (itTypes != outputTypes.end()) {
346 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setCountTableFile(current); }
350 m->mothurOutEndLine();
351 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
352 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
353 m->mothurOutEndLine();
358 catch(exception& e) {
359 m->errorOut(e, "ChopSeqsCommand", "execute");
363 /**************************************************************************************************/
364 bool ChopSeqsCommand::createProcesses(vector<linePair> lines, string filename, string outFasta, string outAccnos) {
367 bool wroteAccnos = false;
368 vector<int> processIDS;
369 vector<string> nonBlankAccnosFiles;
371 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
373 //loop through and create all the processes you want
374 while (process != processors) {
378 processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
381 wroteAccnos = driver(lines[process], filename, outFasta + toString(getpid()) + ".temp", outAccnos + toString(getpid()) + ".temp");
383 //pass numSeqs to parent
385 string tempFile = fastafile + toString(getpid()) + ".bool.temp";
386 m->openOutputFile(tempFile, out);
387 out << wroteAccnos << endl;
392 m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
393 for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
399 wroteAccnos = driver(lines[0], filename, outFasta, outAccnos);
401 //force parent to wait until all the processes are done
402 for (int i=0;i<processIDS.size();i++) {
403 int temp = processIDS[i];
408 if (wroteAccnos) { nonBlankAccnosFiles.push_back(outAccnos); }
409 else { m->mothurRemove(outAccnos); } //remove so other files can be renamed to it
411 //parent reads in and combine Filter info
412 for (int i = 0; i < processIDS.size(); i++) {
413 string tempFilename = fastafile + toString(processIDS[i]) + ".bool.temp";
415 m->openInputFile(tempFilename, in);
418 in >> temp; m->gobble(in);
419 if (temp) { wroteAccnos = temp; nonBlankAccnosFiles.push_back(outAccnos + toString(processIDS[i]) + ".temp"); }
420 else { m->mothurRemove((outAccnos + toString(processIDS[i]) + ".temp")); }
423 m->mothurRemove(tempFilename);
426 //////////////////////////////////////////////////////////////////////////////////////////////////////
427 //Windows version shared memory, so be careful when passing variables through the seqSumData struct.
428 //Above fork() will clone, so memory is separate, but that's not the case with windows,
429 //Taking advantage of shared memory to allow both threads to add info to vectors.
430 //////////////////////////////////////////////////////////////////////////////////////////////////////
432 vector<chopData*> pDataArray;
433 DWORD dwThreadIdArray[processors-1];
434 HANDLE hThreadArray[processors-1];
436 //Create processor worker threads.
437 for( int i=0; i<processors-1; i++ ){
439 string extension = "";
440 if (i != 0) { extension = toString(i) + ".temp"; processIDS.push_back(i); }
441 // Allocate memory for thread data.
442 chopData* tempChop = new chopData(filename, (outFasta+extension), (outAccnos+extension), m, lines[i].start, lines[i].end, keep, countGaps, numbases, Short);
443 pDataArray.push_back(tempChop);
445 //MyChopThreadFunction is in header. It must be global or static to work with the threads.
446 //default security attributes, thread function name, argument to thread function, use default creation flags, returns the thread identifier
447 hThreadArray[i] = CreateThread(NULL, 0, MyChopThreadFunction, pDataArray[i], 0, &dwThreadIdArray[i]);
451 wroteAccnos = driver(lines[processors-1], filename, (outFasta + toString(processors-1) + ".temp"), (outAccnos + toString(processors-1) + ".temp"));
452 processIDS.push_back(processors-1);
454 //Wait until all threads have terminated.
455 WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE);
457 if (wroteAccnos) { nonBlankAccnosFiles.push_back(outAccnos); }
458 else { m->mothurRemove(outAccnos); } //remove so other files can be renamed to it
460 //Close all thread handles and free memory allocations.
461 for(int i=0; i < pDataArray.size(); i++){
462 if (pDataArray[i]->wroteAccnos) { wroteAccnos = pDataArray[i]->wroteAccnos; nonBlankAccnosFiles.push_back(outAccnos + toString(processIDS[i]) + ".temp"); }
463 else { m->mothurRemove((outAccnos + toString(processIDS[i]) + ".temp")); }
464 //check to make sure the process finished
465 if (pDataArray[i]->count != pDataArray[i]->end) {
466 m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true;
468 CloseHandle(hThreadArray[i]);
469 delete pDataArray[i];
473 for (int i = 0; i < processIDS.size(); i++) {
474 m->appendFiles((outFasta + toString(processIDS[i]) + ".temp"), outFasta);
475 m->mothurRemove((outFasta + toString(processIDS[i]) + ".temp"));
478 if (nonBlankAccnosFiles.size() != 0) {
479 m->renameFile(nonBlankAccnosFiles[0], outAccnos);
481 for (int h=1; h < nonBlankAccnosFiles.size(); h++) {
482 m->appendFiles(nonBlankAccnosFiles[h], outAccnos);
483 m->mothurRemove(nonBlankAccnosFiles[h]);
485 }else { //recreate the accnosfile if needed
487 m->openOutputFile(outAccnos, out);
493 catch(exception& e) {
494 m->errorOut(e, "ChopSeqsCommand", "createProcesses");
498 /**************************************************************************************/
499 bool ChopSeqsCommand::driver(linePair filePos, string filename, string outFasta, string outAccnos) {
503 m->openOutputFile(outFasta, out);
506 m->openOutputFile(outAccnos, outAcc);
509 m->openInputFile(filename, in);
511 in.seekg(filePos.start);
514 bool wroteAccnos = false;
519 if (m->control_pressed) { in.close(); out.close(); return 1; }
521 Sequence seq(in); m->gobble(in);
523 if (m->control_pressed) { in.close(); out.close(); outAcc.close(); m->mothurRemove(outFasta); m->mothurRemove(outAccnos); return 0; }
525 if (seq.getName() != "") {
526 string newSeqString = getChopped(seq);
528 //output trimmed sequence
529 if (newSeqString != "") {
530 out << ">" << seq.getName() << endl << newSeqString << endl;
532 outAcc << seq.getName() << endl;
538 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
539 unsigned long long pos = in.tellg();
540 if ((pos == -1) || (pos >= filePos.end)) { break; }
542 if (in.eof()) { break; }
545 if((count) % 1000 == 0){ m->mothurOut(toString(count)); m->mothurOutEndLine(); }
549 if((count) % 1000 != 0){ m->mothurOut(toString(count)); m->mothurOutEndLine(); }
558 catch(exception& e) {
559 m->errorOut(e, "ChopSeqsCommand", "driver");
563 //**********************************************************************************************************************
564 string ChopSeqsCommand::getChopped(Sequence seq) {
566 string temp = seq.getAligned();
567 string tempUnaligned = seq.getUnaligned();
570 //if needed trim sequence
571 if (keep == "front") {//you want to keep the beginning
572 int tempLength = temp.length();
574 if (tempLength > numbases) { //you have enough bases to remove some
577 int numBasesCounted = 0;
579 for (int i = 0; i < temp.length(); i++) {
581 if (toupper(temp[i]) == 'N') { temp[i] = '.'; }
585 if (numBasesCounted >= numbases) { stopSpot = i; break; }
588 if (stopSpot == 0) { temp = ""; }
589 else { temp = temp.substr(0, stopSpot+1); }
592 if (!Short) { temp = ""; } //sequence too short
594 }else { //you are keeping the back
595 int tempLength = temp.length();
596 if (tempLength > numbases) { //you have enough bases to remove some
599 int numBasesCounted = 0;
601 for (int i = (temp.length()-1); i >= 0; i--) {
603 if (toupper(temp[i]) == 'N') { temp[i] = '.'; }
607 if (numBasesCounted >= numbases) { stopSpot = i; break; }
610 if (stopSpot == 0) { temp = ""; }
611 else { temp = temp.substr(stopSpot+1); }
613 if (!Short) { temp = ""; } //sequence too short
619 //if needed trim sequence
620 if (keep == "front") {//you want to keep the beginning
621 int tempLength = tempUnaligned.length();
623 if (tempLength > numbases) { //you have enough bases to remove some
626 int numBasesCounted = 0;
628 for (int i = 0; i < temp.length(); i++) {
630 if (toupper(temp[i]) == 'N') {
633 if (tempLength < numbases) { stopSpot = 0; break; }
636 if(isalpha(temp[i])) { numBasesCounted++; }
638 if (numBasesCounted >= numbases) { stopSpot = i; break; }
641 if (stopSpot == 0) { temp = ""; }
642 else { temp = temp.substr(0, stopSpot+1); }
645 if (!Short) { temp = ""; } //sequence too short
647 }else { //you are keeping the back
648 int tempLength = tempUnaligned.length();
649 if (tempLength > numbases) { //you have enough bases to remove some
652 int numBasesCounted = 0;
654 for (int i = (temp.length()-1); i >= 0; i--) {
656 if (toupper(temp[i]) == 'N') {
659 if (tempLength < numbases) { stopSpot = 0; break; }
662 if(isalpha(temp[i])) { numBasesCounted++; }
664 if (numBasesCounted >= numbases) { stopSpot = i; break; }
667 if (stopSpot == 0) { temp = ""; }
668 else { temp = temp.substr(stopSpot); }
670 if (!Short) { temp = ""; } //sequence too short
677 catch(exception& e) {
678 m->errorOut(e, "ChopSeqsCommand", "getChopped");
682 //**********************************************************************************************************************