Bioperl: Extracting Complement Statement Along With Location
1
0
Entering edit mode
11.0 years ago
robjohn7000 ▴ 110

Hi,

I have a code bioperl (below) that does the job of extracting CDS locations (e.g., (234..1234) from a GenBank file, but does not extract the complement statement when they are indicated such as complement(234530..235249). How can I extract the complement statement together with the location whenever they indicated as mentioned.

if ($feat_object->primary_tag eq "CDS") {
  my $start = $feat_object->location->start;
  my $end = $feat_object->location->end;
  print $start . ".." . $end . "\n";
}

Thanks

bioperl perl • 2.8k views
ADD COMMENT
1
Entering edit mode
11.0 years ago
Pavel Senin ★ 1.9k

will it help to use foreach?

if ( $feature->primary_tag eq 'CDS' ) {
 foreach my $location ( $feature->location->each_Location ) {
  print $location->start, "..", $location->end, "\n";
 }
}

-- update with full code --

#!/bin/perl
use strict;
use Bio::SeqIO;

my $seqio_object = Bio::SeqIO->new(
 -file   => 'tmp/NC_017187.gbk',
 -format => 'genbank'
);

my $seq_object = $seqio_object->next_seq;

foreach my $feature ( $seq_object->top_SeqFeatures ) {
 if ( $feature->primary_tag eq 'CDS' ) {
  foreach my $location ( $feature->location->each_Location ) {
   print $location->start, "..", $location->end, "\n";
  }
 }
}

this code produces output:

...
2254886..2255341
2255356..2255934
2255982..2256446

from the "complement" statement

$ grep "2255356..2255934" NC_017187.gbk
     gene            complement(2255356..2255934)
     CDS             complement(2255356..2255934)
ADD COMMENT
0
Entering edit mode

Thanks seninp. Unfortunately, I got the following error: Can't call "location" on an undefined value at line: foreach my $location ( $feature->location->each_Location ).

ADD REPLY
0
Entering edit mode

just updated the reply

ADD REPLY
0
Entering edit mode

Many thanks Pavel, updated solution using grep did the trick. Very much appreciated!

ADD REPLY

Login before adding your answer.

Traffic: 2832 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6