]> git.donarmstrong.com Git - biopieces.git/blobdiff - bp_bin/assemble_contigs
removed debug message
[biopieces.git] / bp_bin / assemble_contigs
index 3e73a763b82cf101873fcc83b5b09d4f75517cba..e19fdc13e96d7c607e3fe828bbcb4ad87c551f90 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env perl
 
-# 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
@@ -38,10 +38,12 @@ use Maasha::UCSC::Wiggle;
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
-my ( $options, $in, $out, $record, $contig_hash, $i, $s_id, $strand, $new_record, $contig, $beg, $end, @array, $min, $max, $mean );
+my ( $options, $in, $out, $record, $contig_hash, $i, $s_id, $q_id, $strand, $new_record, $contig, $beg, $end, @array, $min, $max, $mean );
 
 $options = Maasha::Biopieces::parse_options(
     [
+        { long => 'q_id',   short => 'q', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
+        { long => 'strand', short => 's', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
         { long => 'bridge', short => 'b', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
     ]   
 );
@@ -53,33 +55,44 @@ while ( $record = Maasha::Biopieces::get_record( $in ) )
 {
     if ( $record->{ 'S_ID' } and $record->{ 'STRAND' } )
     {
-        if ( $record->{ 'Q_ID' } and $record->{ 'S_BEG' } and $record->{ 'S_END' } )
+        if ( $options->{ 'q_id' } ) {
+            next if not $record->{ 'Q_ID' };
+        } else {
+            $record->{ 'Q_ID' } = 'X';
+        }
+
+        if ( $options->{ 'strand' } ) {
+            next if not $record->{ 'STRAND' };
+        } else {
+            $record->{ 'STRAND' } = 'X';
+        }
+
+        if ( defined $record->{ 'S_BEG' } and defined $record->{ 'S_END' } )
         {
             for ( $i = $record->{ 'S_BEG' }; $i <= $record->{ 'S_END' }; $i++ ) {
-                $contig_hash->{ $record->{ 'S_ID' } }->{ $record->{ 'STRAND' } }->[ $i ]++;
+                $contig_hash->{ $record->{ 'S_ID' } }->{ $record->{ 'Q_ID' } }->{ $record->{ 'STRAND' } }->[ $i ]++;
             }
         }
 
-        if ( $record->{ 'Q_ID1' } and $record->{ 'S_BEG1' } and $record->{ 'S_END1' } and 
-             $record->{ 'Q_ID2' } and $record->{ 'S_BEG2' } and $record->{ 'S_END2' }
-        )
+        if ( defined $record->{ 'S_BEG1' } and defined $record->{ 'S_END1' } and
+             defined $record->{ 'S_BEG2' } and defined $record->{ 'S_END2' } )
         {
             if ( $options->{ 'bridge' } )
             {
                 ( $record->{ 'S_BEG1' }, $record->{ 'S_END2' } ) = ( $record->{ 'S_BEG2' }, $record->{ 'S_END1' } ) if ( $record->{ 'S_BEG1' } > $record->{ 'S_END2' } );
 
                 for ( $i = $record->{ 'S_BEG1' }; $i <= $record->{ 'S_END2' }; $i++ ) {
-                    $contig_hash->{ $record->{ 'S_ID' } }->{ $record->{ 'STRAND' } }->[ $i ]++;
+                    $contig_hash->{ $record->{ 'S_ID' } }->{ $record->{ 'Q_ID' } }->{ $record->{ 'STRAND' } }->[ $i ]++;
                 }
             }
             else
             {
                 for ( $i = $record->{ 'S_BEG1' }; $i <= $record->{ 'S_END1' }; $i++ ) {
-                    $contig_hash->{ $record->{ 'S_ID' } }->{ $record->{ 'STRAND' } }->[ $i ]++;
+                    $contig_hash->{ $record->{ 'S_ID' } }->{ $record->{ 'Q_ID' } }->{ $record->{ 'STRAND' } }->[ $i ]++;
                 }
 
                 for ( $i = $record->{ 'S_BEG2' }; $i <= $record->{ 'S_END2' }; $i++ ) {
-                    $contig_hash->{ $record->{ 'S_ID' } }->{ $record->{ 'STRAND' } }->[ $i ]++;
+                    $contig_hash->{ $record->{ 'S_ID' } }->{ $record->{ 'Q_ID' } }->{ $record->{ 'STRAND' } }->[ $i ]++;
                 }
             }
         }
@@ -92,33 +105,37 @@ $contig = 0;
 
 foreach $s_id ( keys %{ $contig_hash } )
 {
-    foreach $strand ( keys %{ $contig_hash->{ $s_id } } )
+    foreach $q_id ( keys %{ $contig_hash->{ $s_id } } )
     {
-        $beg = 0;
-        $end = 0;
-
-        while ( ( $beg, $end ) = Maasha::UCSC::Wiggle::fixedstep_scan( $contig_hash->{ $s_id }->{ $strand }, $beg ) )
+        foreach $strand ( keys %{ $contig_hash->{ $s_id }->{ $q_id } } )
         {
-            @array = @{ $contig_hash->{ $s_id }->{ $strand } }[ $beg .. $end - 1 ];
-
-            ( $min, $max ) = Maasha::Calc::minmax( \@array );
-            $mean          = Maasha::Calc::mean( \@array );
-
-            $new_record->{ 'S_ID' }        = $s_id;
-            $new_record->{ 'STRAND' }      = $strand;
-            $new_record->{ 'CONTIG_ID' }   = $contig;
-            $new_record->{ 'CONTIG_BEG' }  = $beg;
-            $new_record->{ 'CONTIG_END' }  = $end;
-            $new_record->{ 'CONTIG_LEN' }  = $end - $beg + 1;
-            $new_record->{ 'CONTIG_MIN' }  = $min;
-            $new_record->{ 'CONTIG_MAX' }  = $max;
-            $new_record->{ 'CONTIG_MEAN' } = sprintf "%.2f", $mean;
-            $new_record->{ 'CONTIG' }      = join ( ";", @array );
-
-            $beg = $end + 1;
-            $contig++;
-
-            Maasha::Biopieces::put_record( $new_record, $out );
+            $beg = 0;
+            $end = 0;
+
+            while ( ( $beg, $end ) = Maasha::UCSC::Wiggle::fixedstep_scan( $contig_hash->{ $s_id }->{ $q_id }->{ $strand }, $beg ) )
+            {
+                @array = @{ $contig_hash->{ $s_id }->{ $q_id }->{ $strand } }[ $beg .. $end - 1 ];
+
+                ( $min, $max ) = Maasha::Calc::minmax( \@array );
+                $mean          = Maasha::Calc::mean( \@array );
+
+                $new_record->{ 'S_ID' }        = $s_id;
+                $new_record->{ 'Q_ID' }        = $q_id   if $options->{ 'q_id' };
+                $new_record->{ 'STRAND' }      = $strand if $options->{ 'strand' };
+                $new_record->{ 'S_BEG' }       = $beg;
+                $new_record->{ 'S_END' }       = $end;
+                $new_record->{ 'CONTIG_ID' }   = $contig;
+                $new_record->{ 'CONTIG_LEN' }  = $end - $beg + 1;
+                $new_record->{ 'CONTIG_MIN' }  = $min;
+                $new_record->{ 'CONTIG_MAX' }  = $max;
+                $new_record->{ 'CONTIG_MEAN' } = sprintf "%.2f", $mean;
+                $new_record->{ 'CONTIG' }      = join ( ";", @array );
+
+                $beg = $end + 1;
+                $contig++;
+
+                Maasha::Biopieces::put_record( $new_record, $out );
+            }
         }
     }
 }