Skip to content

Commit 8bec856

Browse files
committed
fixed bug where disabling 5-prime trimming discarded all reads
1 parent a9acb65 commit 8bec856

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/sickle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ typedef struct __cutsites_ {
9696
/* Function Prototypes */
9797
int single_main (int argc, char *argv[]);
9898
int paired_main (int argc, char *argv[]);
99-
cutsites* sliding_window (kseq_t *fqrec, int qualtype, int length_threshold, int qual_threshold, int no_fiveprime, int discard_n);
99+
cutsites* sliding_window (kseq_t *fqrec, int qualtype, int length_threshold, int qual_threshold, int no_fiveprime, int trunc_n, int debug);
100100

101101
#endif /*SICKLE_H*/

src/sliding.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int get_quality_num (char qualchar, int qualtype, kseq_t *fqrec, int pos) {
3232
}
3333

3434

35-
cutsites* sliding_window (kseq_t *fqrec, int qualtype, int length_threshold, int qual_threshold, int no_fiveprime, int trunc_n) {
35+
cutsites* sliding_window (kseq_t *fqrec, int qualtype, int length_threshold, int qual_threshold, int no_fiveprime, int trunc_n, int debug) {
3636

3737
int window_size = (int) (0.1 * fqrec->seq.l);
3838
int i,j;
@@ -65,10 +65,14 @@ cutsites* sliding_window (kseq_t *fqrec, int qualtype, int length_threshold, int
6565

6666
window_avg = (double)window_total / (double)window_size;
6767

68+
if (debug) printf ("no_fiveprime: %d, found 5prime: %d, window_avg: %f\n", no_fiveprime, found_five_prime, window_avg);
69+
6870
/* Finding the 5' cutoff */
6971
/* Find when the average quality in the window goes above the threshold starting from the 5' end */
7072
if (no_fiveprime == 0 && found_five_prime == 0 && window_avg >= qual_threshold) {
7173

74+
if (debug) printf ("inside 5-prime cut\n");
75+
7276
/* at what point in the window does the quality go above the threshold? */
7377
for (j=window_start; j<window_start+window_size; j++) {
7478
if (get_quality_num (fqrec->qual.s[j], qualtype, fqrec, j) >= qual_threshold) {
@@ -77,14 +81,16 @@ cutsites* sliding_window (kseq_t *fqrec, int qualtype, int length_threshold, int
7781
}
7882
}
7983

84+
if (debug) printf ("five_prime_cut: %d\n", five_prime_cut);
85+
8086
found_five_prime = 1;
8187
}
8288

8389
/* Finding the 3' cutoff */
8490
/* if the average quality in the window is less than the threshold */
8591
/* or if the window is the last window in the read */
8692
if ((window_avg < qual_threshold ||
87-
window_start+window_size > fqrec->qual.l) && found_five_prime == 1) {
93+
window_start+window_size > fqrec->qual.l) && (found_five_prime == 1 || no_fiveprime)) {
8894

8995
/* at what point in the window does the quality dip below the threshold? */
9096
for (j=window_start; j<window_start+window_size; j++) {
@@ -115,11 +121,14 @@ cutsites* sliding_window (kseq_t *fqrec, int qualtype, int length_threshold, int
115121
/* if cutting length is less than threshold then return -1 for both */
116122
/* to indicate that the read should be discarded */
117123
/* Also, if you never find a five prime cut site, then discard whole read */
118-
if ((found_five_prime == 0) || (three_prime_cut - five_prime_cut < length_threshold)) {
124+
if ((found_five_prime == 0 && !no_fiveprime) || (three_prime_cut - five_prime_cut < length_threshold)) {
119125
three_prime_cut = -1;
120126
five_prime_cut = -1;
127+
128+
if (debug) printf("%s\n", fqrec->name.s);
121129
}
122130

131+
if (debug) printf ("\n\n");
123132

124133
retvals = (cutsites*) malloc (sizeof(cutsites));
125134
retvals->three_prime_cut = three_prime_cut;

src/trim_paired.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ int paired_main(int argc, char *argv[]) {
373373
break;
374374
}
375375

376-
p1cut = sliding_window(fqrec1, qualtype, paired_length_threshold, paired_qual_threshold, no_fiveprime, trunc_n);
377-
p2cut = sliding_window(fqrec2, qualtype, paired_length_threshold, paired_qual_threshold, no_fiveprime, trunc_n);
376+
p1cut = sliding_window(fqrec1, qualtype, paired_length_threshold, paired_qual_threshold, no_fiveprime, trunc_n, debug);
377+
p2cut = sliding_window(fqrec2, qualtype, paired_length_threshold, paired_qual_threshold, no_fiveprime, trunc_n, debug);
378378

379379
if (debug) printf("p1cut: %d,%d\n", p1cut->five_prime_cut, p1cut->three_prime_cut);
380380
if (debug) printf("p2cut: %d,%d\n", p2cut->five_prime_cut, p2cut->three_prime_cut);

src/trim_single.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ int single_main(int argc, char *argv[]) {
191191

192192
while ((l = kseq_read(fqrec)) >= 0) {
193193

194-
p1cut = sliding_window(fqrec, qualtype, single_length_threshold, single_qual_threshold, no_fiveprime, trunc_n);
194+
p1cut = sliding_window(fqrec, qualtype, single_length_threshold, single_qual_threshold, no_fiveprime, trunc_n, debug);
195195

196196
if (debug) printf("P1cut: %d,%d\n", p1cut->five_prime_cut, p1cut->three_prime_cut);
197197

0 commit comments

Comments
 (0)