Bio::DB::Flat::OBDAIndex - Binary search indexing system for sequence files This module can be used both to index sequence files and also to retrieve sequences from existing sequence files.
Index creation
my $sequencefile; # Some fasta sequence file
Patterns have to be entered to define where the keys are to be indexed and also where the start of each record. E.g. for fasta
my $start_pattern = "^>";my $primary_pattern = "^>(\\S+)";
So the start of a record is a line starting with a > and the primary key is all characters up to the first space afterf the > A string also has to be entered to defined what the primary key (primary_namespace) is called. The index can now be created using
my $index = new Bio::DB::Flat::OBDAIndex(-start_pattern => $start_pattern,-primary_pattern => $primary_pattern,-primary_namespace => "ACC",);
To actually write it out to disk we need to enter a directory where the indices will live, a database name and an array of sequence files to index.
my @files = ("file1","file2","file3");
$index->make_index("/Users/michele/indices","mydatabase",@files);
The index is now ready to use. For large sequence files the perl way of indexing takes a *long* time and a *huge* amount of memory. For indexing things like dbEST I recommend using the C indexer.
Creating indices with secondary keys Sometimes just indexing files with one id per entry is not enough. For instance you may want to retrieve sequences from swissprot using their accessions as well as their ids. To be able to do this when creating your index you need to pass in a hash of secondary_patterns which have their namespaces as the keys to the hash. e.g. For Indexing something like ID 1433_CAEEL STANDARD; PRT; 248 AA. AC P41932; DT 01-NOV-1995 (Rel. 32, Created) DT 01-NOV-1995 (Rel. 32, Last sequence update) DT 15-DEC-1998 (Rel. 37, Last annotation update) DE 14-3-3-LIKE PROTEIN 1. GN FTT-1 OR M117.2. OS Caenorhabditis elegans. OC Eukaryota; Metazoa; Nematoda; Chromadorea; Rhabditida; Rhabditoidea; OC Rhabditidae; Peloderinae; Caenorhabditis. OX NCBI_TaxID=6239; RN [1] where we want to index the accession (P41932) as the primary key and the id (1433_CAEEL) as the secondary id. The index is created as follows
my %secondary_patterns;
my $start_pattern = "^ID (\\S+)";my $primary_pattern = "^AC (\\S+)\;";
$secondary_patterns{"ID"} = "^ID (\\S+)";
my $index = new Bio::DB::Flat::OBDAIndex(-start_pattern => $start_pattern,-primary_pattern => $primary_pattern,-primary_namespace => 'ACC',-secondary_patterns => \%secondary_patterns);
$index->make_index("/Users/michele/indices","mydb",($seqfile));
Of course having secondary indices makes indexing slower and more of a memory hog.
Index reading To fetch sequences using an existing index first of all create your sequence object
my $index = new Bio::DB::Flat::OBDAIndex(-index_dir => $index_directory,-dbname => 'swissprot');
Now you can happily fetch sequences either by the primary key or by the secondary keys.
my $entry = $index->get_entry_by_id('HBA_HUMAN');
This returns just a string containing the whole entry. This is useful is you just want to print the sequence to screen or write it to a file. Other ways of getting sequences are
my $fh = $index->get_stream_by_id('HBA_HUMAN');
This can then be passed to a seqio object for output or converting into objects.
my $seq = new Bio::SeqIO(-fh => $fh,-format => 'fasta');
The last way is to retrieve a sequence directly. This is the slowest way of extracting as the sequence objects need to be made.
my $seq = $index->get_Seq_by_id('HBA_HUMAN');
To access the secondary indices the secondary namespace needs to be known (use $index->secondary_namespaces) and the following call used
my $seq = $index->get_Seq_by_secondary('ACC','Q21973');my $fh = $index->get_stream_by_secondary('ACC','Q21973');my $entry = $index->get_entry_by_secondary('ACC','Q21973');
This object allows indexing of sequence files both by a primary key (say accession) and multiple secondary keys (say ids). This is different from the Bio::Index::Abstract (see Bio::Index::Abstract) which uses DBM files as storage. This module uses a binary search to retrieve sequences which is more efficient for large datasets.
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.
[email protected] - General discussionhttp://bioperl.org/MailList.shtml - About the mailing lists
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 email or the web:
[email protected]http://bio.perl.org/bioperl-bugs/
Email - [email protected] The rest of the documentation details each of the object methods. Internal methods are usually preceded with an "_" (underscore).
new
Title : newUsage : For readingmy $index = new Bio::DB::Flat::OBDAIndex(-index_dir => '/Users/michele/indices/',-dbname => 'dbEST',-format => 'fasta');
For writing
my %secondary_patterns = {"ACC" => "^>\\S+ +(\\S+)"}my $index = new Bio::DB::Flat::OBDAIndex(-index_dir => '/Users/michele/indices',-primary_pattern => "^>(\\S+)",-secondary_patterns => \%secondary_patterns,-primary_namespace => "ID");
my @files = ('file1','file2','file3');
$index->make_index('mydbname',@files);
Function: create a new Bio::DB::Flat::OBDAIndex objectReturns : new Bio::DB::Flat::OBDAIndexArgs : -index_dir Directory containing the indices-primary_pattern Regexp defining the primary id-secondary_patterns A hash ref containing the secondarypatterns with the namespaces as keys-primary_namespace A string defining what the primary keyis
Status : Public
get_Seq_by_id
Title : get_Seq_by_idUsage : $obj->get_Seq_by_id($newval)Function:Example :Returns : value of get_Seq_by_idArgs : newvalue (optional)
get_entry_by_id
Title : get_entry_by_idUsage : $obj->get_entry_by_id($newval)Function:Example :Returns :Args :
get_stream_by_id
Title : get_stream_by_idUsage : $obj->get_stream_by_id($newval)Function:Example :Returns : value of get_stream_by_idArgs : newvalue (optional)
get_Seq_by_acc
Title : get_Seq_by_accUsage : $obj->get_Seq_by_acc($newval)Function:Example :Returns : value of get_Seq_by_accArgs : newvalue (optional)
get_Seq_by_secondary
Title : get_Seq_by_secondaryUsage : $obj->get_Seq_by_secondary($newval)Function:Example :Returns : value of get_Seq_by_secondaryArgs : newvalue (optional)
read_header
Title : read_headerUsage : $obj->read_header($newval)Function:Example :Returns : value of read_headerArgs : newvalue (optional)
read_record
Title : read_recordUsage : $obj->read_record($newval)Function:Example :Returns : value of read_recordArgs : newvalue (optional)
find_entry
Title : find_entryUsage : $obj->find_entry($newval)Function:Example :Returns : value of find_entryArgs : newvalue (optional)
make_index
Title : make_indexUsage : $obj->make_index($newval)Function:Example :Returns : value of make_indexArgs : newvalue (optional)
_index_file
Title : _index_fileUsage : $obj->_index_file($newval)Function:Example :Returns : value of _index_fileArgs : newvalue (optional)
write_primary_index
Title : write_primary_indexUsage : $obj->write_primary_index($newval)Function:Example :Returns : value of write_primary_indexArgs : newvalue (optional)
write_secondary_indices
Title : write_secondary_indicesUsage : $obj->write_secondary_indices($newval)Function:Example :Returns : value of write_secondary_indicesArgs : newvalue (optional)
new_secondary_filehandle
Title : new_secondary_filehandleUsage : $obj->new_secondary_filehandle($newval)Function:Example :Returns : value of new_secondary_filehandleArgs : newvalue (optional)
open_secondary_index
Title : open_secondary_indexUsage : $obj->open_secondary_index($newval)Function:Example :Returns : value of open_secondary_indexArgs : newvalue (optional)
_add_id_position
Title : _add_id_positionUsage : $obj->_add_id_position($newval)Function:Example :Returns : value of _add_id_positionArgs : newvalue (optional)
make_indexdir
Title : make_indexdirUsage : $obj->make_indexdir($newval)Function:Example :Returns : value of make_indexdirArgs : newvalue (optional)
make_config_file
Title : make_config_fileUsage : $obj->make_config_file($newval)Function:Example :Returns : value of make_config_fileArgs : newvalue (optional)
read_config_file
Title : read_config_fileUsage : $obj->read_config_file($newval)Function:Example :Returns : value of read_config_fileArgs : newvalue (optional)
get_fileid_by_filename
Title : get_fileid_by_filenameUsage : $obj->get_fileid_by_filename($newval)Function:Example :Returns : value of get_fileid_by_filenameArgs : newvalue (optional)
get_filehandle_by_fileid
Title : get_filehandle_by_fileidUsage : $obj->get_filehandle_by_fileid($newval)Function:Example :Returns : value of get_filehandle_by_fileidArgs : newvalue (optional)
primary_index_file
Title : primary_index_fileUsage : $obj->primary_index_file($newval)Function:Example :Returns : value of primary_index_fileArgs : newvalue (optional)
primary_index_filehandle
Title : primary_index_filehandleUsage : $obj->primary_index_filehandle($newval)Function:Example :Returns : value of primary_index_filehandleArgs : newvalue (optional)
database_name
Title : database_nameUsage : $obj->database_name($newval)Function:Example :Returns : value of database_nameArgs : newvalue (optional)
format
Title : formatUsage : $obj->format($newval)Function:Example :Returns : value of formatArgs : newvalue (optional)
index_directory
Title : index_directoryUsage : $obj->index_directory($newval)Function:Example :Returns : value of index_directoryArgs : newvalue (optional)
record_size
Title : record_sizeUsage : $obj->record_size($newval)Function:Example :Returns : value of record_sizeArgs : newvalue (optional)
primary_namespace
Title : primary_namespaceUsage : $obj->primary_namespace($newval)Function:Example :Returns : value of primary_namespaceArgs : newvalue (optional)
index_type
Title : index_typeUsage : $obj->index_type($newval)Function:Example :Returns : value of index_typeArgs : newvalue (optional)
index_version
Title : index_versionUsage : $obj->index_version($newval)Function:Example :Returns : value of index_versionArgs : newvalue (optional)
primary_pattern
Title : primary_patternUsage : $obj->primary_pattern($newval)Function:Example :Returns : value of primary_patternArgs : newvalue (optional)
secondary_patterns
Title : secondary_patternsUsage : $obj->secondary_patterns($newval)Function:Example :Returns : value of secondary_patternsArgs : newvalue (optional)
secondary_namespaces
Title : secondary_namespacesUsage : $obj->secondary_namespaces($newval)Function:Example :Returns : value of secondary_namespacesArgs : newvalue (optional)