5 * Created by Pat Schloss on 12/22/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "trimflowscommand.h"
11 #include "needlemanoverlap.hpp"
13 //**********************************************************************************************************************
15 vector<string> TrimFlowsCommand::getValidParameters(){
17 string Array[] = {"flow", "totalflows", "minflows",
18 "fasta", "minlength", "maxlength", "maxhomop", "signal", "noise"
19 "oligos", "pdiffs", "bdiffs", "tdiffs",
25 "outputdir","inputdir"
28 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
32 m->errorOut(e, "TrimFlowsCommand", "getValidParameters");
37 //**********************************************************************************************************************
39 vector<string> TrimFlowsCommand::getRequiredParameters(){
41 string Array[] = {"flow"};
42 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
46 m->errorOut(e, "TrimFlowsCommand", "getRequiredParameters");
51 //**********************************************************************************************************************
53 vector<string> TrimFlowsCommand::getRequiredFiles(){
55 vector<string> myArray;
59 m->errorOut(e, "TrimFlowsCommand", "getRequiredFiles");
64 //**********************************************************************************************************************
66 TrimFlowsCommand::TrimFlowsCommand(){
69 //initialize outputTypes
70 vector<string> tempOutNames;
71 outputTypes["flow"] = tempOutNames;
72 outputTypes["fasta"] = tempOutNames;
75 m->errorOut(e, "TrimFlowsCommand", "TrimFlowsCommand");
80 //***************************************************************************************************************
82 TrimFlowsCommand::~TrimFlowsCommand(){ /* do nothing */ }
84 //***************************************************************************************************************
86 void TrimFlowsCommand::help(){
88 m->mothurOut("The trim.flows command reads a flowgram file and creates .....\n");
89 m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n");
90 m->mothurOut("For more details please check out the wiki http://www.mothur.org/wiki/Trim.flows.\n\n");
94 m->errorOut(e, "TrimFlowsCommand", "help");
99 //**********************************************************************************************************************
101 TrimFlowsCommand::TrimFlowsCommand(string option) {
107 //allow user to run help
108 if(option == "help") { help(); abort = true; }
111 //valid paramters for this command
112 string AlignArray[] = {"flow", "totalflows", "minflows",
113 "fasta", "minlength", "maxlength", "maxhomop", "signal", "noise",
114 "oligos", "pdiffs", "bdiffs", "tdiffs",
119 "outputdir","inputdir"
123 vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
125 OptionParser parser(option);
126 map<string,string> parameters = parser.getParameters();
128 ValidParameters validParameter;
129 map<string,string>::iterator it;
131 //check to make sure all parameters are valid for command
132 for (it = parameters.begin(); it != parameters.end(); it++) {
133 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
136 //initialize outputTypes
137 vector<string> tempOutNames;
138 outputTypes["flow"] = tempOutNames;
139 // outputTypes["fasta"] = tempOutNames;
140 // outputTypes["group"] = tempOutNames;
142 //if the user changes the input directory command factory will send this info to us in the output parameter
143 string inputDir = validParameter.validFile(parameters, "inputdir", false);
144 if (inputDir == "not found"){ inputDir = ""; }
147 it = parameters.find("flow");
148 //user has given a template file
149 if(it != parameters.end()){
150 path = m->hasPath(it->second);
151 //if the user has not given a path then, add inputdir. else leave path alone.
152 if (path == "") { parameters["flow"] = inputDir + it->second; }
155 // it = parameters.find("oligos");
156 // //user has given a template file
157 // if(it != parameters.end()){
158 // path = m->hasPath(it->second);
159 // //if the user has not given a path then, add inputdir. else leave path alone.
160 // if (path == "") { parameters["oligos"] = inputDir + it->second; }
164 // it = parameters.find("group");
165 // //user has given a template file
166 // if(it != parameters.end()){
167 // path = m->hasPath(it->second);
168 // //if the user has not given a path then, add inputdir. else leave path alone.
169 // if (path == "") { parameters["group"] = inputDir + it->second; }
174 //check for required parameters
175 flowFileName = validParameter.validFile(parameters, "flow", true);
176 if (flowFileName == "not found") { m->mothurOut("flow is a required parameter for the trim.flows command."); m->mothurOutEndLine(); abort = true; }
177 else if (flowFileName == "not open") { abort = true; }
179 //if the user changes the output directory command factory will send this info to us in the output parameter
180 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){
182 outputDir += m->hasPath(flowFileName); //if user entered a file with a path then preserve it
186 //check for optional parameter and set defaults
187 // ...at some point should added some additional type checking...
190 temp = validParameter.validFile(parameters, "minflows", false); if (temp == "not found") { temp = "360"; }
191 convert(temp, minFlows);
193 temp = validParameter.validFile(parameters, "totalflows", false); if (temp == "not found") { temp = "720"; }
194 convert(temp, totalFlows);
197 temp = validParameter.validFile(parameters, "oligos", true);
198 if (temp == "not found") { oligoFileName = ""; }
199 else if(temp == "not open") { abort = true; }
200 else { oligoFileName = temp; }
202 temp = validParameter.validFile(parameters, "fasta", false); if (temp == "not found"){ fasta = 0; }
203 else if(m->isTrue(temp)) { fasta = 1; }
205 temp = validParameter.validFile(parameters, "maxhomop", false); if (temp == "not found"){ temp = "9"; }
206 convert(temp, maxHomoP);
208 temp = validParameter.validFile(parameters, "signal", false); if (temp == "not found"){ temp = "0.50"; }
209 convert(temp, signal);
211 temp = validParameter.validFile(parameters, "noise", false); if (temp == "not found"){ temp = "0.70"; }
212 convert(temp, noise);
214 temp = validParameter.validFile(parameters, "minlength", false); if (temp == "not found"){ temp = "0"; }
215 convert(temp, minLength);
217 temp = validParameter.validFile(parameters, "maxlength", false); if (temp == "not found"){ temp = "0"; }
218 convert(temp, maxLength);
220 temp = validParameter.validFile(parameters, "bdiffs", false); if (temp == "not found"){ temp = "0"; }
221 convert(temp, bdiffs);
223 temp = validParameter.validFile(parameters, "pdiffs", false); if (temp == "not found"){ temp = "0"; }
224 convert(temp, pdiffs);
226 temp = validParameter.validFile(parameters, "tdiffs", false); if (temp == "not found"){ int tempTotal = pdiffs + bdiffs; temp = toString(tempTotal); }
227 convert(temp, tdiffs);
228 if(tdiffs == 0){ tdiffs = bdiffs + pdiffs; }
230 temp = validParameter.validFile(parameters, "allfiles", false); if (temp == "not found") { temp = "T"; }
231 allFiles = m->isTrue(temp);
233 // temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; }
234 // convert(temp, processors);
236 if(allFiles && oligoFileName == ""){
237 m->mothurOut("You selected allfiles, but didn't enter an oligos file. Ignoring the allfiles request."); m->mothurOutEndLine();
244 catch(exception& e) {
245 m->errorOut(e, "TrimFlowsCommand", "TrimSeqsCommand");
250 //***************************************************************************************************************
252 int TrimFlowsCommand::execute(){
255 if (abort == true) { return 0; }
257 string trimFlowFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "trim.flow";
258 outputNames.push_back(trimFlowFileName); outputTypes["flow"].push_back(trimFlowFileName);
260 string scrapFlowFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "scrap.flow";
261 outputNames.push_back(scrapFlowFileName); outputTypes["flow"].push_back(scrapFlowFileName);
263 string fastaFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "flow.fasta";
265 outputNames.push_back(fastaFileName); outputTypes["fasta"].push_back(fastaFileName);
268 driverCreateTrim(flowFileName, trimFlowFileName, scrapFlowFileName, fastaFileName);
272 catch(exception& e) {
273 m->errorOut(e, "TrimSeqsCommand", "execute");
278 //***************************************************************************************************************
280 int TrimFlowsCommand::driverCreateTrim(string flowFileName, string trimFlowFileName, string scrapFlowFileName, string fastaFileName){
284 ofstream trimFlowFile;
285 m->openOutputFile(trimFlowFileName, trimFlowFile);
286 trimFlowFile.setf(ios::fixed, ios::floatfield); trimFlowFile.setf(ios::showpoint);
288 ofstream scrapFlowFile;
289 m->openOutputFile(scrapFlowFileName, scrapFlowFile);
290 scrapFlowFile.setf(ios::fixed, ios::floatfield); scrapFlowFile.setf(ios::showpoint);
293 m->openInputFile(flowFileName, flowFile);
296 if(fasta){ m->openOutputFile(fastaFileName, fastaFile); }
298 vector<vector<string> > barcodePrimerCombos;
299 if(oligoFileName != ""){ getOligos(barcodePrimerCombos); }
301 // inFASTA.seekg(line->start);
303 // bool done = false;
309 int currentSeqDiffs = 0;
311 string trashCode = "";
313 FlowData currFlow(flowFile, signal, noise, maxHomoP);
315 currFlow.capFlows(totalFlows);
316 Sequence currSeq = currFlow.getSequence();
319 if(!currFlow.hasMinFlows(minFlows)){ //screen to see if sequence is of a minimum number of flows
324 if(minLength > 0 || maxLength > 0){ //screen to see if sequence is above and below a specific number of bases
325 int seqLength = currFlow.getSeqLength();
326 if(seqLength < minLength || seqLength > maxLength){
332 int primerIndex, barcodeIndex;
333 if(barcodes.size() != 0){
334 success = stripBarcode(currSeq, barcodeIndex);
335 if(success > bdiffs) { trashCode += 'b'; }
336 else{ currentSeqDiffs += success; }
339 if(numFPrimers != 0){
340 success = stripForward(currSeq, primerIndex);
341 if(success > pdiffs) { trashCode += 'f'; }
342 else{ currentSeqDiffs += success; }
345 if (currentSeqDiffs > tdiffs) { trashCode += 't'; }
347 if(numRPrimers != 0){
348 success = stripReverse(currSeq);
349 if(!success) { trashCode += 'r'; }
353 if(trashCode.length() == 0){
354 currFlow.printFlows(trimFlowFile);
357 currFlow.printFASTA(fastaFile);
360 if(barcodes.size() != 0 || primers.size() != 0){
361 string fileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + barcodePrimerCombos[barcodeIndex][primerIndex] + ".flow";
363 m->openOutputFileAppend(fileName, output);
364 currFlow.printFlows(output);
370 currFlow.printFlows(scrapFlowFile, trashCode);
373 // if(barcodes.size() != 0){
374 // string thisGroup = groupVector[groupBar];
375 // int indexToFastaFile = groupBar;
376 // if (primers.size() != 0){
377 // //does this primer have a group
378 // if (groupVector[groupPrime] != "") {
379 // thisGroup += "." + groupVector[groupPrime];
380 // indexToFastaFile = combos[thisGroup];
383 // outGroups << currSeq.getName() << '\t' << thisGroup << endl;
386 // m->openOutputFileAppend(fastaNames[indexToFastaFile], outTemp);
387 // //currSeq.printSequence(*fastaFileNames[indexToFastaFile]);
388 // currSeq.printSequence(outTemp);
391 // if(qFileName != ""){
392 // //currQual.printQScores(*qualFileNames[indexToFastaFile]);
393 // ofstream outTemp2;
394 // m->openOutputFileAppend(qualNames[indexToFastaFile], outTemp2);
395 // currQual.printQScores(outTemp2);
402 // currSeq.setName(currSeq.getName() + '|' + trashCode);
403 // currSeq.setUnaligned(origSeq);
404 // currSeq.setAligned(origSeq);
405 // currSeq.printSequence(scrapFASTA);
411 if((count) % 1000 == 0){ m->mothurOut(toString(count)); m->mothurOutEndLine(); }
415 if((count) % 1000 != 0){ m->mothurOut(toString(count)); m->mothurOutEndLine(); }
418 trimFlowFile.close();
419 scrapFlowFile.close();
424 catch(exception& e) {
425 m->errorOut(e, "TrimSeqsCommand", "driverCreateTrim");
430 //***************************************************************************************************************
432 void TrimFlowsCommand::getOligos(vector<vector<string> >& outFlowFileNames){
435 m->openInputFile(oligoFileName, oligosFile);
437 string type, oligo, group;
440 int indexBarcode = 0;
442 while(!oligosFile.eof()){
444 oligosFile >> type; m->gobble(oligosFile); //get the first column value of the row - is it a comment or a feature we are interested in?
446 if(type[0] == '#'){ //igore the line because there's a comment
447 while (!oligosFile.eof()) { char c = oligosFile.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there
449 else{ //there's a feature we're interested in
451 for(int i=0;i<type.length();i++){ type[i] = toupper(type[i]); } //make type case insensitive
453 oligosFile >> oligo; //get the DNA sequence for the feature
455 for(int i=0;i<oligo.length();i++){ //make type case insensitive and change any U's to T's
456 oligo[i] = toupper(oligo[i]);
457 if(oligo[i] == 'U') { oligo[i] = 'T'; }
460 if(type == "FORWARD"){ //if the feature is a forward primer...
463 while (!oligosFile.eof()) { // get rest of line in case there is a primer name = will have the name of the primer
464 char c = oligosFile.get();
465 if (c == 10 || c == 13){ break; }
466 else if (c == 32 || c == 9){;} //space or tab
470 //have we seen this primer already?
471 map<string, int>::iterator itPrimer = primers.find(oligo);
472 if (itPrimer != primers.end()) { m->mothurOut("primer " + oligo + " is in your oligos file already."); m->mothurOutEndLine(); }
474 primers[oligo]=indexPrimer; indexPrimer++;
475 primerNameVector.push_back(group);
478 else if(type == "REVERSE"){
479 Sequence oligoRC("reverse", oligo);
480 oligoRC.reverseComplement();
481 revPrimer.push_back(oligoRC.getUnaligned());
483 else if(type == "BARCODE"){
486 //check for repeat barcodes
487 map<string, int>::iterator itBar = barcodes.find(oligo);
488 if (itBar != barcodes.end()) { m->mothurOut("barcode " + oligo + " is in your oligos file already."); m->mothurOutEndLine(); }
490 barcodes[oligo]=indexBarcode; indexBarcode++;
491 barcodeNameVector.push_back(group);
494 m->mothurOut(type + " is not recognized as a valid type. Choices are forward, reverse, and barcode. Ignoring " + oligo + "."); m->mothurOutEndLine();
498 m->gobble(oligosFile);
502 //add in potential combos
503 outFlowFileNames.resize(barcodeNameVector.size());
504 for(int i=0;i<outFlowFileNames.size();i++){
505 outFlowFileNames[i].assign(primerNameVector.size(), "");
509 for(map<string, int>::iterator itBar = barcodes.begin();itBar != barcodes.end();itBar++){
510 for(map<string, int>::iterator itPrimer = primers.begin();itPrimer != primers.end(); itPrimer++){
512 string primerName = primerNameVector[itPrimer->second];
513 string barcodeName = barcodeNameVector[itBar->second];
515 string comboGroupName = "";
516 string fileName = "";
518 if(primerName == ""){
519 comboGroupName = barcodeNameVector[itBar->second];
520 fileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + comboGroupName + ".flow";
523 comboGroupName = barcodeNameVector[itBar->second] + "." + primerNameVector[itPrimer->second];
524 fileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + comboGroupName + ".flow";
527 outputNames.push_back(fileName);
528 outputTypes["flow"].push_back(fileName);
529 outFlowFileNames[itBar->second][itPrimer->second] = comboGroupName;
532 m->openOutputFile(fileName, temp);
538 numFPrimers = primers.size();
539 numRPrimers = revPrimer.size();
542 catch(exception& e) {
543 m->errorOut(e, "TrimSeqsCommand", "getOligos");
548 //***************************************************************************************************************
550 int TrimFlowsCommand::stripBarcode(Sequence& seq, int& group){
553 string rawSequence = seq.getUnaligned();
554 int success = bdiffs + 1; //guilty until proven innocent
556 //can you find the barcode
557 for(map<string,int>::iterator it=barcodes.begin();it!=barcodes.end();it++){
558 string oligo = it->first;
559 if(rawSequence.length() < oligo.length()){ //let's just assume that the barcodes are the same length
560 success = bdiffs + 10; //if the sequence is shorter than the barcode then bail out
564 if(compareDNASeq(oligo, rawSequence.substr(0,oligo.length()))){
566 seq.setUnaligned(rawSequence.substr(oligo.length()));
573 //if you found the barcode or if you don't want to allow for diffs
575 if ((bdiffs == 0) || (success == 0)) { return success; }
577 else { //try aligning and see if you can find it
582 Alignment* alignment;
583 if (barcodes.size() > 0) {
584 map<string,int>::iterator it=barcodes.begin();
586 for(it;it!=barcodes.end();it++){
587 if(it->first.length() > maxLength){
588 maxLength = it->first.length();
591 alignment = new NeedlemanOverlap(-1.0, 1.0, -1.0, (maxLength+bdiffs+1));
593 }else{ alignment = NULL; }
595 //can you find the barcode
601 for(map<string,int>::iterator it=barcodes.begin();it!=barcodes.end();it++){
602 string oligo = it->first;
603 // int length = oligo.length();
605 if(rawSequence.length() < maxLength){ //let's just assume that the barcodes are the same length
606 success = bdiffs + 10;
610 //use needleman to align first barcode.length()+numdiffs of sequence to each barcode
611 alignment->align(oligo, rawSequence.substr(0,oligo.length()+bdiffs));
612 oligo = alignment->getSeqAAln();
613 string temp = alignment->getSeqBAln();
615 int alnLength = oligo.length();
617 for(int i=oligo.length()-1;i>=0;i--){
618 if(oligo[i] != '-'){ alnLength = i+1; break; }
620 oligo = oligo.substr(0,alnLength);
621 temp = temp.substr(0,alnLength);
624 int numDiff = countDiffs(oligo, temp);
626 if(numDiff < minDiff){
629 minGroup = it->second;
631 for(int i=0;i<alnLength;i++){
637 else if(numDiff == minDiff){
643 if(minDiff > bdiffs) { success = minDiff; } //no good matches
644 else if(minCount > 1) { success = bdiffs + 100; } //can't tell the difference between multiple barcodes
645 else{ //use the best match
647 seq.setUnaligned(rawSequence.substr(minPos));
651 if (alignment != NULL) { delete alignment; }
658 catch(exception& e) {
659 m->errorOut(e, "TrimFlowsCommand", "stripBarcode");
665 //***************************************************************************************************************
667 int TrimFlowsCommand::stripForward(Sequence& seq, int& group){
670 string rawSequence = seq.getUnaligned();
671 int success = pdiffs + 1; //guilty until proven innocent
673 //can you find the primer
674 for(map<string,int>::iterator it=primers.begin();it!=primers.end();it++){
675 string oligo = it->first;
676 if(rawSequence.length() < oligo.length()){ //let's just assume that the primers are the same length
677 success = pdiffs + 10; //if the sequence is shorter than the barcode then bail out
681 if(compareDNASeq(oligo, rawSequence.substr(0,oligo.length()))){
683 seq.setUnaligned(rawSequence.substr(oligo.length()));
689 //if you found the barcode or if you don't want to allow for diffs
691 if ((pdiffs == 0) || (success == 0)) { return success; }
693 else { //try aligning and see if you can find it
698 Alignment* alignment;
699 if (primers.size() > 0) {
700 map<string,int>::iterator it=primers.begin();
702 for(it;it!=primers.end();it++){
703 if(it->first.length() > maxLength){
704 maxLength = it->first.length();
707 alignment = new NeedlemanOverlap(-1.0, 1.0, -1.0, (maxLength+pdiffs+1));
709 }else{ alignment = NULL; }
711 //can you find the barcode
717 for(map<string,int>::iterator it=primers.begin();it!=primers.end();it++){
718 string oligo = it->first;
719 // int length = oligo.length();
721 if(rawSequence.length() < maxLength){
722 success = pdiffs + 100;
726 //use needleman to align first barcode.length()+numdiffs of sequence to each barcode
727 alignment->align(oligo, rawSequence.substr(0,oligo.length()+pdiffs));
728 oligo = alignment->getSeqAAln();
729 string temp = alignment->getSeqBAln();
731 int alnLength = oligo.length();
733 for(int i=oligo.length()-1;i>=0;i--){
734 if(oligo[i] != '-'){ alnLength = i+1; break; }
736 oligo = oligo.substr(0,alnLength);
737 temp = temp.substr(0,alnLength);
740 int numDiff = countDiffs(oligo, temp);
742 // cout << oligo << '\t' << temp << '\t' << numDiff << endl;
744 if(numDiff < minDiff){
747 minGroup = it->second;
749 for(int i=0;i<alnLength;i++){
755 else if(numDiff == minDiff){
761 if(minDiff > pdiffs) { success = minDiff; } //no good matches
762 else if(minCount > 1) { success = pdiffs + 10; } //can't tell the difference between multiple primers
763 else{ //use the best match
765 seq.setUnaligned(rawSequence.substr(minPos));
769 if (alignment != NULL) { delete alignment; }
776 catch(exception& e) {
777 m->errorOut(e, "TrimFlowsCommand", "stripForward");
782 //***************************************************************************************************************
784 bool TrimFlowsCommand::stripReverse(Sequence& seq){
787 string rawSequence = seq.getUnaligned();
788 bool success = 0; //guilty until proven innocent
790 for(int i=0;i<numRPrimers;i++){
791 string oligo = revPrimer[i];
793 if(rawSequence.length() < oligo.length()){
798 if(compareDNASeq(oligo, rawSequence.substr(rawSequence.length()-oligo.length(),oligo.length()))){
799 seq.setUnaligned(rawSequence.substr(0,rawSequence.length()-oligo.length()));
808 catch(exception& e) {
809 m->errorOut(e, "TrimFlowsCommand", "stripReverse");
815 //***************************************************************************************************************
817 bool TrimFlowsCommand::compareDNASeq(string oligo, string seq){
820 int length = oligo.length();
822 for(int i=0;i<length;i++){
824 if(oligo[i] != seq[i]){
825 if(oligo[i] == 'A' || oligo[i] == 'T' || oligo[i] == 'G' || oligo[i] == 'C') { success = 0; }
826 else if((oligo[i] == 'N' || oligo[i] == 'I') && (seq[i] == 'N')) { success = 0; }
827 else if(oligo[i] == 'R' && (seq[i] != 'A' && seq[i] != 'G')) { success = 0; }
828 else if(oligo[i] == 'Y' && (seq[i] != 'C' && seq[i] != 'T')) { success = 0; }
829 else if(oligo[i] == 'M' && (seq[i] != 'C' && seq[i] != 'A')) { success = 0; }
830 else if(oligo[i] == 'K' && (seq[i] != 'T' && seq[i] != 'G')) { success = 0; }
831 else if(oligo[i] == 'W' && (seq[i] != 'T' && seq[i] != 'A')) { success = 0; }
832 else if(oligo[i] == 'S' && (seq[i] != 'C' && seq[i] != 'G')) { success = 0; }
833 else if(oligo[i] == 'B' && (seq[i] != 'C' && seq[i] != 'T' && seq[i] != 'G')) { success = 0; }
834 else if(oligo[i] == 'D' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'G')) { success = 0; }
835 else if(oligo[i] == 'H' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'C')) { success = 0; }
836 else if(oligo[i] == 'V' && (seq[i] != 'A' && seq[i] != 'C' && seq[i] != 'G')) { success = 0; }
838 if(success == 0) { break; }
847 catch(exception& e) {
848 m->errorOut(e, "TrimFlowsCommand", "compareDNASeq");
854 //***************************************************************************************************************
856 int TrimFlowsCommand::countDiffs(string oligo, string seq){
859 int length = oligo.length();
862 for(int i=0;i<length;i++){
864 if(oligo[i] != seq[i]){
865 if(oligo[i] == 'A' || oligo[i] == 'T' || oligo[i] == 'G' || oligo[i] == 'C' || oligo[i] == '-' || oligo[i] == '.') { countDiffs++; }
866 else if((oligo[i] == 'N' || oligo[i] == 'I') && (seq[i] == 'N')) { countDiffs++; }
867 else if(oligo[i] == 'R' && (seq[i] != 'A' && seq[i] != 'G')) { countDiffs++; }
868 else if(oligo[i] == 'Y' && (seq[i] != 'C' && seq[i] != 'T')) { countDiffs++; }
869 else if(oligo[i] == 'M' && (seq[i] != 'C' && seq[i] != 'A')) { countDiffs++; }
870 else if(oligo[i] == 'K' && (seq[i] != 'T' && seq[i] != 'G')) { countDiffs++; }
871 else if(oligo[i] == 'W' && (seq[i] != 'T' && seq[i] != 'A')) { countDiffs++; }
872 else if(oligo[i] == 'S' && (seq[i] != 'C' && seq[i] != 'G')) { countDiffs++; }
873 else if(oligo[i] == 'B' && (seq[i] != 'C' && seq[i] != 'T' && seq[i] != 'G')) { countDiffs++; }
874 else if(oligo[i] == 'D' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'G')) { countDiffs++; }
875 else if(oligo[i] == 'H' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'C')) { countDiffs++; }
876 else if(oligo[i] == 'V' && (seq[i] != 'A' && seq[i] != 'C' && seq[i] != 'G')) { countDiffs++; }
883 catch(exception& e) {
884 m->errorOut(e, "TrimFlowsCommand", "countDiffs");
890 //***************************************************************************************************************