From: martinahansen Date: Thu, 20 May 2010 10:02:22 +0000 (+0000) Subject: added solexa_str_mean to read_454 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=73be94279d528c4c0a4eaee160ba9908a2e86e9c;p=biopieces.git added solexa_str_mean to read_454 git-svn-id: http://biopieces.googlecode.com/svn/trunk@964 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/read_454 b/bp_bin/read_454 index b84ab12..732e81d 100755 --- a/bp_bin/read_454 +++ b/bp_bin/read_454 @@ -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' }; diff --git a/code_perl/Maasha/Fastq.pm b/code_perl/Maasha/Fastq.pm index f65cee2..ced2f0c 100644 --- a/code_perl/Maasha/Fastq.pm +++ b/code_perl/Maasha/Fastq.pm @@ -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 */