@@ -930,24 +930,28 @@ class ReadSelector {
930
930
}
931
931
}
932
932
933
- void trimReadByMarkupLength (const Read &read, ReadTrimType &trim, SequenceLengthType markupLength) {
933
+ bool trimReadByMarkupLength (const Read &read, ReadTrimType &trim, SequenceLengthType markupLength) {
934
+ bool wasTrimmed = false ;
934
935
if ( markupLength == 0 ) {
935
936
trim.trimLength = read.getLength ();
936
937
} else {
937
938
// TODO find longest stretch...
938
939
// trim at first N or X markup
939
940
trim.trimOffset = 0 ;
940
941
trim.trimLength = markupLength - 1 ;
942
+ wasTrimmed = true ;
941
943
}
942
944
trim.score = trim.trimLength ;
945
+ return wasTrimmed;
943
946
}
944
947
945
948
template <typename U>
946
- void trimReadByMinimumKmerScore (double minimumKmerScore, ReadTrimType &trim, U buffBegin, U buffEnd) {
949
+ bool trimReadByMinimumKmerScore (double minimumKmerScore, ReadTrimType &trim, U buffBegin, U buffEnd) {
947
950
948
951
ReadTrimType test, best;
949
952
std::stringstream ss;
950
953
U it = buffBegin;
954
+ int len = buffEnd - buffBegin;
951
955
952
956
while (it != buffEnd) {
953
957
ScoreType score = *(it++);
@@ -1005,6 +1009,8 @@ class ReadSelector {
1005
1009
trim.trimOffset = best.trimOffset ;
1006
1010
trim.trimLength = best.trimLength ;
1007
1011
1012
+ return (int ) trim.trimLength < len;
1013
+
1008
1014
};
1009
1015
void setTrimHeaders (ReadTrimType &trim, bool useKmers, bool wasTrimmed = true ) {
1010
1016
if (trim.trimLength > 0 ) {
@@ -1039,17 +1045,20 @@ class ReadSelector {
1039
1045
}
1040
1046
}
1041
1047
}
1042
- void scoreReadByKmers (const Read &read, SequenceLengthType markupLength, ReadTrimType &trim, double minimumKmerScore, KA &kmers) {
1048
+ bool scoreReadByKmers (const Read &read, SequenceLengthType markupLength, ReadTrimType &trim, double minimumKmerScore, KA &kmers) {
1049
+ bool wasTrimmed = false ;
1043
1050
getKmersForRead (read, kmers);
1044
1051
setKmerValues (kmers, minimumKmerScore);
1045
1052
LOG_DEBUG_OPTIONAL (5 , true , " Trim and Score: " << read.getName ());
1046
1053
1047
- trimReadByKmers (kmers.beginValue (), kmers.endValue (), markupLength, trim, minimumKmerScore);
1054
+ wasTrimmed = trimReadByKmers (kmers.beginValue (), kmers.endValue (), markupLength, trim, minimumKmerScore);
1048
1055
1049
1056
if (trim.trimLength > 0 )
1050
1057
scoreReadByScoringType (kmers.beginValue () + trim.trimOffset , kmers.beginValue () + trim.trimOffset + trim.trimLength , trim, _defaultScoringType);
1051
1058
else
1052
1059
trim.score = -1 ;
1060
+
1061
+ return wasTrimmed;
1053
1062
}
1054
1063
1055
1064
void setKmerValues (KA &kmers, double minimumKmerScore) {
@@ -1067,13 +1076,13 @@ class ReadSelector {
1067
1076
}
1068
1077
1069
1078
template <typename IT>
1070
- void trimReadByKmers (IT begin, IT end, SequenceLengthType markupLength, ReadTrimType &trim, double minimumKmerScore) {
1079
+ bool trimReadByKmers (IT begin, IT end, SequenceLengthType markupLength, ReadTrimType &trim, double minimumKmerScore) {
1071
1080
1072
1081
SequenceLengthType numKmers = end-begin;
1073
1082
1074
1083
_setNumKmers (markupLength, numKmers);
1075
1084
1076
- trimReadByMinimumKmerScore (minimumKmerScore, trim, begin, begin + numKmers);
1085
+ return trimReadByMinimumKmerScore (minimumKmerScore, trim, begin, begin + numKmers);
1077
1086
};
1078
1087
1079
1088
void scoreReadByScoringType (KA &kmers, ReadTrimType &trim, enum KmerScoringType scoringType) {
@@ -1183,19 +1192,19 @@ class ReadSelector {
1183
1192
KA &kmers = _kmers[omp_get_thread_num ()];
1184
1193
ReadTrimType &trim = _trims[i];
1185
1194
const Read &read = _reads.getRead (i);
1186
- SequenceLengthType seqLen = read.getLength ();
1187
1195
if (read.isDiscarded ()) {
1188
1196
continue ;
1189
1197
}
1190
1198
Sequence::BaseLocationVectorType markups = read.getMarkups ();
1191
1199
SequenceLengthType markupLength = TwoBitSequence::firstMarkupNorX (markups);
1192
1200
1201
+ bool wasTrimmed = false ;
1193
1202
if (useKmers) {
1194
- scoreReadByKmers (read, markupLength, trim, minimumKmerScore, kmers);
1203
+ wasTrimmed = scoreReadByKmers (read, markupLength, trim, minimumKmerScore, kmers);
1195
1204
} else { // !useKmers
1196
- trimReadByMarkupLength (read, trim, markupLength);
1205
+ wasTrimmed = trimReadByMarkupLength (read, trim, markupLength);
1197
1206
}
1198
- setTrimHeaders (trim, useKmers, trim. trimLength < seqLen );
1207
+ setTrimHeaders (trim, useKmers, wasTrimmed );
1199
1208
}
1200
1209
}
1201
1210
0 commit comments