I am trying to extract CDS and corresponding amino acid sequences from GenBank file using BioPerl. The script is shown below:
while (my $seq_object = $in->next_seq){
for my $feat_object ($seq_object->get_SeqFeatures) {
if ($feat_object ->primary_tag eq "CDS") {
# warn("all tags are ", join ("," , $feat_object->get_all_tags),"\n");
if ($feat_object->has_tag ("protein_id")){
my ($protein_id) = $feat_object->get_tag_values('protein_id');
my ($pseq) = $feat_object->get_tag_values('translation') ;
my ($pepseq) = Bio::Seq->new(-id => $protein_id , -description => $seq_object -> accession_number,
-seq => $pseq);
$out->write_seq($pepseq);
}
}
}
}
I am getting error message as:
Filehandle GEN1 opened only for input at /Library/Perl/5.12/Bio/Root/IO.pm line 533, <GEN0> line 148.
I'll add this as an answer since it is likely the source of the error. When creating a Bio::SeqIO
object for output, you must follow the normal Perl rules for open
and specify the file is for output. So, try the following:
my $out = Bio::SeqIO->new( -file => ">Oct_test.fasta", -format => 'fasta');
This is a really easy thing to forget and the error message could be a bit more descriptive.