-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
121 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/usr/bin/perl | ||
|
||
########## LICENCE ########## | ||
# Copyright (c) 2014-2018 Genome Research Ltd. | ||
# Copyright (c) 2014-2019 Genome Research Ltd. | ||
# | ||
# Author: CASM/Cancer IT <[email protected]> | ||
# | ||
|
@@ -46,5 +46,6 @@ WriteMakefile( | |
'Devel::Cover' => 1.09, | ||
'Pod::Coverage' => 0.23, | ||
'PerlIO::gzip' => 0.20, | ||
'Set::IntervalTree' => 0.12, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings FATAL=>'all'; | ||
use autodie; | ||
|
||
use IO::Uncompress::Gunzip qw(gunzip $GunzipError); | ||
|
||
if(@ARGV < 2) { | ||
warn "\nUSAGE: $0 normal_panel.gff3[.gz] sampleToRemove_1 sampleToRemove_2 [...]\n\n"; | ||
warn "Output is to stdout, recommended usage:\n"; | ||
warn "\t$0 normal_panel.gff3[.gz] sampleToRemove_1 sampleToRemove_2 [...] | bgzip -c > new_panel.gff3.gz\n"; | ||
exit(1); | ||
} | ||
|
||
my $input = shift @ARGV; | ||
my @samples = @ARGV; | ||
|
||
my $z = IO::Uncompress::Gunzip->new($input, MultiStream => 1) or die "gunzip failed: $GunzipError\n"; | ||
while(my $line = <$z>) { | ||
if($. < 3) { | ||
print $line; | ||
next; | ||
} | ||
if($. == 3) { | ||
print clean_header($line, \@samples); | ||
next; | ||
} | ||
print clean_record($line, \@samples); | ||
} | ||
close $z; | ||
|
||
sub clean_record { | ||
my ($line, $samples) = @_; | ||
chomp $line; | ||
my @columns = split /\t/, $line; | ||
my ($summary, @sample_stat) = split ',', pop @columns; | ||
my $found = 0; | ||
my @cleaned; | ||
|
||
for my $ss(@sample_stat) { | ||
my $matched = 0; | ||
for my $samp (@{$samples}) { | ||
if($ss =~ m/^$samp=/) { | ||
$matched++; | ||
next; | ||
} | ||
} | ||
if($matched > 0){ | ||
$found++; | ||
} | ||
else { | ||
push @cleaned, $ss; | ||
} | ||
} | ||
if($found == 0) { | ||
return $line."\n"; | ||
} | ||
my ($orig_count) = $summary =~ m/(\d+)$/; | ||
my $fixed_count = $orig_count - $found; | ||
return q{} if($fixed_count == 0); # removes line completely | ||
my $corrected = join "\t", @columns, join ',', 'SAMPLE_COUNT='.$fixed_count, @cleaned; | ||
return $corrected."\n"; | ||
} | ||
|
||
sub clean_header { | ||
my ($line, $samples) = @_; | ||
chomp $line; | ||
my @elements = split /\s/, $line; | ||
my @new; | ||
OUTER: for my $e (@elements) { | ||
for my $samp (@{$samples}) { | ||
next OUTER if $e =~ m/$samp/; | ||
} | ||
push @new, $e; | ||
} | ||
my $final = join q{ }, @new; | ||
$final .= "\n"; | ||
return $final; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters