Skip to content

Commit 6a6396a

Browse files
committed
Merge branch 'hotfix/2.1.6'
2 parents d105456 + 862a58c commit 6a6396a

File tree

3 files changed

+64
-49
lines changed

3 files changed

+64
-49
lines changed

perl/bin/filter_fusions.pl

+36-29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/perl
22
##########LICENCE ##########
3-
#Copyright (c) 2015 Genome Research Ltd.
3+
#Copyright (c) 2015-2017 Genome Research Ltd.
44
###
55
#Author: Cancer Genome Project <[email protected]>
66
###
@@ -86,19 +86,22 @@ sub normals_filter {
8686
my $fusions_file = File::Spec->catfile($tmp,"$sample.fusions");
8787
my $fusions_sorted = File::Spec->catfile($tmp,"$sample.fusions.sorted");
8888
PCAP::Cli::file_for_reading('fusions.reformat', $fusions_file.'.reformat');
89-
89+
9090
# Sort the fusions file prior to joining with the normals file
9191
system("sort -k1,1 $fusions_file.reformat > $fusions_file.sorted");
92-
92+
9393
my $normal_file = $options-> {'normals'};
94-
system("join -v 2 $normal_file $fusions_file.sorted > $fusions_file.filtered");
95-
94+
system("join -v 2 $normal_file $fusions_file.sorted > $fusions_file.filtered") && die "An error occurred: $!";
95+
if(-s "$fusions_file.filtered" == 0) {
96+
system("echo '##EOF##' > $fusions_file.filtered") && die "An error occurred: $!";
97+
}
98+
9699
return 1;
97100
}
98101

99102
sub process_program_params {
100103
my $options = shift;
101-
104+
102105
my $program = lc($options->{'program'});
103106
if($program eq 'tophat'){
104107
$options->{'split-char'} = $TOPHAT_SPLIT_CHAR;
@@ -129,7 +132,7 @@ sub process_program_params {
129132
else{
130133
die "An invalid program name has been entered, parameter -p should be tophat, defuse or star.\n"
131134
}
132-
135+
133136
return 1;
134137
}
135138

@@ -144,29 +147,29 @@ sub reformat {
144147

145148
open (my $ifh, $input) or die "Could not open file '$input' $!";
146149
open(my $ofh, '>', $output) or die "Could not open file '$output' $!";
147-
150+
148151
while (<$ifh>) {
149152
chomp;
150153
my $line = $_;
151-
154+
152155
$header_pattern = $options->{'header-pattern'} if(exists $options->{'header-pattern'});
153156
if($line =~ m/$header_pattern/){
154-
157+
155158
if($program eq 'star'){
156159
$line =~ s/([Left|Right]+)Gene/$1Gene\t$1GeneId/g;
157160
$line =~ s/([Left|Right]+)Breakpoint/$1Chr\t$1Pos\t$1Strand/g;
158161
$line =~ s/#//;
159162
}
160-
163+
161164
$options->{'header'} = "breakpoint_ref\t".$line;
162165
}
163166
else{
164167
$line =~ s/\tchr/\t/g;
165168
my @fields = split $options->{'split-char'}, $line;
166169
my $fusion;
167-
170+
168171
if($program eq 'star'){
169-
172+
170173
my @break1 = split $options->{'split-char2'}, $fields[$options->{'chr1'} - 1];
171174
my @break2 = split $options->{'split-char2'}, $fields[$options->{'chr2'} - 1];
172175
$fields[$options->{'chr1'} - 1] = join("\t",@break1);
@@ -177,10 +180,10 @@ sub reformat {
177180
$fields[$options->{'gene2'} - 1] = join("\t",@gene2);
178181
$fusion = $break1[0].":".$break1[1]."-".$break2[0].":".$break2[1];
179182
$line = join("\t",@fields);
180-
183+
181184
}
182185
elsif($program eq 'tophat'){
183-
186+
184187
# Fusion positions for TopHat need adjusting by +1 so that they are directly comparable to Star and deFuse
185188
my $orig_pos1 = $fields[$options->{'pos1'}-1];
186189
my $orig_pos2 = $fields[$options->{'pos2'}-1];
@@ -190,47 +193,47 @@ sub reformat {
190193
$fields[$options->{'pos1'}-1] = $adj_pos1;
191194
$fields[$options->{'pos2'}-1] = $adj_pos2;
192195
$line = join("\t",@fields);
193-
196+
194197
}
195198
else{
196199
$fusion = $fields[$options->{'chr1'}-1].":".$fields[$options->{'pos1'}-1]."-".$fields[$options->{'chr2'}-1].":".$fields[$options->{'pos2'}-1];
197200
}
198-
201+
199202
print $ofh "$fusion\t$line\n";
200203
}
201-
}
204+
}
202205
close ($ifh);
203206
close ($ofh);
204-
207+
205208
return 1;
206209
}
207210

208211
sub setup {
209212
my %opts;
210213
pod2usage(-msg => "\nERROR: Options must be defined.\n", -verbose => 1, -output => \*STDERR) if(scalar @ARGV == 0);
211214
$opts{'cmd'} = join " ", $0, @ARGV;
212-
215+
213216
GetOptions( 'h|help' => \$opts{'h'},
214217
'm|man' => \$opts{'m'},
215218
'i|input=s' => \$opts{'input'},
216219
'o|outdir=s' => \$opts{'outdir'},
217220
'n|normals=s' => \$opts{'normals'},
218221
's|sample=s' => \$opts{'sample'},
219-
'p|program=s' => \$opts{'program'},
222+
'p|program=s' => \$opts{'program'},
220223
) or pod2usage(2);
221224

222225
pod2usage(-verbose => 1) if(defined $opts{'h'});
223226
pod2usage(-verbose => 2) if(defined $opts{'m'});
224-
227+
225228
PCAP::Cli::file_for_reading('input', $opts{'input'});
226229
PCAP::Cli::file_for_reading('normals', $opts{'normals'});
227-
230+
228231
# Setup details specific to each fusion detection program output file
229232
process_program_params(\%opts);
230-
233+
231234
# Check the output directory exists and is writeable, create if not
232235
PCAP::Cli::out_dir_check('outdir', $opts{'outdir'});
233-
236+
234237
# Create working directory for storing intermediate files
235238
my $tmpdir = File::Spec->catdir($opts{'outdir'}, "tmp_$opts{'program'}Filter");
236239
make_path($tmpdir) unless(-d $tmpdir);
@@ -241,7 +244,7 @@ sub setup {
241244

242245
sub write_output {
243246
my $options = shift;
244-
247+
245248
my $tmp = $options->{'tmp'};
246249
my $sample = $options-> {'sample'};
247250
my $program = $options-> {'program'};
@@ -250,7 +253,7 @@ sub write_output {
250253
my $fusions_file = File::Spec->catfile($tmp,"$sample.fusions.filtered");
251254
my $output_file = File::Spec->catfile($outdir,"$sample.$program-fusion.normals.filtered.txt");
252255
PCAP::Cli::file_for_reading('filtered.fusions', $fusions_file);
253-
256+
254257
open (my $ifh, $fusions_file) or die "Could not open file $fusions_file $!";
255258
open(my $ofh, '>', $output_file) or die "Could not open file $output_file $!";
256259
print $ofh $header."\n";
@@ -261,8 +264,12 @@ sub write_output {
261264
print $ofh $line."\n";
262265
}
263266
close ($ifh);
264-
close ($ofh);
265-
267+
close ($ofh);
268+
269+
if(-s $output_file == 0) {
270+
system("echo '##EOF##' > $output_file") && die "An error occurred: $!";
271+
}
272+
266273
return 1;
267274
}
268275

perl/bin/tophat_add_strand.pl

+27-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/perl
22
##########LICENCE ##########
3-
#Copyright (c) 2015 Genome Research Ltd.
3+
#Copyright (c) 2015-2017 Genome Research Ltd.
44
###
55
#Author: Cancer Genome Project <[email protected]>
66
###
@@ -47,7 +47,7 @@
4747

4848
{
4949
my $options = setup();
50-
50+
5151
reformat($options);
5252
add_strand($options);
5353
write_output($options);
@@ -62,12 +62,16 @@ sub add_strand {
6262
my $output = File::Spec->catfile($outdir,"$sample.tophat.fusions");
6363

6464
PCAP::Cli::file_for_reading('filtered.fusions', $fusions_file);
65-
65+
6666
# Sort both files prior to joining
67-
system("sort -k1,1 $fusions_file > $output.sorted");
68-
system("sort -k1,1 $strand_file > $strand_file.sorted");
69-
system("join $output.sorted $strand_file.sorted > $output.strand");
70-
67+
system("sort -k1,1 $fusions_file > $output.sorted") && die "An error occurred: $!";
68+
system("sort -k1,1 $strand_file > $strand_file.sorted") && die "An error occurred: $!";
69+
system("join $output.sorted $strand_file.sorted > $output.strand") && die "An error occurred: $!";
70+
71+
if(-s "$output.strand" == 0) {
72+
system("echo '##EOF##' > $output.strand") && die "An error occurred: $!";
73+
}
74+
7175
return 1;
7276
}
7377

@@ -80,12 +84,12 @@ sub reformat {
8084

8185
open (my $ifh, $potential_fusions) or die "Could not open file '$potential_fusions' $!";
8286
open(my $ofh, '>', $output) or die "Could not open file '$output' $!";
83-
87+
8488
while (<$ifh>) {
8589
chomp;
8690
my $line = $_;
8791
if($line =~ m/^$sample/){
88-
92+
8993
my @fields = split ' ', $line;
9094
$fields[1] =~ s/-|chr/ /g;
9195
my @strands = split '', $fields[4];
@@ -97,31 +101,35 @@ sub reformat {
97101
my $pos1 = $fields_upd[3] + 1;
98102
my $pos2 = $fields_upd[4] + 1;
99103
print $ofh "$fields_upd[1]:$pos1-$fields_upd[2]:$pos2 $fields_upd[5] $fields_upd[6]\n";
100-
104+
101105
}
102-
}
106+
}
103107
close ($ifh);
104108
close ($ofh);
105-
109+
110+
if(-s $output == 0) {
111+
system("echo '##EOF##' > $output") && die "An error occurred: $!";
112+
}
113+
106114
return 1;
107115
}
108116

109117
sub setup {
110118
my %opts;
111119
pod2usage(-msg => "\nERROR: Options must be defined.\n", -verbose => 1, -output => \*STDERR) if(scalar @ARGV == 0);
112120
$opts{'cmd'} = join " ", $0, @ARGV;
113-
121+
114122
GetOptions( 'h|help' => \$opts{'h'},
115123
'm|man' => \$opts{'m'},
116124
'i|input=s' => \$opts{'input'},
117125
'o|outdir=s' => \$opts{'outdir'},
118126
's|sample=s' => \$opts{'sample'},
119-
'p|potfusions=s' => \$opts{'potfusions'},
127+
'p|potfusions=s' => \$opts{'potfusions'},
120128
) or pod2usage(2);
121129

122130
pod2usage(-verbose => 1) if(defined $opts{'h'});
123131
pod2usage(-verbose => 2) if(defined $opts{'m'});
124-
132+
125133
PCAP::Cli::file_for_reading('input', $opts{'input'});
126134
PCAP::Cli::file_for_reading('potential_fusions', $opts{'potfusions'});
127135

@@ -133,13 +141,13 @@ sub setup {
133141

134142
sub write_output {
135143
my $options = shift;
136-
144+
137145
my $sample = $options-> {'sample'};
138146
my $outdir = $options->{'outdir'};
139147
my $fusions_file = File::Spec->catfile($outdir,"$sample.tophat.fusions".'.strand');
140148
my $output_file = File::Spec->catfile($outdir,"$sample.tophat-fusion.normals.filtered.strand.txt");
141149
PCAP::Cli::file_for_reading('filtered.fusions', $fusions_file);
142-
150+
143151
open (my $ifh, $fusions_file) or die "Could not open file $fusions_file $!";
144152
open(my $ofh, '>', $output_file) or die "Could not open file $output_file $!";
145153
print $ofh join("\t", @TOPHAT_HEADER)."\n";
@@ -150,8 +158,8 @@ sub write_output {
150158
print $ofh $line."\n";
151159
}
152160
close ($ifh);
153-
close ($ofh);
154-
161+
close ($ofh);
162+
155163
return 1;
156164
}
157165

perl/lib/Sanger/CGP/CgpRna.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use strict;
3636
use Const::Fast qw(const);
3737
use base 'Exporter';
3838

39-
our $VERSION = '2.1.5';
39+
our $VERSION = '2.1.6';
4040
our @EXPORT = qw($VERSION);
4141

4242
1;

0 commit comments

Comments
 (0)