This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bioperl: Finding Restriction Enzyme Sites
#!usr/bin/perl -w
use Bio::DB::GenBank;
use Bio::Restriction::EnzymeCollection;
use Bio::Restriction::Analysis;

my $gb=new Bio::DB::GenBank();
my $seq=$gb->get_Seq_by_acc('AF303112');
print $seq->seq,"\n";
my $all_collection=Bio::Restriction::EnzymeCollection;
my $my_enzyme=$all_collection->get_enzyme('EcoRI');
my $analysis=Bio::Restriction::Analysis->new(-seq=>$seq);
@fragment=$analysis->fragments($my_enzyme);
print "@fragment\n";
my $pro_obj=$seq->translate(-complete=>1);
print $pro_obj->seq;

I want to get a sequence by accession number, and then find if there is a EcoRI enzyme site in this sequence and finally translate this sequence into protein. But the output is only the Nuclear Acid sequence, what's wrong, can someone tell me? Thanks!

bioperl

(1) I've indented your lines of code with 4 spaces: note how this improves readability. (2) I think you wanted to post this under category "question", not "forum"; changed that too.

Changed the title too. "Bioperl" is not very informative. Nor were "beginner's" or "task" as tags. Good titles and tags make your question easier to find and answer.

1 answer

First: if you're going to declare your variables using my, you should:

use strict;

Second - now that we are using strict, you need to change @fragment to:

my @fragment = $analysis->fragments($my_enzyme);

Third: having done those things, you should now see the error:

Bareword "Bio::Restriction::EnzymeCollection" not allowed while "strict subs" in use at...

I suspect that what you want is:

my $all_collection = Bio::Restriction::EnzymeCollection->new;

Your code should now run and print the sequence, fragment and translation. In this example, there does not appear to be an EcoRI site since the sequence and fragment are the same.

Finally: Perl code is much more readable if you put in more spaces and align related lines. For example, compare this to what you typed:

my $all_collection = Bio::Restriction::EnzymeCollection->new;
my $my_enzyme      = $all_collection->get_enzyme('EcoRI');
my $analysis       = Bio::Restriction::Analysis->new(-seq => $seq);
my @fragment       = $analysis->fragments($my_enzyme);

Regarding writing readable Perl code, there are some automatic plug-ins for VIM, EMACs or JEDIT, or you can simply use PerlTidy: http://perltidy.sourceforge.net/

Log in to answer this question.