-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrun_rcorrector.pl
273 lines (240 loc) · 7.12 KB
/
run_rcorrector.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/usr/bin/env perl
use strict ;
use Cwd 'cwd' ;
use Cwd 'abs_path' ;
use File::Basename;
use Digest::MD5 qw(md5 md5_hex md5_base64) ;
my $i ;
my @readFileList ;
my $numOfThread = 1 ;
my $kmerSize = 23 ;
my $bloomFilterSize = 100000000 ;
my $WD = dirname( abs_path( $0 ) ) ;
my $stage = 0 ;
my $usage = "Usage: perl ./run_rcorrector.pl [OPTIONS]\n".
"OPTIONS:\n".
"Required parameters:\n".
"\t-s seq_files: comma separated files for single-end data sets\n".
"\t-1 seq_files_left: comma separated files for the first mate in the paried-end data sets\n".
"\t-2 seq_files_right: comma separated files for the second mate in the paired-end data sets\n".
"\t-i seq_files_interleaved: comma sperated files for interleaved paired-end data sets\n".
"Other parameters:\n".
"\t-k kmer_length (<=32, default: 23)\n".
"\t-od output_file_directory (default: ./)\n".
"\t-t number_of_threads (default: 1)\n".
#"\t-trim allow trimming (default: false)\n".
"\t-maxcorK INT: the maximum number of correction within k-bp window (default: 4)\n".
"\t-wk FLOAT: the proportion of kmers that are used to estimate weak kmer count threshold, lower for more divergent genome (default: 0.95)\n".
"\t-ek expected_number_of_kmers: does not affect the correctness of program but affect the memory usage (default: 100000000)\n".
"\t-stdout: output the corrected reads to stdout (default: not used)\n".
"\t-verbose: output some correction information to stdout (default: not used)\n".
"\t-stage INT: start from which stage (default: 0)\n".
"\t\t0-start from begining(storing kmers in bloom filter);\n".
"\t\t1-start from count kmers showed up in bloom filter;\n".
"\t\t2-start from dumping kmer counts into a jf_dump file;\n".
"\t\t3-start from error correction." ;
if ( scalar( @ARGV ) == 0 )
{
die "$usage\n" ;
}
my $jellyfishBin = "jellyfish" ;
if ( -e "$WD/jellyfish/bin/jellyfish" )
{
$jellyfishBin = "$WD/jellyfish/bin/jellyfish" ;
}
my $fileArguments ;
my @singleFileList ;
my @firstMateFileList ;
my @secondMateFileList ;
my @interleavedFileList ;
my @rcorrectorArguments ;
my @gzippedFileList ;
sub AddJellyFishReadFile
{
if ( $_[0] =~ /gz$/ )
{
push @gzippedFileList, $_[0] ;
}
else
{
push @readFileList, $_[0] ;
}
}
for ( $i = 0 ; $i < scalar(@ARGV) ; ++$i )
{
if ( $ARGV[$i] eq "-r" )
{
AddJellyFishReadFile( $ARGV[ $i + 1] ) ;
push @rcorrectorArguments, $ARGV[$i] ;
push @rcorrectorArguments, $ARGV[$i + 1] ;
++$i ;
}
elsif ( $ARGV[ $i ] eq "-p" )
{
AddJellyFishReadFile( $ARGV[ $i + 1 ] ) ;
AddJellyFishReadFile( $ARGV[ $i + 2 ] ) ;
push @rcorrectorArguments, $ARGV[$i] ;
push @rcorrectorArguments, $ARGV[$i + 1] ;
push @rcorrectorArguments, $ARGV[$i + 2] ;
$i += 2 ;
}
elsif ( $ARGV[ $i ] eq "-s" )
{
my @cols = split /,/, $ARGV[$i + 1] ;
my $j ;
for ( $j = 0 ; $j < scalar( @cols ) ; ++$j )
{
AddJellyFishReadFile( $cols[ $j ] ) ;
push @singleFileList, $cols[ $j ] ;
}
++$i ;
}
elsif ( $ARGV[ $i ] eq "-1" )
{
my @cols = split /,/, $ARGV[$i + 1] ;
my $j ;
for ( $j = 0 ; $j < scalar( @cols ) ; ++$j )
{
AddJellyFishReadFile( $cols[ $j ] ) ;
push @firstMateFileList, $cols[ $j ] ;
}
++$i ;
}
elsif ( $ARGV[ $i ] eq "-2" )
{
my @cols = split /,/, $ARGV[$i + 1] ;
my $j ;
for ( $j = 0 ; $j < scalar( @cols ) ; ++$j )
{
AddJellyFishReadFile( $cols[ $j ] ) ;
push @secondMateFileList, $cols[ $j ] ;
}
++$i ;
}
elsif ( $ARGV[$i] eq "-i" )
{
my @cols = split /,/, $ARGV[$i + 1] ;
my $j ;
for ( $j = 0 ; $j < scalar( @cols ) ; ++$j )
{
AddJellyFishReadFile( $cols[ $j ] ) ;
push @interleavedFileList, $cols[ $j ] ;
}
++$i ;
}
elsif ( $ARGV[$i] eq "-t" )
{
$numOfThread = $ARGV[$i+1] ;
push @rcorrectorArguments, $ARGV[$i] ;
push @rcorrectorArguments, $ARGV[$i + 1] ;
++$i ;
}
elsif ( $ARGV[$i] eq "-k" )
{
$kmerSize = $ARGV[$i + 1] ;
push @rcorrectorArguments, $ARGV[$i] ;
push @rcorrectorArguments, $ARGV[$i + 1] ;
++$i ;
}
elsif ( $ARGV[$i] eq "-ek" )
{
$bloomFilterSize = $ARGV[$i + 1] ;
++$i ;
}
elsif ( $ARGV[$i] eq "-maxcor" )
{
push @rcorrectorArguments, $ARGV[$i] ;
push @rcorrectorArguments, $ARGV[$i + 1] ;
++$i ;
}
elsif ( $ARGV[$i] eq "-maxcorK" )
{
push @rcorrectorArguments, $ARGV[$i] ;
push @rcorrectorArguments, $ARGV[$i + 1] ;
++$i ;
}
elsif ( $ARGV[$i] eq "-stdout" )
{
push @rcorrectorArguments, $ARGV[$i] ;
}
elsif ( $ARGV[$i] eq "-verbose" )
{
push @rcorrectorArguments, $ARGV[$i] ;
}
elsif ( $ARGV[$i] eq "-stage" )
{
$stage = $ARGV[$i + 1] ;
++$i ;
}
elsif ( $ARGV[$i] eq "-od" )
{
push @rcorrectorArguments, $ARGV[$i] ;
push @rcorrectorArguments, $ARGV[$i + 1] ;
++$i ;
}
elsif ( $ARGV[$i] eq "-wk" )
{
push @rcorrectorArguments, $ARGV[$i] ;
push @rcorrectorArguments, $ARGV[$i + 1] ;
++$i ;
}
else
{
die "Unknown argument ".$ARGV[$i]."\n" ;
}
}
#`echo $numOfThread > tmp.out `
if ( $kmerSize > 32 )
{
die "The kmer size can not be greater than 32.\n" ;
}
# Build the input file arguments for
for ( my $i = 0 ; $i < @singleFileList ; ++$i )
{
$fileArguments = $fileArguments." -r ".$singleFileList[$i] ;
}
die "The number of files from -1,-2 should be the same" if ( scalar( @firstMateFileList ) != scalar( @secondMateFileList ) ) ;
for ( my $i = 0 ; $i < @firstMateFileList ; ++$i )
{
$fileArguments = $fileArguments." -p ".$firstMateFileList[$i]." ".$secondMateFileList[$i] ;
}
for ( my $i = 0 ; $i < @interleavedFileList ; ++$i )
{
$fileArguments = $fileArguments." -i ".$interleavedFileList[$i] ;
}
# build the file list for jellyfish
my $jellyfishFiles = "" ;
for ( my $i = 0 ; $i < @readFileList ; ++$i )
{
$jellyfishFiles .= $readFileList[$i]." " ;
}
for ( my $i = 0 ; $i < @gzippedFileList ; ++$i )
{
$jellyfishFiles .= "<(gzip -cd ".$gzippedFileList[$i].") " ;
}
my $crc = md5_hex( $jellyfishFiles ) ;
if ( $stage <= 0 )
{
print STDERR ( "Put the kmers into bloom filter\n" ) ;
print STDERR ( "$jellyfishBin bc -m $kmerSize -s $bloomFilterSize -C -t $numOfThread -o tmp_$crc.bc $jellyfishFiles\n" ) ;
die "Failed at stage 0.\n" if ( system( "bash -c \"$jellyfishBin bc -m $kmerSize -s $bloomFilterSize -C -t $numOfThread -o tmp_$crc.bc $jellyfishFiles\"" ) != 0 ) ;
}
if ( $stage <= 1 )
{
print STDERR ( "Count the kmers in the bloom filter\n" ) ;
print STDERR ( "$jellyfishBin count -m $kmerSize -s 100000 -C -t $numOfThread --bc tmp_$crc.bc -o tmp_$crc.mer_counts $jellyfishFiles\n" ) ;
die "Failed at stage 1.\n" if ( system( "bash -c \"$jellyfishBin count -m $kmerSize -s 100000 -C -t $numOfThread --bc tmp_$crc.bc -o tmp_$crc.mer_counts $jellyfishFiles\"" ) != 0 ) ;
}
if ( $stage <= 2 )
{
print STDERR ( "Dump the kmers\n" ) ;
print STDERR ( "$jellyfishBin dump -L 2 tmp_$crc.mer_counts > tmp_$crc.jf_dump\n" ) ;
die "Failed at stage 2.\n" if ( system( "$jellyfishBin dump -L 2 tmp_$crc.mer_counts > tmp_$crc.jf_dump" ) != 0 )
}
if ( $stage <= 3 )
{
print STDERR ( "Error correction\n" ) ;
print STDERR ( "$WD/rcorrector @rcorrectorArguments $fileArguments -c tmp_$crc.jf_dump\n" ) ;
die "Failed at stage 3.\n" if ( system( "$WD/rcorrector @rcorrectorArguments $fileArguments -c tmp_$crc.jf_dump" ) != 0 ) ;
}
system( "rm tmp_$crc.bc tmp_$crc.mer_counts tmp_$crc.jf_dump" );