From: martinahansen Date: Thu, 28 May 2009 10:34:23 +0000 (+0000) Subject: migrated 4 more X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=046378391dd12b1004e2f458ea1e171f6552905c;p=biopieces.git migrated 4 more git-svn-id: http://biopieces.googlecode.com/svn/trunk@442 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/remove_indels b/bp_bin/remove_indels index fdf5bd2..f1677c5 100755 --- a/bp_bin/remove_indels +++ b/bp_bin/remove_indels @@ -1,6 +1,77 @@ -#!/usr/bin/env perl +#!/usr/bin/env perl -w + +# Copyright (C) 2007-2009 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 +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# http://www.gnu.org/copyleft/gpl.html + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Remove indels from sequences in the stream. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use warnings; use strict; +use Maasha::Biopieces; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $run_time_beg, $run_time_end, $options, $in, $out, $record ); + +$options = Maasha::Biopieces::parse_options(); + +$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); +$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); + +while ( $record = Maasha::Biopieces::get_record( $in ) ) +{ + $record->{ 'SEQ' } =~ tr/-~.//d if $record->{ "SEQ" }; + + Maasha::Biopieces::put_record( $record, $out ); +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +BEGIN +{ + $run_time_beg = Maasha::Biopieces::run_time(); + + Maasha::Biopieces::log_biopiece(); +} + + +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 ); +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +__END__ -use Maasha::BioRun; diff --git a/bp_bin/remove_keys b/bp_bin/remove_keys index fdf5bd2..5324bf5 100755 --- a/bp_bin/remove_keys +++ b/bp_bin/remove_keys @@ -1,6 +1,91 @@ -#!/usr/bin/env perl +#!/usr/bin/env perl -w + +# Copyright (C) 2007-2009 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 +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# http://www.gnu.org/copyleft/gpl.html + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Removes specified keys from records in stream. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use warnings; use strict; +use Maasha::Biopieces; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $new_record ); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'keys', short => 'k', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'save_keys', short => 'K', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + ] +); + +$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); +$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); + +while ( $record = Maasha::Biopieces::get_record( $in ) ) +{ + if ( $options->{ "keys" } ) + { + map { delete $record->{ $_ } } @{ $options->{ "keys" } }; + } + elsif ( $options->{ "save_keys" } ) + { + map { $new_record->{ $_ } = $record->{ $_ } if exists $record->{ $_ } } @{ $options->{ "save_keys" } }; + + $record = $new_record; + } + + Maasha::Biopieces::put_record( $record, $out ) if keys %{ $record }; +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +BEGIN +{ + $run_time_beg = Maasha::Biopieces::run_time(); + + Maasha::Biopieces::log_biopiece(); +} + + +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 ); +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +__END__ -use Maasha::BioRun; diff --git a/bp_bin/rename_keys b/bp_bin/rename_keys index fdf5bd2..5a8b221 100755 --- a/bp_bin/rename_keys +++ b/bp_bin/rename_keys @@ -1,6 +1,86 @@ -#!/usr/bin/env perl +#!/usr/bin/env perl -w + +# Copyright (C) 2007-2009 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 +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# http://www.gnu.org/copyleft/gpl.html + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Rename keys of records in stream. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use warnings; use strict; +use Maasha::Biopieces; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $run_time_beg, $run_time_end, $options, $in, $out, $record ); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'keys', short => 'k', type => 'list', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + ] +); + +$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); +$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); + +while ( $record = Maasha::Biopieces::get_record( $in ) ) +{ + if ( exists $record->{ $options->{ "keys" }->[ 0 ] } ) + { + $record->{ $options->{ "keys" }->[ 1 ] } = $record->{ $options->{ "keys" }->[ 0 ] }; + + delete $record->{ $options->{ "keys" }->[ 0 ] }; + } + + Maasha::Biopieces::put_record( $record, $out ); +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +BEGIN +{ + $run_time_beg = Maasha::Biopieces::run_time(); + + Maasha::Biopieces::log_biopiece(); +} + + +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 ); +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +__END__ -use Maasha::BioRun; diff --git a/bp_bin/uniq_vals b/bp_bin/uniq_vals index fdf5bd2..c27461d 100755 --- a/bp_bin/uniq_vals +++ b/bp_bin/uniq_vals @@ -1,6 +1,100 @@ -#!/usr/bin/env perl +#!/usr/bin/env perl -w + +# Copyright (C) 2007-2009 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 +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# http://www.gnu.org/copyleft/gpl.html + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Select unique or non-unique records from the stream based on the value of a given key. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use warnings; use strict; +use Maasha::Biopieces; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $run_time_beg, $run_time_end, $options, $in, $out, %hash, $record ); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'key', short => 'k', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'invert', short => 'i', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + ] +); + +$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); +$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); + +while ( $record = Maasha::Biopieces::get_record( $in ) ) +{ + if ( $record->{ $options->{ "key" } } ) + { + if ( not $hash{ $record->{ $options->{ "key" } } } and not $options->{ "invert" } ) + { + Maasha::Biopieces::put_record( $record, $out ); + + $hash{ $record->{ $options->{ "key" } } } = 1; + } + elsif ( $hash{ $record->{ $options->{ "key" } } } and $options->{ "invert" } ) + { + Maasha::Biopieces::put_record( $record, $out ); + } + else + { + $hash{ $record->{ $options->{ "key" } } } = 1; + } + } + else + { + Maasha::Biopieces::put_record( $record, $out ); + } +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +BEGIN +{ + $run_time_beg = Maasha::Biopieces::run_time(); + + Maasha::Biopieces::log_biopiece(); +} + + +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 ); +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +__END__ -use Maasha::BioRun; diff --git a/code_perl/Maasha/BioRun.pm b/code_perl/Maasha/BioRun.pm index e8a5d5a..6a39e40 100644 --- a/code_perl/Maasha/BioRun.pm +++ b/code_perl/Maasha/BioRun.pm @@ -132,7 +132,6 @@ sub run_script elsif ( $script eq "read_ucsc_config" ) { script_read_ucsc_config( $in, $out, $options ) } elsif ( $script eq "uppercase_seq" ) { script_uppercase_seq( $in, $out, $options ) } elsif ( $script eq "complexity_seq" ) { script_complexity_seq( $in, $out, $options ) } - elsif ( $script eq "remove_indels" ) { script_remove_indels( $in, $out, $options ) } elsif ( $script eq "get_genome_align" ) { script_get_genome_align( $in, $out, $options ) } elsif ( $script eq "get_genome_phastcons" ) { script_get_genome_phastcons( $in, $out, $options ) } elsif ( $script eq "soap_seq" ) { script_soap_seq( $in, $out, $options ) } @@ -142,12 +141,9 @@ sub run_script elsif ( $script eq "write_2bit" ) { script_write_2bit( $in, $out, $options ) } elsif ( $script eq "write_solid" ) { script_write_solid( $in, $out, $options ) } elsif ( $script eq "write_ucsc_config" ) { script_write_ucsc_config( $in, $out, $options ) } - elsif ( $script eq "remove_keys" ) { script_remove_keys( $in, $out, $options ) } elsif ( $script eq "remove_adaptor" ) { script_remove_adaptor( $in, $out, $options ) } elsif ( $script eq "remove_mysql_tables" ) { script_remove_mysql_tables( $in, $out, $options ) } elsif ( $script eq "remove_ucsc_tracks" ) { script_remove_ucsc_tracks( $in, $out, $options ) } - elsif ( $script eq "rename_keys" ) { script_rename_keys( $in, $out, $options ) } - elsif ( $script eq "uniq_vals" ) { script_uniq_vals( $in, $out, $options ) } elsif ( $script eq "plot_histogram" ) { script_plot_histogram( $in, $out, $options ) } elsif ( $script eq "plot_lendist" ) { script_plot_lendist( $in, $out, $options ) } elsif ( $script eq "plot_chrdist" ) { script_plot_chrdist( $in, $out, $options ) } @@ -404,13 +400,6 @@ sub get_options ylabel|Y=s ); } - elsif ( $script eq "remove_keys" ) - { - @options = qw( - keys|k=s - save_keys|K=s - ); - } elsif ( $script eq "remove_adaptor" ) { @options = qw( @@ -443,19 +432,6 @@ sub get_options no_stream|x ); } - elsif ( $script eq "rename_keys" ) - { - @options = qw( - keys|k=s - ); - } - elsif ( $script eq "uniq_vals" ) - { - @options = qw( - key|k=s - invert|i - ); - } elsif ( $script eq "plot_histogram" ) { @options = qw( @@ -1490,29 +1466,6 @@ sub script_complexity_seq } -sub script_remove_indels -{ - # Martin A. Hansen, August 2007. - - # Remove indels from sequences in stream. - - my ( $in, # handle to in stream - $out, # handle to out stream - ) = @_; - - # Returns nothing. - - my ( $record ); - - while ( $record = Maasha::Biopieces::get_record( $in ) ) - { - $record->{ 'SEQ' } =~ tr/-~.//d if $record->{ "SEQ" }; - - Maasha::Biopieces::put_record( $record, $out ); - } -} - - sub script_get_genome_align { # Martin A. Hansen, April 2008. @@ -2050,39 +2003,6 @@ sub script_plot_phastcons_profiles } -sub script_remove_keys -{ - # Martin A. Hansen, August 2007. - - # Remove keys from stream. - - my ( $in, # handle to in stream - $out, # handle to out stream - $options, # options hash - ) = @_; - - # Returns nothing. - - my ( $record, $new_record ); - - while ( $record = Maasha::Biopieces::get_record( $in ) ) - { - if ( $options->{ "keys" } ) - { - map { delete $record->{ $_ } } @{ $options->{ "keys" } }; - } - elsif ( $options->{ "save_keys" } ) - { - map { $new_record->{ $_ } = $record->{ $_ } if exists $record->{ $_ } } @{ $options->{ "save_keys" } }; - - $record = $new_record; - } - - Maasha::Biopieces::put_record( $record, $out ) if keys %{ $record }; - } -} - - sub script_remove_adaptor { # Martin A. Hansen, August 2008. @@ -2271,77 +2191,6 @@ sub script_remove_ucsc_tracks } -sub script_rename_keys -{ - # Martin A. Hansen, August 2007. - - # Rename keys in stream. - - my ( $in, # handle to in stream - $out, # handle to out stream - $options, # options hash - ) = @_; - - # Returns nothing. - - my ( $record ); - - while ( $record = Maasha::Biopieces::get_record( $in ) ) - { - if ( exists $record->{ $options->{ "keys" }->[ 0 ] } ) - { - $record->{ $options->{ "keys" }->[ 1 ] } = $record->{ $options->{ "keys" }->[ 0 ] }; - - delete $record->{ $options->{ "keys" }->[ 0 ] }; - } - - Maasha::Biopieces::put_record( $record, $out ); - } -} - - -sub script_uniq_vals -{ - # Martin A. Hansen, August 2007. - - # Find unique values in stream. - - my ( $in, # handle to in stream - $out, # handle to out stream - $options, # options hash - ) = @_; - - # Returns nothing. - - my ( %hash, $record ); - - while ( $record = Maasha::Biopieces::get_record( $in ) ) - { - if ( $record->{ $options->{ "key" } } ) - { - if ( not $hash{ $record->{ $options->{ "key" } } } and not $options->{ "invert" } ) - { - Maasha::Biopieces::put_record( $record, $out ); - - $hash{ $record->{ $options->{ "key" } } } = 1; - } - elsif ( $hash{ $record->{ $options->{ "key" } } } and $options->{ "invert" } ) - { - Maasha::Biopieces::put_record( $record, $out ); - } - else - { - $hash{ $record->{ $options->{ "key" } } } = 1; - } - } - else - { - Maasha::Biopieces::put_record( $record, $out ); - } - } -} - - sub script_plot_histogram { # Martin A. Hansen, September 2007.