]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_perl/Maasha/Fastq.pm
added missing files
[biopieces.git] / code_perl / Maasha / Fastq.pm
index 5015ef36a2c6388e6984bf2fc62a3d5fdea48bf3..b48279c24781b3722cbae9976c776eeb25639eec 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;
 }
 
 
@@ -427,6 +437,7 @@ sub dec_str2solexa_str
 
     # Returns a string.
 
+    $scores =~ s/(-\d{1,2})/0/g;
     $scores =~ s/(\d{1,2});?/dec2solexa( $1 )/eg;
 
     return $scores;