]> git.donarmstrong.com Git - biopieces.git/blobdiff - bp_bin/align_pair_seq
refactoring of assemble_pairs
[biopieces.git] / bp_bin / align_pair_seq
index bfa326bbd8eae9a16bfb38d23e015d949a3a0b44..2b1a710af5951dae853dddbb4b074e8d448cec93 100755 (executable)
@@ -1,6 +1,6 @@
-#!/usr/bin/env perl
+#!/usr/bin/env ruby
 
-# Copyright (C) 2007-2009 Martin A. Hansen.
+# Copyright (C) 2007-2012 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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-# Align sequences in the stream.
-
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
+# This program is part of the Biopieces framework (www.biopieces.org).
 
-use strict;
-use Maasha::Biopieces;
-use Maasha::AlignTwoSeq;
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
+# Find similar sequences between query sequences from the stream and a database.
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
+require 'pp'
+require 'maasha/biopieces'
+require 'maasha/align'
 
-my ( $options, $in, $out, $count, $record, @records );
+options = Biopieces.options_parse(ARGV)
 
-$options = Maasha::Biopieces::parse_options();
+Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
+  entries = []
 
-$in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
-$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
+  input.each_record do |record|
+    if record[:SEQ_NAME] and record[:SEQ]
+      entries << Seq.new_bp(record)
 
-$count = 0;
+      if entries.size == 2
+        Align.pair(entries[0], entries[1])
 
-while ( $record = Maasha::Biopieces::get_record( $in ) ) 
-{
-    if ( defined $record->{ "SEQ" } and $count < 2 )
-    {
-        push @records, $record;
+        entries.each do |entry|
+          output.puts entry.to_bp
+        end
 
-        $count++;
-
-        if ( $count == 2 )
-        {
-            $records[ 0 ]->{ 'SEQ' } = lc $records[ 0 ]->{ 'SEQ' };
-            $records[ 1 ]->{ 'SEQ' } = lc $records[ 1 ]->{ 'SEQ' };
-
-            my $matches = Maasha::AlignTwoSeq::align_two_seq( \$records[ 0 ]->{ 'SEQ' } ,\$records[ 1 ]->{ 'SEQ' } );
-            
-            Maasha::AlignTwoSeq::insert_indels( $matches, \$records[ 0 ]->{ 'SEQ' } ,\$records[ 1 ]->{ 'SEQ' } );
-
-            map { Maasha::Biopieces::put_record( $_, $out ) } @records;
-        }
-    }
+        entries = []
+      end
     else
-    {
-        Maasha::Biopieces::put_record( $record, $out );
-    }
-}
-
-Maasha::Biopieces::close_stream( $in );
-Maasha::Biopieces::close_stream( $out );
-
-
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-
-BEGIN
-{
-    Maasha::Biopieces::status_set();
-}
-
-
-END
-{
-    Maasha::Biopieces::status_log();
-}
-
+      output.puts record
+    end
+  end
+end
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<