bin/bp_biofetch_genbank_proxy: move to Bio-DB-NCBIHelper
[bioperl-live.git] / bin / bp_index
blob11f78744f8c8161d140d5220c1a1a0823ed97786
1 #!/usr/bin/perl
3 =head1 NAME
5 bp_index.pl - indexes files for use by bp_fetch.pl
7 =head1 SYNOPSIS
9 bp_index.pl index_name file1 file2 etc.
11 =head1 DESCRIPTION
13 bp_index.pl builds a bioperl index for the sequence files given in the
14 argument list, under the index name. For example
16 bp_index.pl nrdb /data/nrdb/nrdb.fasta
18 would build an index called 'nrdb' as the index name for the file
19 nrdb.fasta, and
21 bp_index.pl -fmt EMBL swiss /data/swiss/*.dat
23 would build an index called swiss for all the files in /data/swiss
24 which end in .dat which are in EMBL format.
26 The indexes are built using the Bio/Index/* modules, in particular,
27 Bio::Index::EMBL and the Bio::Index::Fasta modules. Any script which
28 uses these modules can use the index. A good example script is bp_fetch
29 which fetches sequences and pipes them to STDOUT, for example
31 bp_fetch swiss:ROA1_HUMAN
33 gets the ROA1_HUMAN sequence from the swiss index and writes it as
34 fasta format on STDOUT.
36 =head1 OPTIONS
38 -fmt <format> - Fasta (default), swiss or EMBL
39 -dir <dir> - directory where the index files are found
40 (overrides BIOPERL_INDEX environment variable)
42 Options for expert use
44 -type <db_type> - DBM_file type.
45 (overrides BIOPERL_INDEX_TYPE environment variable)
46 -v - report every index addition (debugging)
48 =head1 ENVIRONMENT
50 bp_index and bp_fetch coordinate where the databases lie using the
51 environment variable BIOPERL_INDEX. This can be overridden using the
52 -dir option. There is no default value, so you must use the -dir option
53 or set BIOPERL_INDEX.
55 The DB type is coordinated with BIOPERL_INDEX_TYPE which if it
56 is not there, defaults to whatever the bioperl modules have installed,
57 which itself defaults to SDBM_File.
59 =head1 USING IT YOURSELF
61 bp_index.pl is a script that drives the Index modules. If you want to
62 use this script heavily in your work, if it is Perl based, it is
63 almost certainly better to look at the code in this script and copy
64 it across (probably you will be more likely to want to use the bp_fetch
65 code).
67 =head1 EXTENDING IT
69 bp_index is just a wrapper around James Gilbert's excellent Index modules
70 found in bioperl
72 =head1 FEEDBACK
74 =head2 Mailing Lists
76 User feedback is an integral part of the evolution of this and other
77 Bioperl modules. Send your comments and suggestions preferably to
78 the Bioperl mailing list. Your participation is much appreciated.
80 bioperl-l@bioperl.org - General discussion
81 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
83 =head2 Reporting Bugs
85 Report bugs to the Bioperl bug tracking system to help us keep track
86 of the bugs and their resolution. Bug reports can be submitted via the
87 web:
89 https://github.com/bioperl/bioperl-live/issues
91 =head1 AUTHOR - Ewan Birney
93 Ewan Birney E<lt>birney@ebi.ac.ukE<gt>
95 =cut
98 use strict;
99 use warnings;
102 # Doofus catcher for people who are trying this script without
103 # installing bioperl
106 use Bio::Index::Fasta;
107 use Bio::Index::EMBL;
108 use Bio::Index::Swissprot;
109 use Bio::Index::GenBank;
110 use Bio::Index::SwissPfam;
112 my $dir = $ENV{'BIOPERL_INDEX'};
113 my $type = $ENV{'BIOPERL_INDEX_TYPE'};
114 my $fmt = 'Fasta';
115 my $verbose = 0;
117 use Getopt::Long;
118 &GetOptions("f|fmt=s" => \$fmt,
119 "d|dir=s" => \$dir,
120 "t|type=s" => \$type,
121 "v!" => \$verbose);
123 exec('perldoc',$0) unless @ARGV;
125 my $name = shift;
127 if( !$dir ) {
128 print STDERR "\nNo directory specified for index\nDirectory must be specified by the environment variable BIOPERL_INDEX or -dir option\ngo bp_index with no arguments for more help\n\n";
129 exit(1);
133 # Reset the type if needed
136 if( $type ) {
137 $Bio::Index::Abstract::USE_DBM_TYPE = $type;
140 # Rock and roll...
142 my $index;
143 $_ = $fmt;
144 SWITCH : {
145 /Fasta/i && do {
146 $index = Bio::Index::Fasta->new("$dir/$name", 'WRITE');
147 last;
149 /EMBL/i && do {
150 $index = Bio::Index::EMBL->new("$dir/$name", 'WRITE');
151 last;
153 /swisspfam|pfam/i && do {
154 $index = Bio::Index::SwissPfam->new("$dir/$name", 'WRITE');
155 last;
157 /swiss/i && do {
158 $index = Bio::Index::Swissprot->new("$dir/$name", 'WRITE');
159 last;
161 /GenBank/i && do {
162 $index = Bio::Index::GenBank->new("$dir/$name", 'WRITE');
163 last;
165 die("No index format called $fmt");
168 if( $verbose != 0 ) {
169 $index->verbose(1);
172 $index->make_index(@ARGV);
174 # finished. Neat eh.
177 # if you are using this in a script, to
178 # to force deallocation + closing of the index, go
179 # $index = undef;