@@ -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 ;
0 commit comments