]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_perl/Maasha/Fastq.pm
fixed encoding bug in read_454
[biopieces.git] / code_perl / Maasha / Fastq.pm
index 974c9c99abfc5c0c4e5dc9d08a259d5bcb0c0291..d70bf3e6cbbf2675e47feec6523976ae92c7bc9e 100644 (file)
@@ -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;
 }
 
 
@@ -433,6 +443,23 @@ sub dec_str2solexa_str
     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
 {