X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=qualityscores.cpp;h=4dd5b38d4f7ab3895d7fa305bdb57f2e9ab5a628;hb=d04f948b1a2a1a2984fc4a45d04403b8c121c5bc;hp=4b315b1c397d3a42921b0071253065b26b4befe6;hpb=0fb6d165c8dc8dc7153a101513a05f457431d0bc;p=mothur.git diff --git a/qualityscores.cpp b/qualityscores.cpp index 4b315b1..4dd5b38 100644 --- a/qualityscores.cpp +++ b/qualityscores.cpp @@ -16,6 +16,7 @@ QualityScores::QualityScores(){ m = MothurOut::getInstance(); seqName = ""; seqLength = -1; + } catch(exception& e) { m->errorOut(e, "QualityScores", "QualityScores"); @@ -25,32 +26,75 @@ QualityScores::QualityScores(){ /**************************************************************************************************/ -QualityScores::QualityScores(ifstream& qFile){ +QualityScores::QualityScores(ifstream& qFile, int l){ try { m = MothurOut::getInstance(); seqName = ""; - seqLength = -1; + seqLength = l; int score; - string line; - getline(qFile, line); - istringstream nameStream(line); - - nameStream >> seqName; - seqName = seqName.substr(1); + qFile >> seqName; - getline(qFile, line); - istringstream qualStream(line); + while (!qFile.eof()) { char c = qFile.get(); if (c == 10 || c == 13 || c == -1){ break; } } // get rest of line + m->gobble(qFile); + if (seqName == "") { m->mothurOut("Error reading quality file, name blank at position, " + toString(qFile.tellg())); m->mothurOutEndLine(); } + else { + seqName = seqName.substr(1); + } + + //m->getline(qFile, line); + //istringstream qualStream(line); - while(qualStream){ - qualStream >> score; + //while(qualStream){ + // qualStream >> score; + // qScores.push_back(score); + //} + //qScores.pop_back(); + + //seqLength = qScores.size(); + + /*while(!in.eof()){ + string saveName = ""; + string name = ""; + string scores = ""; + + in >> name; + //cout << name << endl; + if (name.length() != 0) { + saveName = name.substr(1); + while (!in.eof()) { + char c = in.get(); + if (c == 10 || c == 13){ break; } + else { name += c; } + } + m->gobble(in); + } + + while(in){ + char letter= in.get(); + if(letter == '>'){ in.putback(letter); break; } + else{ scores += letter; } + } + + //istringstream iss (scores,istringstream::in); + + //int count = 0; int tempScore; + //while (iss) { iss >> tempScore; count++; } + //cout << saveName << '\t' << count << endl; + + m->gobble(in); + }*/ + + + + for(int i=0;i> score; qScores.push_back(score); } - qScores.pop_back(); - - seqLength = qScores.size(); + m->gobble(qFile); + } catch(exception& e) { m->errorOut(e, "QualityScores", "QualityScores"); @@ -58,7 +102,6 @@ QualityScores::QualityScores(ifstream& qFile){ } } - /**************************************************************************************************/ string QualityScores::getName(){ @@ -104,8 +147,10 @@ void QualityScores::trimQScores(int start, int end){ qScores = hold; } if(start == -1){ - hold = vector(qScores.begin(), qScores.begin()+end); //not sure if indexing is correct - qScores = hold; + if(qScores.size() > end){ + hold = vector(qScores.begin(), qScores.begin()+end); + qScores = hold; + } } seqLength = qScores.size(); @@ -153,9 +198,12 @@ bool QualityScores::stripQualThreshold(Sequence& sequence, double qThreshold){ } } + //every score passed + if (end == (seqLength-1)) { end = seqLength; } + sequence.setUnaligned(rawSequence.substr(0,end)); trimQScores(-1, end); - + return 1; } catch(exception& e) { @@ -193,9 +241,11 @@ bool QualityScores::stripQualRollingAverage(Sequence& sequence, double qThreshol if(end == -1){ end = seqLength; } + sequence.setUnaligned(rawSequence.substr(0,end)); trimQScores(-1, end); + return 1; } catch(exception& e) { @@ -213,14 +263,15 @@ bool QualityScores::stripQualWindowAverage(Sequence& sequence, int stepSize, int int seqLength = sequence.getNumBases(); if(seqName != sequence.getName()){ - m->mothurOut("sequence name mismatch btwn fasta: " + sequence.getName() + " and qual file: " + seqName); - m->mothurOutEndLine(); + m->mothurOut("sequence name mismatch between fasta: " + sequence.getName() + " and qual file: " + seqName); + m->mothurOutEndLine(); } int end = windowSize; int start = 0; - + if(seqLength < windowSize) { return 0; } + while(start < seqLength){ double windowSum = 0.0000; @@ -230,7 +281,7 @@ bool QualityScores::stripQualWindowAverage(Sequence& sequence, int stepSize, int double windowAverage = windowSum / (double)(end-start); if(windowAverage < qThreshold){ - end = start; + end = end - stepSize; break; } start += stepSize; @@ -241,6 +292,7 @@ bool QualityScores::stripQualWindowAverage(Sequence& sequence, int stepSize, int if(end == -1){ end = seqLength; } + sequence.setUnaligned(rawSequence.substr(0,end)); trimQScores(-1, end); @@ -287,7 +339,66 @@ bool QualityScores::cullQualAverage(Sequence& sequence, double qAverage){ return success; } catch(exception& e) { - m->errorOut(e, "TrimSeqsCommand", "cullQualAverage"); + m->errorOut(e, "QualityScores", "cullQualAverage"); + exit(1); + } +} + +/**************************************************************************************************/ + +void QualityScores::updateQScoreErrorMap(map >& qualErrorMap, string errorSeq, int start, int stop, int weight){ + try { + + int seqLength = errorSeq.size(); + int qIndex = start - 1; + for(int i=0;ierrorOut(e, "QualityScores", "updateQScoreErrorMap"); + exit(1); + } +} + +/**************************************************************************************************/ + +void QualityScores::updateForwardMap(vector >& forwardMap, int start, int stop, int weight){ + try { + + int index = 0; + for(int i=start-1;ierrorOut(e, "QualityScores", "updateForwardMap"); + exit(1); + } +} + +/**************************************************************************************************/ + +void QualityScores::updateReverseMap(vector >& reverseMap, int start, int stop, int weight){ + try { + + int index = 0; + for(int i=stop-1;i>=start;i--){ + reverseMap[index++][qScores[i]] += weight; + } + + } + catch(exception& e) { + m->errorOut(e, "QualityScores", "updateForwardMap"); exit(1); } }