-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathfindPath.pm
122 lines (107 loc) · 3.21 KB
/
findPath.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package findPath;
use strict;
use FindBin;
sub check_samtools
{
my $samtools_bin = shift;
my $samtools_version = `$samtools_bin --version` ;
die "Can't parse samtools version output" unless($samtools_version =~ /samtools ([\d\.]+)/);
$samtools_version = $1;
my $samtools_version_numeric = $samtools_version;
$samtools_version_numeric =~ /^(\d+)\.(\d+)/;
my $samtools_version_major = $1;
my $samtools_version_minor = $2;
unless($samtools_version_major > 1 or ($samtools_version_major == 1 and $samtools_version_minor >= 3))
{
die "I need samtools >=1.3";
}
}
sub get_working_dir
{
my $workingDir_param = shift;
my $this_bin_dir = $FindBin::RealBin;
my %paths_ini;
my $paths_ini = $this_bin_dir . '/paths.ini';
if(-e $paths_ini)
{
open(INI, '<', $paths_ini) or die "Cannot open $paths_ini";
while(<INI>)
{
chomp;
next unless($_);
$_ =~ s/[\n\r]//g;
next if($_ =~ /^\s+$/);
die "Invalid line format in $paths_ini -- expect all lines to be either empty or key=value pairs" unless($_ =~ /^(.+)=(.*)$/);
my $id = $1;
my @alts = split(/,/, $2);
$paths_ini{$id} = \@alts;
}
close(INI);
}
my $working_dir;
if($paths_ini{workingDir_HLA_ASM}[0] and not defined $workingDir_param)
{
$working_dir = $paths_ini{workingDir_HLA_ASM}[0];
$working_dir =~ s/\$HLA\-LA\-DIR/$this_bin_dir/;
}
else
{
unless(defined $workingDir_param)
{
die "\n\nPlease specify a working directory via --workingDir.\n\nOutput for sample with ID \$sampleID will go a correspondingly named sub-directory of the working directory.\n\nFor example, if --workingDir is /path/working, and --sampleID is mySample, then the output will go into directory /path/working/mySample.\n\n";
}
$working_dir = $workingDir_param;
}
return $working_dir;
}
sub find_path
{
my $id = shift;
my $supplied_value = shift;
my $forWhich = shift;
my $this_bin_dir = $FindBin::RealBin;
my %paths_ini;
my $paths_ini = $this_bin_dir . '/paths.ini';
if(-e $paths_ini)
{
open(INI, '<', $paths_ini) or die "Cannot open $paths_ini";
while(<INI>)
{
chomp;
next unless($_);
$_ =~ s/[\n\r]//g;
next if($_ =~ /^\s+$/);
die "Invalid line format in $paths_ini -- expect all lines to be either empty or key=value pairs" unless($_ =~ /^(.+)=(.*)$/);
my $id = $1;
my @alts = split(/,/, $2);
$paths_ini{$id} = \@alts;
}
close(INI);
}
if(defined $supplied_value)
{
die "Command-line supplied value/file for parameter $id not existing" unless(-e $supplied_value);
return $supplied_value;
}
if(exists $paths_ini{$id})
{
foreach my $alternative (@{$paths_ini{$id}})
{
if(-e $alternative)
{
return $alternative;
}
}
}
if($forWhich)
{
my $which_output = `which $forWhich`;
$which_output =~ s/[\n\r]//g;
if($which_output and (-e $which_output))
{
return $which_output;
}
}
die "I couldn't figure out a path for ${id}. Order of precedence: check for parameter --${id}; check paths.ini in $this_bin_dir for a key named $id; parse, if command string defined, the output of the command 'which ${forWhich}' ('which ' means that the command string is not defined).";
}
1;