1 package Maasha::Config;
3 # Copyright (C) 2006 Martin A. Hansen.
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.
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.
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.
19 # http://www.gnu.org/copyleft/gpl.html
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 # This module contains configuration details for the usual system setup, etc.
28 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
33 use vars qw( @ISA @EXPORT );
35 @ISA = qw( Exporter );
38 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GLOBALS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
41 my ( $HOME, $PATH, $BP_DATA, $BP_TMP, $BP_DIR );
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" };
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;
56 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
61 # Martin A. Hansen, April 2007.
63 # finds a given exe in path and returns
64 # the full path to the exe.
73 foreach $dir ( split /:/, $PATH ) {
74 return "$dir/$exe" if -x "$dir/$exe" and not -d "$dir/$exe";
77 Maasha::Common::error( qq(Could not find executable \'$exe\') );
83 # Martin A. Hansen, November 2007.
85 # Returns the full path to the FASTA file for
88 my ( $genome, # requested genome
93 my $genome_file = "$BP_DATA/genomes/$genome/$genome.fna";
95 if ( not -f $genome_file ) {
96 Maasha::Common::error( qq(Genome file "$genome_file" for genome "$genome" not found) );
103 sub genome_fasta_index
105 # Martin A. Hansen, December 2007.
107 # Returns the full path to the FASTA file index for
110 my ( $genome, # requested genome
115 my $index = "$BP_DATA/genomes/$genome/$genome.fna.index";
117 if ( not -f $index ) {
118 Maasha::Common::error( qq(Index file "$index" for genome -> $genome not found) );
127 # Martin A. Hansen, November 2007.
129 # Returns the BLAST database path for a given genome.
131 my ( $genome, # requested genome
136 my $file = "$BP_DATA/genomes/$genome/blast/$genome.fna";
144 # Martin A. Hansen, November 2007.
146 # Returns the ooc file of a given tile size
147 # for a given genome.
149 my ( $genome, # requested genome
150 $tile_size, # blat tile size
155 my $ooc_file = "$BP_DATA/genomes/$genome/blat/$tile_size.ooc";
157 Maasha::Common::error( qq(ooc file "$ooc_file" not found for genome -> $genome) ) if not -f $ooc_file;
165 # Martin A. Hansen, November 2007.
167 # Returns a list of Vmatch index names for a given genome.
169 my ( $genome, # requested genome
176 @chrs = chromosomes( $genome );
178 map { $_ = "$BP_DATA/genomes/$genome/vmatch/$_" } @chrs;
180 # needs robustness check
182 return wantarray ? @chrs : \@chrs;
188 # Martin A. Hansen, January 2008.
190 # Returns the full path to the location of a concatenated
191 # PhastCons file for a given genome.
193 my ( $genome, # requested genome
198 my $file = "$BP_DATA/genomes/$genome/phastcons/$genome.pp";
204 sub genome_phastcons_index
206 # Martin A. Hansen, January 2008.
208 # Returns the full path to the location of a PhastCons index
209 # for a given genome.
211 my ( $genome, # requested genome
216 my $file = "$BP_DATA/genomes/$genome/phastcons/$genome.pp.index";
224 # Martin A. Hansen, February 2008.
226 # Returns a list of available genomes in the,
231 my ( %genome_hash, $fh, $line, @genomes, $org );
233 $fh = Maasha::Common::read_open( "$BP_DIR/conf/genomes.conf" );
235 while ( $line = <$fh> )
239 next if $line eq "//";
241 ( $org, undef ) = split "\t", $line;
243 $genome_hash{ $org } = 1;
248 @genomes = sort keys %genome_hash;
250 return wantarray ? @genomes : \@genomes;
256 # Martin A. Hansen, November 2007.
258 # Returns a list of chromosome files for a given genome
259 # read from the genomes.conf file.
261 my ( $genome, # requested genome
266 my ( $fh_in, $line, $org, $chr, %genome_hash, @chrs );
268 $fh_in = Maasha::Common::read_open( "$BP_DIR/bp_conf/genomes.conf" );
270 while ( $line = <$fh_in> )
274 next if $line eq "//";
276 ( $org, $chr ) = split "\t", $line;
278 push @{ $genome_hash{ $org } }, $chr;
283 if ( exists $genome_hash{ $genome } ) {
284 @chrs = @{ $genome_hash{ $genome } };
286 Maasha::Common::error( qq(Genome -> $genome not found in genome hash) );
289 return wantarray ? @chrs : \@chrs;
295 # Martin A. Hansen, April 2008.
297 # Given a genome returns the corresponding mafTrack database table name.
299 my ( $genome, # genome to lookup.
306 # The below has should be in a config file - fix later.
309 danRer4 => 'multiz7way',
310 dm2 => 'multiz15way',
311 dm3 => 'multiz15way',
313 galGal3 => 'multiz7way',
314 gasAcu1 => 'multiz7way',
315 hg18 => 'multiz17way',
316 mm8 => 'multiz17way',
317 mm9 => 'multiz17way',
318 oryLat1 => 'multiz7way',
319 panTro2 => 'multiz17way',
320 tetNig1 => 'multiz7way',
323 Maasha::Common::error( qw(multiz track not found) ) if not exists $hash{ $genome };
325 return $hash{ $genome };
329 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<