[Bio] / FigKernelScripts / p3x-eval-bin-site.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/p3x-eval-bin-site.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download) (as text)

1 : parrello 1.1 =head1 Create Master Web Site for Bin Evaluation Pages
2 :    
3 : parrello 1.2 p3x-eval-bin-site.pl [options] binDir webDir
4 : parrello 1.1
5 :     This will create a master web site in the specified location from all the completed bin evaluations in a specified binning sample directory.
6 :     It will look for an C<Eval> subdirectory under the sample directory itself, parse the C<index.tbl>, and move all the HTML files to a web
7 : parrello 1.2 directory with the same name as the sample under the master web directory. In addition, a C<good.tbl> file will be created in the output
8 :     directory that lists all the good genomes.
9 : parrello 1.1
10 :     =head2 Parameters
11 :    
12 :     The positional parameters are the name of the directory containing the binned samples and the name of the output web directory.
13 :    
14 :     The command-line options are those given in L<BinningReports/template_options> plus the following.
15 :    
16 :     =over 4
17 :    
18 :     =item clear
19 :    
20 :     If specified, then the output directory can already exist, and will be cleared prior to building the site.
21 :    
22 :     =back
23 :    
24 :     =cut
25 :    
26 :     use strict;
27 :     use P3DataAPI;
28 :     use P3Utils;
29 :     use File::Copy::Recursive;
30 :     use Template;
31 :     use BinningReports;
32 :    
33 :     $| =1;
34 :     # Get the command-line options.
35 :     my $opt = P3Utils::script_opts('binDir webDir', BinningReports::template_options(),
36 :     ['clear', 'clear output directory before starting']
37 :     );
38 :     # Get the parameters.
39 :     my ($binDir, $webDir) = @ARGV;
40 :     if (! $binDir) {
41 :     die "No input directory specified.";
42 :     } elsif (! -d $binDir) {
43 :     die "$binDir is missing or invalid.";
44 :     } elsif (! $webDir) {
45 :     die "No output directory specified.";
46 :     } elsif (! -d $webDir) {
47 :     print "Creating $webDir.\n";
48 :     File::Copy::Recursive::pathmk($webDir) || die "Could not create $webDir: $!";
49 :     } elsif ($opt->clear) {
50 :     print "Erasing $webDir.\n";
51 :     File::Copy::Recursive::pathempty($webDir) || die "Could not erase $webDir: $!";
52 :     } else {
53 :     die "$webDir already exists.";
54 :     }
55 :     # Set up the templates.
56 :     my ($prefix, $suffix) = BinningReports::build_strings($opt);
57 :     # These structures will contain the data for the master index page.
58 :     my @s;
59 :     my %master = (bad_count => 0, good_count => 0, sample_count => 0);
60 : parrello 1.2 # This will be the output file for the good genomes.
61 :     open(my $gh, ">$webDir/good.tbl") || die "Could not open good.tbl: $!";
62 :     print $gh "genome_id\tgenome_name\n";
63 : parrello 1.1 # Get all the completed samples in the input directory.
64 :     print "Searching $binDir.\n";
65 :     opendir(my $dh, $binDir) || die "Could not open $binDir: $!";
66 :     my @samples = sort grep { -s "$binDir/$_/Eval/index.html" } readdir $dh;
67 :     closedir $dh;
68 :     print scalar(@samples) . " completed samples found in $binDir.\n";
69 :     # Loop through the sample directories.
70 :     for my $sample (@samples) {
71 :     print "Processing $sample.\n";
72 :     # Compute the input and output directories for this sample.
73 :     my $inDir = "$binDir/$sample/Eval";
74 :     my $outDir = "$webDir/$sample";
75 :     # Initialize the counters.
76 :     my ($good, $bad, $total) = (0, 0, 0);
77 :     open(my $ih, "<$inDir/index.tbl") || die "Could not open index file for $sample: $!";
78 : parrello 1.2 my (undef, $cols) = P3Utils::find_headers($ih, indexFile => 'Bin ID', 'Bin Name', 'Good');
79 : parrello 1.1 while (! eof $ih) {
80 : parrello 1.2 my ($binID, $binName, $goodFlag) = P3Utils::get_cols($ih, $cols);
81 : parrello 1.1 # Copy this bin's HTML file.
82 :     File::Copy::Recursive::fcopy("$inDir/$binID.html", "$outDir/$binID.html") || die "Could not copy $binID for $sample: $!";
83 :     # Count the bin.
84 :     $total++;
85 :     if ($goodFlag) {
86 :     $good++;
87 : parrello 1.2 print $gh "$binID\t$binName\n";
88 : parrello 1.1 } else {
89 :     $bad++;
90 :     }
91 :     }
92 :     # Copy the index file.
93 :     File::Copy::Recursive::fcopy("$inDir/index.html", "$outDir/index.html") || die "Could not copy index for $sample: $!";
94 :     # Record the sample.
95 :     push @s, { sample => $sample, good => $good, bad => $bad, total => $total };
96 :     $master{good_count} += $good;
97 :     $master{bad_count} += $bad;
98 :     $master{sample_count}++;
99 :     }
100 :     # Create the master page from the template.
101 :     print "Creating master index.\n";
102 :     $master{samples} = [ sort { $b->{good} <=> $a->{good} or $a->{total} <=> $b->{total} or $a cmp $b } @s];
103 :     my $templateEngine = Template->new(ABSOLUTE => 1);
104 :     my $middle = '';
105 :     $templateEngine->process($opt->templates . "/master.tt", \%master, \$middle) || die "Error in HTML template: " . $templateEngine->error();
106 :     open(my $oh, ">$webDir/index.html") || die "Could not create master index: $!";
107 :     print $oh $prefix . "<title>Master Bin Job Index</title></head></body>" . $middle . $suffix;
108 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3