-
-my ( $options, $in, $out, $record, $mean, $pos );
-
-$options = Maasha::Biopieces::parse_options(
- [
- { long => 'local', short => 'l', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
- { long => 'window_size', short => 'w', type => 'uint', mandatory => 'no', default => 5, allowed => undef, disallowed => 0 },
- { long => 'min', short => 'm', type => 'float', mandatory => 'no', default => 15, allowed => undef, disallowed => undef },
- ]
-);
-
-$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
-$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
-
-while ( $record = Maasha::Biopieces::get_record( $in ) )
-{
- if ( $record->{ 'SCORES' } )
- {
- if ( $options->{ "local" } )
+require 'maasha/biopieces'
+require 'maasha/seq'
+require 'inline'
+
+# Opening class Seq to add scores_mean_local(_C) methods.
+class Seq
+ # Method to run a sliding window of a specified size across a Phred type
+ # scores string and calculate for each window the mean score and return
+ # the minimum mean score.
+ def scores_mean_local(window_size)
+ scores_mean_local_C(self.qual, self.length, Seq::SCORE_BASE, window_size)
+ end
+
+ inline do |builder|
+ builder.c %{
+ VALUE scores_mean_local_C(
+ VALUE _qual,
+ VALUE _qual_len,
+ VALUE _score_base,
+ VALUE _window_size
+ )
+ {
+ unsigned char *qual = (unsigned char *) StringValuePtr(_qual);
+ unsigned int qual_len = FIX2UINT(_qual_len);
+ unsigned int score_base = FIX2UINT(_score_base);
+ unsigned int window_size = FIX2UINT(_window_size);
+ unsigned int sum = 0;
+ unsigned int i = 0;
+ float mean = 0.0;
+
+ // fill window
+ for (i = 0; i < window_size; i++)
+ sum += qual[i] - score_base;
+
+ mean = sum / window_size;
+
+ // run window across the rest of the scores
+ while (i < qual_len)