NAME

Bio::Gonzales::Feat::IO::GFF3 - read and write gff files

SYNOPSIS

  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;

DESCRIPTION

OPTIONS

mode => $mode

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').

fh => $fh

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;
file => $file

read from or write to the file $file

escape_whitespace => 1

Usually, only whitespaces in the Target attribute are escaped. If this feature is turned on, whitespace in all attribute values will be escaped.

record_filter => sub { ... }

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;

METHODS

$gffio->write_feat($feat)

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.

my $feat = $gffio->next_feat()

Retrieve the next feature, if in reading mode.

$gffio->segments
$gffio->pragmas
$gffio->preprocess(\&process)

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.

Example sub: sub process { my @cols = @_;

        $cols[1] = "createdbyme";
        return @cols;
    }
$gffio->comments

SEE ALSO

AUTHOR

jw bargsten, <joachim.bargsten at wur.nl>