~ubuntu-branches/ubuntu/trusty/bioperl/trusty

« back to all changes in this revision

Viewing changes to scripts/index/bp_index.PLS

  • Committer: Package Import Robot
  • Author(s): Charles Plessy
  • Date: 2013-09-22 13:39:48 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20130922133948-c6z62zegjyp7ztou
Tags: 1.6.922-1
* New upstream release.
* Replaces and Breaks grinder (<< 0.5.3-3~) because of overlaping contents.
  Closes: #722910
* Stop Replacing and Breaking bioperl ( << 1.6.9 ): not needed anymore. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl
2
 
 
3
 
=head1 NAME
4
 
 
5
 
bp_index.pl - indexes files for use by bp_fetch.pl
6
 
 
7
 
=head1 SYNOPSIS
8
 
 
9
 
bp_index.pl index_name file1 file2 etc.
10
 
 
11
 
=head1 DESCRIPTION
12
 
 
13
 
bp_index.pl builds a bioperl index for the sequence files given in the
14
 
argument list, under the index name. For example
15
 
 
16
 
   bp_index.pl nrdb /data/nrdb/nrdb.fasta
17
 
 
18
 
would build an index called 'nrdb' as the index name for the file
19
 
nrdb.fasta, and
20
 
 
21
 
   bp_index.pl -fmt EMBL swiss /data/swiss/*.dat
22
 
 
23
 
would build an index called swiss for all the files in /data/swiss
24
 
which end in .dat which are in EMBL format.
25
 
 
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
30
 
 
31
 
   bp_fetch swiss:ROA1_HUMAN
32
 
 
33
 
gets the ROA1_HUMAN sequence from the swiss index and writes it as
34
 
fasta format on STDOUT.
35
 
 
36
 
=head1 OPTIONS
37
 
 
38
 
  -fmt  <format>   - Fasta (default), swiss or EMBL
39
 
  -dir  <dir>      - directory where the index files are found
40
 
                     (overrides BIOPERL_INDEX environment variable)
41
 
 
42
 
Options for expert use
43
 
 
44
 
  -type <db_type>  - DBM_file type. 
45
 
                     (overrides BIOPERL_INDEX_TYPE environment variable)
46
 
  -v               - report every index addition (debugging)
47
 
 
48
 
=head1 ENVIRONMENT
49
 
 
50
 
bp_index and bp_fetch coordinate where the databases lie using the
51
 
enviroment 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.
54
 
 
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.
58
 
 
59
 
=head1 USING IT YOURSELF
60
 
 
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).
66
 
 
67
 
=head1 EXTENDING IT
68
 
 
69
 
bp_index is just a wrapper around James Gilbert's excellent Index modules
70
 
found in bioperl
71
 
 
72
 
=head1 FEEDBACK
73
 
 
74
 
=head2 Mailing Lists
75
 
 
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.
79
 
 
80
 
  bioperl-l@bioperl.org                  - General discussion
81
 
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists
82
 
 
83
 
=head2 Reporting Bugs
84
 
 
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:
88
 
 
89
 
  https://redmine.open-bio.org/projects/bioperl/
90
 
 
91
 
=head1 AUTHOR - Ewan Birney
92
 
 
93
 
Ewan Birney E<lt>birney@ebi.ac.ukE<gt>
94
 
 
95
 
=cut
96
 
 
97
 
#'
98
 
use strict;
99
 
 
100
 
#
101
 
# Doofus catcher for people who are trying this script without
102
 
# installing bioperl
103
 
#
104
 
 
105
 
BEGIN {
106
 
    eval {
107
 
        require Bio::Index::Fasta;
108
 
        require Bio::Index::EMBL;
109
 
        require Bio::Index::Swissprot;
110
 
        require Bio::Index::GenBank;
111
 
        require Bio::Index::SwissPfam;
112
 
    };
113
 
    if ( $@ ) {
114
 
        # one up from here is Bio directory - we hope!
115
 
        push(@INC,"..");
116
 
        eval {
117
 
            require Bio::Index::Fasta;
118
 
            require Bio::Index::EMBL;
119
 
        };
120
 
        if ( $@ ) {
121
 
            print STDERR ("\nbp_index cannot find Bio::Index::Fasta and Bio::Index::EMBL\nbp_index needs to have bioperl installed for it to run.\nBioperl is very easy to install\nSee http://bio.perl.org for more information\n\n");
122
 
            exit(1);
123
 
        } else {
124
 
            print STDERR ("\nYou are running bp_index.pl without installing bioperl.\nYou have done it from bioperl/scripts, and so we can find the necessary information\nbut it is much better to install bioperl\n\nPlease read the README in the bioperl distribution\n\n");
125
 
        }
126
 
    }
127
 
}
128
 
 
129
 
my $dir = $ENV{'BIOPERL_INDEX'};
130
 
my $type = $ENV{'BIOPERL_INDEX_TYPE'};
131
 
my $fmt = 'Fasta';
132
 
my $verbose = 0;
133
 
 
134
 
use Getopt::Long;
135
 
&GetOptions("f|fmt=s" => \$fmt,
136
 
            "d|dir=s" => \$dir,
137
 
            "t|type=s" => \$type,
138
 
            "v!" => \$verbose);
139
 
 
140
 
exec('perldoc',$0) unless @ARGV;
141
 
 
142
 
my $name = shift;
143
 
 
144
 
if( !$dir ) {
145
 
    print STDERR "\nNo directory specified for index\nDirectory must be specified by the environment varaible BIOPERL_INDEX or -dir option\ngo bp_index with no arguments for more help\n\n";
146
 
    exit(1);
147
 
}
148
 
 
149
 
#
150
 
# Reset the type if needed
151
 
#
152
 
 
153
 
if( $type ) {
154
 
   $Bio::Index::Abstract::USE_DBM_TYPE = $type;
155
 
}
156
 
#
157
 
# Rock and roll...
158
 
159
 
my $index;
160
 
$_ = $fmt;
161
 
SWITCH : {
162
 
    /Fasta/i && do {
163
 
        $index = Bio::Index::Fasta->new("$dir/$name", 'WRITE');
164
 
        last;
165
 
    };
166
 
    /EMBL/i && do {
167
 
        $index = Bio::Index::EMBL->new("$dir/$name", 'WRITE');
168
 
        last;
169
 
    };
170
 
    /swisspfam|pfam/i && do {
171
 
        $index = Bio::Index::SwissPfam->new("$dir/$name", 'WRITE');
172
 
        last;
173
 
    };
174
 
    /swiss/i && do {
175
 
        $index = Bio::Index::Swissprot->new("$dir/$name", 'WRITE');
176
 
        last;
177
 
    };
178
 
    /GenBank/i && do {
179
 
        $index = Bio::Index::GenBank->new("$dir/$name", 'WRITE');
180
 
        last;
181
 
    };
182
 
    die("No index format called $fmt");
183
 
}
184
 
 
185
 
if( $verbose != 0 ) {
186
 
  $index->verbose(1);
187
 
}
188
 
 
189
 
$index->make_index(@ARGV);
190
 
 
191
 
# finished. Neat eh.
192
 
 
193
 
#
194
 
# if you are using this in a script, to 
195
 
# to force deallocation + closing of the index, go
196
 
# $index = undef;
197
 
#
198
 
 
199
 
        
200
 
 
201
 
 
202
 
 
203
 
 
204