From 863c9732941a18d51ffbc7f10c8116df53419850 Mon Sep 17 00:00:00 2001 From: Kevin Galinsky Date: Thu, 27 Oct 2011 16:30:02 -0400 Subject: [PATCH] incremented version number, translate_fasta cleans DNA --- bin/translate_fasta.pl | 98 +++++++++++++----------------------------- lib/Bio/Translator.pm | 2 +- 2 files changed, 32 insertions(+), 68 deletions(-) diff --git a/bin/translate_fasta.pl b/bin/translate_fasta.pl index 98cf890..5da0854 100755 --- a/bin/translate_fasta.pl +++ b/bin/translate_fasta.pl @@ -1,85 +1,49 @@ #!/usr/bin/env perl -# $Author$ -# $Date$ -# $Revision$ -# $HeadURL$ - use strict; -#use warnings; +use warnings; use Bio::Translator; -use Getopt::Euclid ':vars'; +use Bio::Util::DNA 'cleanDNA'; + +use Getopt::Std; +our $opt_t = 1; +getopts('t'); # Instantiate the translator -my $t = Bio::Translator->new($ARGV_translation_table); +my $t = Bio::Translator->new($opt_t); # Build the list of file handles or standard input -my @handles; - -foreach my $file (@ARGV_fasta_files) { - # For "-" use standard input - if ( $file eq '-' ) { - push @handles, \*STDIN; - next; - } - - # Open the file or die - open FH, $file - or die qq{Can't open file "$file" for reading: $!}; - push @handles, \*FH; -} - -# Open standard input if no file names provided -@handles = ( \*STDIN ) unless (@handles); - # Set the input record separator -local $/ = '>'; - -foreach my $fh (@handles) { - # Throw away the first "record" (i.e. it is just ">") - $_ = <$fh>; +local $/ = "\n>"; - while (<$fh>) { - chomp; +while (<>) { - next unless ( $_ =~ /\S/ ); + # Extract the sequence and translate it + s/>//g; + my ( $header, $sequence ) = split /\n/, $_, 2; + my $pep_ref = $t->translate( cleanDNA( \$sequence ) ); - # Extract the sequence and translate it - my ( $header, $sequence ) = split /\n/, $_, 2; - my $pep_ref = $t->translate( \$sequence ); - - # Format the peptide and print out the record - $$pep_ref =~ s/(.{1,60})/$1\n/g; - print ">$header\n$$pep_ref"; - } - - close $fh; + # Format the peptide and print out the record + $$pep_ref =~ s/(.{1,60})/$1\n/g; + print ">$header\n$$pep_ref"; } -=head1 NAME - -translate_fasta.pl - translate fasta files +sub HELP_MESSAGE { + print STDERR <... - -Translate list of fasta files. Input "-" for standard input. If no files -given, translate from standard input. - -=item [-]-t[ranslation[_table]] - -Translation table ID. Default is 1. - -=for Euclid: - table_id.type: +int - table_id.default: 1 - -=back - -=cut +Options: + -t translation table id to use +ENDL + exit 1; +} +sub VERSION_MESSAGE { + print STDERR <