[Bio] / FigWebServices / save_to_attributes.cgi Repository:
ViewVC logotype

View of /FigWebServices/save_to_attributes.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (download) (annotate)
Thu Jan 18 21:31:49 2007 UTC (13 years, 5 months ago) by hwang
Branch: MAIN
Changes since 1.4: +7 -7 lines
Take out debugging

#/usr/bin/perl
use FIG;
use strict;
use CGI;
use FigWebServices::SeedComponents::PubMed;

my $cgi =  new CGI;
my $fig =  new FIG;

print $cgi->header;
my @params = $cgi->param;

#curated_journals are journals decided to be relevant or notrelevant by the annotators
#all_journals are the original list of journals

my $curated_journals = $cgi->param("listOfItems");
my $all_publications = $cgi->param("all_publications");
my $peg = $cgi->param ("purpose_peg");
my $name  = $cgi->param ("master");
my $server_name = $ENV{'SERVER_NAME'};


my $add_pmid = $cgi->param ("PMID");

my @pmid_array = split(/\s/, $add_pmid);

#Check to see if the user specify his/her name. If not, then the page exits 
if (($name eq "Name") || ($name eq "")) {

	print "You must specify your name. <p>";
	print "Press the back button <p>";
	exit;
}
#print "$peg<p>";
#print $curated_journals;
 
my @pubmed_r_attributes = $fig->get_attributes($peg, "PUBMED_CURATED_RELEVANT");
my %pmid2whom=();
my %pmid2key=();
my %pmid2value =();

foreach (@pubmed_r_attributes) {
	my @att_line = @{$_};
	my ($peg, $att_key, $value, $url) = @att_line; 
	my ($who_curated, $pmid, undef)  = split(/\,/, $value);
	$pmid2whom{$pmid} = $who_curated;
	$pmid2key{$pmid} = $att_key;	
	$pmid2value{$pmid} = $value;
}

my @pubmed_nr_attributes = $fig->get_attributes($peg, "PUBMED_CURATED_NOTRELEVANT");
my %hash_nr=();
foreach (@pubmed_nr_attributes) {
	my @att_line = @{$_};
	my ($peg, $att_key, $value, $url) = @att_line; 
	my ($who_curated, $pmid, undef)  = split(/\,/, $value);
	$pmid2whom{$pmid} = $who_curated;
	$pmid2key{$pmid} = $att_key;
	$pmid2value{$pmid} = $value;
}

#Begin adding attributes that the curator specified
if (($add_pmid ne "") && ($add_pmid =~ /^\d+/)) {

	foreach my $to_add (@pmid_array) { 
		#Check to see if the pmid is already in the attributes for this peg
		#If it is then we exit
		next if ($to_add =~ /PMID/);
		#print "ADD PMID is $to_add<p>";
				
		if( $pmid2key{$to_add} ne "") {
			print "PMID:$to_add is already in the attribute database<p>";
		
		}
		else {
			my $add_title = &FigWebServices::SeedComponents::PubMed::pmid_to_title($to_add);
			my $add_url = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=pubmed&dopt=Abstract&list_uids=$to_add";	
			$fig->add_attribute($peg, "PUBMED_CURATED_RELEVANT", "$name,$to_add,$add_title", $add_url);	
        		#print "Added to attributes as PUBMED_CURATED_RELEVANT, $name,$to_add, $add_title<p>";
			$pmid2whom{$to_add} = $name;
			$pmid2key{$to_add} = "PUBMED_CURATED_RELEVANT";			
		}
	}
}

#Below conditions are for curated pubmed journals

my @curated = split(/\;/, $curated_journals);

foreach (@curated) {
	my ($curated_key, $key_value) = split(/\|/, $_);
	my $curated_pmid = $key_value;
	$curated_pmid =~ s/\(.*\)//;

	#SKIP if the PMID's KEY is not curated
	next if ($curated_key =~ /\_NOT\_/);
	#print "curated/label key is $curated_key pmid is $curated_pmid<p>";
	
	my $value = &FigWebServices::SeedComponents::PubMed::pmid_to_title($curated_pmid);
	my $base_url = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=pubmed&dopt=Abstract&list_uids=";
	my $url = "$base_url.$curated_pmid";

	#If the pmid is not in the not/relevant hash, add it to the attribute. Also add it to the 
	#hash

	if (! $pmid2key{$curated_pmid}) 
	{	
		#print "Doesn't exist $pmid2key{$curated_pmid}";
		$fig->add_attribute($peg, $curated_key, "$name,$curated_pmid,$value", $url);		
		#print "Doesn't exist - ADD $peg, $curated_key, $name,$curated_pmid, $value <p>";		
		$pmid2whom{$curated_pmid} = $name;
		$pmid2key{$curated_pmid} = $curated_key;			

	last;
	}

	#If the keys are the same, but the person is different - 
	# delete the old attribute
	if ( $curated_key ne $pmid2key{$curated_pmid}
	)  {
		my $delete_url = $url;
		$fig->delete_attribute($peg,$pmid2key{$curated_pmid},$pmid2value{$curated_pmid},$delete_url);		
		$fig->add_attribute($peg,$curated_key,"$name,$curated_pmid,$value",$url);			
		
		#print "ADD $peg, $curated_key, $name,$curated_pmid, $value <p>";		
		#print "DELETE $pmid2key{$curated_pmid} $pmid2value{$curated_pmid}<p>";
		#Update the hash
		$pmid2whom{$curated_pmid} = $name;
		$pmid2key{$curated_pmid} = $curated_key;
		}
	}

	

print "Please refresh protein page and press Attributes button to see the changes<p>";


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3