]> git.donarmstrong.com Git - biopieces.git/blob - code_perl/Maasha/Config.pm
fixed seq qual length check
[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 warnings;
32 use strict;
33 use Data::Dumper;
34 use vars qw( @ISA @EXPORT );
35
36 @ISA = qw( Exporter );
37
38
39 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GLOBALS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
40
41
42 my ( $HOME, $PATH, $BP_DATA, $BP_TMP, $BP_DIR );
43
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" };  
49
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;
55
56
57 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
58
59
60 sub get_exe
61 {
62     # Martin A. Hansen, April 2007.
63
64     # finds a given exe in path and returns
65     # the full path to the exe.
66
67     my ( $exe,
68        ) = @_;
69
70     # returns string
71
72     my ( $dir, $ok );
73
74     foreach $dir ( split /:/, $PATH ) {
75         return "$dir/$exe" if -x "$dir/$exe" and not -d "$dir/$exe";
76     }
77
78     Maasha::Common::error( qq(Could not find executable \'$exe\') );
79 }
80
81
82 sub genome_fasta
83 {
84     # Martin A. Hansen, November 2007.
85
86     # Returns the full path to the FASTA file for
87     # a given genome.
88
89     my ( $genome,   # requested genome
90        ) = @_;
91
92     # Returns string.
93
94     my $genome_file = "$BP_DATA/genomes/$genome/$genome.fna";
95
96     if ( not -f $genome_file ) {
97         Maasha::Common::error( qq(Genome file "$genome_file" for genome "$genome" not found) );
98     }
99
100     return $genome_file;
101 }
102
103
104 sub genome_fasta_index
105 {
106     # Martin A. Hansen, December 2007.
107
108     # Returns the full path to the FASTA file index for
109     # a given genome.
110
111     my ( $genome,   # requested genome
112        ) = @_;
113
114     # Returns string.
115
116     my $index = "$BP_DATA/genomes/$genome/$genome.fna.index";
117
118     if ( not -f $index ) {
119         Maasha::Common::error( qq(Index file "$index" for genome -> $genome not found) );
120     }
121
122     return $index;
123 }
124
125
126 sub genome_blast
127 {
128     # Martin A. Hansen, November 2007.
129
130     # Returns the BLAST database path for a given genome.
131
132     my ( $genome,      # requested genome
133        ) = @_;
134
135     # Returns string.
136
137     my $file = "$BP_DATA/genomes/$genome/blast/$genome.fna";
138
139     return $file;
140 }
141
142
143 sub genome_blat_ooc
144 {
145     # Martin A. Hansen, November 2007.
146
147     # Returns the ooc file of a given tile size
148     # for a given genome.
149
150     my ( $genome,      # requested genome
151          $tile_size,   # blat tile size
152        ) = @_;
153
154     # Returns string.
155
156     my $ooc_file = "$BP_DATA/genomes/$genome/blat/$tile_size.ooc";
157
158     Maasha::Common::error( qq(ooc file "$ooc_file" not found for genome -> $genome) ) if not -f $ooc_file;
159
160     return $ooc_file;
161 }
162
163
164 sub genome_vmatch
165 {
166     # Martin A. Hansen, November 2007.
167
168     # Returns a list of Vmatch index names for a given genome.
169
170     my ( $genome,   # requested genome
171        ) = @_;
172
173     # Returns a list.
174
175     my ( @chrs );
176
177     @chrs = chromosomes( $genome );
178
179     map { $_ = "$BP_DATA/genomes/$genome/vmatch/$_" } @chrs;
180
181     # needs robustness check
182
183     return wantarray ? @chrs : \@chrs;
184 }
185
186
187 sub genomes
188 {
189     # Martin A. Hansen, February 2008.
190
191     # Returns a list of available genomes in the,
192     # genomes.conf file.
193
194     # Returns a list.
195
196     my ( %genome_hash, $fh, $line, @genomes, $org );
197
198     $fh = Maasha::Common::read_open( "$BP_DIR/conf/genomes.conf" );
199
200     while ( $line = <$fh> )
201     {
202         chomp $line;
203
204         next if $line eq "//";
205
206         ( $org, undef ) = split "\t", $line;
207
208         $genome_hash{ $org } = 1;
209     }
210
211     close $fh;
212
213     @genomes = sort keys %genome_hash;
214
215     return wantarray ? @genomes : \@genomes;
216 }
217
218
219 sub chromosomes
220 {
221     # Martin A. Hansen, November 2007.
222
223     # Returns a list of chromosome files for a given genome
224     # read from the genomes.conf file.
225
226     my ( $genome,   # requested genome
227        ) = @_;
228
229     # Returns a list.
230
231     my ( $fh_in, $line, $org, $chr, %genome_hash, @chrs );
232
233     $fh_in = Maasha::Common::read_open( "$BP_DIR/bp_conf/genomes.conf" );
234
235     while ( $line = <$fh_in> )
236     {
237         chomp $line;
238
239         next if $line eq "//";
240
241         ( $org, $chr ) = split "\t", $line;
242
243         push @{ $genome_hash{ $org } }, $chr;
244     }
245
246     close $fh_in;
247
248     if ( exists $genome_hash{ $genome } ) {
249         @chrs = @{ $genome_hash{ $genome } };
250     } else {
251         Maasha::Common::error( qq(Genome -> $genome not found in genome hash) );
252     }
253
254     return wantarray ? @chrs : \@chrs;
255 }
256
257
258 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
259
260 1;