.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Bio::DB::Flat::BinarySearch 3pm" .TH Bio::DB::Flat::BinarySearch 3pm "2021-08-15" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Bio::DB::Flat::BinarySearch \- BinarySearch search indexing system for sequence files .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& TODO: SYNOPSIS NEEDED! .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module can be used both to index sequence files and also to retrieve sequences from existing sequence files. .PP 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 \s-1DBM\s0 files as storage. This module uses a binary search to retrieve sequences which is more efficient for large datasets. .SS "Index creation" .IX Subsection "Index creation" .Vb 1 \& my $sequencefile; # Some fasta sequence file .Ve .PP 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 .PP .Vb 2 \& my $start_pattern = \*(Aq^>\*(Aq; \& my $primary_pattern = \*(Aq^>(\eS+)\*(Aq; .Ve .PP So the start of a record is a line starting with a > and the primary key is all characters up to the first space after the > .PP A string also has to be entered to defined what the primary key (primary_namespace) is called. .PP The index can now be created using .PP .Vb 7 \& my $index = Bio::DB::Flat::BinarySearch\->new( \& \-directory => "/home/max/", \& \-dbname => "mydb", \& \-start_pattern => $start_pattern, \& \-primary_pattern => $primary_pattern, \& \-primary_namespace => "ID", \& \-format => "fasta" ); \& \& my @files = ("file1","file2","file3"); \& \& $index\->build_index(@files); .Ve .PP 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 DB_File indexer, \s-1BDB.\s0 .PP The formats currently supported by this module are fasta, Swissprot, and \s-1EMBL.\s0 .SS "Creating indices with secondary keys" .IX Subsection "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. .PP 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. .PP e.g. For Indexing something like .PP \&\s-1ID\s0 1433_CAEEL \s-1STANDARD\s0; \s-1PRT\s0; 248 \s-1AA. AC\s0 P41932; \&\s-1DT\s0 01\-NOV\-1995 (Rel. 32, Created) \&\s-1DT\s0 01\-NOV\-1995 (Rel. 32, Last sequence update) \&\s-1DT\s0 15\-DEC\-1998 (Rel. 37, Last annotation update) \&\s-1DE\s0 14\-3\-3\-LIKE \s-1PROTEIN 1. GN\s0 \s-1FTT\-1 OR M117.2. OS\s0 Caenorhabditis elegans. \&\s-1OC\s0 Eukaryota; Metazoa; Nematoda; Chromadorea; Rhabditida; Rhabditoidea; \&\s-1OC\s0 Rhabditidae; Peloderinae; Caenorhabditis. \&\s-1OX\s0 NCBI_TaxID=6239; \&\s-1RN\s0 [1] .PP 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 .PP .Vb 1 \& my %secondary_patterns; \& \& my $start_pattern = \*(Aq^ID (\eS+)\*(Aq; \& my $primary_pattern = \*(Aq^AC (\eS+)\e;\*(Aq; \& \& $secondary_patterns{"ID"} = \*(Aq^ID (\eS+)\*(Aq; \& \& my $index = Bio::DB::Flat::BinarySearch\->new( \& \-directory => $index_directory, \& \-dbname => "ppp", \& \-write_flag => 1, \& \-verbose => 1, \& \-start_pattern => $start_pattern, \& \-primary_pattern => $primary_pattern, \& \-primary_namespace => \*(AqAC\*(Aq, \& \-secondary_patterns => \e%secondary_patterns); \& \& $index\->build_index($seqfile); .Ve .PP Of course having secondary indices makes indexing slower and use more memory. .SS "Index reading" .IX Subsection "Index reading" To fetch sequences using an existing index first of all create your sequence object .PP .Vb 2 \& my $index = Bio::DB::Flat::BinarySearch\->new( \& \-directory => $index_directory); .Ve .PP Now you can happily fetch sequences either by the primary key or by the secondary keys. .PP .Vb 1 \& my $entry = $index\->get_entry_by_id(\*(AqHBA_HUMAN\*(Aq); .Ve .PP 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. .PP Other ways of getting sequences are .PP .Vb 1 \& my $fh = $index\->get_stream_by_id(\*(AqHBA_HUMAN\*(Aq); .Ve .PP This can then be passed to a seqio object for output or converting into objects. .PP .Vb 2 \& my $seq = Bio::SeqIO\->new(\-fh => $fh, \& \-format => \*(Aqfasta\*(Aq); .Ve .PP The last way is to retrieve a sequence directly. This is the slowest way of extracting as the sequence objects need to be made. .PP .Vb 1 \& my $seq = $index\->get_Seq_by_id(\*(AqHBA_HUMAN\*(Aq); .Ve .PP To access the secondary indices the secondary namespace needs to be known .PP .Vb 1 \& $index\->secondary_namespaces("ID"); .Ve .PP Then the following call can be used .PP .Vb 1 \& my $seq = $index\->get_Seq_by_secondary(\*(AqID\*(Aq,\*(Aq1433_CAEEL\*(Aq); .Ve .PP These calls are not yet implemented .PP .Vb 2 \& my $fh = $index\->get_stream_by_secondary(\*(AqID\*(Aq,\*(Aq1433_CAEEL\*(Aq); \& my $entry = $index\->get_entry_by_secondary(\*(AqID\*(Aq,\*(Aq1433_CAEEL\*(Aq); .Ve .SH "FEEDBACK" .IX Header "FEEDBACK" .SS "Mailing Lists" .IX Subsection "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. .PP .Vb 2 \& bioperl\-l@bioperl.org \- General discussion \& http://bioperl.org/wiki/Mailing_lists \- About the mailing lists .Ve .SS "Support" .IX Subsection "Support" Please direct usage questions or support issues to the mailing list: .PP \&\fIbioperl\-l@bioperl.org\fR .PP 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. .SS "Reporting Bugs" .IX Subsection "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: .PP .Vb 1 \& https://github.com/bioperl/bioperl\-live/issues .Ve .SH "AUTHOR \- Michele Clamp" .IX Header "AUTHOR - Michele Clamp" Email \- michele@sanger.ac.uk .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" Jason Stajich, jason@bioperl.org .SH "APPENDIX" .IX Header "APPENDIX" The rest of the documentation details each of the object methods. Internal methods are usually preceded with an \*(L"_\*(R" (underscore). .SS "new" .IX Subsection "new" .Vb 6 \& Title : new \& Usage : For reading \& my $index = Bio::DB::Flat::BinarySearch\->new( \& \-directory => \*(Aq/Users/michele/indices/dbest\*(Aq, \& \-dbname => \*(Aqmydb\*(Aq, \& \-format => \*(Aqfasta\*(Aq); \& \& For writing \& \& my %secondary_patterns = {"ACC" => "^>\e\eS+ +(\e\eS+)"} \& my $index = Bio::DB::Flat::BinarySearch\->new( \& \-directory => \*(Aq/Users/michele/indices\*(Aq, \& \-dbname => \*(Aqmydb\*(Aq, \& \-primary_pattern => "^>(\e\eS+)", \& \-secondary_patterns => \e%secondary_patterns, \& \-primary_namespace => "ID"); \& \& my @files = (\*(Aqfile1\*(Aq,\*(Aqfile2\*(Aq,\*(Aqfile3\*(Aq); \& \& $index\->build_index(@files); \& \& \& Function: create a new Bio::DB::Flat::BinarySearch object \& Returns : new Bio::DB::Flat::BinarySearch \& Args : \-directory Root directory for index files \& \-dbname Name of subdirectory containing indices \& for named database \& \-write_flag Allow building index \& \-primary_pattern Regexp defining the primary id \& \-secondary_patterns A hash ref containing the secondary \& patterns with the namespaces as keys \& \-primary_namespace A string defining what the primary key \& is \& \& Status : Public .Ve .SS "get_Seq_by_id" .IX Subsection "get_Seq_by_id" .Vb 6 \& Title : get_Seq_by_id \& Usage : $obj\->get_Seq_by_id($newval) \& Function: \& Example : \& Returns : value of get_Seq_by_id \& Args : newvalue (optional) .Ve .SS "get_entry_by_id" .IX Subsection "get_entry_by_id" .Vb 5 \& Title : get_entry_by_id \& Usage : $obj\->get_entry_by_id($newval) \& Function: Get a Bio::SeqI object for a unique ID \& Returns : Bio::SeqI \& Args : string .Ve .SS "get_stream_by_id" .IX Subsection "get_stream_by_id" .Vb 5 \& Title : get_stream_by_id \& Usage : $obj\->get_stream_by_id($id) \& Function: Gets a Sequence stream for an id \& Returns : Bio::SeqIO stream \& Args : Id to lookup by .Ve .SS "get_Seq_by_acc" .IX Subsection "get_Seq_by_acc" .Vb 5 \& Title : get_Seq_by_acc \& Usage : $obj\->get_Seq_by_acc($acc) \& Function: Gets a Bio::SeqI object by accession number \& Returns : Bio::SeqI object \& Args : string representing accession number .Ve .SS "get_Seq_by_version" .IX Subsection "get_Seq_by_version" .Vb 5 \& Title : get_Seq_by_version \& Usage : $obj\->get_Seq_by_version($version) \& Function: Gets a Bio::SeqI object by accession.version number \& Returns : Bio::SeqI object \& Args : string representing accession.version number .Ve .SS "get_Seq_by_secondary" .IX Subsection "get_Seq_by_secondary" .Vb 5 \& Title : get_Seq_by_secondary \& Usage : $obj\->get_Seq_by_secondary($namespace,$acc) \& Function: Gets a Bio::SeqI object looking up secondary accessions \& Returns : Bio::SeqI object \& Args : namespace name to check secondary namespace and an id .Ve .SS "read_header" .IX Subsection "read_header" .Vb 5 \& Title : read_header \& Usage : $obj\->read_header($fhl) \& Function: Reads the header from the db file \& Returns : width of a record \& Args : filehandle .Ve .SS "read_record" .IX Subsection "read_record" .Vb 5 \& Title : read_record \& Usage : $obj\->read_record($fh,$pos,$len) \& Function: Reads a record from a filehandle \& Returns : String \& Args : filehandle, offset, and length .Ve .SS "get_all_primary_ids" .IX Subsection "get_all_primary_ids" .Vb 6 \& Title : get_all_primary_ids \& Usage : @ids = $seqdb\->get_all_primary_ids() \& Function: gives an array of all the primary_ids of the \& sequence objects in the database. \& Returns : an array of strings \& Args : none .Ve .SS "find_entry" .IX Subsection "find_entry" .Vb 5 \& Title : find_entry \& Usage : $obj\->find_entry($fh,$start,$end,$id,$recsize) \& Function: Extract an entry based on the start,end,id and record size \& Returns : string \& Args : filehandle, start, end, id, recordsize .Ve .SS "build_index" .IX Subsection "build_index" .Vb 5 \& Title : build_index \& Usage : $obj\->build_index(@files) \& Function: Build the index based on a set of files \& Returns : count of the number of entries \& Args : List of filenames .Ve .SS "_index_file" .IX Subsection "_index_file" .Vb 6 \& Title : _index_file \& Usage : $obj\->_index_file($newval) \& Function: \& Example : \& Returns : value of _index_file \& Args : newvalue (optional) .Ve .SS "write_primary_index" .IX Subsection "write_primary_index" .Vb 6 \& Title : write_primary_index \& Usage : $obj\->write_primary_index($newval) \& Function: \& Example : \& Returns : value of write_primary_index \& Args : newvalue (optional) .Ve .SS "write_secondary_indices" .IX Subsection "write_secondary_indices" .Vb 6 \& Title : write_secondary_indices \& Usage : $obj\->write_secondary_indices($newval) \& Function: \& Example : \& Returns : value of write_secondary_indices \& Args : newvalue (optional) .Ve .SS "new_secondary_filehandle" .IX Subsection "new_secondary_filehandle" .Vb 6 \& Title : new_secondary_filehandle \& Usage : $obj\->new_secondary_filehandle($newval) \& Function: \& Example : \& Returns : value of new_secondary_filehandle \& Args : newvalue (optional) .Ve .SS "open_secondary_index" .IX Subsection "open_secondary_index" .Vb 6 \& Title : open_secondary_index \& Usage : $obj\->open_secondary_index($newval) \& Function: \& Example : \& Returns : value of open_secondary_index \& Args : newvalue (optional) .Ve .SS "_add_id_position" .IX Subsection "_add_id_position" .Vb 6 \& Title : _add_id_position \& Usage : $obj\->_add_id_position($newval) \& Function: \& Example : \& Returns : value of _add_id_position \& Args : newvalue (optional) .Ve .SS "make_config_file" .IX Subsection "make_config_file" .Vb 6 \& Title : make_config_file \& Usage : $obj\->make_config_file($newval) \& Function: \& Example : \& Returns : value of make_config_file \& Args : newvalue (optional) .Ve .SS "read_config_file" .IX Subsection "read_config_file" .Vb 6 \& Title : read_config_file \& Usage : $obj\->read_config_file($newval) \& Function: \& Example : \& Returns : value of read_config_file \& Args : newvalue (optional) .Ve .SS "get_fileid_by_filename" .IX Subsection "get_fileid_by_filename" .Vb 6 \& Title : get_fileid_by_filename \& Usage : $obj\->get_fileid_by_filename($newval) \& Function: \& Example : \& Returns : value of get_fileid_by_filename \& Args : newvalue (optional) .Ve .SS "get_filehandle_by_fileid" .IX Subsection "get_filehandle_by_fileid" .Vb 6 \& Title : get_filehandle_by_fileid \& Usage : $obj\->get_filehandle_by_fileid($newval) \& Function: \& Example : \& Returns : value of get_filehandle_by_fileid \& Args : newvalue (optional) .Ve .SS "primary_index_file" .IX Subsection "primary_index_file" .Vb 6 \& Title : primary_index_file \& Usage : $obj\->primary_index_file($newval) \& Function: \& Example : \& Returns : value of primary_index_file \& Args : newvalue (optional) .Ve .SS "primary_index_filehandle" .IX Subsection "primary_index_filehandle" .Vb 6 \& Title : primary_index_filehandle \& Usage : $obj\->primary_index_filehandle($newval) \& Function: \& Example : \& Returns : value of primary_index_filehandle \& Args : newvalue (optional) .Ve .SS "format" .IX Subsection "format" .Vb 6 \& Title : format \& Usage : $obj\->format($newval) \& Function: \& Example : \& Returns : value of format \& Args : newvalue (optional) .Ve .SS "write_flag" .IX Subsection "write_flag" .Vb 6 \& Title : write_flag \& Usage : $obj\->write_flag($newval) \& Function: \& Example : \& Returns : value of write_flag \& Args : newvalue (optional) .Ve .SS "dbname" .IX Subsection "dbname" .Vb 6 \& Title : dbname \& Usage : $obj\->dbname($newval) \& Function: get/set database name \& Example : \& Returns : value of dbname \& Args : newvalue (optional) .Ve .SS "index_directory" .IX Subsection "index_directory" .Vb 6 \& Title : index_directory \& Usage : $obj\->index_directory($newval) \& Function: \& Example : \& Returns : value of index_directory \& Args : newvalue (optional) .Ve .SS "record_size" .IX Subsection "record_size" .Vb 6 \& Title : record_size \& Usage : $obj\->record_size($newval) \& Function: \& Example : \& Returns : value of record_size \& Args : newvalue (optional) .Ve .SS "primary_namespace" .IX Subsection "primary_namespace" .Vb 6 \& Title : primary_namespace \& Usage : $obj\->primary_namespace($newval) \& Function: \& Example : \& Returns : value of primary_namespace \& Args : newvalue (optional) .Ve .SS "index_type" .IX Subsection "index_type" .Vb 6 \& Title : index_type \& Usage : $obj\->index_type($newval) \& Function: \& Example : \& Returns : value of index_type \& Args : newvalue (optional) .Ve .SS "index_version" .IX Subsection "index_version" .Vb 6 \& Title : index_version \& Usage : $obj\->index_version($newval) \& Function: \& Example : \& Returns : value of index_version \& Args : newvalue (optional) .Ve .SS "primary_pattern" .IX Subsection "primary_pattern" .Vb 6 \& Title : primary_pattern \& Usage : $obj\->primary_pattern($newval) \& Function: \& Example : \& Returns : value of primary_pattern \& Args : newvalue (optional) .Ve .SS "start_pattern" .IX Subsection "start_pattern" .Vb 6 \& Title : start_pattern \& Usage : $obj\->start_pattern($newval) \& Function: \& Example : \& Returns : value of start_pattern \& Args : newvalue (optional) .Ve .SS "secondary_patterns" .IX Subsection "secondary_patterns" .Vb 6 \& Title : secondary_patterns \& Usage : $obj\->secondary_patterns($newval) \& Function: \& Example : \& Returns : value of secondary_patterns \& Args : newvalue (optional) .Ve .SS "secondary_namespaces" .IX Subsection "secondary_namespaces" .Vb 6 \& Title : secondary_namespaces \& Usage : $obj\->secondary_namespaces($newval) \& Function: \& Example : \& Returns : value of secondary_namespaces \& Args : newvalue (optional) .Ve