forked from Molmed/sisyphus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metaReporter.pl
executable file
·174 lines (136 loc) · 4.02 KB
/
metaReporter.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
#!/usr/bin/perl -w
use FindBin; # Find the script location
use lib "$FindBin::Bin/lib";# Add the script libdir to libs
use Molmed::Sisyphus::Libpath;
use strict;
use XML::Simple;
use XML::LibXSLT;
use XML::LibXML;
use File::Basename;
use Data::Dumper;
=pod
=head1 NAME
metaReporter.pl - Create a meta report on a project from multiple runs
=head1 SYNOPSIS
metaReporter.pl -help|-man
cat list.txt | metaReporter.pl rootdir project > report.xml
=head1 OPTIONS
=over 4
=item -h|-help
prints out a brief help text.
=item -m|-man
Opens the manpage.
=item rootdir
The runfolder-containing directory
=item project
The name of the project for which to compile the report
=item list.txt
A list of flowcell id and lane, one per row, which to include in the report.
=back
=head1 DESCRIPTION
Creates an xml and html report for all lanes and samples in the specified project for the specified flowcells.
=cut
my %xmlfiles;
my $rootDir = shift;
my $projId = shift;
opendir(my $dFh, $rootDir) or die;
foreach my $dir (grep /^[^\.]/, readdir($dFh)){
next unless(-d "$rootDir/$dir");
if(-e "$rootDir/$dir/Summary/$projId/report.xml"
|| -e "$rootDir/$dir/Summary/$projId/report.xml.gz"){
if(-e "$rootDir/$dir/Summary/$projId/report.xml.gz"){
system("gunzip $rootDir/$dir/Summary/$projId/report.xml");
}
if($dir =~ m/\d+_[^_]+_\d+_[AB](\w+)/){
$xmlfiles{$1} = "$rootDir/$dir/Summary/$projId/report.xml";
}else{
die "Failed to get fcid from '$dir'\n";
}
# }else{
# die "Failed to find '$rootDir/$dir/Summary/$projId/report.xml'";
}
}
my $metaLane = {};
my $metaSample = {};
while(<>){
chomp;
my($fcid, $laneId) = split /\s+/, $_;
die "no xml for $fcid\n" unless(exists $xmlfiles{$fcid});
my $xml = XMLin($xmlfiles{$fcid}, ForceArray=>['Sample', 'Read','Lane','Tag']);
foreach my $lane (@{$xml->{LaneMetrics}->{Lane}}){
# print Dumper $lane;
# exit;
if($lane->{Id} == $laneId){
$lane->{Num} = $laneId;
$lane->{Id} = $fcid . "_L" . $laneId;
$lane->{fcid} = $fcid;
my $projDir = dirname($xmlfiles{$fcid});
foreach my $read (@{$lane->{Read}}){
foreach my $key (keys %{$read}){
if($key =~ m/Plot/ && $read->{$key}=~m/Plot/){
my $old = $read->{$key};
$read->{$key} =~ s:^Plots:Plots/$fcid:;
my $dir = dirname($read->{$key});
unless(-e $dir){
system('mkdir', '-p', $dir)==0 or die;
}
if(-e "$projDir/$old"){
system('cp', "$projDir/$old", $dir)==0 or die;
}
}
}
}
push @{$metaLane->{Lane}}, $lane;
}
}
foreach my $sample (@{$xml->{SampleMetrics}->{Sample}}){
my $samId = $sample->{Id};
# $sample->{fcid}=$fcid;
# print Dumper($sample);
# exit;
my $projDir = dirname($xmlfiles{$fcid});
foreach my $tag (@{$sample->{Tag}}){
# print Dumper($tag->{Lane});
# exit;
foreach my $lane (@{$tag->{Lane}}){
# print Dumper($lane);
# exit;
if($lane->{Id} == $laneId){
$lane->{Num} = $laneId;
$lane->{Id} = $fcid . "_L" . $laneId;
$lane->{fcid} = $fcid;
$lane->{Tag} = $tag->{Id};
foreach my $read (@{$lane->{Read}}){
# delete($read->{Q30PlotThumb});
# delete($read->{Q30Plot});
foreach my $key (keys %{$read}){
if($key =~ m/Plot/ && $read->{$key}=~m/Plot/){
my $old = $read->{$key};
$read->{$key} =~ s:^Plots:Plots/$fcid:;
my $dir = dirname($read->{$key});
unless(-e $dir){
system('mkdir', '-p', $dir)==0 or die;
}
if(-e "$projDir/$old"){
system('cp', "$projDir/$old", $dir)==0 or die;
}
}
}
}
push @{$metaSample->{Sample}->{$sample->{Id}}->{Lane}}, $lane;
}
}
}
}
}
my $xs = XML::Simple->new(RootName=>undef);
print STDOUT q(<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="report.xsl"?>
<SequencingReport>
<MetaData>
<Project>) . $projId . q(</Project>
</MetaData>
);
print STDOUT $xs->XMLout($metaLane, RootName=>'LaneMetrics', KeyAttr => {Lane => 'Id'});
print STDOUT $xs->XMLout($metaSample, RootName=>'SampleMetrics', KeyAttr => {Sample => 'Id'});
print STDOUT "</SequencingReport>\n";