]> git.donarmstrong.com Git - biopieces.git/blobdiff - bp_bin/analyze_seq
refactoring of assemble_pairs
[biopieces.git] / bp_bin / analyze_seq
index 6f76a9496e6041bf03189aa0ed56eb207c169104..2c38a274beeb593394ec5d33663d4dec1129de23 100755 (executable)
@@ -1,6 +1,6 @@
-#!/usr/bin/env perl -w
+#!/usr/bin/env ruby
 
-# Copyright (C) 2007-2009 Martin A. Hansen.
+# Copyright (C) 2007-2010 Martin A. Hansen.
 
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
 
 # http://www.gnu.org/copyleft/gpl.html
 
-
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-
-# Analyze BED entries in the stream.
-
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
+# This program is part of the Biopieces framework (www.biopieces.org).
 
-use strict;
-use Maasha::Biopieces;
-use Maasha::Seq;
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
+# Analyze sequences in the stream.
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
-my ( $options, $in, $out, $record, $analysis );
-
-$options = Maasha::Biopieces::parse_options();
-
-$in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
-$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
+require 'maasha/biopieces'
+require 'maasha/seq'
 
-while ( $record = Maasha::Biopieces::get_record( $in ) ) 
-{
-    if ( $record->{ "SEQ" } )
-    {
-        $analysis = Maasha::Seq::seq_analyze( $record->{ "SEQ" } );
+casts = []
 
-        map { $record->{ $_ } = $analysis->{ $_ } } keys %{ $analysis };
-    }
+options = Biopieces.options_parse(ARGV, casts)
 
-    Maasha::Biopieces::put_record( $record, $out );
-}
+Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
+  input.each_record do |record|
+    if record[:SEQ]
+      seq  = Seq.new_bp(record)
+      comp = seq.composition
 
+      comp.each_pair do |key,val|
+        record["RES[#{key}]"] = val
+      end
 
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-
-BEGIN
-{
-    $run_time_beg = Maasha::Biopieces::run_time();
-
-    Maasha::Biopieces::log_biopiece();
-}
+      record["SOFT_MASK%"] = seq.soft_mask
+      record["HARD_MASK%"] = (comp["N"].to_f / (seq.len - seq.indels).to_f * 100.0).round(2)
+      record["GC%"]        = ((comp["G"] + comp["C"]).to_f / (seq.len - seq.indels).to_f * 100.0).round(2)
+    end
 
-
-END
-{
-    Maasha::Biopieces::close_stream( $in );
-    Maasha::Biopieces::close_stream( $out );
-
-    $run_time_end = Maasha::Biopieces::run_time();
-
-    Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options );
-}
+    output.puts record
+  end
+end
 
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
 __END__
-