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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3