src/hg/instinct/createDescriptionHTML/createSingleDescriptionHTML.pl 1.1

1.1 2009/09/09 18:31:27 cszeto
perl code to generate description html files
Index: src/hg/instinct/createDescriptionHTML/createSingleDescriptionHTML.pl
===================================================================
RCS file: src/hg/instinct/createDescriptionHTML/createSingleDescriptionHTML.pl
diff -N src/hg/instinct/createDescriptionHTML/createSingleDescriptionHTML.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/hg/instinct/createDescriptionHTML/createSingleDescriptionHTML.pl	9 Sep 2009 18:31:27 -0000	1.1
@@ -0,0 +1,127 @@
+#!/usr/bin/perl -w
+
+################################
+# cszeto Aug 27th 2009
+# Small script designed to make HTML pages for datasets
+################################
+
+my $tableName = "";
+my $datasetsFile = "";
+my $whoami = `whoami`;
+chomp($whoami);
+if(!defined($ARGV[0])){
+    print "ERROR: Incorrect usage.\n";
+    printHelp();
+}else{
+    $tableName = $ARGV[0];
+    if(defined($ARGV[1])){
+        $datasetsFile = $ARGV[1];
+    }else{
+        $datasetsFile = "/data/home/$whoami/kent/src/hg/instinct/hgHeatmap2/hgHeatmapData/datasets.ra";
+    }
+}
+
+#iterate to the entry for the specified tableName in the datasets.ra file.
+open(DATASETS, $datasetsFile) || die "Couldn't open $datasetsFile\n";
+my $flag = 0;
+while(<DATASETS>){
+    if($_ !~ m/^#/){
+        if($_ =~ m/^name\s$tableName$/){
+            $flag++;
+            last;
+        }
+    }
+}
+if($flag == 0){
+    die "Couldn't find an entry named $tableName in $datasetsFile\n";
+}
+
+#create a hash of the contents for the dataset, so you can look them up when creating your html entry
+my %elements = ();
+while(<DATASETS>){
+    if($_ =~ m/^\W*$/){
+        last;
+    }else{
+        chomp($_);
+        my $key = $_;
+        $key =~ s/^(\S+)\s.+/$1/g;
+        my $val = $_;
+        $val =~ s/^\S+\s(.+)/$1/g;
+        $elements{$key} = $val; 
+    }
+}
+close(DATASETS);
+
+#open the template html file for copying, and print in your own details
+open(TEMPLATE, "/var/www/html/cancerGenomics/data-descriptions/template.htm") || die "Couldn't open template HTML file.\n";
+my $outputFile = "/var/www/html/cancerGenomics/data-descriptions/".$tableName.".html";
+open(OUTFILE, ">$outputFile") || die "Couldn't open $outputFile. for writing\n";
+while(<TEMPLATE>){
+    if($_ =~ m/DATA_TITLE/){
+        if(defined($elements{'longLabel'})){
+            $_ =~ s/DATA_TITLE/$elements{'longLabel'}/g;
+        }else{
+            die "No longLabel found in datasets.ra file";
+        }
+    }
+    if($_ =~ m/DATA_DESCRIPTION/){
+        $_ = "\t\t\t<P>\n";
+        if(defined($elements{'article_title'})){
+            $_ = $_."\t\t\tArticle Title: ".$elements{'article_title'}."<BR><BR>\n";
+        }else{
+            $_ = $_."Article Title: Unknown<BR><BR>\n";
+        }
+        if(defined($elements{'author_list'})){
+            $_ = $_."\t\t\tAuthor List: ".$elements{'author_list'}."<BR><BR>\n";
+        }else{
+            $_ = $_."Author List: Unknown<BR><BR>\n";
+        }
+        if(defined($elements{'citation'})){
+            if(defined($elements{'url'})){
+                $_ = $_."\t\t\tCitation: <A HREF=".$elements{'url'}.">".$elements{'citation'}."</A><BR><BR>\n";
+            }else{
+                $_  = $_."Citation: ".$elements{'citation'}."<BR><BR>\n";
+            }
+        }else{
+            if(defined($elements{'url'})){
+                $_ = $_."<A HREF=".$elements{'url'}.">".$elements{'url'}."</A><BR><BR>\n";
+            }else{
+                $_ = $_."Citation: Unknown<BR><BR>\n";
+            }
+        }
+        if(defined($elements{'wrangler'})){
+            $_ = $_."\t\t\tWrangled by: ".$elements{'wrangler'}."<BR><BR>\n";
+        }else{
+            $_ = $_."Wrangled by: Unknown<BR><BR>\n";
+        }
+        if(defined($elements{'wrangling_procedure'})){
+            $_ = $_."\t\t\tWrangling Procedure: ".$elements{'wrangling_procedure'}."<BR>\n";
+        }else{
+            $_ = $_."Wrangling Procedure: Unknown\n";
+        }
+        $_ = $_."\t\t\t</P>\n";
+    } 
+    print OUTFILE "$_";
+}
+close(TEMPLATE);
+close(OUTFILE);
+`chmod 755 $outputFile`; #this is needed for the blue bar to appear at the top
+
+print "Success!\n";
+my $relativeOutputFile = "../cancerGenomics/data-descriptions/".$tableName.".html";
+if(!defined($elements{'local_url'})){
+    print "Add the following line to your $datasetsFile entry:\n";
+    print "local_url $relativeOutputFile\n";
+}else{
+    if($elements{'local_url'} ne $relativeOutputFile){
+        print "Change the local_url field in $tableName entry of $datasetsFile to the following:\n";
+        print "local_url $relativeOutputFile\n";
+    }
+}
+
+sub printHelp {
+    print "Usage:\n\$perl createDescriptionHTML.pl [tableName] (optional: [datasets.ra file])\n";
+    print "If you don't specify a datasets.ra file, it'll look in hgHeatmap2/hgHeatmapData/datasets.ra\n";
+    print "This will create a file called [tableName].html in your /var/www/html/cancerGenomics/dataset-descriptions/ directory\n";
+    exit(1);
+}