]> git.donarmstrong.com Git - biopieces.git/blob - code_perl/Maasha/Config.pm
removed & from all Perl Modules
[biopieces.git] / code_perl / Maasha / Config.pm
1 package Maasha::Config;
2
3 # Copyright (C) 2006 Martin A. Hansen.
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 # http://www.gnu.org/copyleft/gpl.html
20
21
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
23
24
25 # This module contains configuration details for the usual system setup, etc.
26
27
28 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
29
30
31 use strict;
32 use Data::Dumper;
33 use vars qw( @ISA @EXPORT );
34
35 @ISA = qw( Exporter );
36
37
38 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GLOBALS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
39
40
41 my ( $HOME, $PATH, $BP_DATA, $BP_TMP, $BP_DIR );
42
43 $HOME     = $ENV{ "HOME" };     
44 $PATH     = $ENV{ "PATH" };     
45 $BP_DIR   = $ENV{ "BP_DIR" };
46 $BP_DATA  = $ENV{ "BP_DATA" }; 
47 $BP_TMP   = $ENV{ "BP_TMP" };  
48
49 warn qq(WARNING: HOME not set in env\n)     if not defined $HOME;
50 warn qq(WARNING: PATH not set in env\n)     if not defined $PATH;
51 warn qq(WARNING: BP_DIR not set in env\n)   if not defined $BP_DIR;
52 warn qq(WARNING: BP_DATA not set in env\n)  if not defined $BP_DATA;
53 warn qq(WARNING: BP_TMP not set in env\n)   if not defined $BP_TMP;
54
55
56 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
57
58
59 sub get_exe
60 {
61     # Martin A. Hansen, April 2007.
62
63     # finds a given exe in path and returns
64     # the full path to the exe.
65
66     my ( $exe,
67        ) = @_;
68
69     # returns string
70
71     my ( $dir, $ok );
72
73     foreach $dir ( split /:/, $PATH ) {
74         return "$dir/$exe" if -x "$dir/$exe" and not -d "$dir/$exe";
75     }
76
77     Maasha::Common::error( qq(Could not find executable \'$exe\') );
78 }
79
80
81 sub genome_fasta
82 {
83     # Martin A. Hansen, November 2007.
84
85     # Returns the full path to the FASTA file for
86     # a given genome.
87
88     my ( $genome,   # requested genome
89        ) = @_;
90
91     # Returns string.
92
93     my $genome_file = "$BP_DATA/genomes/$genome/$genome.fna";
94
95     if ( not -f $genome_file ) {
96         Maasha::Common::error( qq(Genome file "$genome_file" for genome "$genome" not found) );
97     }
98
99     return $genome_file;
100 }
101
102
103 sub genome_fasta_index
104 {
105     # Martin A. Hansen, December 2007.
106
107     # Returns the full path to the FASTA file index for
108     # a given genome.
109
110     my ( $genome,   # requested genome
111        ) = @_;
112
113     # Returns string.
114
115     my $index = "$BP_DATA/genomes/$genome/$genome.fna.index";
116
117     if ( not -f $index ) {
118         Maasha::Common::error( qq(Index file "$index" for genome -> $genome not found) );
119     }
120
121     return $index;
122 }
123
124
125 sub genome_blast
126 {
127     # Martin A. Hansen, November 2007.
128
129     # Returns the BLAST database path for a given genome.
130
131     my ( $genome,      # requested genome
132        ) = @_;
133
134     # Returns string.
135
136     my $file = "$BP_DATA/genomes/$genome/blast/$genome.fna";
137
138     return $file;
139 }
140
141
142 sub genome_blat_ooc
143 {
144     # Martin A. Hansen, November 2007.
145
146     # Returns the ooc file of a given tile size
147     # for a given genome.
148
149     my ( $genome,      # requested genome
150          $tile_size,   # blat tile size
151        ) = @_;
152
153     # Returns string.
154
155     my $ooc_file = "$BP_DATA/genomes/$genome/blat/$tile_size.ooc";
156
157     Maasha::Common::error( qq(ooc file "$ooc_file" not found for genome -> $genome) ) if not -f $ooc_file;
158
159     return $ooc_file;
160 }
161
162
163 sub genome_vmatch
164 {
165     # Martin A. Hansen, November 2007.
166
167     # Returns a list of Vmatch index names for a given genome.
168
169     my ( $genome,   # requested genome
170        ) = @_;
171
172     # Returns a list.
173
174     my ( @chrs );
175
176     @chrs = chromosomes( $genome );
177
178     map { $_ = "$BP_DATA/genomes/$genome/vmatch/$_" } @chrs;
179
180     # needs robustness check
181
182     return wantarray ? @chrs : \@chrs;
183 }
184
185
186 sub genome_phastcons
187 {
188     # Martin A. Hansen, January 2008.
189
190     # Returns the full path to the location of a concatenated
191     # PhastCons file for a given genome.
192
193     my ( $genome,   # requested genome
194        ) = @_;
195
196     # Returns a string.
197     
198     my $file = "$BP_DATA/genomes/$genome/phastcons/$genome.pp";
199
200     return $file;
201 }
202
203
204 sub genome_phastcons_index
205 {
206     # Martin A. Hansen, January 2008.
207
208     # Returns the full path to the location of a PhastCons index
209     # for a given genome.
210
211     my ( $genome,   # requested genome
212        ) = @_;
213
214     # Returns a string.
215     
216     my $file = "$BP_DATA/genomes/$genome/phastcons/$genome.pp.index";
217
218     return $file;
219 }
220
221
222 sub genomes
223 {
224     # Martin A. Hansen, February 2008.
225
226     # Returns a list of available genomes in the,
227     # genomes.conf file.
228
229     # Returns a list.
230
231     my ( %genome_hash, $fh, $line, @genomes, $org );
232
233     $fh = Maasha::Common::read_open( "$BP_DIR/conf/genomes.conf" );
234
235     while ( $line = <$fh> )
236     {
237         chomp $line;
238
239         next if $line eq "//";
240
241         ( $org, undef ) = split "\t", $line;
242
243         $genome_hash{ $org } = 1;
244     }
245
246     close $fh;
247
248     @genomes = sort keys %genome_hash;
249
250     return wantarray ? @genomes : \@genomes;
251 }
252
253
254 sub chromosomes
255 {
256     # Martin A. Hansen, November 2007.
257
258     # Returns a list of chromosome files for a given genome
259     # read from the genomes.conf file.
260
261     my ( $genome,   # requested genome
262        ) = @_;
263
264     # Returns a list.
265
266     my ( $fh_in, $line, $org, $chr, %genome_hash, @chrs );
267
268     $fh_in = Maasha::Common::read_open( "$BP_DIR/bp_conf/genomes.conf" );
269
270     while ( $line = <$fh_in> )
271     {
272         chomp $line;
273
274         next if $line eq "//";
275
276         ( $org, $chr ) = split "\t", $line;
277
278         push @{ $genome_hash{ $org } }, $chr;
279     }
280
281     close $fh_in;
282
283     if ( exists $genome_hash{ $genome } ) {
284         @chrs = @{ $genome_hash{ $genome } };
285     } else {
286         Maasha::Common::error( qq(Genome -> $genome not found in genome hash) );
287     }
288
289     return wantarray ? @chrs : \@chrs;
290 }
291
292
293 sub maf_track
294 {
295     # Martin A. Hansen, April 2008.
296
297     # Given a genome returns the corresponding mafTrack database table name.
298
299     my ( $genome,   # genome to lookup.
300        ) = @_;
301
302     # Returns a string.
303
304     my ( %hash );
305
306     # The below has should be in a config file - fix later.
307
308     %hash = (
309         danRer4 => 'multiz7way',
310         dm2     => 'multiz15way',
311         dm3     => 'multiz15way',
312         fr2     => 'multiz7way',
313         galGal3 => 'multiz7way',
314         gasAcu1 => 'multiz7way',
315         hg18    => 'multiz17way',
316         mm8     => 'multiz17way',
317         mm9     => 'multiz17way',
318         oryLat1 => 'multiz7way',
319         panTro2 => 'multiz17way',
320         tetNig1 => 'multiz7way',
321     );
322
323     Maasha::Common::error( qw(multiz track not found) ) if not exists $hash{ $genome };
324
325     return $hash{ $genome };
326 }
327
328
329 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
330
331 1;