in reply to Re^2: Error with Bio::Seq Translate
in thread Error with Bio::Seq Translate

You're welcome. And what is the goal of the script? To convert the DNA to ribose nucleic acid (RNA) ?
UPDATED CODE TO REFLECT TRANSLATING TO RNA
For starters, here is code I made (with acknowledgements to the Perl Monks for help) to parse a fasta file:
use strict; use warnings; use Data::Dumper; my $file = '/path/to/your/file/here.fasta'; open (my $fh, '<', $file) or die "Could not open file '$file' $!"; my (%sequence_hash, $header); while ( my $line = <$fh> ) { chomp($line); if ( $line =~ m/^>(.*)/ ) { $header = $1; } else { $sequence_hash{$header} .= $line; } } # look at the header and sequence print Dumper(\%sequence_hash); my @translated_sequences; foreach my $seq ( keys %sequence_hash ) { $sequence_hash{$seq} =~ s/t/u/ig; push @translated_sequences, $sequence_hash{$seq}; } print Dumper(\@translated_sequences);

Replies are listed 'Best First'.
Re^4: Error with Bio::Seq Translate
by dmbNEWB (Initiate) on Jan 07, 2015 at 15:22 UTC

    My overall goal is converting DNA to AMINO ACIDS (protein). (DNA to RNA is transcription, not translation).

    Here is information from BioPerl for using this function:

    http://search.cpan.org/~cjfields/BioPerl-1.6.924/Bio/PrimarySeqI.pm#translate

    "Function: Provides the translation of the DNA sequence using full IUPAC ambiguities in DNA/RNA and amino acid codes."

    Here is the code example from the Beginner's guidelines:

    $prot_obj = $my_seq_object->translate(-frame => 1);

    And here is an example code I found online in which they call using Bio::SeqIO

    #!/usr/bin/perl -w use strict; use Bio::Seq; use Bio::SeqIO; my $input = $ARGV[0]; my $seqio_obj = Bio::SeqIO->new(-file => $input, -format => "fasta" ); my $line_count; # process multi-fasta sequences while(my $seq_obj = $seqio_obj->next_seq){ $line_count++; # print "===========================================================\ +n"; # obtain id of the nt sequence my $id = $seq_obj->display_id; # print id of nt sequence # print "SEQ ID\t>\t", $id, "\n"; # print "===========================================================\ +n"; # use translate to convert amino acid squence to protein sequence fr +om frame 0 (default) # 'complete' - do some checks for ORF # print ">>>>>>>> Frame 0 <<<<<<<\n"; print ">", $id, "-0", "\n"; my $prot_obj = $seq_obj->translate(); # print the protein sequence print $prot_obj->seq,"\n"; # print "\n"; # print ">>>>>>>> Frame 1 <<<<<<<\n"; # translation starting from the second nucleotide (frame 1) print ">", $id, "-1", "\n"; $prot_obj = $seq_obj->translate(-frame => 1); # print the protein sequence print $prot_obj->seq,"\n"; # print "\n";

    My script is working fine for the default frame, for the 1st frame, and until line 5401 for the 2nd frame. The part that messes up is when it gets to the (-frame => 2) file, but even that file works until line 5401. So I don't think it is an input issue.

    And thank you for the above code, but I am translating to amino acids.

      Ok.. I don't have much experience using the Bio::* library, so sample input and output would be necessary for me to help you better- sorry :/