]> git.donarmstrong.com Git - biopieces.git/commitdiff
added solexa_str_mean to read_454
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 20 May 2010 10:02:22 +0000 (10:02 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 20 May 2010 10:02:22 +0000 (10:02 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@964 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/read_454
code_perl/Maasha/Fastq.pm

index b84ab12770a270471f997e4d469c5f59c5c6b731..732e81df50f8850a94c9e5cfe360cad8d66f49fe 100755 (executable)
@@ -48,6 +48,7 @@ $options = Maasha::Biopieces::parse_options(
         { long => 'convert2dec', short => 'c', type => 'flag',   mandatory => 'no',  default => undef, allowed => undef, disallowed => undef },
         { long => 'cutoff',      short => 'C', type => 'int',    mandatory => 'no',  default => 20,    allowed => undef, disallowed => undef },
         { long => 'soft_mask',   short => 's', type => 'flag',   mandatory => 'no',  default => undef, allowed => undef, disallowed => undef },
+        { long => 'mean',        short => 'm', type => 'flag',   mandatory => 'no',  default => undef, allowed => undef, disallowed => undef },
     ]   
 );
 
@@ -72,10 +73,12 @@ if ( $options->{ 'data_in' } )
         check_names( $fasta, $qual );
 
         $record = {
-            SEQ_NAME => $fasta->[ 0 ],
-            SEQ      => $fasta->[ 1 ],
-            SCORES   => $qual->[ 1 ],
+            SEQ_NAME    => $fasta->[ 0 ],
+            SEQ         => $fasta->[ 1 ],
+            SCORES      => $qual->[ 1 ],
         };
+
+        $record->{ 'SCORES_MEAN' } = sprintf "%.2f", Maasha::Fastq::solexa_str_mean( $qual->[ 1 ] ) if $options->{ 'mean' };
         
         Maasha::Fastq::softmask_solexa_str( $record->{ 'SEQ' }, $record->{ 'SCORES' }, $options->{ 'cutoff' } ) if $options->{ 'soft_mask' };
         $record->{ 'SCORES' } = Maasha::Fastq::solexa_str2dec_str( $record->{ 'SCORES' } ) if $options->{ 'convert2dec' };
index f65cee20de186c65bbd8bff96de018f8954b969d..ced2f0c6ca0035e9411863a0eb7626d69f6403cd 100644 (file)
@@ -238,6 +238,29 @@ double phred_str_mean( char *scores )
 }
 
 
+double solexa_str_mean( char *scores )
+{
+    /* Martin A. Hansen, November 2009 */
+
+    /* Calculates the mean score as a float which is retuned. */
+
+    int    len  = 0;
+    int    i    = 0;
+    int    sum  = 0;
+    double mean = 0.0;
+
+    len = strlen( scores );
+
+    for ( i = 0; i < len; i++ ) {
+        sum += solexa2dec( scores[ i ] );
+    }
+
+    mean = ( double ) sum / ( double ) len;
+
+    return mean;
+}
+
+
 void softmask_solexa_str( char *seq, char *scores, int threshold )
 {
     /* Martin A. Hansen, July 2009 */