From: martinahansen Date: Sun, 24 May 2009 09:56:12 +0000 (+0000) Subject: migrated add_ident X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=415fce24b8975406d2919667df2f2c3e4585fb82;p=biopieces.git migrated add_ident git-svn-id: http://biopieces.googlecode.com/svn/trunk@390 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/add_ident b/bp_bin/add_ident index fdf5bd2..26497ef 100755 --- a/bp_bin/add_ident +++ b/bp_bin/add_ident @@ -1,6 +1,89 @@ -#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Add a unique identifier to each record in the stream. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use warnings; use strict; +use Maasha::Biopieces; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $key, $prefix, $i ); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'key', short => 'k', type => 'string', mandatory => 'no', default => 'ID', allowed => undef, disallowed => undef }, + { long => 'prefix', short => 'p', type => 'string', mandatory => 'no', default => 'ID', allowed => undef, disallowed => undef }, + ] +); + +$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); +$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); + +$key = $options->{ "key" }; +$prefix = $options->{ "prefix" }; + +$i = 0; + +while ( $record = Maasha::Biopieces::get_record( $in ) ) +{ + $record->{ $key } = sprintf( "$prefix%08d", $i ); + + Maasha::Biopieces::put_record( $record, $out ); + + $i++; +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +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 ecf32f2..ebbd3c5 100644 --- a/code_perl/Maasha/BioRun.pm +++ b/code_perl/Maasha/BioRun.pm @@ -133,7 +133,6 @@ sub run_script elsif ( $script eq "assemble_tag_contigs" ) { script_assemble_tag_contigs( $in, $out, $options ) } elsif ( $script eq "length_seq" ) { script_length_seq( $in, $out, $options ) } elsif ( $script eq "uppercase_seq" ) { script_uppercase_seq( $in, $out, $options ) } - elsif ( $script eq "shuffle_seq" ) { script_shuffle_seq( $in, $out, $options ) } elsif ( $script eq "analyze_seq" ) { script_analyze_seq( $in, $out, $options ) } elsif ( $script eq "analyze_tags" ) { script_analyze_tags( $in, $out, $options ) } elsif ( $script eq "complexity_seq" ) { script_complexity_seq( $in, $out, $options ) } @@ -176,7 +175,6 @@ sub run_script elsif ( $script eq "merge_records" ) { script_merge_records( $in, $out, $options ) } elsif ( $script eq "compute" ) { script_compute( $in, $out, $options ) } elsif ( $script eq "flip_tab" ) { script_flip_tab( $in, $out, $options ) } - elsif ( $script eq "add_ident" ) { script_add_ident( $in, $out, $options ) } elsif ( $script eq "count_records" ) { script_count_records( $in, $out, $options ) } elsif ( $script eq "random_records" ) { script_random_records( $in, $out, $options ) } elsif ( $script eq "sort_records" ) { script_sort_records( $in, $out, $options ) } @@ -660,13 +658,6 @@ sub get_options eval|e=s ); } - elsif ( $script eq "add_ident" ) - { - @options = qw( - prefix|p=s - key|k=s - ); - } elsif ( $script eq "count_records" ) { @options = qw( @@ -1845,29 +1836,6 @@ sub script_length_seq } -sub script_shuffle_seq -{ - # Martin A. Hansen, December 2007. - - # Shuffle 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" } = Maasha::Seq::seq_shuffle( $record->{ "SEQ" } ) if $record->{ "SEQ" }; - - Maasha::Biopieces::put_record( $record, $out ); - } -} - - sub script_analyze_seq { # Martin A. Hansen, August 2007. @@ -4147,37 +4115,6 @@ sub script_flip_tab } -sub script_add_ident -{ - # Martin A. Hansen, May 2008. - - # Add a unique identifier to each record in stream. - - my ( $in, # handle to in stream - $out, # handle to out stream - $options, # options hash - ) = @_; - - # Returns nothing. - - my ( $record, $key, $prefix, $i ); - - $key = $options->{ "key" } || "ID"; - $prefix = $options->{ "prefix" } || "ID"; - - $i = 0; - - while ( $record = Maasha::Biopieces::get_record( $in ) ) - { - $record->{ $key } = sprintf( "$prefix%08d", $i ); - - Maasha::Biopieces::put_record( $record, $out ); - - $i++; - } -} - - sub script_count_records { # Martin A. Hansen, August 2007.