From 09eb7406f23d0f835db62624d4f652954ee17f87 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Wed, 27 May 2009 05:34:40 +0000 Subject: [PATCH] migrated trans family git-svn-id: http://biopieces.googlecode.com/svn/trunk@430 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/merge_vals | 91 +++++++++++++++++- bp_bin/translate_seq | 99 +++++++++++++++++++- bp_bin/transliterate_seq | 94 ++++++++++++++++++- bp_bin/transliterate_vals | 98 +++++++++++++++++++- code_perl/Maasha/BioRun.pm | 185 ------------------------------------- 5 files changed, 370 insertions(+), 197 deletions(-) diff --git a/bp_bin/merge_vals b/bp_bin/merge_vals index fdf5bd2..f53d99a 100755 --- a/bp_bin/merge_vals +++ b/bp_bin/merge_vals @@ -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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Merge values of keys in a record. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use warnings; use strict; +use Maasha::Biopieces; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, @join, $i ); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'keys', short => 'k', type => 'list', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'delimit', short => 'd', type => 'string', mandatory => 'no', default => '_', 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 ] } ) + { + @join = $record->{ $options->{ "keys" }->[ 0 ] }; + + for ( $i = 1; $i < @{ $options->{ "keys" } }; $i++ ) { + push @join, $record->{ $options->{ "keys" }->[ $i ] } if exists $record->{ $options->{ "keys" }->[ $i ] }; + } + + $record->{ $options->{ "keys" }->[ 0 ] } = join $options->{ "delimit" }, @join; + } + + 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/translate_seq b/bp_bin/translate_seq index fdf5bd2..445d545 100755 --- a/bp_bin/translate_seq +++ b/bp_bin/translate_seq @@ -1,6 +1,99 @@ -#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Translate peptide sequences in the stream. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use warnings; use strict; +use Maasha::Biopieces; +use Maasha::Seq; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $frame, %new_record ); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'frames', short => 'f', type => 'list', mandatory => 'no', default => '1,2,3,-1,-2,-3', allowed => '1,2,3,-1,-2,-3', 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->{ "SEQ" } ) + { + if ( Maasha::Seq::seq_guess_type( $record->{ "SEQ" } ) eq "dna" ) + { + foreach $frame ( @{ $options->{ "frames" } } ) + { + %new_record = %{ $record }; + + $new_record{ "SEQ" } = Maasha::Seq::translate( $record->{ "SEQ" }, $frame ); + $new_record{ "SEQ_LEN" } = length $new_record{ "SEQ" }; + $new_record{ "FRAME" } = $frame; + + Maasha::Biopieces::put_record( \%new_record, $out ); + } + } + } + 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/bp_bin/transliterate_seq b/bp_bin/transliterate_seq index fdf5bd2..9e10b65 100755 --- a/bp_bin/transliterate_seq +++ b/bp_bin/transliterate_seq @@ -1,6 +1,94 @@ -#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Transliterate chars from sequences in stream. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use warnings; use strict; +use Maasha::Biopieces; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $search, $replace, $delete ); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'search', short => 's', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'replace', short => 'r', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'delete', short => 'd', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + ] +); + +$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); +$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); + +$search = $options->{ "search" } || ""; +$replace = $options->{ "replace" } || ""; +$delete = $options->{ "delete" } || ""; + +while ( $record = Maasha::Biopieces::get_record( $in ) ) +{ + if ( $record->{ "SEQ" } ) + { + if ( $search and $replace ) { + eval "\$record->{ 'SEQ' } =~ tr/$search/$replace/"; + } elsif ( $delete ) { + eval "\$record->{ 'SEQ' } =~ tr/$delete//d"; + } + } + + 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/transliterate_vals b/bp_bin/transliterate_vals index fdf5bd2..9431239 100755 --- a/bp_bin/transliterate_vals +++ b/bp_bin/transliterate_vals @@ -1,6 +1,98 @@ -#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Transliterate chars from values in stream. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use warnings; use strict; +use Maasha::Biopieces; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $search, $replace, $delete, $key ); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'keys', short => 'k', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'search', short => 's', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'replace', short => 'r', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'delete', short => 'd', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + ] +); + +$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); +$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); + +$search = $options->{ "search" } || ""; +$replace = $options->{ "replace" } || ""; +$delete = $options->{ "delete" } || ""; + +while ( $record = Maasha::Biopieces::get_record( $in ) ) +{ + foreach $key ( @{ $options->{ "keys" } } ) + { + if ( exists $record->{ $key } ) + { + if ( $search and $replace ) { + eval "\$record->{ $key } =~ tr/$search/$replace/"; + } elsif ( $delete ) { + eval "\$record->{ $key } =~ tr/$delete//d"; + } + } + } + + 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 73c7aa6..2c26f63 100644 --- a/code_perl/Maasha/BioRun.pm +++ b/code_perl/Maasha/BioRun.pm @@ -134,9 +134,6 @@ sub run_script elsif ( $script eq "complexity_seq" ) { script_complexity_seq( $in, $out, $options ) } elsif ( $script eq "oligo_freq" ) { script_oligo_freq( $in, $out, $options ) } elsif ( $script eq "remove_indels" ) { script_remove_indels( $in, $out, $options ) } - elsif ( $script eq "transliterate_seq" ) { script_transliterate_seq( $in, $out, $options ) } - elsif ( $script eq "transliterate_vals" ) { script_transliterate_vals( $in, $out, $options ) } - elsif ( $script eq "translate_seq" ) { script_translate_seq( $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 "tile_seq" ) { script_tile_seq( $in, $out, $options ) } @@ -154,7 +151,6 @@ sub run_script 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 "merge_vals" ) { script_merge_vals( $in, $out, $options ) } elsif ( $script eq "sort_records" ) { script_sort_records( $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 ) } @@ -315,29 +311,6 @@ sub get_options all|a ); } - elsif ( $script eq "transliterate_seq" ) - { - @options = qw( - search|s=s - replace|r=s - delete|d=s - ); - } - elsif ( $script eq "transliterate_vals" ) - { - @options = qw( - keys|k=s - search|s=s - replace|r=s - delete|d=s - ); - } - elsif ( $script eq "translate_seq" ) - { - @options = qw( - frames|f=s - ); - } elsif ( $script eq "get_genome_align" ) { @options = qw( @@ -513,13 +486,6 @@ sub get_options invert|i ); } - elsif ( $script eq "merge_vals" ) - { - @options = qw( - keys|k=s - delimit|d=s - ); - } elsif ( $script eq "sort_records" ) { @options = qw( @@ -1638,122 +1604,6 @@ sub script_remove_indels } -sub script_transliterate_seq -{ - # Martin A. Hansen, August 2007. - - # Transliterate chars from sequence in record. - - my ( $in, # handle to in stream - $out, # handle to out stream - $options, # options hash - ) = @_; - - # Returns nothing. - - my ( $record, $search, $replace, $delete ); - - $search = $options->{ "search" } || ""; - $replace = $options->{ "replace" } || ""; - $delete = $options->{ "delete" } || ""; - - while ( $record = Maasha::Biopieces::get_record( $in ) ) - { - if ( $record->{ "SEQ" } ) - { - if ( $search and $replace ) { - eval "\$record->{ 'SEQ' } =~ tr/$search/$replace/"; - } elsif ( $delete ) { - eval "\$record->{ 'SEQ' } =~ tr/$delete//d"; - } - } - - Maasha::Biopieces::put_record( $record, $out ); - } -} - - -sub script_transliterate_vals -{ - # Martin A. Hansen, April 2008. - - # Transliterate chars from values in record. - - my ( $in, # handle to in stream - $out, # handle to out stream - $options, # options hash - ) = @_; - - # Returns nothing. - - my ( $record, $search, $replace, $delete, $key ); - - $search = $options->{ "search" } || ""; - $replace = $options->{ "replace" } || ""; - $delete = $options->{ "delete" } || ""; - - while ( $record = Maasha::Biopieces::get_record( $in ) ) - { - foreach $key ( @{ $options->{ "keys" } } ) - { - if ( exists $record->{ $key } ) - { - if ( $search and $replace ) { - eval "\$record->{ $key } =~ tr/$search/$replace/"; - } elsif ( $delete ) { - eval "\$record->{ $key } =~ tr/$delete//d"; - } - } - } - - Maasha::Biopieces::put_record( $record, $out ); - } -} - - -sub script_translate_seq -{ - # Martin A. Hansen, February 2008. - - # Translate DNA sequence into protein sequence. - - my ( $in, # handle to in stream - $out, # handle to out stream - $options, # options hash - ) = @_; - - # Returns nothing. - - my ( $record, $frame, %new_record ); - - $options->{ "frames" } ||= [ 1, 2, 3, -1, -2, -3 ]; - - while ( $record = Maasha::Biopieces::get_record( $in ) ) - { - if ( $record->{ "SEQ" } ) - { - if ( Maasha::Seq::seq_guess_type( $record->{ "SEQ" } ) eq "dna" ) - { - foreach $frame ( @{ $options->{ "frames" } } ) - { - %new_record = %{ $record }; - - $new_record{ "SEQ" } = Maasha::Seq::translate( $record->{ "SEQ" }, $frame ); - $new_record{ "SEQ_LEN" } = length $new_record{ "SEQ" }; - $new_record{ "FRAME" } = $frame; - - Maasha::Biopieces::put_record( \%new_record, $out ); - } - } - } - else - { - Maasha::Biopieces::put_record( $record, $out ); - } - } -} - - sub script_get_genome_align { # Martin A. Hansen, April 2008. @@ -2731,41 +2581,6 @@ sub script_uniq_vals } -sub script_merge_vals -{ - # 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, @join, $i ); - - $options->{ "delimit" } ||= '_'; - - while ( $record = Maasha::Biopieces::get_record( $in ) ) - { - if ( exists $record->{ $options->{ "keys" }->[ 0 ] } ) - { - @join = $record->{ $options->{ "keys" }->[ 0 ] }; - - for ( $i = 1; $i < @{ $options->{ "keys" } }; $i++ ) { - push @join, $record->{ $options->{ "keys" }->[ $i ] } if exists $record->{ $options->{ "keys" }->[ $i ] }; - } - - $record->{ $options->{ "keys" }->[ 0 ] } = join $options->{ "delimit" }, @join; - } - - Maasha::Biopieces::put_record( $record, $out ); - } -} - - sub script_sort_records { # Martin A. Hansen, August 2007. -- 2.39.5