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 $fcsv_name= "download$$.html.xls"; my $fcsv = "/home/fangfang/public_html/FIG_tmp/$fcsv_name"; #my $fcsv = "$temp_dir/$fcsv_name"; $| = 1; my $webpage = 1; my $table_only = 1; my $def_org = '158879.1'; 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) { 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"; } } my $data = $cgi->param("keys"); open(FIN, ">$fin"); print FIN "$data\n"; close(FIN); #print "data: $data\n"; #print "gen_dt_table -html -orgs=$def_org $fin\n"; { open(FIN, $fin) || (print(STDERR "'$fin': Couldn't open file. Skipped...\n\n"), next); open(FCSV, ">$fcsv"); if (FCSV) { print FCSV gen_html("start_html", ("Drug Targets")); print FCSV gen_html("start_table"); print FCSV gen_html("header", @header); } while () { chomp; if (/^\#/) { next if ($ignore_comment); (/orgs=(.*\w)/i) && ($def_org = $1, $def_cat = $def_tag = $def_url = undef); (/cat=(.*\w)/i) && ($def_cat = $1); (/tag=(.*\w)/i) && ($def_tag = $1); (/url=(\S+)/i) && ($def_url = $1); next; } $org = $def_org || (print(STDERR "'$fin': No genome specified. Skipped...\n\n"), last); $cat = $def_cat; $tag = $def_tag; $url = $def_url; #print "$tag\n"; @cols = split(/\t/); if ($gene = $cols[0]) { if ($gene =~ /(\S+)\,\s*(.*\w)/) { $gene = $1; $tag = $2; } # peg, url, cat next unless $peg = get_peg($org, $gene); $peg_u = "$peg" if ($peg); $gene = $tag ? "$gene, $tag" : $gene; $cat = $cols[1] ? $cols[1] : $cat; $url = $cols[2] ? $cols[2] : $url; $gene_u = "$gene" if ($gene); # funtion role $role = $fig->function_of($peg); # geneId @aliases = $fig->feature_aliases($peg); @genes = grep {$_ !~ /.*(\||\_|\:).*/ } @aliases; $geneId = join (",", @genes); # Genebank ID @gids = grep {/.*gi.*/} @aliases; $gid = join(", ", @gids); @gids_u = map {/gi\|(\S+)/ } @gids; map {$_ = "gi|$_"} @gids_u; $gid_u = join(", ", @gids_u); # uniprot ID @uniIds = grep {/.*uni.*/} @aliases; $uniId = join(", ", @uniIds); @uniIds_u = map {/uni\|(\S+)/} @uniIds; map {$_ = "uni|$_"} @uniIds_u; $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"); my $pdb_bound_u = "$pdb_bound" if ($pdb_bound); # best pdb free my ($pdb, $escore, $pdb_url, $pdb_title) = get_pdb($peg, "free"); my $pdb_u = "$pdb" if ($pdb); # prodist my ($peg_len, $pdb_len, $dist) = get_dist($peg, $pdb) if ($pdb); my $dist_u = "$dist" if ($pdb); 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 = "$pass" 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 (FCSV) {print FCSV gen_html("row", @row_u);} if ($webpage) { print gen_html("row", @row_u); } else { print join("\t", @row_u) . "\n"; } } } if (FCSV) { print FCSV gen_html("end_table"); print FCSV gen_html("end_html"); } close(FCSV); close(FIN); } if ($webpage) { print gen_html("end_table"); print "

Download to Excel \n"; print gen_html("end_html") unless $table_only; } #-------------------- # sub routines #-------------------- 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, ""; 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, ""; } elsif ($part =~ /start_table/i) { push @html, ""; } elsif ($part =~ /end_table/i) { push @html, "
"; } else { $s = ($part =~ /header/i) ? "th" : "td"; push @html, ""; for ($i=0; $i<19; $i++) {$cols[$i] = $content[$i] ? $content[$i] : "N/A"}; map {$_ = "<$s>$_<\/$s>"} @cols; push @html, join(" ", @cols); push @html, ""; } return join("\n", @html) . "\n"; }