Bio::SeqFeature::Tools
IDHandler
Toolbar
Summary
Bio::SeqFeature::Tools::IDHandler - maps $seq_feature->primary_tag
Package variables
No package variables defined.
Inherit
Synopsis
use Bio::SeqIO;
use Bio::SeqFeature::Tools::IDHandler;
Description
Class to map $seq_feature->primary_tag
Methods
Methods description
Title : new Usage : $unflattener = Bio::SeqFeature::Tools::IDHandler->new(); Function: constructor Example : Returns : a new Bio::SeqFeature::Tools::IDHandler Args : see below |
Title : create_hierarchy_from_ParentIDs Usage : $idhandler->set_ParentIDs_from_hierarchy($fholder) Function: inverse of set_ParentIDs_from_hierarchy Example : Returns : list of top SeqFeatures Args : |
Title : generate_unique_persistent_id Usage : Function: generates a unique and persistent identifier for this Example : Returns : value of primary_id (a scalar) Args :
Will generate an ID, and set primary_id() (see above) The ID is a string generated from
seq_id primary_tag start end
There are three underlying assumptions: that all the above accessors are set; that seq_id is a persistent and unique identifier for the sequence containing this feature; and that
(seq_id, primary_tag, start, end)
is a "unique constraint" over features The ID is persistent, so long as none of these values change - if they do, it is considered a separate entity |
Methods code
sub new
{ my($class,@args) = @_;
my $self = $class->SUPER::new(@args);
my($generate_id_sub) =
$self->_rearrange([qw(GENERATE_ID_SUB
)],
@args);
return $self;
} |
sub set_ParentIDs_from_hierarchy()
{ my $self = shift;
my ($featholder) = @_;
my @sfs = $featholder->get_SeqFeatures;
my @all_sfs = $featholder->get_all_SeqFeatures;
foreach (@all_sfs) {
if ($_->has_tag('Parent')) {
$_->remove_tag('Parent');
}
}
while (@sfs) {
my $sf = shift @sfs;
my @subsfs = $sf->get_SeqFeatures;
my $id = $sf->primary_id;
if (!$id) {
$id = $sf->generate_unique_persistent_id;
}
foreach my $subsf (@subsfs) {
$subsf->add_tag_value('Parent', $id);
}
push(@sfs, @subsfs);
}
return; } |
sub create_hierarchy_from_ParentIDs
{ my ($self,$featholder,@args) = @_;
my @sfs = $featholder->get_all_SeqFeatures;
my %sf_by_ID = ();
foreach (@sfs) {
my $id = $_->primary_id;
next unless $id;
if ($sf_by_ID{$id}) {
$featholder->throw("DUPLICATE ID: $id");
}
$sf_by_ID{$id} = $_;
$_->remove_SeqFeatures; }
if (!%sf_by_ID) {
return;
}
my @topsfs =
grep {
my @parents = $_->get_tagset_values('Parent');
foreach my $parent (@parents) {
$sf_by_ID{$parent}->add_SeqFeature($_)
if exists $sf_by_ID{$parent};
}
!@parents;
} @sfs;
$featholder->remove_SeqFeatures;
$featholder->add_SeqFeature($_) foreach @topsfs;
return @topsfs;} |
sub generate_unique_persistent_id
{ my ($self,$sf,@args) = @_;
my $id;
if (!$sf->isa("Bio::SeqFeatureI")) {
$sf->throw("not a Bio::SeqFeatureI");
}
my $seq_id = $sf->seq_id || $sf->throw("seq_id must be set: ".$sf->display_name);
if ($sf->has_tag('transcript_id')) {
($id) = $sf->get_tag_values('transcript_id');
}
elsif ($sf->has_tag('protein_id')) {
($id) = $sf->get_tag_values('protein_id');
}
else {
my $source = $sf->source_tag || $sf->throw("source tag must be set: ".$sf->display_name);
my $start = $sf->start || $sf->throw("start must be set or is zero: ".$sf->display_name);
my $end = $sf->end || $sf->throw("end must be set");
my $type = $sf->primary_tag || $sf->throw("primary_tag/type must be set: ".$sf->display_name);
$id = "$source:$type:$seq_id:$start:$end";
}
$sf->primary_id($id);
return $id;
}
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 lists 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
the bugs and their resolution. Bug reports can be submitted via the
web:
https://redmine.open-bio.org/projects/bioperl/
| AUTHOR - Chris Mungall | Top |
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _
| set_ParentIDs_from_hierarchy() | Top |
Title : set_ParentIDs_from_hierarchy()
Usage : $idhandler->set_ParentIDs_from_hierarchy($fholder)
Function: populates tags Parent and ID via holder hierarchy
Example :
Returns :
Args : Bio::featureHolderI (either a SeqFeature or a Seq)
This is mainly for GFF3 export
GFF3 uses the tags ID and Parent to represent the feature containment
hierarchy; it does NOT use the feature holder tree
This method sets Parent (and ID for any parents not set) based on
feature holder/containement hierarchy, ready for GFF3 output