Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Error with Bio::Seq Translate

by dmbNEWB (Initiate)
on Jan 06, 2015 at 15:46 UTC ( [id://1112356]=perlquestion: print w/replies, xml ) Need Help??

dmbNEWB has asked for the wisdom of the Perl Monks concerning the following question:

Hi all! I am new to perl, and this is my first post ever!

I am trying to translate nucleic acid sequences into amino acid sequences. I create a script (below). When I run the script with only the translate frames 0 & 1, then the script runs fine. Upon adding in the translate frame 2, the script stops working and I receive errors (below). Also, I tried running the translate frame 2 by itself, but receive the same errors.

I've tried searching these errors/message individually to troubleshoot myself, but I can't figure it out. Any guidance is much appreciated!

Script:

#!bin/perl -w use strict; use warnings; use Bio::SeqIO; #script to translate nucleotide sequences to amino acid sequences in f +irst three frames my $in = Bio::SeqIO->new(-file => "sequence.fasta", -format => "fasta" +); my $out = Bio::SeqIO->new(-file => ">Frame1.fasta", -format => "fasta" +); my $out2 = Bio::SeqIO->new(-file => ">Frame2.fasta", -format => "fasta +"); my $out3 = Bio::SeqIO->new(-file => ">Frame3.fasta", -format => "fasta +"); while ( my $seq = $in->next_seq() ) { my $prot = $seq->translate(); $out->write_seq($prot); my $prot2 = $seq->translate(-frame => 1); $out2->write_seq($prot2); my $prot3 = $seq->translate(-frame => 2); $out3->write_seq($prot3); }
Errors: substr outside of string at /sw/lib/perl5/5.16.2/Bio/PrimarySeqI.pm line 644, <GEN0> line 5013. ------------- EXCEPTION: Bio::Root::Exception ------------- MSG: Calling translate without a seq argument! STACK: Error::throw STACK: Bio::Root::Root::throw /sw/lib/perl5/5.16.2/Bio/Root/Root.pm:472 STACK: Bio::Tools::CodonTable::translate /sw/lib/perl5/5.16.2/Bio/Tools/CodonTable.pm:411 STACK: Bio::PrimarySeqI::translate /sw/lib/perl5/5.16.2/Bio/PrimarySeqI.pm:648 STACK: translateframe.pl:11 -----------------------------------------------------------

Replies are listed 'Best First'.
Re: Error with Bio::Seq Translate
by PerlSufi (Friar) on Jan 06, 2015 at 16:25 UTC
    I don't really use the Bio::Seq* namespace much, so I am not completely sure- but maybe the problem is with this line:
    my $prot = $seq->translate();
    ..not giving it a 'seq' argument.
    UPDATE:
    It looks like you have to give translate() a Bio::Seq object, not a Bio::SeqIO object.
    Sample input and output would also help ;)

      Thanks for your reply! Well, it's only the  my $prot3 = $seq->translate(2); part that does not work, which makes me think the input is fine since it works for the $prot and $prot2.

      However, here is sample input if it helps! The file contains 194,503 of these sequences, but here are a couple for an idea:

      >3HSAA000001 CA000001 tgcagccgcgggcccagggtgctgttggtgtcctcagaagtgccggggattctggactgg ctccctcccctcctgttgcagcacaaggccggggtctctggggggctggagaagcctccc tcattcctcccaggaattaataaatgtgaagagaggctctgtttaaaatgtctttggact cccagggctgagtgggctgggatctcgtgtcctcaa >3HSAA000002 CA000002 tgcagccgcgggcccagggtgctgttggtgtcctcagaagtgccggggattctggactgg ctccctcccctcctgttgcagcacaaggccggggtctctggggggctggagaagcctccc tcattcctcccaggaattaataaatgtgaagagaggctctgtttaaaatgtctttggact cccagggctgagtgggctgggatctcgtgtcctcaaagtggatgggttctggggtggctc ctgaggtagaggagtggagaactggctcttaagagcacagttttcttttcttttttcttt tttgagacagggtctcacactgtcacccaggctggagtgcagtgttgcagtccggctcac tgcagttttgacctcccaggctcaagcgatcctcctgcctcagcctcccaagtagctggg agcctgggcatgcatcgccacgtctggctaattattattttttgtagacagggtctcact gtgttgcccaagcttgtcttgaactcctggccttaagtgatcctcccacctcagcctcct gagtagctgggactacaggcatgagccaccatgcctggccaactcacatttttctttcta ttatttattttttgtagagatgagtctcactatgttgcccaggctggtcttgaactcttg ggctcaagtgatcctcccgcctcagcctcccaaagtgttgggattacaggtgtgagccac agcacctggccaaccaacacttctcagggcctctttcatctgtgctcttccaggatgctg cctcttactccctgggcacctcggcctggtcccagcaggtatgggcagttgcttgaggct ccagacatactcacctctacctcgaccacatcaaccccatcaccaagaggaggttcaggg aagctgcattttgtggtcttgtcctcccagtccagggtggtagtgctgggctgttcccag cctcccacagcagagctggacgctgtggaaatggctggattcctctgtgttctttcccat tatccctcagctctgagtcctcttgtgccatctgacatctgatgccttcccaaccactgc cgagtttctgcctggagcagggcctcaaggccctggcacacagaagatgcgtatcagtat tatcaaccaatagttgatgaattgtgtttttcaacgaatttgctagtgatctggtttact gccttagtaatatctagttcctaatatgcctatgccttttaatgtctgcacagtctatga tgatgtcacttctctcaagcctgatgtgtcctctctctctttcttgctagtggtttatca atttttaaaaccttttcttgtttatttgtttttgagacagaattttgctcttgttgccca ggctggagtgcaatggcgtgatcttggctcacagcaacctctacctcctgggttcaagtg attctcgtgcctcagcctcctgagtagctgggctgacaggcacccaccaccacacccagc taatttttatgtttttagtagagatggggtttcaccttgttgggtggccaggctggtctc caactcctgagctcaagtgatccacccgcctcagcctcccaaagtgctgggattacaggg gtgagccaccacgcccagccccagcttagttttttaaaaagtttattttagccattctaa taggtatgtagacatatctaatagtggttttccttgcgtttccttaatgtctgatgatgt taagcattttttccccaagtgcttagttgccatctatatagcatctttgatgaaatgtct gtttatatattttgcacactttaaaatattgggttgttttcttt >3HSAA000003 CA000003 tgcagccgcgggcccagggtgctgttggtgtcctcagaagtgccggggattctggactgg ctccctcccctcctgttgcagcacaaggccggggtctctggggggctggagaagcctccc tcattcctcccaggaattaataaatgtgaagagaggctctgtttaaaatgtc
        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);
Re: Error with Bio::Seq Translate
by GotToBTru (Prior) on Jan 06, 2015 at 17:03 UTC

    In the docs, there are no parentheses after the method call, so maybe try

    my $prot = $seq->translate;

    Strictly a wild guess.

    1 Peter 4:10
      Thanks for your response, but the parentheses are necessary to designate the translation frame.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1112356]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found