+}
+
+//***************************************************************************************************************
+
+bool TrimSeqsCommand::compareDNASeq(string oligo, string seq){
+ try {
+ bool success = 1;
+ int length = oligo.length();
+
+ for(int i=0;i<length;i++){
+
+ if(oligo[i] != seq[i]){
+ if(oligo[i] == 'A' || oligo[i] == 'T' || oligo[i] == 'G' || oligo[i] == 'C') { success = 0; }
+ else if((oligo[i] == 'N' || oligo[i] == 'I') && (seq[i] == 'N')) { success = 0; }
+ else if(oligo[i] == 'R' && (seq[i] != 'A' && seq[i] != 'G')) { success = 0; }
+ else if(oligo[i] == 'Y' && (seq[i] != 'C' && seq[i] != 'T')) { success = 0; }
+ else if(oligo[i] == 'M' && (seq[i] != 'C' && seq[i] != 'A')) { success = 0; }
+ else if(oligo[i] == 'K' && (seq[i] != 'T' && seq[i] != 'G')) { success = 0; }
+ else if(oligo[i] == 'W' && (seq[i] != 'T' && seq[i] != 'A')) { success = 0; }
+ else if(oligo[i] == 'S' && (seq[i] != 'C' && seq[i] != 'G')) { success = 0; }
+ else if(oligo[i] == 'B' && (seq[i] != 'C' && seq[i] != 'T' && seq[i] != 'G')) { success = 0; }
+ else if(oligo[i] == 'D' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'G')) { success = 0; }
+ else if(oligo[i] == 'H' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'C')) { success = 0; }
+ else if(oligo[i] == 'V' && (seq[i] != 'A' && seq[i] != 'C' && seq[i] != 'G')) { success = 0; }
+
+ if(success == 0) { break; }
+ }
+ else{
+ success = 1;
+ }
+ }
+
+ return success;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "TrimSeqsCommand", "compareDNASeq");
+ exit(1);
+ }
+
+}
+//***************************************************************************************************************
+
+int TrimSeqsCommand::countDiffs(string oligo, string seq){
+ try {
+
+ int length = oligo.length();
+ int countDiffs = 0;
+
+ for(int i=0;i<length;i++){
+
+ if(oligo[i] != seq[i]){
+ if(oligo[i] == 'A' || oligo[i] == 'T' || oligo[i] == 'G' || oligo[i] == 'C' || oligo[i] == '-' || oligo[i] == '.') { countDiffs++; }
+ else if((oligo[i] == 'N' || oligo[i] == 'I') && (seq[i] == 'N')) { countDiffs++; }
+ else if(oligo[i] == 'R' && (seq[i] != 'A' && seq[i] != 'G')) { countDiffs++; }
+ else if(oligo[i] == 'Y' && (seq[i] != 'C' && seq[i] != 'T')) { countDiffs++; }
+ else if(oligo[i] == 'M' && (seq[i] != 'C' && seq[i] != 'A')) { countDiffs++; }
+ else if(oligo[i] == 'K' && (seq[i] != 'T' && seq[i] != 'G')) { countDiffs++; }
+ else if(oligo[i] == 'W' && (seq[i] != 'T' && seq[i] != 'A')) { countDiffs++; }
+ else if(oligo[i] == 'S' && (seq[i] != 'C' && seq[i] != 'G')) { countDiffs++; }
+ else if(oligo[i] == 'B' && (seq[i] != 'C' && seq[i] != 'T' && seq[i] != 'G')) { countDiffs++; }
+ else if(oligo[i] == 'D' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'G')) { countDiffs++; }
+ else if(oligo[i] == 'H' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'C')) { countDiffs++; }
+ else if(oligo[i] == 'V' && (seq[i] != 'A' && seq[i] != 'C' && seq[i] != 'G')) { countDiffs++; }
+
+ }
+ }
+
+ return countDiffs;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "TrimSeqsCommand", "countDiffs");
+ exit(1);
+ }
+
+}
+//***************************************************************************************************************
+
+bool TrimSeqsCommand::stripQualThreshold(Sequence& seq, ifstream& qFile){
+ try {
+// string rawSequence = seq.getUnaligned();
+// int seqLength; // = rawSequence.length();
+// string name, temp, temp2;
+//
+// qFile >> name;
+//
+// //get rest of line
+// temp = "";
+// while (!qFile.eof()) {
+// char c = qFile.get();
+// if (c == 10 || c == 13){ break; }
+// else { temp += c; }
+// }
+//
+// int pos = temp.find("length");
+// if (pos == temp.npos) { m->mothurOut("Cannot find length in qfile for " + seq.getName()); m->mothurOutEndLine(); seqLength = 0; }
+// else {
+// string tempLength = temp.substr(pos);
+// istringstream iss (tempLength,istringstream::in);
+// iss >> temp;
+// }
+//
+// splitAtEquals(temp2, temp); //separates length=242, temp=length, temp2=242
+// convert(temp, seqLength); //converts string to int
+//
+// if (name.length() != 0) { if(name.substr(1) != seq.getName()) { m->mothurOut("sequence name mismatch btwn fasta and qual file"); m->mothurOutEndLine(); } }
+
+ string rawSequence = seq.getUnaligned();
+ int seqLength = seq.getNumBases();
+ bool success = 0; //guilty until proven innocent
+ string name;
+
+ qFile >> name;
+ if (name[0] == '>') { if(name.substr(1) != seq.getName()) { m->mothurOut("sequence name mismatch btwn fasta: " + seq.getName() + " and qual file: " + name); m->mothurOutEndLine(); } }
+
+ while (!qFile.eof()) { char c = qFile.get(); if (c == 10 || c == 13){ break; } }
+
+ int score;
+ int end = seqLength;
+
+ for(int i=0;i<seqLength;i++){
+ qFile >> score;
+
+ if(score < qThreshold){
+ end = i;
+ break;
+ }
+ }
+ for(int i=end+1;i<seqLength;i++){
+ qFile >> score;
+ }
+
+ seq.setUnaligned(rawSequence.substr(0,end));
+
+ return 1;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "TrimSeqsCommand", "stripQualThreshold");
+ exit(1);
+ }
+}
+
+//***************************************************************************************************************
+
+bool TrimSeqsCommand::cullQualAverage(Sequence& seq, ifstream& qFile){
+ try {
+ string rawSequence = seq.getUnaligned();
+ int seqLength = seq.getNumBases();
+ bool success = 0; //guilty until proven innocent
+ string name;
+
+ qFile >> name;
+ if (name[0] == '>') { if(name.substr(1) != seq.getName()) { m->mothurOut("sequence name mismatch btwn fasta: " + seq.getName() + " and qual file: " + name); m->mothurOutEndLine(); } }
+
+ while (!qFile.eof()) { char c = qFile.get(); if (c == 10 || c == 13){ break; } }
+
+ float score;
+ float average = 0;
+
+ for(int i=0;i<seqLength;i++){
+ qFile >> score;
+ average += score;
+ }
+ average /= seqLength;
+
+ if(average >= qAverage) { success = 1; }
+ else { success = 0; }
+
+ return success;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "TrimSeqsCommand", "cullQualAverage");
+ exit(1);
+ }