6 my $library_info = shift;
9 my $expxml = XML::Simple->new();
10 my $xml = $expxml->XMLin("Project.xml", ForceArray => [ qw(ComparePeakCalls CompareLibraries PeakCalling ProfileReads qPCR MotifFinding)]);
11 my @peak_calling = ();
13 my $project_name = $xml->{Name};
14 my $project_id= $xml->{ProjectId};
16 if(exists($xml->{PeakCalling})) {
17 for my $i (0..scalar(@{$xml->{PeakCalling}})-1) {
18 my $task = $xml->{PeakCalling}->[$i]->{TaskId};
19 my $name = $xml->{PeakCalling}->[$i]->{Name};
20 my $caller = $xml->{PeakCalling}->[$i]->{Caller};
21 my $genome = $xml->{PeakCalling}->[$i]->{Genome};
22 my $signal = $xml->{PeakCalling}->[$i]->{Signal}->{Library};
23 my $bg = $xml->{PeakCalling}->[$i]->{Background}->{Library};
24 $libs{$signal} = 0; $libs{$bg} = 0;
26 my $caller_dir = "../../Tasks/$task";
27 my %desc = (Name => $name, Dir => $caller_dir, Caller => $caller);
30 if($caller eq "QuEST") {
31 $desc{Summary} = `$root_dir/scripts/SummarizeQuEST.pm $caller_dir`;
32 $desc{outfile} = "$caller_dir/peak_caller.ChIP.out.bedgraph";
33 $desc{fasta} = "$caller_dir/peak_caller.ChIP.out.fasta";
34 } elsif($caller eq "WingPeaks") {
35 $desc{Summary} = `$root_dir/scripts/SummarizeWingPeaks.pm $caller_dir/$name.peaks`;
36 $desc{outfile} = "$caller_dir/$name.peaks.bed";
37 $desc{fasta} = "$caller_dir/$name.peaks.fasta";
38 } elsif($caller eq "MACS") {
39 my $peakfile = $caller_dir.'/'.$name.'_peaks.xls';
40 my $negpeakfile = $caller_dir.'/'.$name.'_negative_peaks.xls';
41 $desc{Summary} = `$root_dir/scripts/SummarizeMACS.pm $peakfile $negpeakfile`;
42 $desc{outfile} = "$caller_dir/".$name."_peaks.bed";
43 $desc{fasta} = "$caller_dir/".$name."_peaks.fasta";
46 if($genome eq "scer") { $genome = "sacCer1"; }
47 $desc{Genome} = $genome;
49 push @peak_calling, \%desc;
53 my $qPCR_Summary = "";
54 if(exists($xml->{qPCR})) {
55 $qPCR_Summary .= "<H2><EM>In-silico</EM> qPCR Summary</H2><BR><TABLE BORDER=1><TR><TD><EM>Library</EM></TD><TD><EM>Factor</EM></TD><TD><EM>Fold Enrichment</EM></TD></TR>\n";
56 for my $i (0..scalar(@{$xml->{qPCR}})-1) {
57 my $task = $xml->{qPCR}->[$i]->{TaskId};
58 my $name = $xml->{qPCR}->[$i]->{Name}; $name =~ s/\s/_/g;
59 my $genome = $xml->{qPCR}->[$i]->{Genome};
60 my $lib = $xml->{qPCR}->[$i]->{Library};
61 my $outfile = "../../Tasks/$task/$name.qPCR";
65 if( ! -e $outfile ) { $qPCR_Summary .= "<TR BCOLOR=#FFBBBB><TD>$name</TD><TD>Processing...</TD></TR>\n"; } else {
66 my $summary_line = `$root_dir/scripts/Summarize_qPCR.pm $name $lib $outfile`;
67 if($summary_line eq "") { $qPCR_Summary .= "<TR BCOLOR=#FFBBBB><TD>$name</TD><TD>Processing...</TD></TR>\n"; }
69 $qPCR_Summary .= $summary_line;
73 $qPCR_Summary .= "</TABLE>\n";
76 my $profile_summary = "";
77 if(exists($xml->{ProfileReads})) {
78 $profile_summary = "<BR><H2>Read Profiles (<A HREF=http://genome.ucsc.edu/cgi-bin/hgGateway>Genome Browser</A>)</H2>\n";
79 $profile_summary .= "<TABLE BORDER=1><TR><TD><EM>Library</EM></TD><TD><EM>Wiggle file</EM></TD></TR>";
80 for my $i (0..scalar(@{$xml->{ProfileReads}})-1) {
81 my $task = $xml->{ProfileReads}->[$i]->{TaskId};
82 my $name = $xml->{ProfileReads}->[$i]->{Name};
83 my $genome = $xml->{ProfileReads}->[$i]->{Genome};
84 my $lib = $xml->{ProfileReads}->[$i]->{Library};
87 if($genome eq "scer") { $genome = "sacCer1"; }
88 $profile_summary .= "<TR><TD>$name ($lib)</TD><TD><A HREF=../../Tasks/$task/$lib.wig.gz>$lib.wig.gz</A><BR><A HREF=http://genome.ucsc.edu/cgi-bin/hgTracks?db=$genome&position=chr1:1000-2000&hgt.customText=http://171.65.76.194/Tasks/$task/$lib.wig.gz TARGET=\"_blank\">View in UCSC Genome Browser</A></TD>\n";
89 $profile_summary .= "<TD><A HREF=../../Tasks/$task/$lib.profile.gif><IMG WIDTH=300 SRC=../../Tasks/$task/$lib.profile.gif></A></TD></TR>\n";
91 $profile_summary .= "</TABLE>\n";
94 my $library_comparisons = "";
95 if(exists($xml->{CompareLibraries})) {
96 $library_comparisons .= "<H2>Library Comparisons</H2>\n";
97 $library_comparisons .= "<TABLE BORDER=1>\n";
98 $library_comparisons .= "<TR><TD><EM>Factor</EM></TD><TD><EM>Library 1</EM></TD><TD><EM>Library 2</EM></TD><TD><EM>Correlation</EM></TD></TR>\n";
99 for my $i (0..scalar(@{$xml->{CompareLibraries}})-1) {
100 my $task = $xml->{CompareLibraries}->[$i]->{TaskId};
101 my $tf = $xml->{CompareLibraries}->[$i]->{TF};
102 my $genome = $xml->{CompareLibraries}->[$i]->{Genome};
103 my $features = "$root_dir/reference_data/".$genome."_uptream5k_downtream1k";
104 my $name1 = $xml->{CompareLibraries}->[$i]->{Library}->[0]->{Library};
105 my $name2 = $xml->{CompareLibraries}->[$i]->{Library}->[1]->{Library};
106 my $outfile = "../../Tasks/".$task.'/'.$name1."_".$name2.".compare";
107 $libs{$name1} = 0; $libs{$name2} = 0;
108 my $correlation; my $color;
109 if( !(-e $outfile) ) { $correlation = "In Progress..."; $color = "#FFBBBB"; }
111 $correlation = `cat $outfile | awk '{print \$8}'`;
112 if($correlation > 0.9) { $color = "#BBFFBB"; }
113 elsif($correlation > 0.6) { $color = "#BBBBFF"; }
114 else { $color = "#FFBBBB"; }
116 $library_comparisons .= "<TR BGCOLOR=$color><TD>$tf</TD><TD>$name1</TD><TD>$name2</TD<TD>$correlation</TD></TR>\n";
118 $library_comparisons .= "</TABLE>\n";
121 my $peak_call_comparisons = "";
122 if(exists($xml->{ComparePeakCalls})) {
123 $peak_call_comparisons = "<H2>Peak Calling Comparisons</H2>\n";
124 $peak_call_comparisons .= "<TABLE BORDER=1><TR><TD><EM>Caller1</EM></TD><TD><EM>Set1</EM></TD><TD><EM>Caller2</EM></TD><TD><EM>Set2</EM></TD><TD>|Union|</TD><TD>|Intersect|</TD><TD>|Difference|</TD><TD>Jaccard</TD><TD>Correlation</TD></TR>\n";
125 for my $i (0..scalar(@{$xml->{ComparePeakCalls}})-1) {
126 my $task = $xml->{ComparePeakCalls}->[$i]->{TaskId};
127 my $caller1 = $xml->{ComparePeakCalls}->[$i]->{Caller1};
128 my $caller2 = $xml->{ComparePeakCalls}->[$i]->{Caller2};
129 my $genome = $xml->{ComparePeakCalls}->[$i]->{Genome};
130 my $set1 = $xml->{ComparePeakCalls}->[$i]->{Set1}; $set1 =~ s/\s/_/g;
131 my $set2 = $xml->{ComparePeakCalls}->[$i]->{Set2}; $set2 =~ s/\s/_/g;
132 my $outfile .= "../../Tasks/".$task.'/'.$set1."-".$caller1."_v_".$set2."-".$caller2.".compare";
133 my $correlation = -1;
136 my $color = "#FFBBBB";
137 $peak_call_comparisons .= "<TR BGCOLOR=$color><TD>$caller1</TD><TD>$set1</TD><TD>$caller2</TD><TD>$set2</TD><TD COLSPAN=5><B>Processing...</B></TD></TR>\n";
139 my $line = `cat $outfile`; chomp $line;
140 my($tf,$set1_id,$set2_id,$U,$I,$D,$J,$R) = split(/\t/,$line);
141 my $color = "#FFBBBB";
142 if(!defined($R)) { $peak_call_comparisons .= "<TR BGCOLOR=$color><TD>$caller1</TD><TD>$set1</TD><TD>$caller2</TD><TD>$set2</TD><TD COLSPAN=5><B>Processing...</B></TD></TR>\n"; } else {
143 $set1_id =~ /.+?\((\d+)\)$/; my $n1 = $1;
144 $set2_id =~ /.+?\((\d+)\)$/; my $n2 = $1;
145 if($R > 0.85) { $color = "#BBFFBB"; } elsif($R > 0.5) { $color="#BBBBFF"; } else { $color="#FFBBBB"; }
146 $peak_call_comparisons .= "<TR BGCOLOR=$color><TD>$caller1</TD><TD>$set1 ($n1)</TD><TD>$caller2</TD><TD>$set2 ($n2)</TD><TD>$U</TD><TD>$I</TD><TD>$D</TD><TD>$J</TD><TD>$R</TD></TR>\n";
150 $peak_call_comparisons .= "</TABLE>\n";
153 my $motif_finding = "";
154 if(exists($xml->{MotifFinding})) {
155 $motif_finding = "<H2>Motif Finding</H2>\n";
156 $motif_finding .= "<TABLE BORDER=1><TR><TD><EM>Caller</EM></TD><TD><EM>Set</EM></TD><TD><EM>Width</EM></TD><TD>Motifs</TD><TD><EM>Motif Information</EM></TD></TR>\n";
157 for my $i (0..scalar(@{$xml->{MotifFinding}})-1) {
158 my $task = $xml->{MotifFinding}->[$i]->{TaskId};
159 my $caller = $xml->{MotifFinding}->[$i]->{Caller};
160 my $genome = $xml->{MotifFinding}->[$i]->{Genome};
161 my $set = $xml->{MotifFinding}->[$i]->{Set}; $set =~ s/\s/_/g;
162 my $width = $xml->{MotifFinding}->[$i]->{Width};
163 my $outfile .= "../../Tasks/".$task.'/'.$set."-".$caller.".w".$width.".biop";
166 my $color = "#FFBBBB";
167 $motif_finding .= "<TR BGCOLOR=$color><TD>$caller</TD><TD>$set</TD><TD COLSPAN=3><B>Processing...</B></TD></TR>\n";
169 my $color = "#BBFFBB";
170 my $line = `cat $outfile | grep "Motif #"`; $line =~ s/\n/<BR>/g;
171 my $score = `cat $outfile | grep "MotifScore"`; $score=~ s/\n/<BR>/g;
172 $motif_finding .= "<TR BGCOLOR=$color><TD>$caller</TD><TD>$set</TD><TD>$width</TD><TD>$line</TD><TD>$score</TD></TR>\n";
175 $motif_finding .= "</TABLE>\n";
178 print "<HTML><HEAD><TITLE>$project_name Analysis Summary</TITLE></HEAD><BODY>\n";
179 print "<H1><CENTER>$project_name Analysis Summary</CENTER></H1>\n";
180 print SummarizeLibrary($library_info);
181 print $profile_summary;
182 print $library_comparisons;
183 print $peak_call_comparisons;
184 print $motif_finding;
187 if(exists($xml->{PeakCalling})) {
188 print "<H2>Peak Calling Summary</H2>";
189 print "<TABLE BORDER=1><TR><TD><EM>Experiment</EM></TD><TD><EM>Peak Caller</EM></TD><TD><EM>Summary</EM></TD></TR>\n";
194 #my $color = $row % 2?"#CCCCFF":"#FFFFFF";
195 my $color = "#EEEEFF";
196 print "<TR BGCOLOR=$color><TD><B>$hash{Name}</B></TD>";
197 print "<TD>$hash{Caller}</TD><TD>$hash{Summary}</TD>\n";
198 print "<TD><A HREF=$hash{outfile}>BED file</A><BR><A HREF=http://genome.ucsc.edu/cgi-bin/hgTracks?db=$hash{Genome}&hgt.customText=http://171.65.76.194/Tasks/$hash{Task}/$hash{outfile}>View in Genome Browser</A></TD><TD><A HREF=$hash{fasta}>FASTA</A></TD>\n";
203 print "</BODY></HTML>\n";
204 sub SummarizeLibrary {
205 my $xml_file = shift;
206 my $xml = XMLin($xml_file, ForceArray => 1);
208 $summary .= "<H2>Libraries Used</H2><TABLE BORDER=1><TR><TD><EM>Library</EM></TD><TD><EM>Name</EM></TD><TD><EM>Num Lanes</EM></TD><TD><EM>Num Reads</EM></TD></TR>\n";
209 for my $i (0..scalar(@{$xml->{Library}})-1) {
210 my $lib = $xml->{Library}->[$i]->{Name};
211 next unless(scalar(keys %libs) == 0 || exists($libs{$lib}));
212 my $N = scalar(@{$xml->{Library}->[$i]->{Track}});
213 my($date,$fc,$lane,$desc);
216 for my $t (0..$N-1) {
217 my $filename = $xml->{Library}->[$i]->{Track}->[$t]->{Filename};
218 $filename = `basename $filename`;
219 $filename =~ /^(\d+)_(.+?)_s(\d+)_(.+?)_$lib.align/;
220 ($date,$fc,$lane,$desc) = ($1,$2,$3,$4);
221 $num_lanes += length($lane);
222 $num_reads += $xml->{Library}->[$i]->{Track}->[$t]->{Count};
225 if($num_reads < 3000000) { $bgcolor = "FF3300"; }
226 elsif($num_reads < 5000000) { $bgcolor = "FFCC33"; }
227 elsif($num_reads < 10000000) { $bgcolor = "00CCFF"; }
228 else { $bgcolor = "66FF66"; }
230 $summary .= sprintf("<TR BGCOLOR=#%s><TD>%s</TD><TD>%s</TD><TD>%d</TD><TD>%0.2fM</TD></TR>\n",$bgcolor,$lib,$desc,$num_lanes,$num_reads/1000000.0);
232 $summary .= "</TABLE>\n";