Bio::FeatureIO(3pm)
NAME π
okay bestie, gather round, because this is the manual page for Bio::FeatureIO(3pm) β the handler for FeatureIO, and honestly? it's iconic. it's the officially sanctioned way to get at all the FeatureIO format modules, and yes, you're gonna want to use it. π
β¨ SYNOPSIS β¨
like, here's the whole vibe in one go:
use Bio::FeatureIO;
#read from a file
$in = Bio::FeatureIO->new(-file => "my.gff" , -format => 'GFF');
#read from a filehandle
$in = Bio::FeatureIO->new(-fh => \*GFF , -format => 'GFF');
#read features already attached to a sequence
my $feat = Bio::FeatureIO->new(-seq => $seq , -format => 'features');
#read new features for existing sequence
my $seq = Bio::FeatureIO->new(-seq => $seq , -format => 'Das');
#write out features
$out = Bio::FeatureIO->new(-file => ">outputfilename" ,
-format => 'GFF' ,
-version => 3);
while ( my $feature = $in->next_feature() ) {
$out->write_feature($feature);
}
no cap, that loop right there is the entire plot of your bioinformatics pipeline. π
πΈ DESCRIPTION πΈ
so Bio::FeatureIO is an I/O iterator subsystem for genomic sequence features. it's the handler module for all the formats in the FeatureIO set (think Bio::FeatureIO::GFF and friends), and it is the officially sanctioned way of getting at the format objects β which, bestie, means it's what most people should be using. periodt.
the way to think about the whole Bio::FeatureIO system is like biological filehandles. they get attached to filehandles with smart formatting rules (GFF format, BED format, you know the drill), and they can either read or write feature objects β that's Bio::SeqFeature objects, or more correctly, objects implementing Bio::FeatureHolderI, of which Bio::SeqFeature is one such object. and if you wanna know what to do with a Bio::SeqFeatureI object, go read Bio::SeqFeatureI. iykyk. π
the idea is that you request a stream object for a particular format. every stream object has a notion of an internal file that gets read from or written to. a particular FeatureIO object instance is configured for either input or output. a specific example of a stream object is the Bio::FeatureIO::gff object. slay.
each stream object has these functions:
$stream->next_feature();
$stream->write_feature($feature);
π¦ SUPPORTED FORMATS π¦
here's the lineup, name and module, no gatekeeping:
BEDβbed.pmGFFβgff.pmGTFβgtf.pmInterPro (IPRScan 4.0)βinterpro.pmPTT (NCBI protein table)βptt.pm
π CONSTRUCTORS π
π Bio::FeatureIO->new()
$featureIO = Bio::FeatureIO->new(-file => 'filename', -format=>$format);
$featureIO = Bio::FeatureIO->new(-fh => \*FILEHANDLE, -format=>$format);
$featureIO = Bio::FeatureIO->new(-seq => $seq, -format=>$format);
the new() class method constructs a new Bio::FeatureIO object. the returned object can be used to retrieve or print Seq objects. new() accepts the following parameters:
π -file
a file path to be opened for reading or writing. the usual Perl conventions apply, and yes they go hard:
'file' # open file for reading
'>file' # open file for writing
'>>file' # open file for appending
'+<file' # open file read/write
'command |' # open a pipe from the command
'| command' # open a pipe to the command
π -fh
you may provide new() with a previously-opened filehandle. for example, to read from STDIN:
$featio = Bio::FeatureIO->new(-fh => \*STDIN);
note: you must pass filehandles as references to globs. no exceptions bestie.
if neither a filehandle nor a filename is specified, then the module will read from the @ARGV array or STDIN, using the familiar <> semantics. very demure, very mindful.
a string filehandle is handy if you want to modify the output in the memory, before printing it out. the following program reads in EMBL formatted entries from a file and prints them out in fasta format with some HTML tags (yes, really, and we're reproducing it exactly as it is, don't come for me):
use Bio::FeatureIO;
use IO::String;
my $in = Bio::FeatureIO->new('-file' => "my.gff" ,
'-format' => 'EMBL');
while ( my $f = $in->next_feature() ) {
# the output handle is reset for every file
my $stringio = IO::String->new($string);
my $out = Bio::FeatureIO->new('-fh' => $stringio,
'-format' => 'gtf');
# output goes into $string
$out->write_feature($f);
# modify $string
$string =~ s|(>)(\w+)|$1<font color="Red">$2</font>|g;
# print into STDOUT
print $string;
}
π§ -format
specify the format of the file. see above for the list of supported formats. β¨
π -flush
by default, all files (or filehandles) opened for writing sequences will be flushed after each write_seq() (which makes the file immediately usable). if you don't need this facility and would like to marginally improve the efficiency of writing multiple sequences to the same file (or filehandle), pass the -flush option '0' or any other value that evaluates as defined but false:
my $f1 = Bio::FeatureIO->new -file => "<a.f1",
-format => "f1";
my $f2 = Bio::FeatureIO->new -file => ">a.f2",
-format => "f2",
-flush => 0; # go as fast as we can!
while($feature = $f1->next_feature) { $f2->write_feature($feature) }
π Bio::FeatureIO->newFh()
$fh = Bio::FeatureIO->newFh(-fh => \*FILEHANDLE, -format=>$format);
$fh = Bio::FeatureIO->newFh(-format => $format);
# etc.
this constructor behaves like new(), but returns a tied filehandle rather than a Bio::FeatureIO object. you can read sequences from this object using the familiar <> operator, and write to it using print(). the usual array and $_ semantics work. for example, you can read all sequence objects into an array like this:
@features = <$fh>;
other operations, such as read(), sysread(), write(), close(), and printf() are not supported. sorry babe, those just aren't on the menu. π
π OBJECT METHODS π
see below for more detailed summaries. the main methods are:
next_featureβ fetch the next feature from the stream.write_featureβ write the specified feature(s) to the stream.feature_factoryβ this gets/sets the specificBio::Factory::FeatureFactoryI
the following methods delegate to the inter
yeah bestie it literally just ends there in the original, mid-sentence, the sentence said "the inter" and dipped π keeping it verbatim because facts are facts.
feature_classβ set the specificBio::SeqFeatureIclass to returntype_featuresβ boolean flag, ensures the returned features are typedunflatten_featuresβ ensure the returned features are unflattened
β TIEHANDLE(), READLINE(), PRINT()
these provide the tie interface. see perltie for more details. π
π«Ά FEEDBACK π«Ά
π Mailing Lists
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. fr fr. π₯Ή
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
π Support
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. the more detail the better, bestie. π«‘
π Reporting Bugs
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.open-bio.org/
π AUTHOR - Allen Day π
email allenday@ucla.edu
to be continued, bestie β part 2 is coming and we are not done yet πβ¨
π APPENDIX π
The rest of the docs spill all the tea on each object method. Internal methods are usually preceded with a _, so if you see one, just know it's private-ish. π«Ά
new β¨
- Title: new
- Usage:
$stream = Bio::FeatureIO->new(-file => $filename, -format => 'Format') - Function: hands you back a brand-new feature stream, all set up in whatever format you asked for. π
- Returns: a Bio::FeatureIO stream, initialized with the appropriate format.
- Args: named parameters, bestie:
-file => $filename-fh => filehandle to attach to-format => format
newFh πΈ
- Title: newFh
- Usage:
$fh = Bio::FeatureIO->newFh(-file=>$filename,-format=>'Format') - Function: literally does a
new()followed by anfh(). Two steps, one vibe. β¨ - Example:
$fh = Bio::FeatureIO->newFh(-file=>$filename,-format=>'Format')
$feature = <$fh>; # read a feature object
print $fh $feature; # write a feature object
- Returns: a filehandle tied to the
Bio::FeatureIO::Fhclass. - Args:
See Bio::FeatureIO::Fh
fh π
- 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: a filehandle tied to the
Bio::FeatureIOclass. - Args: none
next_feature π₯
- Title: next_feature
- Usage:
$feature = stream->next_feature - Function: reads the next feature object from the stream and returns it.
Okay but listen: certain driver modules may encounter entries in the stream that are either misformatted or that use syntax not yet understood by the driver. If that kind of incident is recoverable β like by dismissing a feature of a feature table or some other non-mandatory part of an entry β the driver will issue a warning. In the case of a non-recoverable situation, an exception will be thrown. And bestie, do not assume you can resume parsing the same stream after catching that exception. Also note: you can always turn recoverable errors into exceptions by calling $stream->verbose(2). π
- Returns: a
Bio::SeqFeatureIfeature object. - Args: none
SeeBio::Root::RootI,Bio::SeqFeatureI
write_feature π
- Title: write_feature
- Usage:
$stream->write_feature($feature) - Function: writes the
$featureobject into the stream. - Returns:
1for success and0for error. - Args:
Bio::SeqFeatureobject
_load_format_module π§
- Title: _load_format_module
- Usage:
*INTERNAL FeatureIO stuff* - Function: loads up (like
use) a module at run time on demand. - Example:
- Returns:
- Args:
seq π¦
- Title: seq
- Usage:
$obj->seq() OR $obj->seq($newSeq) - Example:
- Returns:
Bio::SeqIobject - Args:
newSeq(optional)
_filehandle π
- Title: _filehandle
- Usage:
$obj->_filehandle($newval) - Function: This method is deprecated. Call
_fh()instead. π« - Example:
- Returns: value of
_filehandle - Args:
newvalue(optional)
_guess_format π
- Title: _guess_format
- Usage:
$obj->_guess_format($filename) - Function: guesses format based on file suffix.
- Example:
- Returns: guessed format of filename (lower case)
- Args:
- Notes: See
"SUPPORTED FORMATS"
This page is from perl v5.30.0, dated 2020-01-13, and it's Bio::FeatureIO(3pm) β bye bestie, go parse something iconic! π β¨
π¦ where this page comes from
- debian bookworm: libbio-featureio-perl 1.6.905-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libbio-featureio-perl 1.6.905-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libbio-featureio-perl 1.6.905-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libbio-featureio-perl 1.6.905-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms