-#!/usr/bin/env perl -w
+#!/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
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<