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 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
34 use vars qw( @ISA @EXPORT );
36 @ISA = qw( Exporter );
39 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GLOBALS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
42 my ( $HOME, $PATH, $BP_DATA, $BP_TMP, $BP_DIR );
44 $HOME = $ENV{ "HOME" };
45 $PATH = $ENV{ "PATH" };
46 $BP_DIR = $ENV{ "BP_DIR" };
47 $BP_DATA = $ENV{ "BP_DATA" };
48 $BP_TMP = $ENV{ "BP_TMP" };
50 warn qq(WARNING: HOME not set in env\n) if not defined $HOME;
51 warn qq(WARNING: PATH not set in env\n) if not defined $PATH;
52 warn qq(WARNING: BP_DIR not set in env\n) if not defined $BP_DIR;
53 warn qq(WARNING: BP_DATA not set in env\n) if not defined $BP_DATA;
54 warn qq(WARNING: BP_TMP not set in env\n) if not defined $BP_TMP;
57 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
62 # Martin A. Hansen, April 2007.
64 # finds a given exe in path and returns
65 # the full path to the exe.
74 foreach $dir ( split /:/, $PATH ) {
75 return "$dir/$exe" if -x "$dir/$exe" and not -d "$dir/$exe";
78 Maasha::Common::error( qq(Could not find executable \'$exe\') );
84 # Martin A. Hansen, November 2007.
86 # Returns the full path to the FASTA file for
89 my ( $genome, # requested genome
94 my $genome_file = "$BP_DATA/genomes/$genome/$genome.fna";
96 if ( not -f $genome_file ) {
97 Maasha::Common::error( qq(Genome file "$genome_file" for genome "$genome" not found) );
104 sub genome_fasta_index
106 # Martin A. Hansen, December 2007.
108 # Returns the full path to the FASTA file index for
111 my ( $genome, # requested genome
116 my $index = "$BP_DATA/genomes/$genome/$genome.fna.index";
118 if ( not -f $index ) {
119 Maasha::Common::error( qq(Index file "$index" for genome -> $genome not found) );
128 # Martin A. Hansen, November 2007.
130 # Returns the BLAST database path for a given genome.
132 my ( $genome, # requested genome
137 my $file = "$BP_DATA/genomes/$genome/blast/$genome.fna";
145 # Martin A. Hansen, November 2007.
147 # Returns the ooc file of a given tile size
148 # for a given genome.
150 my ( $genome, # requested genome
151 $tile_size, # blat tile size
156 my $ooc_file = "$BP_DATA/genomes/$genome/blat/$tile_size.ooc";
158 Maasha::Common::error( qq(ooc file "$ooc_file" not found for genome -> $genome) ) if not -f $ooc_file;
166 # Martin A. Hansen, November 2007.
168 # Returns a list of Vmatch index names for a given genome.
170 my ( $genome, # requested genome
177 @chrs = chromosomes( $genome );
179 map { $_ = "$BP_DATA/genomes/$genome/vmatch/$_" } @chrs;
181 # needs robustness check
183 return wantarray ? @chrs : \@chrs;
189 # Martin A. Hansen, February 2008.
191 # Returns a list of available genomes in the,
196 my ( %genome_hash, $fh, $line, @genomes, $org );
198 $fh = Maasha::Common::read_open( "$BP_DIR/conf/genomes.conf" );
200 while ( $line = <$fh> )
204 next if $line eq "//";
206 ( $org, undef ) = split "\t", $line;
208 $genome_hash{ $org } = 1;
213 @genomes = sort keys %genome_hash;
215 return wantarray ? @genomes : \@genomes;
221 # Martin A. Hansen, November 2007.
223 # Returns a list of chromosome files for a given genome
224 # read from the genomes.conf file.
226 my ( $genome, # requested genome
231 my ( $fh_in, $line, $org, $chr, %genome_hash, @chrs );
233 $fh_in = Maasha::Common::read_open( "$BP_DIR/bp_conf/genomes.conf" );
235 while ( $line = <$fh_in> )
239 next if $line eq "//";
241 ( $org, $chr ) = split "\t", $line;
243 push @{ $genome_hash{ $org } }, $chr;
248 if ( exists $genome_hash{ $genome } ) {
249 @chrs = @{ $genome_hash{ $genome } };
251 Maasha::Common::error( qq(Genome -> $genome not found in genome hash) );
254 return wantarray ? @chrs : \@chrs;
258 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<