-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPATHWAY.pm
executable file
·61 lines (58 loc) · 1.53 KB
/
PATHWAY.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package PATHWAY;
use strict qw(subs refs);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw( get_pathway );
#Usage:
#use lib "/System/Pipline/DNA/DNA_Micro/16S_pipeline/16S_pipeline_V1.10/lib/00.Commbin/";
#use PATHWAY;
#
#Example1:
#my ($qimme,$mother,$usearch) = get_path("config.txt",[qimme mother usearch],$Bin,$lib);
#Example2:
#my %path = get_path("config.txt",0,$Bin);
#my ($qimme,$mother,$usearch) = ($path{qimme},$path{mother},$path{usearch});
sub get_pathway{
my ($config,$outpath,$Bin,$Lib) = @_;
($config && -s $config) || return(0);
my %DIR;
$Bin && ($DIR{BIN} = $Bin);
$Lib && ($DIR{LIB} = $Lib);
my %path;
open CONFIGPATH,$config || die$!;
while(<CONFIGPATH>){
/^#/ && next;
/\S/ || next;
chomp;
if(/(\S+)\s+==\s+(.+)/){
$DIR{$1} = $2;
}elsif(/(\S+)\s+=\s+(.+)/){
my ($key,$value) = ($1,$2);
if($value !~ /^\//){
my @val = split/\s+/,$value;
for(@val){
(m#/# && m#^([^/]+)/# && $DIR{$1}) &&
(s#^([^/]+)/#$DIR{$1}/#);
}
$value = "@val";
}
$path{$key} = $value;
}
}
close CONFIGPATH;
if($outpath){
my @out;
for (@$outpath){
if($path{$_}){
push @out,$path{$_};
}else{
die"error: can't find key work: $_, at $config\n";
}
}
return(@out);
}else{
return(%path);
}
}
1;
__END__