Fasta - Fasta index utilities.
use Index::Fasta;
This package is used to index Fasta format file. It indexes the sequence id name (see below '>(...)').
# examples here use Index::Fasta;
my($res, $msg, $index); ($res, $index) = new Index::Fasta($file); #Fasta file to index die $index unless $res;
($res, $msg) = $index->setRecDel('dumper', '\n'); die($msg) unless($res);
($res, $r_inx) = $index->buildIndex(['ac', 'name']); #list of entries you want to index. $regexp in this module for allowing rules. die($r_inx) unless($res); #if no argument given, will build the index with all the rules describe in $regexp.
#or you can build the index on your own key-value pairs based on regular expression. Only the first match is taken into account. #so if you want to index multiple things based on the same line, you need to create another key-value pair. ($res, $r_inx) = $index->builIndex({ 'id' => '>(\S+)', 'name' => '^\s+\w+\s+(\S+)' }); die $r_inx unless $res;
($res, $mess) = $index->indexOut($r_inx); #need a reference to hash table. die $mess unless $res;
my $id = 'PS50885'; my ($res, $pos) = $index->getIndex($id); #return the position in the file for this $id. die $pos unless $res;
#getEntry returns a reference to an array in case of multiple entries found. my ($res, $entry) = $index->getEntry($id); #return the complete entry. die $entry unless $res; $entry = $entry->[0] if($entry);
#Either (parsing once the whole entry) my($res, $msg) = $index->parseFields(\$entry); die $msg unless $res;
my ($res, $name) = $index->getField('name'); #return the name of this entry. $name = $name->[0] if $name; my ($res, $name) = $index->getField(['ac', 'name', 'desc']); #return the ac, name and description of this entry. if($name){ my $nm = $name->[0]; my $ac = $name->[1]; my $de = $name->[2]; }
.... # see below for fields you can retrieve. my ($res, $name) = $index->get_name(); #return the name of this entry. $name = $name->[0] if $name; #or simplier my ($res, $name) = $index->getField('name', \$entry); #return the name of this entry by parsing it on the fly $name = $name->[0] if $name;
$Id: Fasta.pm.html,v 1.1.1.1 2005/08/18 13:18:25 hunter Exp $
Copyright (c) European Bioinformatics Institute 2002
Emmanuel Quevillon <tuco@ebi.ac.uk>
Description: Create a new object Index.
Arguments: $in a file to index, optional $tool Do you want to use Dispatcher::Tool to index.conf values? (optional)
Returns: 1, $self on success 0, msg on failure
Description: Initialize record delimiter, file and parse configuration file from index configuration file. Argument: Returns: 1, '' on success 0, msg on error