Question: Bioperl: Extracting Complement Statement Along With Location
0
gravatar for robjohn7000
7.1 years ago by
robjohn7000100
United Kingdom
robjohn7000100 wrote:

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

perl bioperl • 2.0k views
ADD COMMENTlink modified 7.1 years ago by Pavel Senin1.9k • written 7.1 years ago by robjohn7000100
1
gravatar for Pavel Senin
7.1 years ago by
Pavel Senin1.9k
Los Alamos, NM
Pavel Senin1.9k wrote:

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 COMMENTlink modified 7.1 years ago • written 7.1 years ago by Pavel Senin1.9k

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 REPLYlink written 7.1 years ago by robjohn7000100

just updated the reply

ADD REPLYlink written 7.1 years ago by Pavel Senin1.9k

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

ADD REPLYlink written 7.1 years ago by robjohn7000100
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1610 users visited in the last hour
_