-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalayze_contamination_estimates_from_GATK4.pl
More file actions
69 lines (58 loc) · 1.66 KB
/
Copy pathanalayze_contamination_estimates_from_GATK4.pl
File metadata and controls
69 lines (58 loc) · 1.66 KB
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
#!/usr/bin/perl -w
use strict;
=head1
Author: Ian Beddows
Date: 3/22/18
Short description:
Input a directory where there are '${SAMPLE}_contamination.table' files.
These will be found automatically and the contamination estimates writte to the output:
One outfiles:
contamination_stats.txt:
sample contamination std_error
=cut
use Getopt::Long;
my $usage = <<EOF;
OPTIONS:
-dir
OPTIONAL:
-h|help = print usage
-b = uppercase arguments
EOF
my($help,$bold,$dir);
#======================================================================# get options
GetOptions(
'dir=s' => \$dir, # string
#~ '=i' => \$, # integer
#~ '=f' => \$, # floating point number
#~ 'bold' => \$bold, # flag
'h|help' => \$help # flag for help
);
if (defined($help)){die print "HELP:\n",$usage;}
if (!defined($dir)){die print "define -dir:\n",$usage;}
#======================================================================# done with get options
open(my $out,'>','contamination_stats.txt')||die;
# Print the header:
print $out join("\t",'sample','contamination','std_error'),"\n";
my @files = `ls -1 $dir|grep contamination.table`; chomp(@files);
print STDOUT "Found ",scalar @files," contamination.table files:\n";
foreach my $fh (@files){
my $sample = $fh;
$sample =~s/\_contamination.table//;
# open & get info
open(my $in,'<',"$dir/$fh") || die;
my $contam;
my $err;
while(<$in>){
chomp;
next if 1..1;
my @data = split('\t',$_);
my $whole_bam = shift @data;
$contam = shift @data;
$err = shift @data;
#~ print "\t\t$_\n";
#~ print "contam: $contam\n";
}
print $out join("\t",$sample,$contam,$err),"\n";
print STDOUT "\t$sample:\t$fh\n";
}
close($out);