-
Notifications
You must be signed in to change notification settings - Fork 5
/
imputeChunks.pl
executable file
·136 lines (125 loc) · 3.87 KB
/
imputeChunks.pl
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
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/perl
## generate impute2 jobs for one or several chromosomes,
## splitting chromosomes into chunks of ~5MB
use strict;
use warnings;
use File::Basename;
use Getopt::Long;
use POSIX;
sub usage {
print STDERR basename($0) . " [options] [-- impute2 options]\n";
print STDERR "Options:\n";
print STDERR " --gen-prefix: Prefix for genotype files.\n";
print STDERR " --gen-suffix: Suffix for genotype files.\n";
print STDERR " --phased: Flag indicating that study genotypes have been pre-phased.\n";
print STDERR
" --length: File with chromosome length information. This file should have at least two columns with the chromosome name in the first and length in the second column.\n";
print STDERR
" --chromosomes: List with chromosome names to process. This may include ranges, e.g., 1-5,7,9,Y. [default: 1-22]\n";
print STDERR " --map-prefix: Prefix for recombination map files.\n";
print STDERR " --map-suffix: Suffix for recombination map files.\n";
print STDERR " --output: Name of output directory.\n";
print STDERR " --hap-prefix: Prefix for reference haplotype files.\n";
print STDERR " --hap-suffix: Suffix for reference haplotype files.\n";
print STDERR " --legend-prefix: Prefix for legend files.\n";
print STDERR " --legend-suffix: Suffix for legend files.\n";
print STDERR " --submit: The command (and options) that should be used job submission. [\"qsub -cwd -V -pe shmem 2 -b y\"]\n";
print STDERR "\nimpute2 options:\n";
print STDERR
" The options -m, -h, -l, -g, -int and -o will be generated by this script based on the \
options given above. Other impute2 parameters may be added to the command line after a '--'.\n";
exit();
}
my (
$gPref, $gSuf, $lengthFile, $chromString,
@chroms, $mPref, $mSuf, $hPref,
$hSuf, $lPref, $lSuf, %chromLength,
@entry, $cmd, $cmd2, $output,
$submit, $phased
);
$chromString = '1-22';
$submit = 'qsub -cwd -V -pe shmem 2 -b y';
$phased = '';
my $status = GetOptions(
"gen-prefix=s" => \$gPref,
"gen-suffix=s" => \$gSuf,
"length=s" => \$lengthFile,
"chromosomes=s" => \$chromString,
"map-prefix=s" => \$mPref,
"map-suffix=s" => \$mSuf,
"hap-prefix=s" => \$hPref,
"hap-suffix=s" => \$hSuf,
"legend-prefix=s" => \$lPref,
"legend-suffix=s" => \$lSuf,
"output=s" => \$output,
"submit=s" => \$submit,
"phased" => \$phased
);
if ( !$status
or not defined $gPref
or not defined $gSuf
or not defined $mPref
or not defined $mSuf
or not $lengthFile) {
usage();
}
## parse chromosome string
@chroms = ();
for my $chrom (split /,/, $chromString) {
if ($chrom =~ /(chr)?(\d+)-(chr)?(\d+)/) {
push @chroms, ($2 .. $4);
}
else {
push @chroms, $chrom;
}
}
## read chromosome lengths
open LENGTH, $lengthFile or die "Cannot read $lengthFile: $!";
while (<LENGTH>) {
@entry = split /\s/;
$entry[0] =~ s/chr//;
$chromLength{ $entry[0] } = $entry[1];
}
## generate impute commands
for my $chrom (@chroms) {
$cmd = "impute2 ";
if($phased){
$cmd .= "-use_prephased_g -known_haps_g $gPref$chrom$gSuf ";
}
else{
$cmd .= "-g $gPref$chrom$gSuf ";
}
$cmd .= "-m $mPref" . $chrom . "$mSuf";
if (defined $hPref) {
$cmd .= " -h $hPref";
if (defined $hSuf) {
$cmd .= $chrom . "$hSuf";
}
}
if (defined $lPref) {
$cmd .= " -l $lPref";
if (defined $lSuf) {
$cmd .= $chrom . "$lSuf";
}
}
$cmd .= ' ' . join(' ', @ARGV);
for (my $i = 0; $i < ceil($chromLength{$chrom} / 5000000); $i++) {
$cmd2 = $cmd . " -int " . ($i * 5000000 + 1) . " ";
if (($i + 1) * 5000000 < $chromLength{$chrom}) {
$cmd2 .= ($i + 1) * 5000000;
}
else {
$cmd2 .= $chromLength{$chrom};
}
$cmd2 .=
" -o $output/"
. basename($gPref)
. $chrom
. ".chunk"
. sprintf("%03d", $i + 1)
. "$gSuf"
. ".impute2";
## submit to cluster
system("$submit -N impute2_chr$chrom." . sprintf("%03d", $i + 1) . " $cmd2");
}
}