Bio::Tools
GFF
Summary
Bio::Tools::GFF - A Bio::SeqAnalysisParserI compliant GFF format parser
Package variables
Privates (from "my" definitions)
$i = 0
$gff3_featureID = 0
%GFF3_ID_Tags = map { $_ => $i++ } qw(ID Parent Target)
Included modules
Inherit
Synopsis
use Bio::Tools::GFF;
# specify input via -fh or -file
my $gffio = Bio::Tools::GFF->new(-fh => \*STDIN, -gff_version => 2);
my $feature;
# loop over the input stream
while($feature = $gffio->next_feature()) {
# do something with feature
}
$gffio->close();
# you can also obtain a GFF parser as a SeqAnalasisParserI in
# HT analysis pipelines (see Bio::SeqAnalysisParserI and
# Bio::Factory::SeqAnalysisParserFactory)
my $factory = Bio::Factory::SeqAnalysisParserFactory->new();
my $parser = $factory->get_parser(-input => \*STDIN, -method => "gff");
while($feature = $parser->next_feature()) {
# do something with feature
}
Description
This class provides a simple GFF parser and writer. In the sense of a
SeqAnalysisParser, it parses an input file or stream into SeqFeatureI
objects, but is not in any way specific to a particular analysis
program and the output that program produces.
That is, if you can get your analysis program spit out GFF, here is
your result parser.
Methods
Methods description
Title : new Usage : my $parser = Bio::Tools::GFF->new(-gff_version => 2, -file => "filename.gff"); or my $writer = Bio::Tools::GFF->new(-gff_version => 3, -file => ">filename.gff3"); Function: Creates a new instance. Recognized named parameters are -file, -fh, and -gff_version. Returns : a new object Args : named parameters -gff_version => [1,2,3] |
Title : _parse_header Usage : $gffio->_parse_header() Function: used to turn parse GFF header lines. currently produces Bio::LocatableSeq objects from ##sequence-region lines Returns : 1 on success Args : none |
Title : next_segment Usage : my $seq = $gffio->next_segment; Function: Returns a Bio::LocatableSeq object corresponding to a GFF "##sequence-region" header line. Example : Returns : A Bio::LocatableSeq object, or undef if there are no more sequences. Args : none |
Title : next_feature Usage : $seqfeature = $gffio->next_feature(); Function: Returns the next feature available in the input file or stream, or undef if there are no more features. Example : Returns : A Bio::SeqFeatureI implementing object, or undef if there are no more features. Args : none |
Title : from_gff_string Usage : $gff->from_gff_string($feature, $gff_string); Function: Sets properties of a SeqFeatureI object from a GFF-formatted string. Interpretation of the string depends on the version that has been specified at initialization.
This method is used by next_feature(). It actually dispatches to
one of the version-specific (private) methods.
Example :
Returns : void
Args : A Bio::SeqFeatureI implementing object to be initialized
The GFF-formatted string to initialize it from |
Title : _from_gff1_string Usage : Function: Example : Returns : void Args : A Bio::SeqFeatureI implementing object to be initialized The GFF-formatted string to initialize it from |
Title : _from_gff2_string Usage : Function: Example : Returns : void Args : A Bio::SeqFeatureI implementing object to be initialized The GFF2-formatted string to initialize it from |
Title : write_feature Usage : $gffio->write_feature($feature); Function: Writes the specified SeqFeatureI object in GFF format to the stream associated with this instance. Returns : none Args : An array of Bio::SeqFeatureI implementing objects to be serialized |
Title : gff_string Usage : $gffstr = $gffio->gff_string($feature); Function: Obtain the GFF-formatted representation of a SeqFeatureI object. The formatting depends on the version specified at initialization.
This method is used by write_feature(). It actually dispatches to
one of the version-specific (private) methods.
Example :
Returns : A GFF-formatted string representation of the SeqFeature
Args : A Bio::SeqFeatureI implementing object to be GFF-stringified |
Title : _gff1_string Usage : $gffstr = $gffio->_gff1_string Function: Example : Returns : A GFF1-formatted string representation of the SeqFeature Args : A Bio::SeqFeatureI implementing object to be GFF-stringified |
Title : _gff2_string Usage : $gffstr = $gffio->_gff2_string Function: Example : Returns : A GFF2-formatted string representation of the SeqFeature Args : A Bio::SeqFeatureI implementing object to be GFF2-stringified |
Title : _gff25_string Usage : $gffstr = $gffio->_gff2_string Function: To get a format of GFF that is peculiar to Gbrowse/Bio::DB::GFF Example : Returns : A GFF2.5-formatted string representation of the SeqFeature Args : A Bio::SeqFeatureI implementing object to be GFF2.5-stringified |
Title : _gff3_string Usage : $gffstr = $gffio->_gff3_string Function: Example : Returns : A GFF3-formatted string representation of the SeqFeature Args : A Bio::SeqFeatureI implementing object to be GFF3-stringified |
Title : _gff_version Usage : $gffversion = $gffio->gff_version Function: Example : Returns : The GFF version this parser will accept and emit. Args : none |
Title : newFh Usage : $fh = Bio::Tools::GFF->newFh(-file=>$filename,-format=>'Format') Function: does a new() followed by an fh() Example : $fh = Bio::Tools::GFF->newFh(-file=>$filename,-format=>'Format') $feature = <$fh>; # read a feature object print $fh $feature; # write a feature object Returns : filehandle tied to the Bio::Tools::GFF class Args : |
Title : fh Usage : $obj->fh Function: Example : $fh = $obj->fh; # make a tied filehandle $feature = <$fh>; # read a feature object print $fh $feature; # write a feature object Returns : filehandle tied to Bio::Tools::GFF class Args : none |
Title : get_seqs Usage : Function: Returns all Bio::Seq objects populated by GFF3 file Example : Returns : Args : |
Title : features_attached_to_seqs Usage : $obj->features_attached_to_seqs(1); Function: For use with GFF3 containg sequence only
Setting this before parsing ensures that all Bio::Seq object created will have the appropriate features added to them
defaults to false (off)
Note that this mode will incur higher memory usage because features
will have to be cached until the relevant feature comes along
Example :
Returns : value of features_attached_to_seqs (a boolean)
Args : on set, new value (a boolean, optional) |
Title : ignore_sequence Usage : $obj->ignore_sequence(1); Function: For use with GFF3 containg sequence only
Setting this before parsing means that all sequence data will be ignored
Example :
Returns : value of ignore_sequence (a boolean)
Args : on set, new value (a boolean, optional) |
Methods code
| _incrementGFF3ID | description | prev | next | Top |
sub _incrementGFF3ID
{ my ($self) = @_;
return ++ $gff3_featureID;
}} |
sub new
{ my ($class, @args) = @_;
my $self = $class->SUPER::new(@args);
my ($gff_version, $noparse) = $self->_rearrange([qw(GFF_VERSION NOPARSE)],@args);
$self->_initialize_io(@args);
$self->_parse_header() unless $noparse;
$gff_version ||= 2;
if( ! $self->gff_version($gff_version) ) {
$self->throw("Can't build a GFF object with the unknown version ".
$gff_version);
}
$self->{'_first'} = 1;
return $self; } |
sub _parse_header
{ my ($self) = @_;
my @unhandled;
local $^W = 0; while(my $line = $self->_readline()){
my $handled = 0;
next if /^\s+$/;
if($line =~ /^\#\#sequence-region\s+(\S+)\s+(\S+)\s+(\S+)\s*/){
my($seqid,$start,$end) = ($1,$2,$3);
push @{ $self->{'segments'} }, Bio::LocatableSeq->new
(
-id => unescape($seqid),
-start => $start,
-end => $end,
-length => ($end - $start + 1), );
$handled = 1;
} elsif($line =~ /^(\#\#feature-ontology)/) {
$self->warn("$1 header tag parsing unimplemented");
} elsif($line =~ /^(\#\#attribute-ontology)/) {
$self->warn("$1 header tag parsing unimplemented");
} elsif($line =~ /^(\#\#source-ontology)/) {
$self->warn("$1 header tag parsing unimplemented");
} elsif($line =~ /^(\#\#\#)/) {
$self->warn("$1 header tag parsing unimplemented");
} elsif($line =~ /^(\#\#FASTA)/) {
$line = $self->_readline();
if ($line !~ /^\>(\S+)/) {
$self->throw("##FASTA directive must be followed by fasta header, not: $line");
}
} else {
}
if ($line =~ /^\>(.*)/) {
my $seq = $self->_parse_sequence($line);
if ($seq) {
$self->_seq_by_id_h->{$seq->primary_id} = $seq;
}
}
if(!$handled){
push @unhandled, $line
}
last unless $line =~ /^\#/;
}
foreach my $line (@unhandled){
$self->_pushback($line);
}
return 1; } |
sub _parse_sequence
{ my ($self, $line) = @_;
if ($line =~ /^\>(.*)/) {
my $seqid = $1;
$seqid =~ s/\s+$//;
my $desc = '';
if ($seqid =~ /(\S+)\s+(.*)/) {
($seqid, $desc) = ($1,$2);
}
my $res = '';
while (my $line = $self->_readline) {
if ($line =~ /^\#/) {
last;
}
if ($line =~ /^\>/) {
$self->_pushback($line);
last;
}
$line =~ s/\s//g;
$res .= $line;
}
return if $self->ignore_sequence;
my $seqfactory = Bio::Seq::SeqFactory->new('Bio::Seq');
my $seq = $seqfactory->create(-seq=>$res,
-id=>$seqid,
-desc=>$desc);
$seq->accession_number($seqid);
if ($self->features_attached_to_seqs) {
my @feats =
@{$self->_feature_idx_by_seq_id->{$seqid}};
$seq->add_SeqFeature($_) foreach @feats;
@{$self->_feature_idx_by_seq_id->{$seqid}} = ();
}
return $seq;
}
else {
$self->throw("expected fasta header, not: $line");
}} |
sub next_segment
{ my ($self,@args) = @_;
return shift @{ $self->{'segments'} } if defined $self->{'segments'};
return;} |
sub next_feature
{ my ($self) = @_;
my $gff_string;
while(($gff_string = $self->_readline()) && defined($gff_string)) {
if ($gff_string =~ /^\#\#\#/) {
}
next if($gff_string =~ /^\#/ || $gff_string =~ /^\s*$/ ||
$gff_string =~ m{^//});
while ($gff_string =~ /^\>(.+)/) {
my $seq = $self->_parse_sequence($gff_string);
if ($seq) {
$self->_seq_by_id_h->{$seq->primary_id} = $seq;
$gff_string = $self->_readline;
last unless $gff_string;
}
}
last;
}
return unless $gff_string;
my $feat = Bio::SeqFeature::Generic->new();
$self->from_gff_string($feat, $gff_string);
if ($self->features_attached_to_seqs) {
push(@{$self->_feature_idx_by_seq_id->{$feat->seq_id}},
$feat);
}
return $feat;} |
sub _feature_idx_by_seq_id
{ my $self = shift;
$self->{__feature_idx_by_seq_id} = shift if @_;
$self->{__feature_idx_by_seq_id} = {}
unless $self->{__feature_idx_by_seq_id};
return $self->{__feature_idx_by_seq_id};} |
sub from_gff_string
{ my ($self, $feat, $gff_string) = @_;
if($self->gff_version() == 1) {
return $self->_from_gff1_string($feat, $gff_string);
} elsif( $self->gff_version() == 3 ) {
return $self->_from_gff3_string($feat, $gff_string);
} else {
return $self->_from_gff2_string($feat, $gff_string);
}} |
sub _from_gff1_string
{ my ($gff, $feat, $string) = @_;
chomp $string;
my ($seqname, $source, $primary, $start, $end, $score,
$strand, $frame, @group) = split(/\t/, $string);
if ( !defined $frame ) {
$feat->throw("[$string] does not look like GFF to me");
}
$frame = 0 unless( $frame =~ /^\d+$/);
$feat->seq_id($seqname);
$feat->source_tag($source);
$feat->primary_tag($primary);
$feat->start($start);
$feat->end($end);
$feat->frame($frame);
if ( $score eq '.' ) {
} else {
$feat->score($score);
}
if ( $strand eq '-' ) { $feat->strand(-1); }
if ( $strand eq '+' ) { $feat->strand(1); }
if ( $strand eq '.' ) { $feat->strand(0); }
foreach my $g ( @group ) {
if ( $g =~ /(\S+)=(\S+)/ ) {
my $tag = $1;
my $value = $2;
$feat->add_tag_value($1, $2);
} else {
$feat->add_tag_value('group', $g);
}
}} |
sub _from_gff2_string
{ my ($gff, $feat, $string) = @_;
chomp($string);
my ($seqname, $source, $primary, $start,
$end, $score, $strand, $frame, @attribs) = split(/\t+/, $string);
my $attribs = join ' ', @attribs;
if ( !defined $frame ) {
$feat->throw("[$string] does not look like GFF2 to me");
}
$feat->seq_id($seqname);
$feat->source_tag($source);
$feat->primary_tag($primary);
$feat->start($start);
$feat->end($end);
$feat->frame($frame);
if ( $score eq '.' ) {
} else {
$feat->score($score);
}
if ( $strand eq '-' ) { $feat->strand(-1); }
if ( $strand eq '+' ) { $feat->strand(1); }
if ( $strand eq '.' ) { $feat->strand(0); }
my $flag = 0; my @parsed;
for my $a ( split //, $attribs ) {
if( $a eq '"') { $flag = ( $flag == 0 ) ? 1:0 }
elsif( $a eq ';' && $flag ) { $a = "INSERT_SEMICOLON_HERE"}
elsif( $a eq '#' && ! $flag ) { last }
push @parsed, $a;
}
$attribs = join "", @parsed;
my @key_vals = split /;/, $attribs;
foreach my $pair ( @key_vals ) {
$pair =~ s/INSERT_SEMICOLON_HERE/;/g;
my ($blank, $key, $values) = split /^\s*([\w\d]+)\s/, $pair;
if( defined $values ) {
my @values;
while ($values =~ s/"(.*?)"//){
push @values, $1;
}
my @othervals = split /\s+/, $values;
foreach my $othervalue(@othervals){
if (CORE::length($othervalue) > 0) {push @values, $othervalue}
}
foreach my $value(@values){
$feat->add_tag_value($key, $value);
}
}
} } |
sub _from_gff3_string
{ my ($gff, $feat, $string) = @_;
chomp($string);
my ($seqname, $source, $primary, $start, $end,
$score, $strand, $frame, $groups) = split(/\t/, $string);
if ( ! defined $frame ) {
$feat->throw("[$string] does not look like GFF3 to me");
}
$feat->seq_id($seqname);
$feat->source_tag($source);
$feat->primary_tag($primary);
$feat->start($start);
$feat->end($end);
$feat->frame($frame);
if ( $score eq '.' ) {
} else {
$feat->score($score);
}
if ( $strand eq '-' ) { $feat->strand(-1); }
if ( $strand eq '+' ) { $feat->strand(1); }
if ( $strand eq '.' ) { $feat->strand(0); }
my @groups = split(/\s*;\s*/, $groups);
for my $group (@groups) {
my ($tag,$value) = split /=/,$group;
$tag = unescape($tag);
my @values = map {unescape($_)} split /,/,$value;
for my $v ( @values ) { $feat->add_tag_value($tag,$v); }
}
}
} |
sub unescape
{ my $v = shift;
$v =~ tr/+/ /;
$v =~ s/%([0-9a-fA-F]{2})/chr hex($1)/ge;
return $v;} |
sub write_feature
{ my ($self, @features) = @_;
return unless @features;
if( $self->{'_first'} && $self->gff_version() == 3 ) {
$self->_print("##gff-version 3\n");
}
$self->{'_first'} = 0;
foreach my $feature ( @features ) {
$self->_print($self->gff_string($feature)."\n");
}} |
sub gff_string
{ my ($self, $feature) = @_;
if($self->gff_version() == 1) {
return $self->_gff1_string($feature);
} elsif( $self->gff_version() == 3 ) {
return $self->_gff3_string($feature);
} elsif( $self->gff_version() == 2.5 ) {
return $self->_gff25_string($feature);
} else {
return $self->_gff2_string($feature);
}} |
sub _gff1_string
{ my ($gff, $feat) = @_;
my ($str,$score,$frame,$name,$strand);
if( $feat->can('score') ) {
$score = $feat->score();
}
$score = '.' unless defined $score;
if( $feat->can('frame') ) {
$frame = $feat->frame();
}
$frame = '.' unless defined $frame;
$strand = $feat->strand();
if(! $strand) {
$strand = ".";
} elsif( $strand == 1 ) {
$strand = '+';
} elsif ( $feat->strand == -1 ) {
$strand = '-';
}
if( $feat->can('seqname') ) {
$name = $feat->seq_id();
$name ||= 'SEQ';
} else {
$name = 'SEQ';
}
$str = join("\t",
$name,
$feat->source_tag(),
$feat->primary_tag(),
$feat->start(),
$feat->end(),
$score,
$strand,
$frame);
foreach my $tag ( $feat->all_tags ) {
foreach my $value ( $feat->each_tag_value($tag) ) {
$str .= " $tag=$value" if $value;
}
}
return $str;} |
sub _gff2_string
{ my ($gff, $origfeat) = @_;
my $feat;
if ($origfeat->isa('Bio::SeqFeature::FeaturePair')){
$feat = $origfeat->feature2;
} else {
$feat = $origfeat;
}
my ($str1, $str2,$score,$frame,$name,$strand);
if( $feat->can('score') ) {
$score = $feat->score();
}
$score = '.' unless defined $score;
if( $feat->can('frame') ) {
$frame = $feat->frame();
}
$frame = '.' unless defined $frame;
$strand = $feat->strand();
if(! $strand) {
$strand = ".";
} elsif( $strand == 1 ) {
$strand = '+';
} elsif ( $feat->strand == -1 ) {
$strand = '-';
}
if( $feat->can('seqname') ) {
$name = $feat->seq_id();
$name ||= 'SEQ';
} else {
$name = 'SEQ';
}
$str1 = join("\t",
$name,
$feat->source_tag(),
$feat->primary_tag(),
$feat->start(),
$feat->end(),
$score,
$strand,
$frame);
my @all_tags = $feat->all_tags;
my @group;
if (@all_tags) { foreach my $tag ( @all_tags ) {
my @v;
foreach my $value ( $feat->each_tag_value($tag) ) {
unless( defined $value && length($value) ) {
$value = '""';
} elsif ($value =~ /[^A-Za-z0-9_]/){
$value =~ s/\t/\\t/g; $value =~ s/\n/\\n/g; $value = '"' . $value . '" ';
} push @v, $value;
}
push @group, "$tag ".join(" ", @v);
}
}
$str2 .= join(' ; ', @group);
if( ! $feat->has_tag('Target') && ! $feat->has_tag('Group') &&
$origfeat->isa('Bio::SeqFeature::FeaturePair') ) {
$str2 = sprintf("Target %s %d %d", $origfeat->feature1->seq_id,
( $origfeat->feature1->strand < 0 ?
( $origfeat->feature1->end,
$origfeat->feature1->start) :
( $origfeat->feature1->start,
$origfeat->feature1->end)
)) . ($str2?" ; ".$str2:""); }
return $str1."\t".$str2;} |
sub _gff25_string
{ my ($gff, $origfeat) = @_;
my $feat;
if ($origfeat->isa('Bio::SeqFeature::FeaturePair')){
$feat = $origfeat->feature2;
} else {
$feat = $origfeat;
}
my ($str1, $str2,$score,$frame,$name,$strand);
if( $feat->can('score') ) {
$score = $feat->score();
}
$score = '.' unless defined $score;
if( $feat->can('frame') ) {
$frame = $feat->frame();
}
$frame = '.' unless defined $frame;
$strand = $feat->strand();
if(! $strand) {
$strand = ".";
} elsif( $strand == 1 ) {
$strand = '+';
} elsif ( $feat->strand == -1 ) {
$strand = '-';
}
if( $feat->can('seqname') ) {
$name = $feat->seq_id();
$name ||= 'SEQ';
} else {
$name = 'SEQ';
}
$str1 = join("\t",
$name,
$feat->source_tag(),
$feat->primary_tag(),
$feat->start(),
$feat->end(),
$score,
$strand,
$frame);
my @all_tags = $feat->all_tags;
my @group; my @firstgroup;
if (@all_tags) { foreach my $tag ( @all_tags ) {
my @v;
foreach my $value ( $feat->each_tag_value($tag) ) {
unless( defined $value && length($value) ) {
$value = '""';
} elsif ($value =~ /[^A-Za-z0-9_]/){
$value =~ s/\t/\\t/g; $value =~ s/\n/\\n/g; $value = '"' . $value . '" ';
} push @v, $value;
}
if (($tag eq 'Group') || ($tag eq 'Target')){ push @firstgroup, "$tag ".join(" ", @v);
} else {
push @group, "$tag ".join(" ", @v);
}
}
}
$str2 = join(' ; ', (@firstgroup, @group));
if( ! $feat->has_tag('Target') && ! $feat->has_tag('Group') &&
$origfeat->isa('Bio::SeqFeature::FeaturePair') ) {
$str2 = sprintf("Target %s ; tstart %d ; tend %d", $origfeat->feature1->seq_id,
( $origfeat->feature1->strand < 0 ?
( $origfeat->feature1->end,
$origfeat->feature1->start) :
( $origfeat->feature1->start,
$origfeat->feature1->end)
)) . ($str2?" ; ".$str2:""); }
return $str1 . "\t". $str2;} |
sub _gff3_string
{ my ($gff, $origfeat) = @_;
my $feat;
if ($origfeat->isa('Bio::SeqFeature::FeaturePair')){
$feat = $origfeat->feature2;
} else {
$feat = $origfeat;
}
my $ID = $gff->_incrementGFF3ID();
my ($score,$frame,$name,$strand);
if( $feat->can('score') ) {
$score = $feat->score();
}
$score = '.' unless defined $score;
if( $feat->can('frame') ) {
$frame = $feat->frame();
}
$frame = '.' unless defined $frame;
$strand = $feat->strand();
if(! $strand) {
$strand = ".";
} elsif( $strand == 1 ) {
$strand = '+';
} elsif ( $feat->strand == -1 ) {
$strand = '-';
}
if( $feat->can('seqname') ) {
$name = $feat->seq_id();
$name ||= 'SEQ';
} else {
$name = 'SEQ';
}
my @groups;
my @all_tags = grep { ! exists $GFF3_ID_Tags{$_} } $feat->all_tags;
for my $t ( sort { $GFF3_ID_Tags{$b} <=> $GFF3_ID_Tags{$a} }
keys %GFF3_ID_Tags ) {
unshift @all_tags, $t if $feat->has_tag($t);
}
for my $tag ( @all_tags ) {
if ($tag eq 'Target' && ! $origfeat->isa('Bio::SeqFeature::FeaturePair')){
my($target_id, $b,$e,$strand) = $feat->get_tag_values($tag);
next unless(defined($e) && defined($b) && $target_id);
($b,$e)= ($e,$b) if(defined $strand && $strand<0);
$target_id =~ s/([\t\n\r%&\=;,])/sprintf("%%%X",ord($1))/ge;
push @groups, sprintf("Target=%s %d %d", $target_id,$b,$e);
next;
}
my $valuestr;
my @v;
for my $value ( $feat->each_tag_value($tag) ) {
if( defined $value && length($value) ) {
if ( ref $value eq 'Bio::Annotation::Comment') {
$value = $value->text;
}
if ($value =~ /[^a-zA-Z0-9\,\;\=\.:\%\^\*\$\@\!\+\_\?\-]/) {
$value =~ s/\t/\\t/g; $value =~ s/\n/\\n/g;
}
$value =~ s/([\t\n\r%&\=;,])/sprintf("%%%X",ord($1))/ge;
} else {
$value = '""';
}
push @v, $value;
}
$tag= lcfirst($tag) unless ($tag
=~ /^(ID|Name|Alias|Parent|Gap|Target|Derives_from|Note|Dbxref|Ontology_term)$/);
push @groups, "$tag=".join(",",@v);
}
if( $feat->has_tag('Target') &&
! $feat->has_tag('Group') &&
$origfeat->isa('Bio::SeqFeature::FeaturePair') ) {
my $target_id = $origfeat->feature1->seq_id;
$target_id =~ s/([\t\n\r%&\=;,])/sprintf("%%%X",ord($1))/ge;
push @groups, sprintf("Target=%s %d %d",
$target_id,
( $origfeat->feature1->strand < 0 ?
( $origfeat->feature1->end,
$origfeat->feature1->start) :
( $origfeat->feature1->start,
$origfeat->feature1->end)
));
}
if ( $feat->can('name') && defined($feat->name) ) {
unshift @groups, 'Name=' . $feat->name;
}
my $gff_string = "";
if ($feat->location->isa("Bio::Location::SplitLocationI")) {
my @locs = $feat->location->each_Location;
foreach my $loc (@locs) {
$gff_string .= join("\t",
$name,
$feat->source_tag() || '.',
$feat->primary_tag(),
$loc->start(),
$loc->end(),
$score,
$strand,
$frame,
join(';', @groups)) . "\n";
}
chop $gff_string;
return $gff_string;
} else {
$gff_string = join("\t",
$name,
$feat->source_tag() || '.',
$feat->primary_tag(),
$feat->start(),
$feat->end(),
$score,
$strand,
$frame,
join(';', @groups));
}
return $gff_string;} |
sub gff_version
{ my ($self, $value) = @_;
if(defined $value && grep {$value == $_ } ( 1, 2, 2.5, 3)) {
$self->{'GFF_VERSION'} = $value;
}
return $self->{'GFF_VERSION'};
}
} |
sub newFh
{ my $class = shift;
return unless my $self = $class->new(@_);
return $self->fh;} |
sub fh
{ my $self = shift;
my $class = ref($self) || $self;
my $s = Symbol::gensym;
tie $$s,$class,$self;
return $s;
}
} |
sub _seq_by_id_h
{ my $self = shift;
return $self->{'_seq_by_id_h'} = shift if @_;
$self->{'_seq_by_id_h'} = {}
unless $self->{'_seq_by_id_h'};
return $self->{'_seq_by_id_h'};} |
sub get_seqs
{ my ($self,@args) = @_;
return values %{$self->_seq_by_id_h};} |
sub features_attached_to_seqs
{ my $self = shift;
return $self->{'_features_attached_to_seqs'} = shift if @_;
return $self->{'_features_attached_to_seqs'};} |
sub ignore_sequence
{ my $self = shift;
return $self->{'_ignore_sequence'} = shift if @_;
return $self->{'_ignore_sequence'};} |
sub DESTROY
{ my $self = shift;
$self->close();} |
sub TIEHANDLE
{ my ($class,$val) = @_;
return bless {'gffio' => $val}, $class;} |
sub READLINE
{ my $self = shift;
return $self->{'gffio'}->next_feature() unless wantarray;
my (@list, $obj);
push @list, $obj while $obj = $self->{'gffio'}->next_feature();
return @list;} |
sub PRINT
{ my $self = shift;
$self->{'gffio'}->write_feature(@_);
}
1;} |
General documentation
| GFF3 AND SEQUENCE DATA | Top |
GFF3 supports sequence data; see
http://www.sequenceontology.org/gff3.shtmlThere are a number of ways to deal with this -
If you call
$gffio->ignore_sequence(1)
prior to parsing the sequence data is ignored; this is useful if you
just want the features. It avoids the memory overhead in building and
caching sequences
Alternatively, you can call either
$gffio->get_seqs()
Or
$gffio->seq_id_by_h()
At the
end of parsing to get either a list or hashref of Bio::Seq
objects (see the documentation for each of these methods)
Note that these objects will not have the features attached - you have
to do this yourself, OR call
$gffio->features_attached_to_seqs(1)
PRIOR to parsing; this will ensure that the Seqs have the features
attached; ie you will then be able to call
$seq->get_SeqFeatures();
And use Bio::SeqIO methods
Note that auto-attaching the features to seqs will incur a higher
memory overhead as the features must be cached until the sequence data
is found
Make a Bio::SeqIO class specifically for GFF3 with sequence data
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://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 the web:
http://bugzilla.open-bio.org/
| AUTHOR - Matthew Pocock | Top |
Email mrp-at-sanger.ac.uk
Jason Stajich, jason-at-biperl-dot-org
Chris Mungall, cjm-at-fruitfly-dot-org
Steffen Grossmann [SG], grossman at molgen.mpg.de
Malcolm Cook, mec-at-stowers-institute.org
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _