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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3