Bio::Factory
FTLocationFactory
Toolbar
Summary
Bio::Factory::FTLocationFactory - A FeatureTable Location Parser
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
# parse a string into a location object
$loc = Bio::Factory::FTLocationFactory->from_string("join(100..200,
400..500");
Description
Implementation of string-encoded location parsing for the Genbank feature
table encoding of locations.
Methods
Methods description
Title : from_string Usage : $loc = $locfactory->from_string("100..200"); Function: Parses the given string and returns a Bio::LocationI implementing object representing the location encoded by the string.
This implementation parses the Genbank feature table
encoding of locations.
Example :
Returns : A Bio::LocationI implementing object.
Args : A string. |
Title : _parse_location Usage : $loc = $locfactory->_parse_location( $loc_string)
Function: Parses the given location string and returns a location object
with start() and end() and strand() set appropriately.
Note that this method is private.
Returns : A Bio::LocationI implementing object or undef on failure
Args : location string |
Methods code
BEGIN { $LOCREG = qr{ (?> [^()]+ | \( (??{$LOCREG}) \) )*
} |
sub from_string
{ my ($self,$locstr,$op) = @_;
my $loc;
if (!defined($op)) {
$locstr =~ s{\((\d+\.\d+)\)}{\[$1\]}g;
$locstr =~ s{:\((\d+\.{2}\d+)\)}{:\[$1\]}g;
}
if ($locstr =~ m{(.*?)\(($LOCREG)\)(.*)}o) {
my ($beg, $mid, $end) = ($1, $2, $3);
my (@sublocs) = (split(q(,),$beg), $mid, split(q(,),$end));
my @loc_objs;
my $loc_obj;
SUBLOCS:
while (@sublocs) {
my $subloc = shift @sublocs;
next if !$subloc;
my $oparg = ($subloc eq 'join' || $subloc eq 'bond' ||
$subloc eq 'order' || $subloc eq 'complement') ? $subloc : undef;
if ($oparg) {
my $sub = shift @sublocs;
if (($oparg eq 'join' || $oparg eq 'order' || $oparg eq 'bond' )
&& $sub !~ m{(?:join|order|bond)}) {
my @splitlocs = split(q(,), $sub);
$loc_obj = Bio::Location::Split->new(-verbose => 1,
-splittype => $oparg);
while (my $splitloc = shift @splitlocs) {
next unless $splitloc;
my $sobj;
if ($splitloc =~ m{\(($LOCREG)\)}) {
my $comploc = $1;
$sobj = $self->_parse_location($comploc);
$sobj->strand(-1);
} else {
$sobj = $self->_parse_location($splitloc);
}
$loc_obj->add_sub_Location($sobj);
}
} else {
$loc_obj = $self->from_string($sub, $oparg);
$loc_obj->splittype($oparg) unless $oparg eq 'complement';
}
}
else {
$loc_obj = $self->from_string($subloc,1);
}
$loc_obj->strand(-1) if ($op && $op eq 'complement');
push @loc_objs, $loc_obj;
}
my $ct = @loc_objs;
if ($op && !($op eq 'join' || $op eq 'order' || $op eq 'bond')
&& $ct > 1 ) {
$self->throw("Bad operator $op: had multiple locations ".
scalar(@loc_objs).", should be SplitLocationI");
}
if ($ct > 1) {
$loc = Bio::Location::Split->new();
$loc->add_sub_Location(shift @loc_objs) while (@loc_objs);
return $loc;
} else {
$loc = shift @loc_objs;
return $loc;
}
} else { $loc = $self->_parse_location($locstr);
$loc->strand(-1) if ($op && $op eq 'complement');
}
return $loc;} |
sub _parse_location
{ my ($self, $locstr) = @_;
my ($loc, $seqid);
if($locstr =~ m{^(\S+):(.*)$}o) {
$seqid = $1;
$locstr = $2;
}
my ($start, $end) = split(/\.\./, $locstr);
$start =~ s/(?:^\[+|\]+$)//g if $start;
$end =~ s/(?:^\[+|\]+$)//g if $end;
my $loctype = "..";
$loctype = '?' if ( ($locstr =~ /\?/) && ($locstr !~ /\?\d+/) );
my $locclass = "Bio::Location::Simple";
if(! defined($end)) {
if($locstr =~ /(\d+)([\.\^])(\d+)/) {
$start = $1;
$end = $3;
$loctype = $2;
$locclass = "Bio::Location::Fuzzy"
unless (abs($end-$start) <= 1) && ($loctype eq "^");
} else {
$end = $start;
}
}
my ($start_num, $end_num) = ($start,$end);
if ( ($start =~ /[\>\<\?\.\^]/) || ($end =~ /[\>\<\?\.\^]/) ) {
$locclass = 'Bio::Location::Fuzzy';
if($start =~ /(\d+)/) {
($start_num) = $1;
} else {
$start_num = 0
}
if ($end =~ /(\d+)/) {
($end_num) = $1;
} else { $end_num = 0 }
}
my $strand = 1;
if( $start_num > $end_num && $loctype ne '?') {
($start,$end,$strand) = ($end,$start,-1);
}
$loc = $locclass->new(-verbose => $self->verbose,
-start => $start,
-end => $end,
-strand => $strand,
-location_type => $loctype);
if($seqid) {
$loc->is_remote(1);
$loc->seq_id($seqid);
}
return $loc;
}
1;} |
General documentation
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Please direct usage questions or support issues to the mailing list:
bioperl-l@bioperl.org
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via the
web:
https://redmine.open-bio.org/projects/bioperl/
Email hlapp at gmx.net
Jason Stajich, jason-at-bioperl-dot-org
Chris Fields, cjfields-at-uiuc-dot-edu
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
Title : new
Usage : my $obj = Bio::Factory::FTLocationFactory->new();
Function: Builds a new Bio::Factory::FTLocationFactory object
Returns : an instance of Bio::Factory::FTLocationFactory
Args :