#!/usr/bin/perl
use strict;
use warnings;

my $pub_tsv = 'page_and_litReview_pubs.tsv';
open PUBS, $pub_tsv or die "Cant open pub file: $pub_tsv\n";

my $header = <PUBS>;
my @header = split "\t", $header;

my $table .= "<table id=\"planarian_ontology\"><thead>\n\t<tr><th>" . join("</th><th>",qw(Title Authors Citation PMID PAGE))  . "</th></tr>\n</thead>\n<tbody>\n";
while (my $line = <PUBS>){
  chomp $line;
  my ($num,$citation,$PMID,$flag,$authors,$title,$url) = split "\t", $line;
  my $textlink = $url;
  if (defined $url){
    $textlink = "<a href=\"$url\">Full Text</a>"; 
  }else{
     $textlink = "None available";
  }
  my $pmidlink = $PMID;
  if ($PMID =~ /^\d+$/){
     $pmidlink = "<a href=\"http://www.ncbi.nlm.nih.gov/pubmed/$PMID\">$PMID</a>";
     if ($flag eq 'Y'){
       $flag = "<a href=\"/search/page/publication?litpmid=$PMID\">search</a>";
     }
  }

  
  $table .= "\t<tr><td>" . join("</td><td>",$title,$authors,$citation,$pmidlink,$flag) . "</td></tr>\n";
}
$table .= "</tbody></table>";
print $table, "\n";
