[Bio] / DrugTargets / drug_targets_table.pl Repository:
ViewVC logotype

View of /DrugTargets/drug_targets_table.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (download) (as text) (annotate)
Wed Aug 31 15:31:29 2005 UTC (14 years, 3 months ago) by hwang
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +2 -1 lines
Changed files to incorporate fangfang's and kaitlyn's script.
ShowTable.pl
	Shows and edits the tables in the archives

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

my $temp_dir = $FIG_Config::temp;
my $fin      = "$temp_dir/tmp$$.in";
my $fxls_name= "download$$.html.xls";
my $fxls_dir = "/home/fangfang/public_html/FIG_tmp";
my $fxls     = (-e $fxls_dir) ? "$fxls_dir/$fxls_name" : "$temp_dir/$fxls_name";
my $down_url = (-e $fxls_dir) ? "http://ci-www.uchicago.edu/~fangfang/FIG_tmp/$fxls_name" : "http://seed-mac-1.mcs.anl.gov/fangfang/FIG-Tmp/$fxls_name";

$| = 1;

my $webpage    = 1;
my $table_only = 1;
my $include_all= 1;

my $data = $cgi->param("keys");
$data =~ s/^\s*//s;
my @korgs = $cgi->param('korgs');
@korgs = map { /\((\d+\.*\d*)\)/} @korgs;
$data = "#orgs=". join(",", @korgs). "\n$data";

print $cgi->header();

if ($webpage || !$no_header) {
    @header = ('Category', 'Gene Name', 'Gene Id', 'PEG ID', 'PEG SeqLen', 'GenBank ID', 'UniProt ID', 'Functional Role', 'Conservation of Seqs', 'PDB (bound)', 'e-Value (bound)', 'PDB (free)', 'e-Value', 'PDB Title', 'PDB SeqLen', 'ProtDist', 'PASS ASPs'
, 'PASS Weight of Largest Pocket', 'PDB Ligand CLiBE');
    if ($webpage) {
	if ($table_only) {
	    if (check_org($data)) {print gen_html("warning", ("Organism list not defined properly."));}
	    print gen_html("start_table");
	} else {
	    print gen_html("start_html", ("Drug Targets - ") . join(" ", @infiles));
	    print gen_html("start_table");
	}
	print gen_html("header", @header); 
    } else { 
	print join("\t", @header). "\n"; 
    } 
} 

{
    open(FXLS, ">$fxls");

    if (FXLS) {
	print FXLS gen_html("start_html", ("Drug Targets")); 
	print FXLS gen_html("start_table"); 
	print FXLS gen_html("header", @header); 
    }

    for (@lines = split(/\n/, $data)) {
	chomp;
	if (/^\#/) {
	    next if ($ignore_comment);
	    (/orgs=(.*\S)/i) && ($def_org = $1, $def_cat = $def_tag = $def_url = undef);
	    (/cat=(.*\S)/i)  && ($def_cat = $1);
	    (/tag=(.*\S)/i)  && ($def_tag = $1);
	    (/url=(\S+)/i)   && ($def_url = $1);
	    next;
	}
	
	$org = $def_org || (print(STDERR "'$fin': No genome specified. Skipped...\n\n"), last);
	my $cat = $def_cat;
	my $tag = $def_tag;
	my $url = $def_url;

	@cols = split(/[;\t]/);

	if ($gene = $cols[0]) {
	    if ($gene =~ /(\S+)?\s*\,\s*(.*\S)/) {
		$gene = $1;
		$tag = $2;
	    } else {
		$gene =~ /(\S+)/;
		$gene = $1;
	    }
	    $gene =~ s/fig\|//;
	    next unless ($gene || $cols[3]);

	    # peg, url, cat
            my $peg;
            if ($cols[3]) {
                $cols[3] =~ /(\d+\.\d+\.peg\.\d+)/;
                $peg = "fig|$1";
            } else {
                if ($org) {
                    $peg = get_peg($org, $gene);
                } else {
                    print(STDERR "'$gene': No genome specified. Skipped...\n\n");
                    next unless ($include_all);
                }
            }

	    ($fig->function_of($peg)) || ($peg = undef); 
	    unless ($include_all) {next unless $peg};

	    my $peg_u = "<a href=http://theseed.uchicago.edu/FIG/protein.cgi?prot=$peg&user= target=_blank>$peg</a>" if ($peg);
	    $gene = $tag ? "$gene, $tag" : $gene;
	    $cat = $cols[1] ? $cols[1] : $cat;
	    $url = $cols[2] ? $cols[2] : $url;
	    my $gene_u = "<a href=$url>$gene</a>" if ($gene);
	 
	    # funtion role
	    my $role = $fig->function_of($peg);
	    
	    # geneId
	    my @aliases = $fig->feature_aliases($peg);
	    my @genes = grep {$_ !~ /.*(\||\_|\:).*/ } @aliases;
	    my $geneId = join (",", @genes);

	    # Genebank ID
	    my @gids = grep {/.*gi.*/} @aliases;
	    my $gid = join(", ", @gids);
	    my @gids_u = map {/gi\|(\S+)/ } @gids;	    
	    map {$_ = "<a href=http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?db=protein&val=$_ target=_blank>gi|$_</a>"} @gids_u;
	    my $gid_u = join(", ", @gids_u); 
	 
	    # uniprot ID
	    my @uniIds = grep {/.*uni.*/} @aliases; 
	    my $uniId = join(", ", @uniIds);
	    my @uniIds_u = map {/uni\|(\S+)/} @uniIds;
	    map {$_ = "<a href=http://www.pir.uniprot.org/cgi-bin/upEntry?id=$_ target=_blank>uni|$_</a>"} @uniIds_u;
	    my $uniId_u = join(", ", @uniIds_u);

	    # conservation of sequences
	    #my $cons = get_cons($peg);

	    # best pdb bound
	    my ($pdb_bound, $escore_bound, $pdb_bound_url) = get_pdb($peg, "bound") if ($peg);
	    my $pdb_bound_u = "<a href=$pdb_bound_url>$pdb_bound</a>" if ($pdb_bound);

	    # best pdb free
	    my ($pdb, $escore, $pdb_url, $pdb_title) = get_pdb($peg, "free") if ($peg);
	    my $pdb_u = "<a href=$pdb_url>$pdb</a>" if ($pdb);

	    # prodist 
	    my ($peg_len, $pdb_len, $dist) = get_dist($peg, $pdb) if ($pdb);
	    my $dist_u = "<a href=peg_pdb_align.cgi?peg=$peg&pdb=$pdb>$dist</a>" if ($dist);
	    my $peg_len = $fig->translation_length($peg);

	    # pass info for pdb free
	    my ($pass, $pass_maxwgt, $pass_gif) = get_pass($pdb) if ($pdb);
	    my $pass_u = "<a href=$pass_gif>$pass</a>" if ($pass && $pass_gif);

	    # CLiBE
	    my $clibe_u = get_clibe_u($pdb) if ($pdb);
	    my $clibe   = ($clibe_u =~ /<.*>(.*)<.*>/, $1);
	    
	    @row = ($cat, $gene, $geneId, $peg, $peg_len, $gid, $uniId, $role, $cons, $pdb_bound, $escore_bound, $pdb, $escore, $pdb_title, $pdb_len, $dist, $pass, $pass_maxwgt, $clibe);
	    
	    @row_u = ($cat, $gene_u, $geneId, $peg_u, $peg_len, $gid_u, $uniId_u, $role, $cons, $pdb_bound_u, $escore_bound, $pdb_u, $escore, $pdb_title, $pdb_len, $dist_u, $pass_u, $pass_maxwgt, $clibe_u);

	    @row_e= ($cat, "\"$gene\"", "\"$geneId\"", $peg, $peg_len, "\"$gid\"", "\"$uniId\"", "\"$role\"", $cons, $pdb_bound, $escore_bound, $pdb, $escore, "\"$pdb_title\"", $pdb_len, $dist, $pass, $pass_maxwgt, "\"$clibe\"");
	    
	    if (FXLS) {print FXLS gen_html("row", @row_u);}

	    if ($webpage) {
		print gen_html("row", @row_u);
	    } else {
		print join("\t", @row_u) . "\n"; 
	    }
	}
    }
    if (FXLS) {
	print FXLS gen_html("end_table");
	print FXLS gen_html("end_html");
    }
    close(FXLS);    
}

if ($webpage) {
    print gen_html("end_table");
    print "<p> <a href=$down_url> Download to Excel </a>\n";
    print gen_html("end_html") unless $table_only;
}


#--------------------
#   sub routines
#--------------------

sub check_org {
    my ($data) = @_;
    my @lines = split(/\n/, $data);
    my $rv = 1;
    for (@lines) {
 	if ($_ =~ /^(#orgs=\s*\d+\.\d+)/) {$rv=0;last;}
	elsif ($_ =~ /^\s*([^#]\w+)/) {last;}
    }
    # return true on error
    return $rv;
}

sub get_peg {
    my ($org, $gene) = @_;
    my ($pegs_index_data) = $fig->search_index($gene);

    my @orgs = split(/[^0-9.]/, $org);

    my $peg;
    for $g (@orgs) {
	my @pegs = grep {/$g/} map {$_->[0]} @$pegs_index_data;
	#if (@pegs > 1) {print STDERR "get_peg: more than one hits for '$gene' in '$g'.\n";}
	if ($peg = $pegs[0]) {last};
    }
    return $peg;
}

sub get_pdb {
    my ($peg, $domain) = @_;
    my ($pdb, $escore, $pdb_url, $pdb_title) = ();
    my $best_pdb = "$FIG_Config::bin/best_pdb";

    $best_pdb = "perl best_pdb.pl" unless (-e $best_pdb);
    ($domain =~ /bound/) && ($domain = "-bound");
    
    ($pdb, $escore, $pdb_url, $pdb_title) = split(/\t/, `$best_pdb $domain '$peg'`);
    chomp($pdb_title);

    return ($pdb, $escore, $pdb_url, $pdb_title);
}

sub get_pass {
    my ($pdb) = @_;
    my ($pass, $pass_maxwgt, $pass_gif) = ();
    my $pass_pdb = "$FIG_Config::bin/pass_pdb";
    my $pdb2passinfo = "$FIG_Config::bin/pdb2passinfo";
    
    $pdb2passinfo = "perl pdb2passinfo.pl" unless (-e $pdb2passinfo);
    $pass_pdb = "perl pass_pdb.pl";
    system "$pass_pdb $pdb";

    ($pass, $pass_maxwgt, $pass_gif) = split(/\t/, `$pdb2passinfo $pdb`);
    chomp($pass_gif);

    return ($pass, $pass_maxwgt, $pass_gif);
}

sub get_dist {
    my ($peg, $pdb) = @_;
    my ($peg_len, $pdb_len, $dist) = ();
    my $peg_pdb_dist = "$FIG_Config::bin/peg_pdb_dist";
    
    $peg_pdb_dist = "perl peg_pdb_dist.pl" unless (-e $peg_pdb_dist);

    ($peg_len, $pdb_len, $dist) = split(/\t/, `$peg_pdb_dist -len '$peg' $pdb`);
    chomp($dist);

    return ($peg_len, $pdb_len, $dist);
}

sub get_cons {
    my ($peg) = @_;
    my $get_homo = "$FIG_Config::bin/get_homologs";
    my $aln_cons = "$FIG_Config::bin/aln_conservation";

    $get_homo = "perl get_homologs.pl" unless (-e $get_homo);
    $aln_cons = "perl aln_conservation.pl" unless (-e $aln_cons);
    
    my $cons = `$get_homo -max=20 '$peg' | $aln_cons`;
    chomp($cons);

    return $cons;
}

sub get_clibe_u {
    my ($pdb) = @_;
    my $clibe_db = "$FIG_Config::fig/var/DrugTargets/pdb_ligand_table_CLiBE.txt";
    $clibe_db = "pdb_ligand_table_CLiBE.txt" unless (-e $clibe_db);
    my $pdb_key =  ($pdb =~/(\d\w{3})/, $1);

    my ($clibe) = split(/\n/, `cut -f2 $clibe_db |grep $pdb_key`); 
    chomp($clibe);

    return $clibe;
}

sub gen_html {
    my ($part, @content) = @_;
    my @html;
    if ($part =~ /start_html/i) {
	push @html, "<html>";
	push @html, $cgi->head($cgi->title($content[0]));
	push @html, $cgi->start_body();
    } elsif ($part =~ /end_html/i) {
	push @html, $cgi->end_body();
	push @html, "</html>";
    } elsif ($part =~ /start_table/i) {
	push @html, "<table ID=DrugTargets BORDER=1 width=80%>";
    } elsif ($part =~ /end_table/i) {
	push @html, "</table>";
    } elsif ($part =~ /warning/i) {
	push @html, "<h3><font color=#cc0000>Warning: $content[0]</font></h3>";
    } else {
	$s = ($part =~ /header/i) ? "th" : "td";
	push @html, "<tr>";
	for ($i=0; $i<19; $i++) {$cols[$i] = $content[$i] ? $content[$i] : "N/A"};	
	map {$_ = "<$s>$_<\/$s>"} @cols;
	push @html, join(" ", @cols);
	push @html, "</tr>";
    }
    return join("\n", @html) . "\n";
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3