Bio::SeqFeature
Generic
Summary
Bio::SeqFeature::Generic - Generic SeqFeature
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
$feat = new Bio::SeqFeature::Generic ( -start => 10, -end => 100,
-strand => -1, -primary => 'repeat',
-source_tag => 'repeatmasker',
-display_name => 'alu family',
-score => 1000,
-tag => {
new => 1,
author => 'someone',
sillytag => 'this is silly!' } );
$feat = new Bio::SeqFeature::Generic ( -gff_string => $string );
# if you want explicitly GFF1
$feat = new Bio::SeqFeature::Generic ( -gff1_string => $string );
# add it to an annotated sequence
$annseq->add_SeqFeature($feat);
Description
Bio::SeqFeature::Generic is a generic implementation for the
Bio::SeqFeatureI interface, providing a simple object to provide all
the information for a feature on a sequence.
For many Features, this is all you will need to use (for example, this
is fine for Repeats in DNA sequence or Domains in protein
sequence). For other features, which have more structure, this is a
good base class to extend using inheritence to have new things: this
is what is done in the Bio::SeqFeature::Gene,
Bio::SeqFeature::Transcript and Bio::SeqFeature::Exon, which provide
well coordinated classes to represent genes on DNA sequence (for
example, you can get the protein sequence out from a transcript
class).
For many Features, you want to add some piece of information, for
example a common one is that this feature is 'new' whereas other
features are 'old'. The tag system, which here is implemented using a
hash can be used here. You can use the tag system to extend the
SeqFeature::Generic programmatically: that is, you know that you have
read in more information into the tag 'mytag' which you can then
retrieve. This means you do not need to know how to write inherieted
Perl to provide more complex information on a feature, and/or, if you
do know but you do not want to write a new class every time you need
some extra piece of information, you can use the tag system to easily
store and then retrieve information.
The tag system can be written in/out of GFF format, and also into EMBL
format via the SeqIO system
Methods
Methods description
Title : set_attributes
Usage :
Function: Sets a whole array of parameters at once.
Example :
Returns : none
Args : Named parameters, in the form as they would otherwise be passed
to new(). Currently recognized are:
-start start position
-end end position
-strand strand
-primary primary tag
-source source tag
-frame frame
-score score value
-tag a reference to a tag/value hash
-gff_string GFF v.2 string to initialize from
-gff1_string GFF v.1 string to initialize from
-seq_id the display name of the sequence
-annotation the AnnotationCollectionI object
-location the LocationI object |
Title : direct_new
Usage : my $obj = Bio::SeqFeature::Generic->direct_new
Function: create a blessed hash - for performance improvement in
object creation
Returns : Bio::SeqFeature::Generic object
Args : none |
Title : location
Usage : my $location = $seqfeature->location()
Function: returns a location object suitable for identifying location
of feature on sequence or parent feature
Returns : Bio::LocationI object
Args : [optional] Bio::LocationI object to set the value to. |
Title : start
Usage : $start = $feat->start
$feat->start(20)
Function: Get/set on the start coordinate of the feature
Returns : integer
Args : none |
Title : end
Usage : $end = $feat->end
$feat->end($end)
Function: get/set on the end coordinate of the feature
Returns : integer
Args : none |
Title : length
Usage : my $len = $feature->length
Function: Get the feature length computed as
$feat->end - $feat->start + 1
Returns : integer
Args : none |
Title : strand
Usage : $strand = $feat->strand()
$feat->strand($strand)
Function: get/set on strand information, being 1,-1 or 0
Returns : -1,1 or 0
Args : none |
Title : score
Usage : $score = $feat->score()
$feat->score($score)
Function: get/set on score information
Returns : float
Args : none if get, the new value if set |
Title : frame
Usage : $frame = $feat->frame()
$feat->frame($frame)
Function: get/set on frame information
Returns : 0,1,2, '.'
Args : none if get, the new value if set |
Title : primary_tag
Usage : $tag = $feat->primary_tag()
$feat->primary_tag('exon')
Function: get/set on the primary tag for a feature,
eg 'exon'
Returns : a string
Args : none |
Title : source_tag
Usage : $tag = $feat->source_tag()
$feat->source_tag('genscan');
Function: Returns the source tag for a feature,
eg, 'genscan'
Returns : a string
Args : none |
Title : attach_seq
Usage : $sf->attach_seq($seq)
Function: Attaches a Bio::Seq object to this feature. This
Bio::Seq object is for the *entire* sequence: ie
from 1 to 10000
Example :
Returns : TRUE on success
Args : a Bio::PrimarySeqI compliant object |
Title : seq
Usage : $tseq = $sf->seq()
Function: returns the truncated sequence (if there) for this
Example :
Returns : sub seq (a Bio::PrimarySeqI compliant object) on attached sequence
bounded by start & end, or undef if there is no sequence attached
Args : none |
Title : entire_seq
Usage : $whole_seq = $sf->entire_seq()
Function: gives the entire sequence that this seqfeature is attached to
Example :
Returns : a Bio::PrimarySeqI compliant object, or undef if there is no
sequence attached
Args : |
Title : seq_id
Usage : $obj->seq_id($newval)
Function: There are many cases when you make a feature that you
do know the sequence name, but do not know its actual
sequence. This is an attribute such that you can store
the ID (e.g., display_id) of the sequence.
This attribute should *not* be used in GFF dumping, as
that should come from the collection in which the seq
feature was found.
Returns : value of seq_id
Args : newvalue (optional) |
Title : display_name
Usage : $featname = $obj->display_name
Function: Implements the display_name() method, which is a human-readable
name for the feature.
Returns : value of display_name (a string)
Args : Optionally, on set the new value or undef |
Title : annotation
Usage : $obj->annotation($annot_obj)
Function: Get/set the annotation collection object for annotating this
feature.
Example :
Returns : A Bio::AnnotationCollectionI object
Args : newvalue (optional) |
Title : get_SeqFeatures
Usage : @feats = $feat->get_SeqFeatures();
Function: Returns an array of sub Sequence Features
Returns : An array
Args : none |
Title : add_SeqFeature
Usage : $feat->add_SeqFeature($subfeat);
$feat->add_SeqFeature($subfeat,'EXPAND')
Function: adds a SeqFeature into the subSeqFeature array.
with no 'EXPAND' qualifer, subfeat will be tested
as to whether it lies inside the parent, and throw
an exception if not.
If EXPAND is used, the parent's start/end/strand will
be adjusted so that it grows to accommodate the new
subFeature
Returns : nothing
Args : An object which has the SeqFeatureI interface |
Title : remove_SeqFeatures
Usage : $sf->remove_SeqFeatures
Function: Removes all sub SeqFeatures
If you want to remove only a subset, remove that subset from the
returned array, and add back the rest.
Example :
Returns : The array of Bio::SeqFeatureI implementing sub-features that was
deleted from this feature.
Args : none |
Title : gff_format
Usage : # get:
$gffio = $feature->gff_format();
# set (change the default version of GFF2):
$feature->gff_format(Bio::Tools::GFF->new(-gff_version => 1));
Function: Get/set the GFF format interpreter. This object is supposed to
format and parse GFF. See Bio::Tools::GFF for the interface.
If this method is called as class method, the default for all
newly created instances will be changed. Otherwise only this
instance will be affected.
Example :
Returns : a Bio::Tools::GFF compliant object
Args : On set, an instance of Bio::Tools::GFF or a derived object. |
Title : gff_string
Usage : $str = $feat->gff_string;
$str = $feat->gff_string($gff_formatter);
Function: Provides the feature information in GFF format.
We override this here from Bio::SeqFeatureI in order to use the
formatter returned by gff_format().
Returns : A string
Args : Optionally, an object implementing gff_string(). |
Title : slurp_file
Usage : @features = Bio::SeqFeature::Generic::slurp_gff_file(\*FILE);
Function: Sneaky function to load an entire file as in memory objects.
Beware of big files.
This method is deprecated. Use Bio::Tools::GFF instead, which can
also handle large files.
Example :
Returns :
Args : |
Title : _from_gff_string
Usage :
Function: Set feature properties from GFF string.
This method uses the object returned by gff_format() for the
actual interpretation of the string. Set a different GFF format
interpreter first if you need a specific version, like GFF1. (The
default is GFF2.)
Example :
Returns :
Args : a GFF-formatted string |
Title : _expand_region
Usage : $self->_expand_region($feature);
Function: Expand the total region covered by this feature to
accomodate for the given feature.
May be called whenever any kind of subfeature is added to this
feature. add_sub_SeqFeature() already does this.
Returns :
Args : A Bio::SeqFeatureI implementing object. |
Title : _parse
Usage :
Function: Parsing hints
Example :
Returns :
Args : |
Title : _tag_value
Usage :
Function: For internal use only. Convenience method for those tags that
may only have a single value.
Returns : The first value under the given tag as a scalar (string)
Args : The tag as a string. Optionally, the value on set. |
Methods code
sub new
{ my ( $caller, @args) = @_;
my ($self) = $caller->SUPER::new(@args);
$self->_register_for_cleanup(\&cleanup_generic);
$self->{'_parse_h'} = {};
$self->{'_gsf_tag_hash'} = {};
$self->set_attributes(@args);
return $self;} |
sub set_attributes
{ my ($self,@args) = @_;
my ($start, $end, $strand, $primary_tag, $source_tag, $primary, $source, $frame,
$score, $tag, $gff_string, $gff1_string,
$seqname, $seqid, $annot, $location,$display_name) =
$self->_rearrange([qw(START
END
STRAND
PRIMARY_TAG
SOURCE_TAG
PRIMARY
SOURCE
FRAME
SCORE
TAG
GFF_STRING
GFF1_STRING
SEQNAME
SEQ_ID
ANNOTATION
LOCATION
DISPLAY_NAME
)], @args);
$location && $self->location($location);
$gff_string && $self->_from_gff_string($gff_string);
$gff1_string && do {
$self->gff_format(Bio::Tools::GFF->new('-gff_version' => 1));
$self->_from_gff_stream($gff1_string);
};
$primary_tag && $self->primary_tag($primary_tag);
$source_tag && $self->source_tag($source_tag);
$primary && $self->primary_tag($primary);
$source && $self->source_tag($source);
defined $start && $self->start($start);
defined $end && $self->end($end);
defined $strand && $self->strand($strand);
defined $frame && $self->frame($frame);
defined $display_name && $self->display_name($display_name);
defined $score && $self->score($score);
$annot && $self->annotation($annot);
if($seqname) {
$self->warn("-seqname is deprecated. Please use -seq_id instead.");
$seqid = $seqname unless $seqid;
}
$seqid && $self->seq_id($seqid);
$tag && do {
foreach my $t ( keys %$tag ) {
$self->add_tag_value($t, UNIVERSAL::isa($tag->{$t}, "ARRAY") ? @{$tag->{$t}} : $tag->{$t});
}
};} |
sub direct_new
{ my ( $class) = @_;
my ($self) = {};
bless $self,$class;
return $self;} |
sub location
{ my($self, $value ) = @_;
if (defined($value)) {
unless (ref($value) and $value->isa('Bio::LocationI')) {
$self->throw("object $value pretends to be a location but ".
"does not implement Bio::LocationI");
}
$self->{'_location'} = $value;
}
elsif (! $self->{'_location'}) {
$self->{'_location'} = Bio::Location::Simple->new();
}
return $self->{'_location'};} |
sub start
{ my ($self,$value) = @_;
return $self->location->start($value); } |
sub end
{ my ($self,$value) = @_;
return $self->location->end($value); } |
sub length
{ my $self = shift;
return $self->end - $self->start() + 1; } |
sub strand
{ my $self = shift;
return $self->location->strand(@_); } |
sub score
{ my $self = shift;
if (@_) {
my $value = shift;
if ( defined $value && $value &&
$value !~ /^[+-]?\d+\.?\d*(e-\d+)?/ and $value != 0) {
$self->throw(-class=>'Bio::Root::BadParameter',
-text=>"'$value' is not a valid score",
-value=>$value);
}
return $self->{'_gsf_score'} = $value;
}
return $self->{'_gsf_score'};} |
sub frame
{ my $self = shift;
if ( @_ ) {
my $value = shift;
if ( defined $value &&
$value !~ /^[0-2.]$/ ) {
$self->throw("'$value' is not a valid frame");
}
if( defined $value && $value eq '.' ) { $value = '.' }
return $self->{'_gsf_frame'} = $value;
}
return $self->{'_gsf_frame'};} |
sub primary_tag
{ my $self = shift;
return $self->{'_primary_tag'} = shift if @_;
return $self->{'_primary_tag'};} |
sub source_tag
{ my $self = shift;
return $self->{'_source_tag'} = shift if @_;
return $self->{'_source_tag'};} |
sub attach_seq
{ my ($self, $seq) = @_;
if ( ! ($seq && ref($seq) && $seq->isa("Bio::PrimarySeqI")) ) {
$self->throw("Must attach Bio::PrimarySeqI objects to SeqFeatures");
}
$self->{'_gsf_seq'} = $seq;
foreach ( $self->sub_SeqFeature() ) {
$_->attach_seq($seq);
}
return 1;} |
sub seq
{ my ($self, $arg) = @_;
if ( defined $arg ) {
$self->throw("Calling SeqFeature::Generic->seq with an argument. You probably want attach_seq");
}
if ( ! exists $self->{'_gsf_seq'} ) {
return undef;
}
my $seq = $self->{'_gsf_seq'}->trunc($self->start(), $self->end());
if ( defined $self->strand &&
$self->strand == -1 ) {
$seq = $seq->revcom;
}
return $seq;} |
sub entire_seq
{ return shift->{'_gsf_seq'};} |
sub seq_id
{ my $obj = shift;
return $obj->{'_gsf_seq_id'} = shift if @_;
return $obj->{'_gsf_seq_id'};} |
sub display_name
{ my $self = shift;
return $self->{'display_name'} = shift if @_;
return $self->{'display_name'};} |
sub annotation
{ my ($obj,$value) = @_;
if(defined $value || ! defined $obj->{'annotation'} ) {
$value = new Bio::Annotation::Collection unless ( defined $value );
$obj->{'annotation'} = $value;
}
return $obj->{'annotation'};} |
sub get_SeqFeatures
{ return @{ shift->{'_gsf_sub_array'} || []};} |
sub add_SeqFeature
{ my ($self,$feat,$expand) = @_;
unless( defined $feat ) {
$self->warn("Called add_SeqFeature with no feature, ignoring");
return;
}
if ( !$feat->isa('Bio::SeqFeatureI') ) {
$self->warn("$feat does not implement Bio::SeqFeatureI. Will add it anyway, but beware...");
}
if($expand && ($expand eq 'EXPAND')) {
$self->_expand_region($feat);
} else {
if ( !$self->contains($feat) ) {
$self->throw("$feat is not contained within parent feature, and expansion is not valid");
}
}
$self->{'_gsf_sub_array'} = [] unless exists($self->{'_gsf_sub_array'});
push(@{$self->{'_gsf_sub_array'}},$feat);} |
sub remove_SeqFeatures
{ my ($self) = @_;
my @subfeats = @{$self->{'_gsf_sub_array'} || []};
$self->{'_gsf_sub_array'} = []; return @subfeats;} |
sub gff_format
{ my ($self, $gffio) = @_;
if(defined($gffio)) {
if(ref($self)) {
$self->{'_gffio'} = $gffio;
} else {
$Bio::SeqFeatureI::static_gff_formatter = $gffio;
}
}
return (ref($self) && exists($self->{'_gffio'}) ?
$self->{'_gffio'} : $self->_static_gff_formatter);} |
sub gff_string
{ my ($self,$formatter) = @_;
$formatter = $self->gff_format() unless $formatter;
return $formatter->gff_string($self); } |
sub slurp_gff_file
{ my ($f) = @_;
my @out;
if ( !defined $f ) {
die "Must have a filehandle";
}
Bio::Root::Root->warn("deprecated method slurp_gff_file() called in Bio::SeqFeature::Generic. Use Bio::Tools::GFF instead.");
while(<$f>) {
my $sf = Bio::SeqFeature::Generic->new('-gff_string' => $_);
push(@out, $sf);
}
return @out;} |
sub _from_gff_string
{ my ($self, $string) = @_;
$self->gff_format()->from_gff_string($self, $string); } |
sub _expand_region
{ my ($self, $feat) = @_;
if(! $feat->isa('Bio::SeqFeatureI')) {
$self->warn("$feat does not implement Bio::SeqFeatureI");
}
if((! defined($self->start)) && (! defined $self->end)) {
$self->start($feat->start);
$self->end($feat->end);
$self->strand($feat->strand) unless $self->strand;
} else {
my ($start,$end,$strand) = $self->union($feat);
$self->start($start);
$self->end($end);
$self->strand($strand);
}} |
sub _parse
{ my ($self) = @_;
return $self->{'_parse_h'};} |
sub _tag_value
{ my $self = shift;
my $tag = shift;
if(@_ || (! $self->has_tag($tag))) {
$self->remove_tag($tag) if($self->has_tag($tag));
$self->add_tag_value($tag, @_);
}
return ($self->get_tag_values($tag))[0];} |
sub seqname
{ my $self = shift;
$self->warn("SeqFeatureI::seqname() is deprecated. Please use seq_id() instead.");
return $self->seq_id(@_);} |
sub display_id
{ my $self = shift;
$self->warn("SeqFeatureI::display_id() is deprecated. Please use display_name() instead.");
return $self->display_name(@_);} |
sub each_tag_value
{ return shift->get_tag_values(@_); } |
sub all_tags
{ return shift->get_all_tags(@_); } |
| cleanup_generic | description | prev | next | Top |
sub cleanup_generic
{ my $self = shift;
foreach my $f ( @{$self->{'_gsf_sub_array'} || []} ) {
$f = undef;
}
$self->{'_gsf_seq'} = undef;
foreach my $t ( keys %{$self->{'_gsf_tag_hash'} || {}} ) {
$self->{'_gsf_tag_hash'}->{$t} = undef;
delete($self->{'_gsf_tag_hash'}->{$t}); }} |
General documentation
| Implemented Interfaces | Top |
This class implementes the following interfaces.
Bio::SeqFeatureI
Note that this includes implementing Bio::RangeI.
Bio::AnnotatableI
Bio::FeatureHolderI
Features held by a feature are essentially sub-features.
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bio.perl.org/MailList.html - About the mailing lists
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:
http://bugzilla.bioperl.org/
Ewan Birney <birney@sanger.ac.uk>
This class has been written with an eye out of inheritence. The fields
the actual object hash are:
_gsf_tag_hash = reference to a hash for the tags
_gsf_sub_array = reference to an array for subfeatures
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _
| Methods for implementing Bio::AnnotatableI | Top |
| Methods to implement Bio::FeatureHolderI | Top |
This includes methods for retrieving, adding, and removing
features. Since this is already a feature, features held by this
feature holder are essentially sub-features.
| INHERITED METHODS FOR Bio::AnnotatableI VIA Bio::SeqFeatureI | Top |