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

Annotation of /DrugTargets/drug_targets_table.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (view) (download) (as text)

1 : fangfang 1.1
2 :     use FIG;
3 :     use CGI;
4 :     use FIG_Config;
5 :     my $fig = new FIG;
6 :     my $cgi = new CGI;
7 :     my $temp_dir = $FIG_Config::temp;
8 :     my $fin = "$temp_dir/tmp$$.in";
9 : fangfang 1.4 my $fcsv_name= "download$$.html.xls";
10 : fangfang 1.6 my $fcsv = "/home/fangfang/public_html/FIG_tmp/$fcsv_name";
11 :     #my $fcsv = "$temp_dir/$fcsv_name";
12 : fangfang 1.5
13 : fangfang 1.1 $| = 1;
14 :    
15 :     my $webpage = 1;
16 :     my $table_only = 1;
17 :     my $def_org = '158879.1';
18 :    
19 :     print $cgi->header();
20 :    
21 :     if ($webpage || !$no_header) {
22 : fangfang 1.2 @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');
23 : fangfang 1.1 if ($webpage) {
24 :     if ($table_only) {
25 :     print gen_html("start_table");
26 :     } else {
27 :     print gen_html("start_html", ("Drug Targets - ") . join(" ", @infiles));
28 :     print gen_html("start_table");
29 :     }
30 :     print gen_html("header", @header);
31 :     } else {
32 :     print join("\t", @header). "\n";
33 :     }
34 :     }
35 :    
36 :     my $data = $cgi->param("keys");
37 :    
38 :     open(FIN, ">$fin");
39 :     print FIN "$data\n";
40 :     close(FIN);
41 :     #print "data: $data\n";
42 :     #print "gen_dt_table -html -orgs=$def_org $fin\n";
43 :    
44 :     {
45 :     open(FIN, $fin) || (print(STDERR "'$fin': Couldn't open file. Skipped...\n\n"), next);
46 : fangfang 1.2 open(FCSV, ">$fcsv");
47 : fangfang 1.5
48 :     if (FCSV) {
49 :     print FCSV gen_html("start_html", ("Drug Targets"));
50 :     print FCSV gen_html("start_table");
51 :     print FCSV gen_html("header", @header);
52 :     }
53 : fangfang 1.1
54 :     while (<FIN>) {
55 :     chomp;
56 :     if (/^\#/) {
57 :     next if ($ignore_comment);
58 : fangfang 1.3 (/orgs=(.*\w)/i) && ($def_org = $1, $def_cat = $def_tag = $def_url = undef);
59 :     (/cat=(.*\w)/i) && ($def_cat = $1);
60 :     (/tag=(.*\w)/i) && ($def_tag = $1);
61 :     (/url=(\S+)/i) && ($def_url = $1);
62 : fangfang 1.1 next;
63 :     }
64 :    
65 :     $org = $def_org || (print(STDERR "'$fin': No genome specified. Skipped...\n\n"), last);
66 :     $cat = $def_cat;
67 :     $tag = $def_tag;
68 :     $url = $def_url;
69 :     #print "$tag\n";
70 :    
71 :     @cols = split(/\t/);
72 :    
73 :     if ($gene = $cols[0]) {
74 : fangfang 1.3 if ($gene =~ /(\S+)\,\s*(.*\w)/) {
75 : fangfang 1.1 $gene = $1;
76 :     $tag = $2;
77 :     }
78 :    
79 :     # peg, url, cat
80 :     next unless $peg = get_peg($org, $gene);
81 :     $peg_u = "<a href=http://theseed.uchicago.edu/FIG/protein.cgi?prot=$peg&user= target=_blank>$peg</a>" if ($peg);
82 :     $gene = $tag ? "$gene, $tag" : $gene;
83 :     $cat = $cols[1] ? $cols[1] : $cat;
84 :     $url = $cols[2] ? $cols[2] : $url;
85 :     $gene_u = "<a href=$url>$gene</a>" if ($gene);
86 :    
87 :     # funtion role
88 :     $role = $fig->function_of($peg);
89 :    
90 :     # geneId
91 :     @aliases = $fig->feature_aliases($peg);
92 :     @genes = grep {$_ !~ /.*(\||\_|\:).*/ } @aliases;
93 :     $geneId = join (",", @genes);
94 :    
95 :     # Genebank ID
96 :     @gids = grep {/.*gi.*/} @aliases;
97 :     $gid = join(", ", @gids);
98 :     @gids_u = map {/gi\|(\S+)/ } @gids;
99 :     map {$_ = "<a href=http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?db=protein&val=$_ target=_blank>gi|$_</a>"} @gids_u;
100 :     $gid_u = join(", ", @gids_u);
101 :    
102 :     # uniprot ID
103 :     @uniIds = grep {/.*uni.*/} @aliases;
104 :     $uniId = join(", ", @uniIds);
105 :     @uniIds_u = map {/uni\|(\S+)/} @uniIds;
106 :     map {$_ = "<a href=http://www.pir.uniprot.org/cgi-bin/upEntry?id=$_ target=_blank>uni|$_</a>"} @uniIds_u;
107 :     $uniId_u = join(", ", @uniIds_u);
108 :    
109 :     # conservation of sequences
110 : fangfang 1.4 #my $cons = get_cons($peg);
111 : fangfang 1.1
112 :     # best pdb bound
113 :     my ($pdb_bound, $escore_bound, $pdb_bound_url) = get_pdb($peg, "bound");
114 :     my $pdb_bound_u = "<a href=$pdb_bound_url>$pdb_bound</a>" if ($pdb_bound);
115 :    
116 :     # best pdb free
117 :     my ($pdb, $escore, $pdb_url, $pdb_title) = get_pdb($peg, "free");
118 :     my $pdb_u = "<a href=$pdb_url>$pdb</a>" if ($pdb);
119 :    
120 :     # prodist
121 :     my ($peg_len, $pdb_len, $dist) = get_dist($peg, $pdb) if ($pdb);
122 :     my $dist_u = "<a href=peg_pdb_align.cgi?peg=$peg&pdb=$pdb>$dist</a>" if ($pdb);
123 : fangfang 1.3 my $peg_len = $fig->translation_length($peg);
124 : fangfang 1.1
125 :     # pass info for pdb free
126 :     my ($pass, $pass_maxwgt, $pass_gif) = get_pass($pdb) if ($pdb);
127 :     my $pass_u = "<a href=$pass_gif>$pass</a>" if ($pass && $pass_gif);
128 :    
129 :     # CLiBE
130 :     my $clibe_u = get_clibe_u($pdb) if ($pdb);
131 :     my $clibe = ($clibe_u =~ /<.*>(.*)<.*>/, $1);
132 :    
133 : fangfang 1.2 @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);
134 :    
135 :     @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);
136 : fangfang 1.3
137 :     @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\"");
138 : fangfang 1.2
139 : fangfang 1.5 if (FCSV) {print FCSV gen_html("row", @row_u);}
140 : fangfang 1.2
141 : fangfang 1.1 if ($webpage) {
142 : fangfang 1.2 print gen_html("row", @row_u);
143 : fangfang 1.1 } else {
144 : fangfang 1.2 print join("\t", @row_u) . "\n";
145 : fangfang 1.1 }
146 :     }
147 :     }
148 : fangfang 1.5 if (FCSV) {
149 :     print FCSV gen_html("end_table");
150 :     print FCSV gen_html("end_html");
151 :     }
152 : fangfang 1.2 close(FCSV);
153 : fangfang 1.1 close(FIN);
154 :     }
155 :    
156 : fangfang 1.2
157 :    
158 : fangfang 1.1 if ($webpage) {
159 :     print gen_html("end_table");
160 : fangfang 1.2 print "<p> <a href=http://ci-www.uchicago.edu/~fangfang/FIG_tmp/$fcsv_name> Download to Excel </a>\n";
161 : fangfang 1.1 print gen_html("end_html") unless $table_only;
162 :     }
163 :    
164 :     #--------------------
165 :     # sub routines
166 :     #--------------------
167 :    
168 :     sub get_peg {
169 :     my ($org, $gene) = @_;
170 :     my ($pegs_index_data) = $fig->search_index($gene);
171 :    
172 :     my @orgs = split(/[^0-9.]/, $org);
173 :    
174 :     my $peg;
175 :     for $g (@orgs) {
176 :     my @pegs = grep {/$g/} map {$_->[0]} @$pegs_index_data;
177 :     #if (@pegs > 1) {print STDERR "get_peg: more than one hits for '$gene' in '$g'.\n";}
178 :     if ($peg = $pegs[0]) {last};
179 :     }
180 :     return $peg;
181 :     }
182 :    
183 :     sub get_pdb {
184 :     my ($peg, $domain) = @_;
185 :     my ($pdb, $escore, $pdb_url, $pdb_title) = ();
186 :     my $best_pdb = "$FIG_Config::bin/best_pdb";
187 :    
188 :     $best_pdb = "perl best_pdb.pl" unless (-e $best_pdb);
189 :     ($domain =~ /bound/) && ($domain = "-bound");
190 :    
191 :     ($pdb, $escore, $pdb_url, $pdb_title) = split(/\t/, `$best_pdb $domain '$peg'`);
192 :     chomp($pdb_title);
193 :    
194 :     return ($pdb, $escore, $pdb_url, $pdb_title);
195 :     }
196 :    
197 :     sub get_pass {
198 :     my ($pdb) = @_;
199 :     my ($pass, $pass_maxwgt, $pass_gif) = ();
200 :     my $pass_pdb = "$FIG_Config::bin/pass_pdb";
201 :     my $pdb2passinfo = "$FIG_Config::bin/pdb2passinfo";
202 :    
203 :     $pdb2passinfo = "perl pdb2passinfo.pl" unless (-e $pdb2passinfo);
204 :     $pass_pdb = "perl pass_pdb.pl";
205 :     system "$pass_pdb $pdb";
206 :    
207 :     ($pass, $pass_maxwgt, $pass_gif) = split(/\t/, `$pdb2passinfo $pdb`);
208 :     chomp($pass_gif);
209 :    
210 :     return ($pass, $pass_maxwgt, $pass_gif);
211 :     }
212 :    
213 :     sub get_dist {
214 :     my ($peg, $pdb) = @_;
215 :     my ($peg_len, $pdb_len, $dist) = ();
216 :     my $peg_pdb_dist = "$FIG_Config::bin/peg_pdb_dist";
217 :    
218 :     $peg_pdb_dist = "perl peg_pdb_dist.pl" unless (-e $peg_pdb_dist);
219 :    
220 :     ($peg_len, $pdb_len, $dist) = split(/\t/, `$peg_pdb_dist -len '$peg' $pdb`);
221 :     chomp($dist);
222 :    
223 :     return ($peg_len, $pdb_len, $dist);
224 :     }
225 :    
226 :     sub get_cons {
227 :     my ($peg) = @_;
228 :     my $get_homo = "$FIG_Config::bin/get_homologs";
229 :     my $aln_cons = "$FIG_Config::bin/aln_conservation";
230 :    
231 :     $get_homo = "perl get_homologs.pl" unless (-e $get_homo);
232 :     $aln_cons = "perl aln_conservation.pl" unless (-e $aln_cons);
233 :    
234 :     my $cons = `$get_homo -max=20 '$peg' | $aln_cons`;
235 :     chomp($cons);
236 :    
237 :     return $cons;
238 :     }
239 :    
240 :     sub get_clibe_u {
241 :     my ($pdb) = @_;
242 :     my $clibe_db = "$FIG_Config::fig/var/DrugTargets/pdb_ligand_table_CLiBE.txt";
243 :     $clibe_db = "pdb_ligand_table_CLiBE.txt" unless (-e $clibe_db);
244 :     my $pdb_key = ($pdb =~/(\d\w{3})/, $1);
245 :    
246 :     my ($clibe) = split(/\n/, `cut -f2 $clibe_db |grep $pdb_key`);
247 :     chomp($clibe);
248 :    
249 :     return $clibe;
250 :     }
251 :    
252 :     sub gen_html {
253 :     my ($part, @content) = @_;
254 :     my @html;
255 :     if ($part =~ /start_html/i) {
256 :     push @html, "<html>";
257 :     push @html, $cgi->head($cgi->title($content[0]));
258 :     push @html, $cgi->start_body();
259 :     } elsif ($part =~ /end_html/i) {
260 :     push @html, $cgi->end_body();
261 :     push @html, "</html>";
262 :     } elsif ($part =~ /start_table/i) {
263 :     push @html, "<table ID=DrugTargets BORDER=1 width=80%>";
264 :     } elsif ($part =~ /end_table/i) {
265 :     push @html, "</table>";
266 :     } else {
267 :     $s = ($part =~ /header/i) ? "th" : "td";
268 :     push @html, "<tr>";
269 :     for ($i=0; $i<19; $i++) {$cols[$i] = $content[$i] ? $content[$i] : "N/A"};
270 :     map {$_ = "<$s>$_<\/$s>"} @cols;
271 :     push @html, join(" ", @cols);
272 :     push @html, "</tr>";
273 :     }
274 :     return join("\n", @html) . "\n";
275 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3