2 * filterseqscommand.cpp
5 * Created by Thomas Ryabin on 5/4/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "filterseqscommand.h"
11 #include "sequence.hpp"
13 /**************************************************************************************/
15 FilterSeqsCommand::FilterSeqsCommand(string option) {
20 //allow user to run help
21 if(option == "help") { help(); abort = true; }
24 //valid paramters for this command
25 string Array[] = {"fasta", "trump", "soft", "hard", "vertical", "outputdir","inputdir", "processors"};
26 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
28 OptionParser parser(option);
29 map<string,string> parameters = parser.getParameters();
31 ValidParameters validParameter;
32 map<string,string>::iterator it;
34 //check to make sure all parameters are valid for command
35 for (it = parameters.begin(); it != parameters.end(); it++) {
36 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
39 //if the user changes the input directory command factory will send this info to us in the output parameter
40 string inputDir = validParameter.validFile(parameters, "inputdir", false);
41 if (inputDir == "not found"){ inputDir = ""; }
44 it = parameters.find("fasta");
45 //user has given a template file
46 if(it != parameters.end()){
47 path = hasPath(it->second);
48 //if the user has not given a path then, add inputdir. else leave path alone.
49 if (path == "") { parameters["fasta"] = inputDir + it->second; }
52 it = parameters.find("hard");
53 //user has given a template file
54 if(it != parameters.end()){
55 path = hasPath(it->second);
56 //if the user has not given a path then, add inputdir. else leave path alone.
57 if (path == "") { parameters["hard"] = inputDir + it->second; }
61 //check for required parameters
62 fasta = validParameter.validFile(parameters, "fasta", false);
63 if (fasta == "not found") { m->mothurOut("fasta is a required parameter for the filter.seqs command."); m->mothurOutEndLine(); abort = true; }
65 splitAtDash(fasta, fastafileNames);
67 //go through files and make sure they are good, if not, then disregard them
68 for (int i = 0; i < fastafileNames.size(); i++) {
70 string path = hasPath(fastafileNames[i]);
71 //if the user has not given a path then, add inputdir. else leave path alone.
72 if (path == "") { fastafileNames[i] = inputDir + fastafileNames[i]; }
77 ableToOpen = openInputFile(fastafileNames[i], in);
78 if (ableToOpen == 1) {
79 m->mothurOut(fastafileNames[i] + " will be disregarded."); m->mothurOutEndLine();
80 //erase from file list
81 fastafileNames.erase(fastafileNames.begin()+i);
84 string simpleName = getSimpleName(fastafileNames[i]);
85 filterFileName += simpleName.substr(0, simpleName.find_first_of('.'));
90 //make sure there is at least one valid file left
91 if (fastafileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; }
95 //if the user changes the output directory command factory will send this info to us in the output parameter
96 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){
98 outputDir += hasPath(fastafileNames[0]); //if user entered a file with a path then preserve it
101 //check for optional parameter and set defaults
102 // ...at some point should added some additional type checking...
105 temp = validParameter.validFile(parameters, "trump", false); if (temp == "not found") { temp = "*"; }
108 temp = validParameter.validFile(parameters, "soft", false); if (temp == "not found") { soft = 0; }
109 else { soft = (float)atoi(temp.c_str()) / 100.0; }
111 temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; }
112 convert(temp, processors);
114 hard = validParameter.validFile(parameters, "hard", true); if (hard == "not found") { hard = ""; }
115 else if (hard == "not open") { abort = true; }
117 vertical = validParameter.validFile(parameters, "vertical", false); if (vertical == "not found") { vertical = "T"; }
124 catch(exception& e) {
125 m->errorOut(e, "FilterSeqsCommand", "FilterSeqsCommand");
130 //**********************************************************************************************************************
132 void FilterSeqsCommand::help(){
135 m->mothurOut("The filter.seqs command reads a file containing sequences and creates a .filter and .filter.fasta file.\n");
136 m->mothurOut("The filter.seqs command parameters are fasta, trump, soft, hard and vertical. \n");
137 m->mothurOut("The fasta parameter is required. You may enter several fasta files to build the filter from and filter, by separating their names with -'s.\n");
138 m->mothurOut("For example: fasta=abrecovery.fasta-amazon.fasta \n");
139 m->mothurOut("The trump parameter .... The default is ...\n");
140 m->mothurOut("The soft parameter .... The default is ....\n");
141 m->mothurOut("The hard parameter .... The default is ....\n");
142 m->mothurOut("The vertical parameter .... The default is T.\n");
143 m->mothurOut("The filter.seqs command should be in the following format: \n");
144 m->mothurOut("filter.seqs(fasta=yourFastaFile, trump=yourTrump, soft=yourSoft, hard=yourHard, vertical=yourVertical) \n");
145 m->mothurOut("Example filter.seqs(fasta=abrecovery.fasta, trump=..., soft=..., hard=..., vertical=T).\n");
146 m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
149 catch(exception& e) {
150 m->errorOut(e, "FilterSeqsCommand", "help");
155 /**************************************************************************************/
157 int FilterSeqsCommand::execute() {
160 if (abort == true) { return 0; }
163 openInputFile(fastafileNames[0], inFASTA);
165 Sequence testSeq(inFASTA);
166 alignmentLength = testSeq.getAlignLength();
169 ////////////create filter/////////////////
171 filter = createFilter();
173 if (m->control_pressed) { return 0; }
177 string filterFile = outputDir + filterFileName + ".filter";
178 openOutputFile(filterFile, outFilter);
179 outFilter << filter << endl;
181 outputNames.push_back(filterFile);
184 ////////////run filter/////////////////
188 int filteredLength = 0;
189 for(int i=0;i<alignmentLength;i++){
190 if(filter[i] == '1'){ filteredLength++; }
193 if (m->control_pressed) { for(int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
196 m->mothurOutEndLine();
197 m->mothurOut("Length of filtered alignment: " + toString(filteredLength)); m->mothurOutEndLine();
198 m->mothurOut("Number of columns removed: " + toString((alignmentLength-filteredLength))); m->mothurOutEndLine();
199 m->mothurOut("Length of the original alignment: " + toString(alignmentLength)); m->mothurOutEndLine();
200 m->mothurOut("Number of sequences used to construct filter: " + toString(numSeqs)); m->mothurOutEndLine();
203 m->mothurOutEndLine();
204 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
205 for(int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
206 m->mothurOutEndLine();
211 catch(exception& e) {
212 m->errorOut(e, "FilterSeqsCommand", "execute");
216 /**************************************************************************************/
217 int FilterSeqsCommand::filterSequences() {
220 for (int s = 0; s < fastafileNames.size(); s++) {
222 for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
224 string filteredFasta = outputDir + getRootName(getSimpleName(fastafileNames[s])) + "filter.fasta";
230 MPI_Comm_size(MPI_COMM_WORLD, &processors); //set processors to the number of mpi processes running
231 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
235 int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY;
236 int inMode=MPI_MODE_RDONLY;
238 char outFilename[filteredFasta.length()];
239 strcpy(outFilename, filteredFasta.c_str());
241 char inFileName[fastafileNames[s].length()];
242 strcpy(inFileName, fastafileNames[s].c_str());
244 MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer
245 MPI_File_open(MPI_COMM_WORLD, outFilename, outMode, MPI_INFO_NULL, &outMPI);
247 if (pid == 0) { //you are the root process
249 setLines(fastafileNames[s]);
251 for (int j = 0; j < lines.size(); j++) { //each process
252 if (j != 0) { //don't send to yourself
253 MPI_Send(&lines[j]->start, 1, MPI_INT, j, tag, MPI_COMM_WORLD); //start position in file
254 MPI_Send(&bufferSizes[j], 1, MPI_INT, j, tag, MPI_COMM_WORLD); //how bytes for the read
258 //read your peice of file
259 char buf[bufferSizes[0]];
260 MPI_File_read_at(inMPI, lines[0]->start, buf, bufferSizes[0], MPI_CHAR, &status);
261 istringstream iss (buf,istringstream::in);
264 driverMPIRun(iss, outMPI);
267 for(int i = 1; i < processors; i++) {
269 MPI_Recv(buf, 4, MPI_CHAR, i, tag, MPI_COMM_WORLD, &status);
272 }else { //you are a child process
273 //receive your section of file
274 int startPos, numLines, bufferSize;
275 MPI_Recv(&startPos, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
276 MPI_Recv(&bufferSize, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
278 //read your peice of file
279 char buf2[bufferSize];
280 MPI_File_read_at(inMPI, startPos, buf2, bufferSize, MPI_CHAR, &status);
281 istringstream iss (buf2,istringstream::in);
284 driverMPIRun(iss, outMPI);
289 //tell parent you are done.
290 MPI_Send(buf, 4, MPI_CHAR, 0, tag, MPI_COMM_WORLD);
293 MPI_File_close(&outMPI);
294 MPI_File_close(&inMPI);
297 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
300 openInputFile(fastafileNames[s], inFASTA);
301 int numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
304 lines.push_back(new linePair(0, numFastaSeqs));
306 driverRunFilter(filter, filteredFasta, fastafileNames[s], lines[0]);
308 setLines(fastafileNames[s]);
309 createProcessesRunFilter(filter, fastafileNames[s]);
311 rename((fastafileNames[s] + toString(processIDS[0]) + ".temp").c_str(), filteredFasta.c_str());
314 for(int i=1;i<processors;i++){
315 appendAlignFiles((fastafileNames[s] + toString(processIDS[i]) + ".temp"), filteredFasta);
316 remove((fastafileNames[s] + toString(processIDS[i]) + ".temp").c_str());
320 if (m->control_pressed) { return 1; }
323 openInputFile(fastafileNames[s], inFASTA);
324 int numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
327 lines.push_back(new linePair(0, numFastaSeqs));
329 driverRunFilter(filter, filteredFasta, fastafileNames[s], lines[0]);
331 if (m->control_pressed) { return 1; }
334 outputNames.push_back(filteredFasta);
339 catch(exception& e) {
340 m->errorOut(e, "FilterSeqsCommand", "filterSequences");
344 /**************************************************************************************/
345 int FilterSeqsCommand::driverMPIRun(istringstream& in, MPI_File& outMPI) {
347 string outputString = "";
353 Sequence seq(in); gobble(in);
355 if (seq.getName() != "") {
356 string align = seq.getAligned();
357 string filterSeq = "";
359 for(int j=0;j<alignmentLength;j++){
360 if(filter[j] == '1'){
361 filterSeq += align[j];
366 outputString += ">" + seq.getName() + "\n" + filterSeq + "\n";
368 if(count % 10 == 0){ //output to file
369 //send results to parent
370 int length = outputString.length();
372 strcpy(buf, outputString.c_str());
374 MPI_File_write_shared(outMPI, buf, length, MPI_CHAR, &status);
381 if(outputString != ""){ //output to file
382 //send results to parent
383 int length = outputString.length();
385 strcpy(buf, outputString.c_str());
387 MPI_File_write_shared(outMPI, buf, length, MPI_CHAR, &status);
394 catch(exception& e) {
395 m->errorOut(e, "FilterSeqsCommand", "driverRunFilter");
399 /**************************************************************************************/
400 int FilterSeqsCommand::driverRunFilter(string F, string outputFilename, string inputFilename, linePair* line) {
403 openOutputFile(outputFilename, out);
406 openInputFile(inputFilename, in);
408 in.seekg(line->start);
410 for(int i=0;i<line->numSeqs;i++){
412 if (m->control_pressed) { in.close(); out.close(); return 0; }
415 if (seq.getName() != "") {
416 string align = seq.getAligned();
417 string filterSeq = "";
419 for(int j=0;j<alignmentLength;j++){
420 if(filter[j] == '1'){
421 filterSeq += align[j];
425 out << '>' << seq.getName() << endl << filterSeq << endl;
434 catch(exception& e) {
435 m->errorOut(e, "FilterSeqsCommand", "driverRunFilter");
439 /**************************************************************************************************/
441 int FilterSeqsCommand::createProcessesRunFilter(string F, string filename) {
443 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
448 //loop through and create all the processes you want
449 while (process != processors) {
453 processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
456 string filteredFasta = filename + toString(getpid()) + ".temp";
457 driverRunFilter(F, filteredFasta, filename, lines[process]);
459 }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
462 //force parent to wait until all the processes are done
463 for (int i=0;i<processors;i++) {
464 int temp = processIDS[i];
471 catch(exception& e) {
472 m->errorOut(e, "FilterSeqsCommand", "createProcessesRunFilter");
476 /**************************************************************************************/
477 string FilterSeqsCommand::createFilter() {
479 string filterString = "";
483 if (soft != 0) { F.setSoft(soft); }
484 if (trump != '*') { F.setTrump(trump); }
486 F.setLength(alignmentLength);
488 if(soft != 0 || isTrue(vertical)){
492 if(hard.compare("") != 0) { F.doHard(hard); }
493 else { F.setFilter(string(alignmentLength, '1')); }
497 if(trump != '*' || isTrue(vertical) || soft != 0){
498 for (int s = 0; s < fastafileNames.size(); s++) {
502 int Atag = 1; int Ttag = 2; int Ctag = 3; int Gtag = 4; int Gaptag = 5;
507 rc = MPI_Comm_size(MPI_COMM_WORLD, &processors);
508 rc = MPI_Comm_rank(MPI_COMM_WORLD, &pid);
510 char tempFileName[fastafileNames[s].length()];
511 strcpy(tempFileName, fastafileNames[s].c_str());
512 cout << pid << " tempFileName " << tempFileName << endl;
513 MPI_File_open(MPI_COMM_WORLD, tempFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &in); //comm, filename, mode, info, filepointer
514 cout << pid << " here" << endl;
515 if (pid == 0) { //you are the root process
516 setLines(fastafileNames[s]);
517 cout << pid << " after setlines" << endl;
518 for (int j = 0; j < lines.size(); j++) { //each process
519 if (j != 0) { //don't send to yourself
520 MPI_Send(&lines[j]->start, 1, MPI_INT, j, tag, MPI_COMM_WORLD); //start position in file
521 MPI_Send(&bufferSizes[j], 1, MPI_INT, j, tag, MPI_COMM_WORLD); //how bytes for the read
524 cout << pid << " done sending" << endl;
525 char buf[bufferSizes[0]];
526 MPI_File_read_at(in, 0, buf, bufferSizes[0], MPI_CHAR, &status);
527 cout << pid << " done reading" << endl;
528 string tempBuf = buf;
529 if (tempBuf.length() > bufferSizes[0]) { tempBuf = tempBuf.substr(0, bufferSizes[0]); }
531 MPICreateFilter(F, tempBuf);
532 cout << pid << "done with mpi create filter " << endl;
533 if (m->control_pressed) { MPI_File_close(&in); return filterString; }
535 vector<int> temp; temp.resize(alignmentLength+1);
537 //get the frequencies from the child processes
538 for(int i = 0; i < ((processors-1)*5); i++) {
539 MPI_Recv(&temp[0], (alignmentLength+1), MPI_INT, MPI_ANY_SOURCE, tag, MPI_COMM_WORLD, &status);
540 int receiveTag = temp[temp.size()-1]; //child process added a int to the end to indicate what letter count this is for
542 if (receiveTag == Atag) { //you are recieveing the A frequencies
543 for (int k = 0; k < alignmentLength; k++) { F.a[k] += temp[k]; }
544 }else if (receiveTag == Ttag) { //you are recieveing the T frequencies
545 for (int k = 0; k < alignmentLength; k++) { F.t[k] += temp[k]; }
546 }else if (receiveTag == Ctag) { //you are recieveing the C frequencies
547 for (int k = 0; k < alignmentLength; k++) { F.c[k] += temp[k]; }
548 }else if (receiveTag == Gtag) { //you are recieveing the G frequencies
549 for (int k = 0; k < alignmentLength; k++) { F.g[k] += temp[k]; }
550 }else if (receiveTag == Gaptag) { //you are recieveing the gap frequencies
551 for (int k = 0; k < alignmentLength; k++) { F.gap[k] += temp[k]; }
556 }else { //i am the child process
558 int startPos, bufferSize;
559 ierr = MPI_Recv(&startPos, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
560 ierr = MPI_Recv(&bufferSize, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
561 cout << pid << '\t' << startPos << '\t' << bufferSize << endl;
563 char buf2[bufferSize];
564 MPI_File_read_at( in, startPos, buf2, bufferSize, MPI_CHAR, &status);
566 string tempBuf = buf2;
567 if (tempBuf.length() > bufferSize) { tempBuf = tempBuf.substr(0, bufferSize); }
569 MPICreateFilter(F, tempBuf);
570 cout << pid << "done with mpi create filter " << endl;
571 if (m->control_pressed) { MPI_File_close(&in); return filterString; }
573 //send my fequency counts
575 int ierr = MPI_Send(&(F.a[0]), (alignmentLength+1), MPI_INT, 0, tag, MPI_COMM_WORLD);
577 ierr = MPI_Send (&(F.t[0]), (alignmentLength+1), MPI_INT, 0, tag, MPI_COMM_WORLD);
579 ierr = MPI_Send(&(F.c[0]), (alignmentLength+1), MPI_INT, 0, tag, MPI_COMM_WORLD);
581 ierr = MPI_Send(&(F.g[0]), (alignmentLength+1), MPI_INT, 0, tag, MPI_COMM_WORLD);
582 F.gap.push_back(Gaptag);
583 ierr = MPI_Send(&(F.gap[0]), (alignmentLength+1), MPI_INT, 0, tag, MPI_COMM_WORLD);
586 MPI_Barrier(MPI_COMM_WORLD);
590 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
593 openInputFile(fastafileNames[s], inFASTA);
594 int numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
597 numSeqs += numFastaSeqs;
599 for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
600 lines.push_back(new linePair(0, numFastaSeqs));
602 driverCreateFilter(F, fastafileNames[s], lines[0]);
604 setLines(fastafileNames[s]);
605 createProcessesCreateFilter(F, fastafileNames[s]);
608 if (m->control_pressed) { return filterString; }
611 openInputFile(fastafileNames[s], inFASTA);
612 int numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
615 numSeqs += numFastaSeqs;
617 for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
618 lines.push_back(new linePair(0, numFastaSeqs));
620 driverCreateFilter(F, fastafileNames[s], lines[0]);
621 if (m->control_pressed) { return filterString; }
628 F.setNumSeqs(numSeqs);
630 if(isTrue(vertical) == 1) { F.doVertical(); }
631 if(soft != 0) { F.doSoft(); }
633 filterString = F.getFilter();
637 catch(exception& e) {
638 m->errorOut(e, "FilterSeqsCommand", "createFilter");
642 /**************************************************************************************/
643 int FilterSeqsCommand::driverCreateFilter(Filters& F, string filename, linePair* line) {
647 openInputFile(filename, in);
649 in.seekg(line->start);
651 for(int i=0;i<line->numSeqs;i++){
653 if (m->control_pressed) { in.close(); return 1; }
656 if (seq.getName() != "") {
657 if (seq.getAligned().length() != alignmentLength) { m->mothurOut("Sequences are not all the same length, please correct."); m->mothurOutEndLine(); m->control_pressed = true; }
659 if(trump != '*'){ F.doTrump(seq); }
660 if(isTrue(vertical) || soft != 0){ F.getFreqs(seq); }
665 if((i+1) % 100 == 0){ m->mothurOut(toString(i+1)); m->mothurOutEndLine(); }
669 if((line->numSeqs) % 100 != 0){ m->mothurOut(toString(line->numSeqs)); m->mothurOutEndLine(); }
675 catch(exception& e) {
676 m->errorOut(e, "FilterSeqsCommand", "driverCreateFilter");
680 /**************************************************************************************/
681 int FilterSeqsCommand::MPICreateFilter(Filters& F, string input) {
684 vector<string> seqStrings;
685 parseBuffer(input, seqStrings);
687 for(int i=0;i<seqStrings.size();i++){
689 if (seqStrings[i].length() != alignmentLength) { cout << i << '\t' << seqStrings[i].length() << "Sequences are not all the same length, please correct." << endl; m->control_pressed = true; }
691 if (m->control_pressed) { return 1; }
693 Sequence seq("", seqStrings[i]);
695 if(trump != '*'){ F.doTrump(seq); }
696 if(isTrue(vertical) || soft != 0){ F.getFreqs(seq); }
700 if((i+1) % 100 == 0){ m->mothurOut(toString(i+1)); m->mothurOutEndLine(); }
704 if((seqStrings.size()) % 100 != 0){ m->mothurOut(toString(seqStrings.size())); m->mothurOutEndLine(); }
708 catch(exception& e) {
709 m->errorOut(e, "FilterSeqsCommand", "MPICreateFilter");
714 /**************************************************************************************************/
716 int FilterSeqsCommand::createProcessesCreateFilter(Filters& F, string filename) {
718 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
723 //loop through and create all the processes you want
724 while (process != processors) {
728 processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
731 driverCreateFilter(F, filename, lines[process]);
733 }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
736 //force parent to wait until all the processes are done
737 for (int i=0;i<processors;i++) {
738 int temp = processIDS[i];
745 catch(exception& e) {
746 m->errorOut(e, "FilterSeqsCommand", "createProcessesCreateFilter");
750 /**************************************************************************************************/
752 int FilterSeqsCommand::setLines(string filename) {
754 for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
755 vector<long int> positions;
759 openInputFile(filename, inFASTA);
762 while(!inFASTA.eof()){
763 input = getline(inFASTA);
765 if (input.length() != 0) {
766 if(input[0] == '>'){ long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); }
771 int numFastaSeqs = positions.size();
776 //get num bytes in file
777 pFile = fopen (filename.c_str(),"rb");
778 if (pFile==NULL) perror ("Error opening file");
780 fseek (pFile, 0, SEEK_END);
785 numSeqs += numFastaSeqs;
787 int numSeqsPerProcessor = numFastaSeqs / processors;
789 for (int i = 0; i < processors; i++) {
791 long int startPos = positions[ i * numSeqsPerProcessor ];
792 if(i == processors - 1){
793 numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor;
794 bufferSizes.push_back(size - startPos);
796 long int myEnd = positions[ (i+1) * numSeqsPerProcessor ];
797 bufferSizes.push_back(myEnd-startPos);
799 lines.push_back(new linePair(startPos, numSeqsPerProcessor));
804 catch(exception& e) {
805 m->errorOut(e, "FilterSeqsCommand", "setLines");
809 /**************************************************************************************************/
810 int FilterSeqsCommand::parseBuffer(string file, vector<string>& seqs) {
812 istringstream iss (file); //,istringstream::in
813 string name, seqstring;
817 if (m->control_pressed) { return 0; }
819 Sequence seq(iss); gobble(iss);
821 if (seq.getName() != "") {
822 seqs.push_back(seq.getAligned());
828 catch(exception& e) {
829 m->errorOut(e, "FilterSeqsCommand", "parseBuffer");
833 /**************************************************************************************/