X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=code_perl%2FMaasha%2FFastq.pm;h=d70bf3e6cbbf2675e47feec6523976ae92c7bc9e;hb=0253e2b8737fba111f4ec7406704dacaa4877d8d;hp=5015ef36a2c6388e6984bf2fc62a3d5fdea48bf3;hpb=d2b48a034defcacac6e9134894560818b2790426;p=biopieces.git diff --git a/code_perl/Maasha/Fastq.pm b/code_perl/Maasha/Fastq.pm index 5015ef3..d70bf3e 100644 --- a/code_perl/Maasha/Fastq.pm +++ b/code_perl/Maasha/Fastq.pm @@ -243,7 +243,7 @@ double solexa_str_mean( char *scores ) } -double solexa_str_mean_window( char *scores, int window_size, double min ) +void solexa_str_mean_window( char *scores, int window_size, double min ) { /* Martin A. Hansen, June 2010. */ @@ -253,9 +253,11 @@ double solexa_str_mean_window( char *scores, int window_size, double min ) /* is lower than a given minimum otherwise the smallest mean */ /* score is returned. */ - int i = 0; - double sum = 0; - double mean = 0.0; + int found = 0; + int i = 0; + int pos = -1; + double sum = 0; + double mean = 0.0; if ( window_size > strlen( scores ) ) { @@ -271,13 +273,14 @@ double solexa_str_mean_window( char *scores, int window_size, double min ) mean = sum / window_size; - if ( mean < min ) { - return mean; + if ( mean <= min ) { + found = 1; + pos = 0; } /* --- scan the rest of the scores ---- */ - while ( i < strlen( scores ) ) + while ( ! found && i < strlen( scores ) ) { sum += solexa2dec( scores[ i ] ); sum -= solexa2dec( scores[ i - window_size ] ); @@ -286,14 +289,21 @@ double solexa_str_mean_window( char *scores, int window_size, double min ) // printf( "char->%c score->%d sum->%f mean->%f\n", scores[i], solexa2dec(scores[i]),sum, mean); - if ( mean < min ) { - return mean; - } - i++; + + if ( mean <= min ) { + found = 1; + pos = i - window_size; + } } - return mean; + Inline_Stack_Vars; + Inline_Stack_Reset; + + Inline_Stack_Push( sv_2mortal( newSViv( mean ) ) ); + Inline_Stack_Push( sv_2mortal( newSViv( pos ) ) ); + + Inline_Stack_Done; } @@ -427,11 +437,29 @@ sub dec_str2solexa_str # Returns a string. + $scores =~ s/(-\d{1,2})/0/g; $scores =~ s/(\d{1,2});?/dec2solexa( $1 )/eg; return $scores; } +sub dec_str2phred_str +{ + # Martin A. Hansen, November 2013. + + # Converts a ; separated string of decimal scores to a + # string of Phred scores. + + my ( $scores, # Decimal score string + ) = @_; + + # Returns a string. + + $scores =~ s/(-\d{1,2})/0/g; + $scores =~ s/(\d{1,2});?/dec2phred( $1 )/eg; + + return $scores; +} sub get_entry {