[Bio] / GBBergeyDB / get_notes.cgi Repository:
ViewVC logotype

View of /GBBergeyDB/get_notes.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (annotate)
Mon Mar 5 18:50:41 2007 UTC (12 years, 8 months ago) by paczian
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +96 -15 lines
*** empty log message ***

use strict;
use warnings;
use CGI;
use LWP::Simple;

use Table;
use DBMaster;

my $dbmaster = DBMaster->new('GBBergeyDB');
my $cgi = new CGI;

my $spec_name = $cgi->param('spec');
my $species = $dbmaster->Species->get_objects({ name => $spec_name })->[0];
my $genomes = $dbmaster->Genome->get_objects( { Species => $species } );

my $content = "<script type='text/javascript' src='./Html/WAC_PopupTooltip.js'></script><link rel='stylesheet' type='text/css' href='./Html/genomeselector.css'>";

my $dbmaster2 = DBMaster->new('FortyEight_WebApplication');
my $uid = $cgi->param('uid');
my $user_object = $dbmaster2->User->get_objects( { _id => $cgi->param('uid') } )->[0];
my $user = $user_object->firstName . " " . $user_object->lastName;

# check if a new not was added
if ($cgi->param('submitted')) {

    # get the parameters
    my $description = $cgi->param('comment') || "";
    my $timestamp = time();
    my $passed_strain = $cgi->param('strain') || "";
    my $strain;
    unless ($passed_strain =~ /the species/) {
	$strain = $dbmaster->Genome->get_objects( { name => $passed_strain } )->[0];
    }

    # create the note object
    $dbmaster->Note->create( { user        => $user,
			       description => $description,
			       timestamp   => time(),
			       Species     => $species,
			       Strain      => $strain } );
}

# check for ncbi link
my $ncbi_link = "";
my $lineage = "";
if ($species->taxid) {
    $ncbi_link = " <a href='http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=" . $species->taxid . "' target=_blank>" . $species->taxid . "</a>";

    # get ncbi lineage
    my $url="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=taxonomy&report=sgml&id=" . $species->taxid;
    my $ncbi_tax_page = get($url);
    if ($ncbi_tax_page =~ /\&lt\;Lineage\&gt\;cellular organisms; (.*)\&lt\;\/Lineage\&gt\;/) {
	$lineage = $1;
    }
}

# check for bacterio link
my $bacterio_link = "";
if ($species->getBacterioLink) {
    $bacterio_link = " <a href='" . $species->getBacterioLink . "' target=_blank>LPSN</a>";
}

# check for DMSZ link
my $dsmz_link = "-";
if ($species->getDSMZLink) {

    # check if link is valid
    my $page = get($species->getDSMZLink);
    if ($page) {
	$dsmz_link = "<a href='" . $species->getDSMZLink . "' target=_blank>DMSZ</a>";
    }
}

# check for CCUG link
my $ccug_link = "-";
if ($species->getCCUGLink) {

    # check if link is valid
    my $page = get($species->getCCUGLink);
    unless ($page =~ /No record found in ALX with supplied URL/) {
	$ccug_link = "<a href='" . $species->getCCUGLink . "' target=_blank>CCUG</a>";
    }
}

# print Species information
$content .= "<h2>Species: " . $species->name . "</h2>";

# check if this is just an alias
if (($species->ScientificSpecies) && (ref($species->ScientificSpecies))) {
    my $ssname = $species->ScientificSpecies->name;
    $content .= "<b>The new name of this species is <span title='click for details' style='color: blue; cursor: pointer;' onclick='window.open(\"get_notes.cgi?uid=$uid&spec=" . $ssname . "\", \"Species " . $ssname . "\", \"location=no,menu=no,width=850,height=700,status=no,toolbar=no,scrollbars=yes,resizable=yes\");'>" . $ssname . "</span></b><br><br>";
}

my $genus = $species->Genus;
my $family = $genus->Family;
my $order = $family->GOrder;
my $class = $order->Class;
my $phyla = $class->Phyla;
my $domain = $phyla->Domain;

# create species info table
$content .= "<table>";
$content .= "<tr><td><b><a href='http://www.bergeys.org/' target=_blank>Bergey Taxonomy</a></b></td><td>" . $domain->name . "; " .$phyla->name . "; " . $class->name . "; " . $order->name . "; " . $family->name . "; " . $genus->name . "</td></tr>";
$content .= "<tr><td><b><a href='http://www.ncbi.nlm.nih.gov/Taxonomy/' target=_blank>NCBI Taxonomy</a></b></td><td>" . $lineage . "</td></tr>";
$content .= "<tr><td><b><a href='http://www.ncbi.nlm.nih.gov/Taxonomy/' target=_blank>NCBI Taxonomy ID</a></b></td><td>" . $ncbi_link . "</td></tr>";
$content .= "<tr><td><b><a href='http://www.bacterio.cict.fr/' target=_blank>French LPSN</a></b></td><td>" . $bacterio_link . "</td></tr>";
$content .= "<tr><td><b><a href='http://www.dsmz.de/' target=_blank>DMSZ</a></b></td><td>" . $dsmz_link . "</td></tr>";
$content .= "<tr><td><b><a href='http://www.ccug.se/' target=_blank>CCUG</a></b></td><td>" . $ccug_link . "</td></tr>";
$content .= "</table>";

# print list of strains
$content .= "<hr><b>Strains (Type Strain highlighted in blue)</b><br><br>";
my $first = 1;
my $i = 1;
foreach my $genome (@$genomes) {

    # create popup
    my $link_list = "<table>";

    # check for ncbi link
    $ncbi_link = "";
    if ($genome->taxid) {
	$ncbi_link = " <a href='http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=" . $genome->taxid . "' target=_blank>(NCBI)</a>";
	$link_list .= "<tr><td><b>NCBI Taxonomy ID</b></td><td>" . $genome->taxid . "</td></tr>";
    }

    # check for gold link
    my $gold_link = "";
    if ($genome->goldstamp) {
	$gold_link = $genome->goldstamp;
	$gold_link =~ s/\s\(.*\)//;
	$link_list .= "<tr><td><b>GOLD</b></td><td>" . $gold_link . "</td></tr>";
	$gold_link = " <a href='http://genomesonline.org/GOLD_CARDS/" . $gold_link . ".html' target=_blank>(GOLD)</a>";
    }

    # check for DMSZ link
    $dsmz_link = "";
    if ($genome->getDSMZLink) {
	$dsmz_link = " <a href='" . $genome->getDSMZLink . "' target=_blank>(DMSZ)</a>";
	my $dsmz_id = $genome->getDSMZLink;
	$dsmz_id =~ s/(.*)\/strain\.(.*)\.html/$2/;
	$link_list .= "<tr><td><b>DSMZ</b></td><td>" . $dsmz_id . "</td></tr>";
    }

    # check for CCUG link
    $ccug_link = "";
    if ($genome->getCCUGLink) {
	$ccug_link = " <a href='" . $genome->getCCUGLink . "' target=_blank>(CCUG)</a>";
	my $ccug_id = $genome->getCCUGLink;
	$ccug_id =~ s/(.*)\=(.*)/$2/;
	$link_list .= "<tr><td><b>CCUG</b></td><td>" . $ccug_id . "</td></tr>";
    }
    
    # check for ATCC link
    my $atcc_link = "";
    if ($genome->getATCCLink) {
	$atcc_link = " <a href='" . $genome->getATCCLink . "' target=_blank>(ATCC)</a>";
	my $atcc_id = $genome->getATCCLink;
	$atcc_id =~ s/(.*)\=(.*)/$2/;
	$link_list .= "<tr><td><b>ATCC</b></td><td>" . $atcc_id . "</td></tr>";
    }
    
    # check for 16s
    my $sixTeenS = "</td>";
    if ($genome->sixTeenS) {
	$sixTeenS = $genome->sixTeenS;
	$sixTeenS =~ s/(.{50})/$1\<br\>/g;
	$sixTeenS = " <input type='button' value='16S' onclick='var w = window.open(\"\", \"\", \"location=no,menu=no,width=450,height=450,status=no,toolbar=no,scrollbars=yes,resizable=yes\");w.document.open();w.document.write(\"<pre>>" . $genome->name . "<br/>" . $sixTeenS . "</pre>\");w.document.close();'></td>";
    }

    $link_list .= "</table>";

    # check for typestrain
    my $highlight = " style='cursor: default; padding-left: 3px; padding-right: 2px; '";
    if ($genome->typeStrain) {
	$highlight = " style='border: 1px solid blue; padding-left: 2px; padding-right: 2px; cursor: default;'";
    }

    # write popup string
    my $popup = " onmouseover=\"javascript:if(!this.tooltip) this.tooltip=new Popup_Tooltip(this, 'Reference IDs', '" . $link_list . "', '', '', '#466d94', '#ffffff'); this.tooltip.addHandler(); return false;\"";

    # create entry
    $content .= "<span" . $popup . $highlight. ">" . $genome->name . "</span>" . $ncbi_link . $gold_link . $dsmz_link . $ccug_link . $atcc_link . $sixTeenS . "<br/>";
    $i++;
}

# print note-form
$content .= "<hr/>";
$content .= "<h2>Add your comment</h2>";
$content .= "<form action='get_notes.cgi' method='get'>";
$content .= "<input type='hidden' name='spec' value='" . $spec_name . "'>";
$content .= "<input type='hidden' name='submitted' value='1'>";

if (scalar(@$genomes) > 1) {
    $content .= "This note refers to <select name='strain'><option value='species'>the species <i>" . $spec_name . "</i></option>";
    foreach my $genome (@$genomes) {
	$content .= "<option value='" . $genome->name . "'>strain <i>" . $genome->name . "</i></option>";
    }
    $content .= "</select>";
}

# $content .= "<br/>I vote for this species to be <select name='vote'>";
# $content .= "<option value='no_vote'>- no opinion -</option>";
# $content .= "<option value='top_100'>in the top 100</option>";
# $content .= "<option value='top_200'>in the top 200</option>";
# $content .= "<option value='top_300'>in the top 300</option>";
# $content .= "<option value='not_in_list'>not sequenced</option>";
# $content .= "</select>";

# $content .= "<br/>My confidence about this vote is <select name='confidence'>";
# $content .= "<option value='high'>high</option>";
# $content .= "<option value='average' selected=selected>average</option>";
# $content .= "<option value='low'>low</option>";
# $content .= "</select>";

$content .= "<br/><textarea name='comment' cols='50' rows='6'></textarea>";
$content .= "<br/><input type='submit' value='Add'>";
$content .= "<input type='hidden' name='uid' value='" . $cgi->param('uid') . "'>";
$content .= "</form>";

$content .= "<hr/><h2>Current Notes</h2>";
my $notes = $dbmaster->Note->get_objects( { Species => $species } );
if (scalar(@$notes)) {
    foreach my $note (@$notes) {

	# get time of note
	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($note->timestamp);
	my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
	my $time = "$hour:$min";
	$time =~ s/\:(\d)$/\:0$1/;
	my $date = "$abbr[$mon] $mday $time";

	# contruct note headline
	$content .= "<b>" . $date . " " . $note->user . ":</b><br/>";

	# check for reference to strain
	if ($note->Strain) {
	    $content .= "<b>Referred Strain:</b> " . $note->Strain->name . "<br/>";
	}

	# check for voting
	if ($note->voting) {

	    # check confidence
	    my $confidence;
	    if ($note->confidence == 1) {
		$confidence = " high";
	    } elsif ($note->confidence == 2) {
		$confidence = "n average";
	    } else {
		$confidence = " low";
	    }

	    # check voting
	    my $voting;
	    if ($note->voting == 1) {
		$voting = "be in the top 100 to be sequenced.";
	    } elsif ($note->voting == 2) {
		$voting = "be in the top 200 to be sequenced.";
	    } elsif ($note->voting == 3) {
		$voting = "be in the top 300 to be sequenced.";
	    } else {
		$voting = "not be sequenced.";
	    }

	    # construct voting sentence
	    $content .= "<b>Vote:</b><br/>I have a" . $confidence . " confidence that this species should " . $voting . "<br/>";
	}

	# print description
	$content .= "<b>Note:</b><br/><div style='width: 300px;'>" . $note->description . "</div><br/>";
    }
} else {
    $content .= "There are currently no notes for this species.";
}

print $cgi->header();
print "<html><head><title>" . $species->name . "</title></head><body>";
print '<link rel="stylesheet" type="text/css" href="./Html/genomeselector.css">';
print "<div style='padding: 15px;'>";
print $content;
print "</div></body></html>";

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3