/
MetagenomeOverview.pm
1807 lines (1637 loc) · 91.2 KB
/
MetagenomeOverview.pm
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package MGRAST::WebPage::MetagenomeOverview;
# $Id: MetagenomeOverview.pm,v 1.119 2012-05-30 17:22:14 tharriso Exp $
use base qw( WebPage );
use strict;
use warnings;
use List::Util qw(first max min sum);
use POSIX;
use Data::Dumper;
use DateTime;
use Date::Parse;
use WebConfig;
use WebComponent::WebGD;
use GD;
use Conf;
use MGRAST::Metadata;
use MGRAST::Analysis;
1;
=pod
=head1 NAME
MetagenomeOverview - an instance of WebPage which gives overview information about a metagenome
=head1 DESCRIPTION
Overview page about a metagenome
=head1 METHODS
=over 4
=item * B<init> ()
Called when the web page is instanciated.
=cut
sub init {
my ($self) = @_;
$self->title('Metagenome Overview');
$self->application->register_component('VerticalBarChart', 'vbar1');
$self->application->register_component('PieChart', 'pchart1');
$self->application->register_component('Table', 'metadata_tbl');
$self->application->register_component('Table', 'func_tbl');
$self->application->register_component('Table', 'org_tbl');
$self->application->register_component('Ajax', 'ajax');
$self->application->register_action($self, 'edit_name', 'edit_name');
$self->application->register_action($self, 'chart_export', 'chart_export');
# get the metagenome id
my $id = $self->application->cgi->param('metagenome') || '';
# sanity check on job
if ($id) {
my $mgrast = $self->application->data_handle('MGRAST');
my $jobs_array = $mgrast->Job->get_objects( { metagenome_id => $id } );
unless (@$jobs_array > 0) {
$self->app->add_message('warning', "Unable to retrieve the metagenome '$id'. This metagenome does not exist.");
return 1;
}
my $job = $jobs_array->[0];
my $user = $self->application->session->user;
if(! $job->public) {
if(! $user) {
$self->app->add_message('warning', 'Please log into MG-RAST to view private metagenomes.');
return 1;
} elsif(! $user->has_right(undef, 'view', 'metagenome', $id)) {
$self->app->add_message('warning', "You have no access to the metagenome '$id'. If someone is sharing this data with you please contact them with inquiries. However, if you believe you have reached this message in error please contact the <a href='mailto:mg-rast\@mcs.anl.gov'>MG-RAST mailing list</a>.");
return 1;
}
}
my $attr = $mgrast->JobAttributes->init({ job => $job, tag => 'deleted' });
if($attr) {
$self->app->add_message('warning', "Unable to view metagenome '$id' because it has been deleted.");
return 1;
}
unless ($job->viewable) {
$self->app->add_message('warning', "Unable to view metagenome '$id' because it is still processing.");
return 1;
}
$self->data('job', $job);
}
# init the metadata database
my $mddb = MGRAST::Metadata->new();
$self->data('mddb', $mddb);
# init the metagenome database
my $mgdb = new MGRAST::Analysis( $self->app->data_handle('MGRAST')->db_handle );
unless ($mgdb) {
$self->app->error("Unable to retrieve the analysis database for metagenome '$id'.");
return 1;
}
$mgdb->set_jobs([$id]);
$self->data('mgdb', $mgdb);
$self->data('bin_size', 20);
$self->data('tax_levels', ['domain', 'phylum', 'class', 'order', 'family', 'genus', 'species']);
return 1;
}
=pod
=item * B<output> ()
Returns the html output of the page.
=cut
sub output {
my ($self) = @_;
# get metagenome id
my $mgid = $self->application->cgi->param('metagenome') || '';
unless ($mgid) {
$self->application->redirect('MetagenomeSelect');
$self->application->add_message('info', 'Redirected from Metagenome Overview: No metagenome id given.');
$self->application->do_redirect();
exit;
}
my $non_ajax_action = $self->application->cgi->param('non_ajax_action') || '';
if($non_ajax_action eq 'delete_job') {
$self->delete_job();
return "";
}
my $job = $self->data('job');
my $mgdb = $self->data('mgdb');
my $mddb = $self->data('mddb');
my $user = $self->application->session->user;
my $job_id = $job->job_id;
my $mg_link = "http://metagenomics.anl.gov/linkin.cgi?metagenome=$mgid";
# get project information
my $project_link = "";
my $projectjob_num = 0;
my $projectjob_url = "";
my $jobdbm = $self->application->data_handle('MGRAST');
my $project = $job->primary_project;
if ($project && ref($project)) {
$self->{project} = $project;
$self->{meta_info} = $project->data;
my $proj_jobs = $jobdbm->ProjectJob->get_objects({project => $project});
$project_link = "<a target=_blank href='?page=MetagenomeProject&project=".$project->id."'>".$project->name."</a>";
$projectjob_num = scalar(@$proj_jobs) - 1;
$projectjob_url = "?page=MetagenomeProject&project=".$project->id."#jobs";
}
# get job metadata
my $md_seq_type = $job->seq_type;
my $md_biome = $job->biome;
my $md_feature = $job->feature;
my $md_material = $job->material;
my $md_country = $job->country;
my $md_region = $job->geo_loc_name;
my $md_seqmethod = $job->seq_method;
my $md_ext_ids = $job->external_ids;
my $md_coordinate = $job->lat_lon;
my $md_date_time = $job->collection_date;
my $md_enviroment = $job->env_package_type;
# short info
my $html = $self->application->component('ajax')->output;
$html .= "<p><table><tr>";
$html .= "<td style='font-size:large;'><b>MG-RAST ID</b></td>";
$html .= "<td style='font-size:large;'> $mgid".($user && $user->is_admin('MGRAST') ? " (".$job->job_id.")" : "")."</td>";
$html .= "<td> <a class='nav_top' style='color:rgb(82, 129, 176);' target=_blank href='metagenomics.cgi?page=DownloadMetagenome&metagenome=$mgid'><img src='./Html/mg-download.png' style='width:20px;height:20px;' title='Download $mgid'> Download</a></td>";
$html .= "<td> <a class='nav_top' style='color:rgb(82, 129, 176);' target=_blank href='metagenomics.cgi?page=Analysis&metagenome=$mgid'><img src='./Html/analysis.gif' style='width:20px;height:20px;' title='Analyze $mgid'> Analyze</a></td>";
$html .= "<td> <a class='nav_top' style='color:rgb(82, 129, 176);' href='#search_ref'><img src='./Html/lupe.png' style='width:20px;height:20px;' title='Search $mgid'> Search</a></td>";
$html .= "</tr></table></p>";
$html .= "<p><div style='width: 700px'>";
$html .= "<div style='float: left'><table>";
$html .= "<tr><td><b>Metagenome Name</b></td><td>".$job->name."</td></tr>";
if ($self->{project}) {
$html .= "<tr><td><b>PI</b></td><td><a href='mailto:".($self->{meta_info}->{PI_email}||"")."'>".($self->{meta_info}->{PI_firstname}||"")." ".($self->{meta_info}->{PI_lastname}||"")."</a></td></tr>";
$html .= "<tr><td><b>Organization</b></td><td>".($self->{meta_info}->{PI_organization}||"")."</td></tr>";
}
$html .= "<tr><td><b>Visibility</b></td><td>".($job->public ? 'Public' : 'Private')."</td></tr>";
$html .= "<tr><td><b>Static Link</b></td><td><a href='$mg_link'>$mg_link</a></td></tr>";
$html .= "</table></div><div style='float: right'><table>";
$html .= "<tr><td><b>NCBI Project ID</b></td><td>".($md_ext_ids->{ncbi} ? join(", ", map { "<a href='http://www.ncbi.nlm.nih.gov/genomeprj/".$_."' target=_blank>".$_."</a>" } split(/, /, $md_ext_ids->{ncbi})) : "-")."</td></tr>";
$html .= "<tr><td><b>GOLD ID</b></td><td>".($md_ext_ids->{gold} ? join(", ", map { "<a href='http://genomesonline.org/cgi-bin/GOLD/bin/GOLDCards.cgi?goldstamp=".$_."' target=_blank>".$_."</a>" } split(/, /, $md_ext_ids->{gold})) : "-")."</td></tr>";
$html .= "<tr><td><b>PubMed ID</b></td><td>".($md_ext_ids->{pubmed} ? join(", ", map { "<a href='http://www.ncbi.nlm.nih.gov/pubmed/".$_."' target=_blank>".$_."</a>" } split(/, /, $md_ext_ids->{pubmed})) : "-")."</td></tr>";
$html .= "</table></div></div></p>";
$html .= "<div style='clear: both; height: 10px'></div>";
if ($user && $user->has_right(undef, 'edit', 'metagenome', $mgid)) {
$html .= "<p><div class='quick_links'><ul>";
$self->{metagenome_id} = $mgid;
if (! $job->public) {
if($user->has_right(undef, 'delete', 'metagenome', $mgid)) {
$html .= qq~<li><a style='cursor:pointer;' onclick='
if (document.getElementById("delete_div").style.display == "none") {
document.getElementById("delete_div").style.display = "inline";
} else {
document.getElementById("delete_div").style.display = "none";
}'>Delete</a></li>~;
}
}
$html .= "<li><a target=_blank href='?page=JobShare&metagenome=$mgid&job=".$job->job_id."'>Share</a></li>";
$html .= qq~<li><a style='cursor:pointer;' onclick='
if (document.getElementById("edit_name_div").style.display == "none") {
document.getElementById("edit_name_div").style.display = "inline";
} else {
document.getElementById("edit_name_div").style.display = "none";
}'>Edit Name</a></li>~;
unless ($job->public) {
$html .= "<li><a target=_blank href='?page=PublishGenome&metagenome=$mgid'>Make Public</a></li>";
}
my $attr = $job->data();
if (!exists($attr->{priority}) || (exists($attr->{priority}) && $attr->{priority} eq 'never')) {
$html .= "</ul></div></p><p><div style='display:none;' id='delete_div'>".$self->delete_info($job)."</div>";
} else {
$html .= "</ul></div></p><p><div style='display:none;' id='delete_div'><h3>Delete</h3><p>During job submission this job was marked to go public at some point in the future. Thus, this job cannot be deleted.</p></div><br />";
}
$html .= "<div style='display:none;' id='edit_name_div'>".$self->edit_name_info($job)."</div></p>";
}
# get job stats
my $job_dt = DateTime->from_epoch( epoch => str2time($job->created_on) );
my $job_stats = $job->stats();
my $raw_bps = exists($job_stats->{bp_count_raw}) ? $job_stats->{bp_count_raw} : 0;
my $qc_rna_bps = exists($job_stats->{bp_count_preprocessed_rna}) ? $job_stats->{bp_count_preprocessed_rna} : 0;
my $qc_bps = exists($job_stats->{bp_count_preprocessed}) ? $job_stats->{bp_count_preprocessed} : 0;
my $raw_seqs = exists($job_stats->{sequence_count_raw}) ? $job_stats->{sequence_count_raw} : 0;
my $derep_seqs = exists($job_stats->{sequence_count_dereplication_removed}) ? $job_stats->{sequence_count_dereplication_removed} : 0;
my $qc_rna_seqs = exists($job_stats->{sequence_count_preprocessed_rna}) ? $job_stats->{sequence_count_preprocessed_rna} : 0;
my $qc_seqs = exists($job_stats->{sequence_count_preprocessed}) ? $job_stats->{sequence_count_preprocessed} : 0;
my $raw_len_avg = exists($job_stats->{average_length_raw}) ? $job_stats->{average_length_raw} : 0;
my $qc_rna_len_avg = exists($job_stats->{average_length_preprocessed_rna}) ? $job_stats->{average_length_preprocessed_rna} : 0;
my $qc_len_avg = exists($job_stats->{average_length_preprocessed}) ? $job_stats->{average_length_preprocessed} : 0;
my $raw_len_std = exists($job_stats->{standard_deviation_length_raw}) ? $job_stats->{standard_deviation_length_raw} : 0;
my $qc_rna_len_std = exists($job_stats->{standard_deviation_length_preprocessed_rna}) ? $job_stats->{standard_deviation_length_preprocessed_rna} : 0;
my $qc_len_std = exists($job_stats->{standard_deviation_length_preprocessed}) ? $job_stats->{standard_deviation_length_preprocessed} : 0;
my $raw_gc_avg = exists($job_stats->{average_gc_content_raw}) ? $job_stats->{average_gc_content_raw} : 0;
my $qc_rna_gc_avg = exists($job_stats->{average_gc_content_preprocessed_rna}) ? $job_stats->{average_gc_content_preprocessed_rna} : 0;
my $qc_gc_avg = exists($job_stats->{average_gc_content_preprocessed}) ? $job_stats->{average_gc_content_preprocessed} : 0;
my $raw_gc_std = exists($job_stats->{standard_deviation_gc_content_raw}) ? $job_stats->{standard_deviation_gc_content_raw} : 0;
my $qc_rna_gc_std = exists($job_stats->{standard_deviation_gc_content_preprocessed_rna}) ? $job_stats->{standard_deviation_gc_content_preprocessed_rna} : 0;
my $qc_gc_std = exists($job_stats->{standard_deviation_gc_content_preprocessed}) ? $job_stats->{standard_deviation_gc_content_preprocessed} : 0;
my $r_clusts = exists($job_stats->{cluster_count_processed_rna}) ? $job_stats->{cluster_count_processed_rna} : 0;
my $r_clust_seq = exists($job_stats->{clustered_sequence_count_processed_rna}) ? $job_stats->{clustered_sequence_count_processed_rna} : 0;
my $aa_reads = exists($job_stats->{read_count_processed_aa}) ? $job_stats->{read_count_processed_aa} : 0;
my $rna_reads = exists($job_stats->{read_count_processed_rna}) ? $job_stats->{read_count_processed_rna} : 0;
my $aa_feats = exists($job_stats->{sequence_count_processed_aa}) ? $job_stats->{sequence_count_processed_aa} : 0;
my $rna_feats = exists($job_stats->{sequence_count_processed_rna}) ? $job_stats->{sequence_count_processed_rna} : 0;
my $aa_sims = exists($job_stats->{sequence_count_sims_aa}) ? $job_stats->{sequence_count_sims_aa} : 0;
my $rna_sims = exists($job_stats->{sequence_count_sims_rna}) ? $job_stats->{sequence_count_sims_rna} : 0;
my $aa_ontol = exists($job_stats->{sequence_count_ontology}) ? $job_stats->{sequence_count_ontology} : 0;
my $ann_reads = exists($job_stats->{read_count_annotated}) ? $job_stats->{read_count_annotated} : 0;
my $alpha_num = exists($job_stats->{alpha_diversity_shannon}) ? $job_stats->{alpha_diversity_shannon} : 0;
my $drisee_num = exists($job_stats->{drisee_score_raw}) ? $job_stats->{drisee_score_raw} : 0;
my $is_rna = ($md_seq_type =~ /amplicon/i) ? 1 : 0;
my $qc_fail_seqs = $raw_seqs - $qc_seqs;
my $ann_rna_reads = $rna_sims ? ($rna_sims - $r_clusts) + $r_clust_seq : 0;
my $ann_aa_reads = ($ann_reads && ($ann_reads > $ann_rna_reads)) ? $ann_reads - $ann_rna_reads : 0;
my $unkn_aa_reads = $aa_reads - $ann_aa_reads;
my $unknown_all = $raw_seqs - ($qc_fail_seqs + $unkn_aa_reads + $ann_aa_reads + $ann_rna_reads);
if ($is_rna) {
$qc_fail_seqs = $raw_seqs - $qc_rna_seqs;
$unkn_aa_reads = 0;
$ann_aa_reads = 0;
$unknown_all = $raw_seqs - ($qc_fail_seqs + $ann_rna_reads);
} else {
if ($unknown_all < 0) { $unknown_all = 0; }
if ($raw_seqs < ($qc_fail_seqs + $unknown_all + $unkn_aa_reads + $ann_aa_reads + $ann_rna_reads)) {
my $diff = ($qc_fail_seqs + $unknown_all + $unkn_aa_reads + $ann_aa_reads + $ann_rna_reads) - $raw_seqs;
$unknown_all = ($diff > $unknown_all) ? 0 : $unknown_all - $diff;
}
if (($unknown_all == 0) && ($raw_seqs < ($qc_fail_seqs + $unkn_aa_reads + $ann_aa_reads + $ann_rna_reads))) {
my $diff = ($qc_fail_seqs + $unkn_aa_reads + $ann_aa_reads + $ann_rna_reads) - $raw_seqs;
$unkn_aa_reads = ($diff > $unkn_aa_reads) ? 0 : $unkn_aa_reads - $diff;
}
## hack to make MT numbers add up
if (($unknown_all == 0) && ($unkn_aa_reads == 0) && ($raw_seqs < ($qc_fail_seqs + $ann_aa_reads + $ann_rna_reads))) {
my $diff = ($qc_fail_seqs + $ann_aa_reads + $ann_rna_reads) - $raw_seqs;
$ann_rna_reads = ($diff > $ann_rna_reads) ? 0 : $ann_rna_reads - $diff;
}
}
# get charts
my $colors = ["#6C6C6C","#dc3912","#ff9900","#109618","#3366cc","#990099"];
my $summary_chart = $self->get_summary_chart($colors, $qc_fail_seqs, $unknown_all, $unkn_aa_reads, $ann_aa_reads, $ann_rna_reads);
my $source_chart = $self->get_source_chart($job, $is_rna, format_number($aa_sims), percent($aa_sims,$aa_feats), format_number($aa_ontol), percent($aa_ontol,$aa_sims), format_number($ann_rna_reads), percent($ann_rna_reads,$raw_seqs));
my $taxa_chart = $self->get_taxa_chart($job);
my $func_chart = $self->get_func_charts($job, $aa_feats, $aa_sims);
my $drisee_plot = $self->get_drisee_chart($job);
my $bp_consensus = $self->get_consensus_chart($job);
# mg summary text
$html .= "<a name='summary_ref'></a><table><tr><td>";
$html .= "<h3>Metagenome Summary</h3><div style='width:450px;'>";
$html .= "<p>Dataset ".$job->name." was uploaded on ".$job_dt->mdy('/')." and contains ".format_number($raw_seqs)." sequences totaling ".format_number($raw_bps)." basepairs with an average length of ".format_number($raw_len_avg)." bps. The piechart below breaks down the uploaded sequences into ".($is_rna ? '3' : '5')." distinct categories.</p>";
$html .= "<p>".format_number($qc_fail_seqs)." sequences (".percent($qc_fail_seqs,$raw_seqs).") failed to pass the QC pipeline. Of the sequences that passed QC, ".format_number($ann_rna_reads)." sequences (".percent($ann_rna_reads,$raw_seqs).") contain ribosomal RNA genes. ";
unless ($is_rna) {
$html .= "Of the remainder, ".format_number($ann_aa_reads)." sequences (".percent($ann_aa_reads,$raw_seqs).") contain predicted proteins with known functions and ".format_number($unkn_aa_reads)." sequences (".percent($unkn_aa_reads,$raw_seqs).") contain predicted proteins with unknown function. ";
}
$html .= format_number($unknown_all)." sequences (".percent($unknown_all,$raw_seqs).") have no rRNA genes";
unless ($is_rna) {
$html .= " or predicted proteins";
}
$html .= ".</p><p>The analysis results shown on this page are computed by MG-RAST. Please note that authors may upload data that they have published their own analysis for, in such cases comparison within the MG-RAST framework can not be done.</p>";
$html .= "<p><a class='nav_top' target=_blank href='metagenomics.cgi?page=DownloadMetagenome&metagenome=$mgid'><img src='./Html/mg-download.png' style='width:20px;height:20px;' title='Download $mgid'></a> <span style='font-variant:small-caps'>download</span> data and annotations";
$html .= "<br><a class='nav_top' target=_blank href='metagenomics.cgi?page=Analysis&metagenome=$mgid'><img src='./Html/analysis.gif' style='width:20px;height:20px;' title='Analyze $mgid'></a> <span style='font-variant:small-caps'>analyze</span> annotations in detail.";
$html .= "<br><a class='nav_top' href='#search_ref'><img src='./Html/lupe.png' style='width:20px;height:20px;' title='Search $mgid'></a> <span style='font-variant:small-caps'>search</span> through annotations.</p>";
$html .= "</div><p><span style='padding-left:15px;'><b>Sequence Breakdown</b></span>$summary_chart";
$html .= "<em style='padding-left:25px;font-size:x-small'>Note: Sequences containing multiple predicted features are only counted in one category.</em><br>";
$html .= "<em style='padding-left:50px;font-size:x-small'>Currently downloading of sequences via chart slices is not enabeled.</em>";
$html .= "</p></td><td style='padding-left:25px;'></td>";
# toc
$html .= "<td><h3>Table of Contents</h3>";
$html .= "<div style='border:2px solid #AAAAAA;padding:10px;background-color:#EEEEEE;'>";
# tools
$html .= "<li>Work with Metagenome Data</li>";
$html .= "<ul style='margin:0;'>";
$html .= "<li><a href='#download_ref'>Download</a></li>";
$html .= "<li><a href='#analyze_ref'>Analyze</a></li>";
$html .= "<li><a href='#search_ref'>Search</a></li>";
$html .= "</ul>";
# overview
$html .= "<li style='padding-top:5px;'>Overview of Metagenome</li>";
$html .= "<ul style='margin:0;'>";
$html .= "<li><a href='#summary_ref'>Summary</a></li>";
if (exists($self->{meta_info}->{project_description})) {
$html .= "<li><a href='#project_ref'>Project Information</a></li>";
}
$html .= "<li><a href='#mixs_ref'>GSC MIxS Info</a></li>";
if ($md_ext_ids->{pubmed}) {
$html .= "<li><a href='#pub_ref'>Publication Abstracts</a></li>";
}
$html .= "</ul>";
# qc
$html .= "<li style='padding-top:5px;'>Metagenome QC</li>";
$html .= "<ul style='margin:0;'>";
if (exists $job_stats->{drisee_score_raw}) {
$html .= "<li><a href='#drisee_ref'>DRISEE</a></li>";
}
$html .= "<li><a href='#kmer_ref'>Kmer Profile</a></li>";
if ($bp_consensus) {
$html .= "<li><a href='#consensus_ref'>Nucleotide Histogram</a></li>";
}
$html .= "</ul>";
# organism
$html .= "<li style='padding-top:5px;'>Organism Breakdown</li>";
$html .= "<ul style='margin:0;'>";
if ($taxa_chart) {
$html .= "<li><a href='#org_ref'>Taxonomic Distribution</a></li>";
}
$html .= "<li><a href='#rank_ref'>Rank Abundance Plot</a></li>";
$html .= "<li><a href='#rare_ref'>Rarefaction Curve</a></li>";
$html .= "<li><a href='#alpha_ref'>Alpha Diversity</a></li>";
$html .= "</ul>";
# function
if ($func_chart && (! $is_rna)) {
$html .= "<li style='padding-top:5px;'>Functional Breakdown</li>";
$html .= "<ul style='margin:0;'><li><a href='#func_ref'>Functional Categories</a></li></ul>";
}
# technical
$html .= "<li style='padding-top:5px;'>Technical Data</li>";
$html .= "<ul style='margin:0;'>";
$html .= "<li><a href='#stats_ref'>Statistics</a></li>";
$html .= "<li><a href='#meta_ref'>Metadata</a></li>";
if ($source_chart) {
$html .= "<li><a href='#source_ref'>Source Distribution</a></li>";
}
# sequence length histogram
my @len_raw_hist = sort {$a->[0] <=> $b->[0]} @{ $mgdb->get_histogram_nums($job->job_id, 'len', 'raw') };
my @len_qc_hist = sort {$a->[0] <=> $b->[0]} @{ $mgdb->get_histogram_nums($job->job_id, 'len', 'qc') };
my $len_min = (@len_raw_hist && @len_qc_hist) ? min($len_raw_hist[0][0], $len_qc_hist[0][0]) : (@len_raw_hist ? $len_raw_hist[0][0] : (@len_qc_hist ? $len_qc_hist[0][0] : 0));
my $len_max = (@len_raw_hist && @len_qc_hist) ? max($len_raw_hist[-1][0], $len_qc_hist[-1][0]) : (@len_raw_hist ? $len_raw_hist[-1][0] : (@len_qc_hist ? $len_qc_hist[-1][0] : 0));
my $len_raw_bins = @len_raw_hist ? &get_bin_set(\@len_raw_hist, $len_min, $len_max, $self->data('bin_size')) : [];
my $len_qc_bins = @len_qc_hist ? &get_bin_set(\@len_qc_hist, $len_min, $len_max, $self->data('bin_size')) : [];
unless($len_max == $len_min) {
$html .= "<li><a href='#len_ref'>Sequence Length Histogram</a></li>";
}
$html .= "<li><a href='#gc_ref'>Sequence GC Distribution</a></li>";
$html .= "</ul></ul></div></td></tr></table><br>";
# project description
$html .= "<br><a name='project_ref'></a><a name='mixs_ref'></a><table><tr>";
if ($self->{project}) {
$html .= "<td><h3>Project Information</h3>";
$html .= "<div style='width:375px;'><p>This dataset is part of project $project_link.</p>";
if (exists $self->{meta_info}->{project_description}) {
$html .= "<p>".$self->{meta_info}->{project_description}."</p>";
}
$html .= "<p>There are $projectjob_num other metagenomes in this project</p></div></td>";
$html .= "<td rowspan='2' style='padding-left:25px;'></td>";
$html .= "<td rowspan='2'>";
} else {
$html .= "<td>";
}
# gsc mixs
$html .= "<h3>GSC MIxS Info</h3>";
$html .= "<div class='metagenome_info' style='width: 300px;'><ul style='margin: 0; padding: 0;'>";
$html .= "<li class='even'><label style='text-align: left;'>Investigation Type</label><span style='width: 180px'>".(($md_seq_type =~ /wgs|amplicon|mt/i) ? $mddb->investigation_type_alias($md_seq_type) : "unknown")."</span></li>";
$html .= "<li class='odd'><label style='text-align: left;'>Project Name</label><span style='width: 180px'>".($self->{project} ? $project_link : "-")."</span></li>";
$html .= "<li class='even'><label style='text-align: left;'>Latitude and Longitude</label><span style='width: 180px'>".(scalar(@$md_coordinate) ? join(", ", @$md_coordinate) : "-, -")."</span></li>";
$html .= "<li class='odd'><label style='text-align: left;'>Country and/or Sea, Location</label><span style='width: 180px'>".(scalar(@$md_region) ? join("<br>", @$md_region) : "-")."</span></li>";
$html .= "<li class='even'><label style='text-align: left;'>Collection Date</label><span style='width: 180px'>".($md_date_time ? $md_date_time : "-")."</span></li>";
$html .= "<li class='odd'><label style='text-align: left;'>Environment (Biome)</label><span style='width: 180px'>".($md_biome ? $md_biome : "-")."</span></li>";
$html .= "<li class='even'><label style='text-align: left;'>Environment (Feature)</label><span style='width: 180px'>".($md_feature ? $md_feature : "-")."</span></li>";
$html .= "<li class='odd'><label style='text-align: left;'>Environment (Material)</label><span style='width: 180px'>".($md_material ? $md_material : "-")."</span></li>";
$html .= "<li class='even'><label style='text-align: left;'>Environmental Package</label><span style='width: 180px'>".($md_enviroment ? $md_enviroment : "-")."</span></li>";
$html .= "<li class='odd'><label style='text-align: left;'>Sequencing Method</label><span style='width: 180px'>".($md_seqmethod ? $md_seqmethod : "-")."</span></li>";
$html .= "<li class='even'><label style='text-align: left;'><a href='#meta_ref'>More Metadata</a></label><span style='width: 180px'> </span></li>";
$html .= "</ul></div></td></tr><tr><td style='vertical-align:top'><ul>";
# link to similar mgs
$html .= "<li style='margin-top:0.25em;margin-bottom:0.25em;list-style-type:none;'>";
if (($projectjob_num > 0) && $projectjob_url) {
$html .= "<a target=_blank href='$projectjob_url'>» find metagenomes within this project</a>";
} else {
$html .= "» find metagenomes within this project";
}
$html .= "</li><li style='margin-top:0.25em;margin-bottom:0.25em;list-style-type:none;'>";
if ($md_biome) {
$html .= "<a target=_blank href='metagenomics.cgi?page=MetagenomeSearch&run_now=1&smode=2&qnum=1&type_q1=metadata&match_q1=1_1&extra_q1=biome-information_envo_lite&input_q1=$md_biome'>» find metagenomes within this biome</a>";
} else {
$html .= "» find metagenomes within this biome";
}
$html .= "</li><li style='margin-top:0.25em;margin-bottom:0.25em;list-style-type:none;'>";
if ($md_country) {
$html .= "<a target=_blank href='metagenomics.cgi?page=MetagenomeSearch&run_now=1&smode=2&qnum=1&type_q1=metadata&match_q1=1_1&extra_q1=sample-origin_country&input_q1=$md_country'>» find metagenomes within this country</a>";
} else {
$html .= "» find metagenomes within this country";
}
$html .= "</li><li style='margin-top:0.25em;margin-bottom:0.25em;list-style-type:none;'>";
if (scalar(@$md_coordinate) && ($md_coordinate->[0] =~ /^-?\d+\.?\d*$/) && ($md_coordinate->[1] =~ /^-?\d+\.?\d*$/)) {
my ($lat, $lng) = @$md_coordinate;
my $lat_10 = "input_q1=" . join("_", sort {$a <=> $b} ($lat - 0.1, $lat + 0.1));
my $lng_10 = "input_q2=" . join("_", sort {$a <=> $b} ($lng - 0.1, $lng + 0.1));
my $lat_30 = "input_q1=" . join("_", sort {$a <=> $b} ($lat - 0.3, $lat + 0.3));
my $lng_30 = "input_q2=" . join("_", sort {$a <=> $b} ($lng - 0.3, $lng + 0.3));
my $lat_100 = "input_q1=" . join("_", sort {$a <=> $b} ($lat - 1.0, $lat + 1.0));
my $lng_100 = "input_q2=" . join("_", sort {$a <=> $b} ($lng - 1.0, $lng + 1.0));
my $link = "metagenomics.cgi?page=MetagenomeSearch&run_now=1&smode=2&qnum=2&type_q1=metadata&type_q2=metadata&match_q1=2_1&match_q2=2_1&extra_q1=sample-origin_latitude&extra_q2=sample-origin_longitude";
$html .= "» find metagenomes within <a target=_blank href='$link&$lat_10&$lng_10'>10</a> | <a target=_blank href='$link&$lat_30&$lng_30'>30</a> | <a target=_blank href='$link&$lat_100&$lng_100'>100</a> kilometers";
} else {
$html .= "» find metagenomes within 10 | 30 | 100 kilometers";
}
$html .= "</li></ul></td></tr></table><br>";
# technical text
$html .= "<br><a name='stats_ref'><table><tr><td>";
$html .= "<h3>Analysis Flowchart</h3><div style='width:375px;'>";
if ($is_rna) {
$html .= "<p>".format_number($qc_fail_seqs)." sequences failed quality control. Of the ".format_number($qc_rna_seqs)." sequences (totaling ".format_number($qc_rna_bps)." bps) that passed quality control, ".format_number($ann_rna_reads)." (".percent($ann_rna_reads,$qc_rna_seqs).") produced a total of ".format_number($rna_sims)." identified ribosomal RNAs.</p>";
} else {
$html .= "<p>".format_number($qc_fail_seqs)." sequences failed quality control. Of those, dereplication identified ".format_number($derep_seqs)." sequences (".percent($derep_seqs,$raw_seqs)." of total) as artificial duplicate reads (ADRs). Of the ".format_number($qc_seqs)." sequences (totaling ".format_number($qc_bps)." bps) that passed quality control, ".format_number($aa_reads)." (".percent($aa_reads,$qc_seqs).") produced a total of ".format_number($aa_feats)." predicted protein coding regions. Of these ".format_number($aa_feats)." predicted protein features, ".format_number($aa_sims)." (".percent($aa_sims,$aa_feats)." of features) have been assigned an annotation using at least one of our protein databases (M5NR) and ".format_number($aa_feats-$aa_sims)." (".percent($aa_feats-$aa_sims,$aa_feats)." of features) have no significant similarities to the protein database (orfans). ".format_number($aa_ontol)." features (".percent($aa_ontol,$aa_sims)." of annotated features) were assigned to functional categories.</p>";
}
$html .= "</td><td rowspan='3' style='padding-left:25px;'></td>";
# technical stats
$html .= "<td rowspan='3'><h3>Analysis Statistics</h3>";
$html .= "<div class='metagenome_info' style='width: 320px;'><ul style='margin: 0; padding: 0;'>";
$html .= "<li class='even'><label style='text-align: left;white-space:nowrap;'>Upload: bp Count</label><span style='width: 200px'>".format_number($raw_bps)." bp</span></li>";
$html .= "<li class='odd'><label style='text-align: left;white-space:nowrap;'>Upload: Sequences Count</label><span style='width: 200px'>".format_number($raw_seqs)."</span></li>";
$html .= "<li class='even'><label style='text-align: left;white-space:nowrap;'>Upload: Mean Sequence Length</label><span style='width: 200px'>".format_number($raw_len_avg)." ± ".format_number($raw_len_std)." bp</span></li>";
$html .= "<li class='odd'><label style='text-align: left;white-space:nowrap;'>Upload: Mean GC percent</label><span style='width: 200px'>".format_number($raw_gc_avg)." ± ".format_number($raw_gc_std)." %</span></li>";
if ($is_rna) {
$html .= "<li class='even'><label style='text-align: left;white-space:nowrap;'>Post QC: bp Count</label><span style='width: 200px'>".format_number($qc_rna_bps)." bp</span></li>";
$html .= "<li class='odd'><label style='text-align: left;white-space:nowrap;'>Post QC: Sequences Count</label><span style='width: 200px'>".format_number($qc_rna_seqs)."</span></li>";
$html .= "<li class='even'><label style='text-align: left;white-space:nowrap;'>Post QC: Mean Sequence Length</label><span style='width: 200px'>".format_number($qc_rna_len_avg)." ± ".format_number($qc_len_std)." bp</span></li>";
$html .= "<li class='odd'><label style='text-align: left;white-space:nowrap;'>Post QC: Mean GC percent</label><span style='width: 200px'>".format_number($qc_rna_gc_avg)." ± ".format_number($qc_gc_std)." %</span></li>";
$html .= "<li class='even'><label style='text-align: left;white-space:nowrap;'>Processed: Predicted rRNA Features</label><span style='width: 200px'>".format_number($rna_feats)."</span></li>";
$html .= "<li class='odd'><label style='text-align: left;white-space:nowrap;'>Alignment: Identified rRNA Features</label><span style='width: 200px'>".format_number($rna_sims)."</span></li>";
} else {
$html .= "<li class='even'><label style='text-align: left;white-space:nowrap;'>Artificial Duplicate Reads: Sequence Count</label><span style='width: 200px'>".format_number($derep_seqs)."</span></li>";
$html .= "<li class='odd'><label style='text-align: left;white-space:nowrap;'>Post QC: bp Count</label><span style='width: 200px'>".format_number($qc_bps)." bp</span></li>";
$html .= "<li class='even'><label style='text-align: left;white-space:nowrap;'>Post QC: Sequences Count</label><span style='width: 200px'>".format_number($qc_seqs)."</span></li>";
$html .= "<li class='odd'><label style='text-align: left;white-space:nowrap;'>Post QC: Mean Sequence Length</label><span style='width: 200px'>".format_number($qc_len_avg)." ± ".format_number($qc_len_std)." bp</span></li>";
$html .= "<li class='even'><label style='text-align: left;white-space:nowrap;'>Post QC: Mean GC percent</label><span style='width: 200px'>".format_number($qc_gc_avg)." ± ".format_number($qc_gc_std)." %</span></li>";
$html .= "<li class='odd'><label style='text-align: left;white-space:nowrap;'>Processed: Predicted Protein Features</label><span style='width: 200px'>".format_number($aa_feats)."</span></li>";
$html .= "<li class='even'><label style='text-align: left;white-space:nowrap;'>Processed: Predicted rRNA Features</label><span style='width: 200px'>".format_number($rna_feats)."</span></li>";
$html .= "<li class='odd'><label style='text-align: left;white-space:nowrap;'>Alignment: Identified Protein Features</label><span style='width: 200px'>".format_number($aa_sims)."</span></li>";
$html .= "<li class='even'><label style='text-align: left;white-space:nowrap;'>Alignment: Identified rRNA Features</label><span style='width: 200px'>".format_number($rna_sims)."</span></li>";
$html .= "<li class='odd'><label style='text-align: left;white-space:nowrap;'>Annotation: Identified Functional Categories</label><span style='width: 200px'>".format_number($aa_ontol)."</span></li>";
}
$html .= "</ul></div></td></tr>";
# technical flowchart
my $fc_aa_titles = ["Passed QC","Predicted\\nFeatures","Annotated\\nProtein","Functional\\nCategory"];
my $fc_rna_titles = ["Passed QC","Predicted\\nrRNAs"];
my $fc_aa_colors = [[$colors->[0],$colors->[1]], [$colors->[1],$colors->[4],$colors->[2]], [$colors->[2],$colors->[3]], [$colors->[3],$colors->[5]]];
my $fc_rna_colors = [[$colors->[0],$colors->[1]], [$colors->[1],$colors->[4]]];
my $fc_aa_data = [[$raw_seqs,$qc_seqs], [$qc_seqs,$ann_rna_reads,$aa_reads], [$aa_feats,$aa_sims], [$aa_sims,$aa_ontol]];
my $fc_rna_data = [[$raw_seqs,$qc_rna_seqs], [$qc_rna_seqs,$ann_rna_reads]];
my $fc_titles = $is_rna ? array2json($fc_rna_titles, 1) : array2json($fc_aa_titles, 1);
my $fc_colors = $is_rna ? array2json($fc_rna_colors, 2) : array2json($fc_aa_colors, 2);
my $fc_data = $is_rna ? array2json($fc_rna_data, 2) : array2json($fc_aa_data, 2);
$html .= "<tr><td><div id='flowchart_div'></div>";
$html .= "<img src='./Html/clear.gif' onload='draw_bar_plot(\"flowchart_div\", $fc_titles, $fc_colors, $fc_data);'></td></tr></table>";
# drisee score
my $drisee_refrence = "<p>Duplicate Read Inferred Sequencing Error Estimation (<a target=_blank href='http://www.ploscompbiol.org/article/info%3Adoi%2F10.1371%2Fjournal.pcbi.1002541'>Keegan et al., PLoS Computational Biology, 2012</a>)</p>";
my $drisee_boilerplate = qq~
<p>DRISEE is a tool that utilizes artificial duplicate reads (ADRs) to provide a platform independent assessment of sequencing error in metagenomic (or genomic) sequencing data. DRISEE is designed to consider shotgun data. Currently, it is not appropriate for amplicon data.</p>
<p>Note that DRISEE is designed to examine sequencing error in raw whole genome shotgun sequence data. It assumes that adapter and/or barcode sequences have been removed, but that the sequence data have not been modified in any additional way. (e.g.) Assembly or merging, QC based triage or trimming will both reduce DRISEE's ability to provide an accurate assessment of error by removing error before it is analyzed.</p>~;
if (exists($job_stats->{drisee_score_raw}) && ($drisee_num == 0) && (! $is_rna)) {
$html .= qq~<a name='drisee_ref'></a>
<h3>DRISEE
<a target=_blank href='http://blog.metagenomics.anl.gov/glossary-of-mg-rast-terms-and-concepts/#drisee' style='font-size:14px;padding-left:5px;'>[?]</a></h3>
$drisee_refrence
<p>DRISEE could not produce a profile; the sample failed to meet the minimal ADR requirements to calculate an error profile (see Keegan et al. 2012)</p>
$drisee_boilerplate
~;
} elsif (($drisee_num > 0) && (! $is_rna)) {
my ($min, $max, $avg, $stdv) = @{ $jobdbm->JobStatistics->stats_for_tag('drisee_score_raw', undef, undef, 1) };
my $drisee_score = sprintf("%.3f", $drisee_num);
my $drisee_info = $self->get_drisee_info($job);
## [ Input seqs, Processed bins, Processed seqs, Drisee score ]
$html .= qq~<a name='drisee_ref'></a>
<h3>DRISEE
<a target=_blank href='http://blog.metagenomics.anl.gov/glossary-of-mg-rast-terms-and-concepts/#drisee' style='font-size:14px;padding-left:5px;'>[?]</a>
<a style='cursor:pointer;clear:both;font-size:small;padding-left:10px;' onclick='
if (this.innerHTML=="show") {
this.innerHTML = "hide";
document.getElementById("drisee_show").style.display = "";
} else {
document.getElementById("drisee_show").style.display = "none";
this.innerHTML = "show";
}'>hide</a></h3>
<div id='drisee_show'>
$drisee_refrence
<p><b>Total DRISEE Error = $drisee_score %</b></p>
<img src='./Html/clear.gif' onload='draw_position_on_range("drisee_bar_div", $drisee_num, $min, $max, $avg, $stdv);'>
<div id='drisee_bar_div'></div>
<p>The above image shows the range of total DRISEE percent errors in all of MG-RAST. The min, max, and mean values are shown, with the standard deviation ranges (σ and 2σ) in different shades. The total DRISEE percent error of this metagenome is shown in red.</p>
<p>DRISEE successfully calculated an error profile. DRISEE used ~.format_number($drisee_info->[0]).qq~ reads randomly selected from the ~.format_number($raw_seqs).qq~ reads in this sample. ~.format_number($drisee_info->[2]).qq~ duplicate reads were found with bins of 20 or more reads. A total of ~.format_number($drisee_info->[1]).qq~ such bins were detected</p>
$drisee_boilerplate
$drisee_plot
</div>~;
} elsif ($is_rna) {
$html .= qq~<a name='drisee_ref'></a>
<h3>DRISEE
<a target=_blank href='http://blog.metagenomics.anl.gov/glossary-of-mg-rast-terms-and-concepts/#drisee' style='font-size:14px;padding-left:5px;'>[?]</a></h3>
$drisee_refrence
<p>DRISEE could not produce a profile, this is an Amplicon dataset.</p>
$drisee_boilerplate
~;
}
# kmer profiles
$html .= qq~<a name='kmer_ref'></a>
<h3>Kmer Profiles
<a target=_blank href='http://blog.metagenomics.anl.gov/glossary-of-mg-rast-terms-and-concepts/#kmer_profile' style='font-size:14px;padding-left:5px;'>[?]</a>
<a style='cursor:pointer;clear:both;font-size:small;padding-left:10px;' onclick='
if (this.innerHTML=="show") {
this.innerHTML = "hide";
document.getElementById("kmer_show").style.display = "";
} else {
document.getElementById("kmer_show").style.display = "none";
this.innerHTML = "show";
}'>hide</a></h3>
<div id='kmer_show'>
<a style='cursor:pointer;clear:both;padding-right:20px;' onclick='
var new_type = document.getElementById("kmer_type").value;
var new_size = document.getElementById("kmer_size").value;
execute_ajax("get_kmer_plot", "kmer_div", "metagenome=$mgid&job=$job_id&size="+new_size+"&type="+new_type);'>
Redraw the below plot using the following kmer-plot type:</a>
<select id='kmer_type'>
<option value='abundance'>kmer rank abundance</option>
<option value='ranked'>ranked kmer consumed</option>
<option value='spectrum'>kmer spectrum</option>
</select>
<select id='kmer_size'>
<option value='15'>15-mer</option>
<option value='6'>6-mer</option>
</select>
<img src='./Html/clear.gif' onload='execute_ajax("get_kmer_plot", "kmer_div", "metagenome=$mgid&job=$job_id&size=15&type=abundance");'>
<div id='kmer_div'></div>
</div><br />~;
# consensus plot
if ($bp_consensus) {
$html .= $bp_consensus;
}
# source hits distribution
if ($source_chart) {
$html .= $source_chart;
}
# ontology hits distrubtion
if ($func_chart && (! $is_rna)) {
$html .= $func_chart
}
# taxa hits distribution
if ($taxa_chart) {
$html .= $taxa_chart;
}
# rank abundance plot
my @rank_levels = @{$self->data('tax_levels')};
shift @rank_levels;
my $default_level = $rank_levels[0];
my $level_opts = '';
foreach my $l (@rank_levels) {
$level_opts .= "<option value='$l'>$l</option>";
}
$html .= qq~<a name='rank_ref'></a>
<h3>Rank Abundance Plot
<a style='cursor:pointer;clear:both;font-size:small;padding-left:10px;' onclick='
if (this.innerHTML=="show") {
this.innerHTML = "hide";
document.getElementById("abund_show").style.display = "";
} else {
document.getElementById("abund_show").style.display = "none";
this.innerHTML = "show";
}'>hide</a></h3>
<a style='cursor:pointer;clear:both;padding-right:20px;' onclick='
var new_level = document.getElementById("tax_level").value;
execute_ajax("get_abund_plot", "rank_abund_div", "metagenome=$mgid&job=$job_id&level="+new_level);'>
Redraw the below plot using the following taxonomic level:</a>
<select id='tax_level'>$level_opts</select><br>
<div id='abund_show'>
<img src='./Html/clear.gif' onload='execute_ajax("get_abund_plot", "rank_abund_div", "metagenome=$mgid&job=$job_id&level=$default_level");'>
<div id='rank_abund_div'></div>
</div>~;
# rarefaction curve
$html .= qq~<a name='rare_ref'></a>
<h3>Rarefaction Curve
<a style='cursor:pointer;clear:both;font-size:small;padding-left:10px;' onclick='
if (this.innerHTML=="show") {
this.innerHTML = "hide";
document.getElementById("rare_show").style.display = "";
} else {
document.getElementById("rare_show").style.display = "none";
this.innerHTML = "show";
}'>hide</a></h3>
<div id='rare_show'>
<img src='./Html/clear.gif' onload='execute_ajax("get_rare_curve", "rare_curve_div", "metagenome=$mgid&job=$job_id");'>
<div id='rare_curve_div'></div>
</div>~;
# alpha diversity
$html .= qq~<a name='alpha_ref'></a>
<h3>Alpha Diversity
<a target=_blank href='http://blog.metagenomics.anl.gov/glossary-of-mg-rast-terms-and-concepts/#alpha_diversity' style='font-size:14px;padding-left:5px;'>[?]</a>
<a style='cursor:pointer;clear:both;font-size:small;padding-left:10px;' onclick='
if (this.innerHTML=="show") {
this.innerHTML = "hide";
document.getElementById("alpha_show").style.display = "";
} else {
document.getElementById("alpha_show").style.display = "none";
this.innerHTML = "show";
}'>hide</a></h3>
<div id='alpha_show'>
<img src='./Html/clear.gif' onload='execute_ajax("get_alpha", "alpha_div", "metagenome=$mgid&job=$job_id&alpha=$alpha_num");'>
<div id='alpha_div'></div>
</div>~;
unless($len_max == $len_min) {
$html .= qq~<a name='len_ref'></a>
<h3>Sequence Length Histogram
<a style='cursor:pointer;clear:both;font-size:small;padding-left:10px;' onclick='
if (this.innerHTML=="show") {
this.innerHTML = "hide";
document.getElementById("len_show").style.display = "";
} else {
document.getElementById("len_show").style.display = "none";
this.innerHTML = "show";
}'>hide</a></h3>
<div id='len_show'>
<p>The histograms below show the distribution of sequence lengths in basepairs for this metagenome. Each position represents the number of sequences within a length bp range.</p><p>The data used in these graphs are based on raw upload and post QC sequences.</p>~;
if (@$len_raw_bins > 1) {
my $len_raw_data = join("~", map { $_->[0] .";;" . $_->[1] } @$len_raw_bins);
my $len_raw_link = $self->chart_export_link($len_raw_bins, 'upload_len_hist');
$html .= qq~<p>$len_raw_link</p>
<div id='static2'>
The image is currently dynamic. To be able to right-click/save the image, please click the static button
<input type='button' value='static' onclick='
document.getElementById("static2").style.display = "none";
document.getElementById("dynamic2").style.display = "";
save_image("length_hist_raw");
document.getElementById("length_hist_rawcanvas").style.display = "";
document.getElementById("length_hist_raw").style.display = "none";'>
</div>
<div style='display: none;' id='dynamic2'>The image is currently static. You can right-click/save it. To enable dynamic image, please click the dynamic button
<input type='button' value='dynamic' onclick='
document.getElementById("static2").style.display = "";
document.getElementById("dynamic2").style.display = "none";
document.getElementById("length_hist_rawcanvas").style.display = "none";
document.getElementById("length_hist_raw").style.display = "";'>
</div>
<div><div id='length_hist_raw'></div></div>
<input type='hidden' id='len_data_raw' value='$len_raw_data'>
<img src='./Html/clear.gif' onload='draw_histogram_plot("len_data_raw", "length_hist_raw", "bps", "Number of Reads Uploaded");'>~;
} else {
$html .= "<p><em>Raw sequence length histogram " . (@$len_raw_bins ? "has insufficient data" : "not yet computed") . ".</em></p>";
}
if (@$len_qc_bins > 1) {
my $len_qc_data = join("~", map { $_->[0] .";;" . $_->[1] } @$len_qc_bins);
my $len_qc_link = $self->chart_export_link($len_qc_bins, 'postqc_len_hist');
$html .= qq~<p>$len_qc_link</p>
<div id='static3'>
The image is currently dynamic. To be able to right-click/save the image, please click the static button
<input type='button' value='static' onclick='
document.getElementById("static3").style.display = "none";
document.getElementById("dynamic3").style.display = "";
save_image("length_hist_qc");
document.getElementById("length_hist_qccanvas").style.display = "";
document.getElementById("length_hist_qc").style.display = "none";'>
</div>
<div style='display: none;' id='dynamic3'>The image is currently static. You can right-click/save it. To enable dynamic image, please click the dynamic button
<input type='button' value='dynamic' onclick='
document.getElementById("static3").style.display = "";
document.getElementById("dynamic3").style.display = "none";
document.getElementById("length_hist_qccanvas").style.display = "none";
document.getElementById("length_hist_qc").style.display = "";'>
</div>
<div><div id='length_hist_qc'></div></div>
<input type='hidden' id='len_data_qc' value='$len_qc_data'>
<img src='./Html/clear.gif' onload='draw_histogram_plot("len_data_qc", "length_hist_qc", "bps", "Number of Reads Post QC");'>~;
} else {
$html .= "<p><em>QC sequence length histogram " . (@$len_qc_bins ? "has insufficient data" : "not yet computed") . ".</em></p>";
}
$html .= "</div>";
}
# sequence gc distribution
my @gc_raw_hist = sort {$a->[0] <=> $b->[0]} @{ $mgdb->get_histogram_nums($job->job_id, 'gc', 'raw') };
my @gc_qc_hist = sort {$a->[0] <=> $b->[0]} @{ $mgdb->get_histogram_nums($job->job_id, 'gc', 'qc') };
my $gc_raw_bins = @gc_raw_hist ? &get_bin_set(\@gc_raw_hist, 0, 100, $self->data('bin_size')) : [];
my $gc_qc_bins = @gc_qc_hist ? &get_bin_set(\@gc_qc_hist, 0, 100, $self->data('bin_size')) : [];
$html .= qq~<a name='gc_ref'></a>
<h3>Sequence GC Distribution
<a style='cursor:pointer;clear:both;font-size:small;padding-left:10px;' onclick='
if (this.innerHTML=="show") {
this.innerHTML = "hide";
document.getElementById("gc_show").style.display = "";
} else {
document.getElementById("gc_show").style.display = "none";
this.innerHTML = "show";
}'>hide</a></h3>
<div id='gc_show'>
<p>The histograms below show the distribution of the GC percentage for this metagenome. Each position represents the number of sequences within a GC percentage range. The data used in these graphs is based on raw upload and post QC sequences.</p>~;
if (@$gc_raw_bins > 1) {
my $gc_raw_data = join("~", map { $_->[0] .";;" . $_->[1] } @$gc_raw_bins);
my $gc_raw_link = $self->chart_export_link($gc_raw_bins, 'upload_gc_hist');
$html .= qq~<p>$gc_raw_link</p>
<div id='static4'>
The image is currently dynamic. To be able to right-click/save the image, please click the static button
<input type='button' value='static' onclick='
document.getElementById("static4").style.display = "none";
document.getElementById("dynamic4").style.display = "";
save_image("gc_percent_hist_raw");
document.getElementById("gc_percent_hist_rawcanvas").style.display = "";
document.getElementById("gc_percent_hist_raw").style.display = "none";'>
</div>
<div style='display: none;' id='dynamic4'>The image is currently static. You can right-click/save it. To enable dynamic image, please click the dynamic button
<input type='button' value='dynamic' onclick='
document.getElementById("static4").style.display = "";
document.getElementById("dynamic4").style.display = "none";
document.getElementById("gc_percent_hist_rawcanvas").style.display = "none";
document.getElementById("gc_percent_hist_raw").style.display = "";'>
</div>
<div><div id='gc_percent_hist_raw'></div></div>
<input type='hidden' id='gc_data_raw' value='$gc_raw_data'>
<img src='./Html/clear.gif' onload='draw_histogram_plot("gc_data_raw", "gc_percent_hist_raw", "% gc", "Number of Reads Uploaded");'>~;
} else {
$html .= "<p><em>Raw GC distribution histogram " . (@$gc_raw_bins ? "has insufficient data" : "not yet computed") . ".</em></p>";
}
if (@$gc_qc_bins > 1) {
my $gc_qc_data = join("~", map { $_->[0] .";;" . $_->[1] } @$gc_qc_bins);
my $gc_qc_link = $self->chart_export_link($gc_qc_bins, 'postqc_gc_hist');
$html .= qq~<p>$gc_qc_link</p>
<div id='static5'>
The image is currently dynamic. To be able to right-click/save the image, please click the static button
<input type='button' value='static' onclick='
document.getElementById("static5").style.display = "none";
document.getElementById("dynamic5").style.display = "";
save_image("gc_percent_hist_qc");
document.getElementById("gc_percent_hist_qccanvas").style.display = "";
document.getElementById("gc_percent_hist_qc").style.display = "none";'>
</div>
<div style='display: none;' id='dynamic5'>The image is currently static. You can right-click/save it. To enable dynamic image, please click the dynamic button
<input type='button' value='dynamic' onclick='
document.getElementById("static5").style.display = "";
document.getElementById("dynamic5").style.display = "none";
document.getElementById("gc_percent_hist_qccanvas").style.display = "none";
document.getElementById("gc_percent_hist_qc").style.display = "";'>
</div>
<div><div id='gc_percent_hist_qc'></div></div>
<input type='hidden' id='gc_data_qc' value='$gc_qc_data'>
<img src='./Html/clear.gif' onload='draw_histogram_plot("gc_data_qc", "gc_percent_hist_qc", "% gc", "Number of Reads Post QC");'>~;
} else {
$html .= "<p><em>QC GC distribution histogram " . (@$gc_qc_bins ? "has insufficient data" : "not yet computed") . ".</em></p>";
}
$html .= "</div>";
# download
$html .= "<a name='download_ref'></a><h3>Download This Metagenome</h3>";
$html .= "<p>We provide download capabilities for the submitted sequences, metadata, and all files with results that are produced in the process of MG-RAST analysis on the <a target=_blank href='metagenomics.cgi?page=DownloadMetagenome&metagenome=$mgid'>download page for this metagenome</a>. This includes fasta files with annotations using the <a target=_blank href='http://blog.metagenomics.anl.gov/glossary-of-mg-rast-terms-and-concepts/#m5nr'>M5NR</a>.</p>";
$html .= "<p>We also provide access to the blat alignment summaries underlying our sequence analysis work on the <a target=_blank href='metagenomics.cgi?page=DownloadMetagenome&metagenome=$mgid'>download page</a>.</p>";
$html .= "<p>Please note: The graphs on this page allow downloading the underlying information as tables. The search results and most of the pie-charts allow selecting the fraction of sequences in an element to work with in the <a target=_blank href='http://blog.metagenomics.anl.gov/glossary-of-mg-rast-terms-and-concepts/#workbench'>workbench</a> feature on the <a target=_blank href='metagenomics.cgi?page=Analysis&metagenome=$mgid'>analysis page</a>.</p>";
# analysis
$html .= "<a name='analyze_ref'></a><h3>Analyze This Metagenome</h3>";
$html .= "<p>The <a target=_blank href='metagenomics.cgi?page=Analysis&metagenome=$mgid'>analysis page</a> provides access to analysis and comparative tools including tables, bar charts, trees, principle coordinate analysis, heatmaps and various exports (including FASTA and QIIME). The <a target=_blank href='http://blog.metagenomics.anl.gov/glossary-of-mg-rast-terms-and-concepts/#workbench'>workbench</a> feature allows sub-selections of data to be used e.g. select all E. coli reads and then display the functional categories present just in E. coli reads across multiple data sets.</p>";
# MG search
$html .= qq~<a name='search_ref'></a>
<h3>Search This Metagenome</h3>
<p>Below searches return all predicted functions or organisms that contain the input text.</p>
<input id='func_txt' type='text' />
<button onclick='
var aText=document.getElementById("func_txt").value;
execute_ajax("search_stuff","func_div","type=func&metagenome=$mgid&text="+aText);'>Search Functions</button>
<br><div id='func_div'></div><br>
<input id='org_txt' type='text' />
<button onclick='
var aText=document.getElementById("org_txt").value;
execute_ajax("search_stuff","org_div","type=org&metagenome=$mgid&text="+aText);'>Search Organisms</button>
<br><div id='org_div'></div><br>~;
# metadata table
my $mdata = $mddb->get_metadata_for_table($job);
if (@$mdata > 0) {
my $mtable = $self->application->component('metadata_tbl');
$mtable->width(800);
$mtable->show_export_button({title => "Download this table", strip_html => 1});
if ( scalar(@$mdata) > 25 ) {
$mtable->show_top_browse(1);
$mtable->show_bottom_browse(1);
$mtable->items_per_page(25);
$mtable->show_select_items_per_page(1);
}
$mtable->columns([ { name => 'Category', filter => 1, sortable => 1, operator => 'combobox' },
{ name => 'Label', filter => 1, sortable => 1 },
{ name => 'Value', filter => 1, sortable => 1 }
]);
$mtable->data($mdata);
$html .= qq~<a name='meta_ref'></a>
<h3>Metadata
<a target=_blank href='http://blog.metagenomics.anl.gov/glossary-of-mg-rast-terms-and-concepts/#metadata' style='font-size:14px;padding-left:5px;'>[?]</a>
<a style='cursor:pointer;clear:both;font-size:small;padding-left:10px;' onclick='
if (this.innerHTML=="show") {
this.innerHTML = "hide";
document.getElementById("metadata_show").style.display = "";
} else {
document.getElementById("metadata_show").style.display = "none";
this.innerHTML = "show";
}'>show</a></h3>
<div id='metadata_show' style='display: none;'>
<p>The table below contains contextual metadata describing sample location, acquisition, library construction, sequencing using <a target=_blank href='http://gensc.org'>GSC</a> compliant metadata.</p>~ . $mtable->output . "</div>";
}
# pubmed abstracts
if ($md_ext_ids->{pubmed}) {
my @ids = split(/, /, $md_ext_ids->{pubmed});
$html .= "<a name='pub_ref'></a><h3>Publication Abstracts";
$html .= "<span style='font-size:12px;padding-left:15px;'>[" . join(", ", map { "<a href='http://www.ncbi.nlm.nih.gov/pubmed/".$_."' target=_blank>".$_."</a>" } @ids) . "]</span>";
$html .= "<a style='cursor:pointer;clear:both;font-size:small;padding-left:10px;' onclick='if(this.innerHTML==\"show\"){this.innerHTML=\"hide\";document.getElementById(\"abstracts\").style.display=\"\";}else{document.getElementById(\"abstracts\").style.display=\"none\";this.innerHTML=\"show\"};'>show</a></h3><div id='abstracts' style='display: none;'>";
foreach my $id (@ids) {
$html .= $self->get_pubmed_abstract($id)."<br><br>";
}
$html .= "</div>";
}
# bottom padding
$html .= "<br><br><br><br>";
return $html;
}
sub edit_name_info {
my ($self, $job) = @_;
my $html = "<h3>Edit Metagenome Name</h3>";
$html .= $self->start_form('edit_name', {metagenome => $job->metagenome_id, action => 'edit_name'});
$html .= "Enter new metagenome name: <input type='text' name='new_name' style='width:250px;' value='".$job->name."' />";
$html .= "<span> </span><input type='submit' value='update'>".$self->end_form()."<br />";
return $html;
}
sub edit_name {
my ($self) = @_;
my $app = $self->application();
my $cgi = $app->cgi;
my $user = $app->session->user;
my $mgid = $cgi->param('metagenome');
my $name = $cgi->param('new_name') || '';
$name =~ s/^\s+//;
$name =~ s/\s+$//;
if ($user && ($user->has_right(undef, 'edit', 'metagenome', $mgid))) {
my $job = $app->data_handle('MGRAST')->Job->init({ metagenome_id => $mgid });
my $size = length($name);
if ($size < 5) {
$app->add_message('warning', "new name is too short: ".$name); return 0;
}
elsif ($size > 64) {
$app->add_message('warning', "new name is too long: ".$name); return 0;
}
if ($name eq $job->name) {
$app->add_message('warning', "new name same as old: ".$name); return 0;
}
$job->name($name);
$app->add_message('info', "successfully changed name of $mgid to $name");
}
else {
$app->add_message('warning', "you do not have the permission to edit $mgid"); return 0;
}
return 1;
}
sub delete_info {
my ($self, $job) = @_;
my $html = "<h3>Delete</h3>";
$html .= $self->start_form('delete_job', {metagenome => $job->metagenome_id, non_ajax_action => 'delete_job'});
$html .= "<p><strong>To delete this job, type 'DELETE' into the textbox and click 'delete job'.<br /><div style='color:red;'>THIS WILL DELETE THE JOB AND ALL ASSOCIATED METADATA PERMANENTLY!</div></strong></p>";
$html .= "<input name='confirmation' type='text'>";
$html .= " <input type='submit' value='delete job'>".$self->end_form."<br />";
return $html;
}
sub delete_job {
my ($self) = @_;
my $application = $self->application;
my $user = $application->session->user;
my $cgi = $application->cgi;
my $jobdbm = $application->data_handle('MGRAST');
my $mgid = $cgi->param('metagenome');
my $job = $jobdbm->Job->init({ metagenome_id => $mgid });
my $conf = lc($cgi->param('confirmation'));
unless ($conf && $conf eq 'delete') {
$application->add_message('warning', "Unable to delete metagenome.");
return 1;
}
my ($status, $msg) = $job->user_delete($user);
if($status) {
$cgi->delete('metagenome_id');
$application->add_message('info', "Metagenome $mgid has been deleted");
} else {
$application->add_message('warning', $msg);
}
return 1;
}
sub get_summary_chart {
# failed, unknown, unknown aa, ann aa, ann rna
my ($self, $colors, $failed, $unknown, $aa_unknown, $aa_annotated, $rna_annotated) = @_;
my $colstr = '"'. join('","', @$colors) . '"';
return qq~
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var color = [$colstr];
var data = new google.visualization.DataTable();
data.addColumn("string", "Description");
data.addColumn("number", "Sequences");
data.addRow(["Failed QC", $failed]);
data.addRow(["Unknown", $unknown]);
data.addRow(["Unknown Protein", $aa_unknown]);
data.addRow(["Annotated Protein", $aa_annotated]);
data.addRow(["ribosomal RNA", $rna_annotated]);
var chart = new google.visualization.PieChart(document.getElementById("summary_chart_div"));
chart.draw(data, {width: 400, height: 300, colors: color, sliceVisibilityThreshold: 1/25000, chartArea: {left:25,top:0,width:"100%",height:"100%"}});
}