Bio::Gonzales::Feat::IO::GFF3 - read and write gff files
use Bio::Gonzales::Feat::IO::GFF3; my $output = Bio::Gonzales::Feat::IO::GFF3->new( file => 'a.gff', mode => '>', escape_whitespace => 1 ); my $gffin = Bio::Gonzales::Feat::IO::GFF3->new( file => 'a.gff' ); # gzipped files can be read directly. my $gffin = Bio::Gonzales::Feat::IO::GFF3->new( file => 'a.gff.gz' ); my $gffin = Bio::Gonzales::Feat::IO::GFF3->new('a.gff'); while ( my $feat = $gffin->next_feat ) { # $feat is a Bio::Gonzales::Feat next if ( $feat->type ne 'mRNA' ); say STDERR $feat->id . " - " . $feat->parent_id; } $gffin->close;
Bio::Gonzales::Feat::IO::GFF3 supports 3 different modes,
Bio::Gonzales::Feat::IO::GFF3->new(mode => '>', ...); #output Bio::Gonzales::Feat::IO::GFF3->new(mode => '<', ...); #input, DEFAULT Bio::Gonzales::Feat::IO::GFF3->new(mode => '>>', ...); #append
all modes also work with gzipped files (ending on '.gz').
Bio::Gonzales::Feat::IO::GFF3 uses $fh to read or write data.
open my $fh, '<', 'file.gff3' or confess "Can't open filehandle: $!"; my $gff = Bio::Gonzales::Feat::IO::GFF3->new(fh => $fh, ...); # ... do something ... $gff->close; close $fh;
read from or write to the file $file
$file
Usually, only whitespaces in the Target attribute are escaped. If this feature is turned on, whitespace in all attribute values will be escaped.
Target
Before reading in the GFF3 information, filter the raw line content according to the supplied function. This functionality is handy for big gff3 files where only a part of the output should be parsed.
Example:
my $sub = sub { my $line = shift; return $line =~ /\tmRNA\t/; }; my $gff = Bio::Gonzales::Feat::IO::GFF3->new( file => '...', mode => '<', record_filter => $sub ); # ... only lines with the type 'mRNA' will be parsed ... $gff->close;
Write the feature to the output. Do not forget to call $gffio-close> at the end of the processing, otherwise you probably end up writing only half of the features.
$gffio-
Retrieve the next feature, if in reading mode.
Change the gff input before the feature object gets instantiated. Arguments of the &process sub are the nine columns of the gff file split into an array.
&process
Example sub: sub process { my @cols = @_;
$cols[1] = "createdbyme"; return @cols; }
jw bargsten, <joachim.bargsten at wur.nl>
<joachim.bargsten at wur.nl>
To install Bio::Gonzales, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bio::Gonzales
CPAN shell
perl -MCPAN -e shell install Bio::Gonzales
For more information on module installation, please visit the detailed CPAN module installation guide.