]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_perl/Maasha/Biopieces.pm
fixed rename bug
[biopieces.git] / code_perl / Maasha / Biopieces.pm
index ab7add7e4adb71c953f954918a0c2b9f72345e20..6c38e430698324319052305b5c1c3afcf5fd84dc 100644 (file)
@@ -110,14 +110,8 @@ close $log_local;
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> RUN SCRIPT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
-my $t0 = gettimeofday();
-
 run_script( $script );
 
-my $t1 = gettimeofday();
-
-print STDERR "Program: $script" . ( " " x ( 25 - length( $script ) ) ) . sprintf( "Run time: %.4f\n", ( $t1 - $t0 ) );
-
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
@@ -158,7 +152,9 @@ sub run_script
 
     # Returns nothing.
 
-    my ( $options, $in, $out );
+    my ( $t0, $t1, $options, $in, $out );
+
+    $t0 = gettimeofday();
 
     $options = get_options( $script );
 
@@ -267,6 +263,10 @@ sub run_script
 
     close $in if defined $in;
     close $out;
+
+    $t1 = gettimeofday();
+
+    print STDERR "Program: $script" . ( " " x ( 25 - length( $script ) ) ) . sprintf( "Run time: %.4f\n", ( $t1 - $t0 ) ) if $options->{ 'verbose' };
 }
 
 
@@ -747,7 +747,7 @@ sub get_options
         @options = qw(
             adaptor|a=s
             mismatches|m=s
-            no_remove|n
+            remove|r=s
             offset|o=s
         );
     }
@@ -1048,6 +1048,10 @@ sub get_options
         {
             Maasha::Common::error( qq(Argument to --$opt must be octal or decimal - not "$options{ $opt }") );
         }
+        elsif ( $opt eq "remove" and $script eq "remove_adaptor" and $options{ $opt } !~ /before|after|skip/ )
+        {
+            Maasha::Common::error( qq(Argument to --$opt must be before, after, or skip - not "$options{ $opt }") );
+        }
     }
 
     Maasha::Common::error( qq(no --database specified) )                if $script eq "create_blast_db"     and not $options{ "database" };
@@ -1422,7 +1426,7 @@ sub script_read_fixedstep
 {
     # Martin A. Hansen, Juli 2008.
 
-    # Read fixedStep wiggle format from stream or file.
+    # Read fixedstep wiggle format from stream or file.
 
     my ( $in,        # handle to in stream
          $out,       # handle to out stream
@@ -3101,7 +3105,7 @@ sub script_get_genome_phastcons
     $phastcons_file  = Maasha::Config::genome_phastcons( $options->{ "genome" } );
     $phastcons_index = Maasha::Config::genome_phastcons_index( $options->{ "genome" } );
 
-    $index           = Maasha::UCSC::phastcons_index_retrieve( $phastcons_index );
+    $index           = Maasha::UCSC::fixedstep_index_retrieve( $phastcons_index );
     $fh_phastcons    = Maasha::Common::read_open( $phastcons_file );
 
     if ( defined $options->{ "chr" } and defined $options->{ "beg" } and ( defined $options->{ "end" } or defined $options->{ "len" } ) )
@@ -3113,7 +3117,7 @@ sub script_get_genome_phastcons
             $options->{ "end" } = $options->{ "beg" } + $options->{ "len" } - 1;
         }
 
-        $scores = Maasha::UCSC::phastcons_index_lookup( $index, $fh_phastcons, $options->{ "chr" }, $options->{ "beg" }, $options->{ "end" }, $options->{ "flank" } );
+        $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $options->{ "chr" }, $options->{ "beg" }, $options->{ "end" }, $options->{ "flank" } );
 
         $record->{ "CHR" }       = $options->{ "chr" };
         $record->{ "CHR_BEG" }   = $options->{ "beg" } - $options->{ "flank" };
@@ -4696,6 +4700,8 @@ sub script_remove_adaptor
 
     my ( $record, $adaptor, $seq, $adaptor_len, $seq_len, $offset, $max_match, $max_mismatch, $pos );
 
+    $options->{ "remove" } ||= "after";
+
     $max_mismatch = $options->{ "mismatches" } || 0;
     $offset       = $options->{ "offset" };
 
@@ -4719,10 +4725,18 @@ sub script_remove_adaptor
 
             $record->{ "ADAPTOR_POS" } = $pos;
 
-            if ( $pos >= 0 and not $options->{ "no_remove" } )
+            if ( $pos >= 0 and $options->{ "remove" } ne "skip" )
             {
-                $record->{ "SEQ" }     = substr $record->{ "SEQ" }, 0, $pos;
-                $record->{ "SEQ_LEN" } = $pos;
+                if ( $options->{ "remove" } eq "after" )
+                {
+                    $record->{ "SEQ" }     = substr $record->{ "SEQ" }, 0, $pos;
+                    $record->{ "SEQ_LEN" } = $pos;
+                }
+                else
+                {
+                    $record->{ "SEQ" }     = substr $record->{ "SEQ" }, $pos + $adaptor_len;
+                    $record->{ "SEQ_LEN" } = length $record->{ "SEQ" };
+                }
             }
 
             put_record( $record, $out );
@@ -5583,7 +5597,7 @@ sub script_plot_histogram
 
     while ( $record = get_record( $in ) ) 
     {
-        $data_hash{ $record->{ $options->{ "key" } } }++ if $record->{ $options->{ "key" } };
+        $data_hash{ $record->{ $options->{ "key" } } }++ if defined $record->{ $options->{ "key" } };
 
         put_record( $record, $out ) if not $options->{ "no_stream" };
     }
@@ -5623,7 +5637,7 @@ sub script_plot_lendist
 
     while ( $record = get_record( $in ) ) 
     {
-        $data_hash{ $record->{ $options->{ "key" } } }++ if $record->{ $options->{ "key" } };
+        $data_hash{ $record->{ $options->{ "key" } } }++ if defined $record->{ $options->{ "key" } };
 
         put_record( $record, $out ) if not $options->{ "no_stream" };
     }
@@ -6438,7 +6452,7 @@ sub clean_tmp
 {
     # Martin A. Hansen, July 2008.
 
-    # Cleans out any unused temporary files and direcotries in BP_TMP.
+    # Cleans out any unused temporary files and directories in BP_TMP.
 
     # Returns nothing.
 
@@ -6468,7 +6482,7 @@ sub clean_tmp
                 elsif ( $pid == $curr_pid )
                 {
                     # print STDERR "Removing current dir: $dir\n";
-                    Maasha::Common::dir_remove( $dir );
+                    Maasha::Common::dir_remove( $dir );
                 }
             }
         }