This repository has been archived by the owner on Jul 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
GeneQuery.pl
executable file
·292 lines (243 loc) · 6.47 KB
/
GeneQuery.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/usr/bin/perl
# Copyright SRA International
#
# Distributed under the OSI-approved BSD 3-Clause License.
# See http://ncip.github.com/pathway-interaction-database/LICENSE.txt for details.
use strict;
BEGIN {
my @path_elems = split("/", $0);
pop @path_elems;
push @INC, join("/", @path_elems);
}
use CGI;
use DBI;
use PWAppConfig;
use PathwayDB;
use Pathway;
use PWLabel;
use EquationOutput;
if (-d "/app/oracle/product/dbhome/current") {
$ENV{'ORACLE_HOME'} = "/app/oracle/product/dbhome/current";
} elsif (-d "/app/oracle/product/8.1.7") {
$ENV{'ORACLE_HOME'} = "/app/oracle/product/8.1.7";
} elsif (-d "/app/oracle/product/8.1.6") {
$ENV{'ORACLE_HOME'} = "/app/oracle/product/8.1.6";
}
#my $geneid = shift @ARGV;
my $query = new CGI;
my $geneid = $query->param("geneid");
my ($db_inst, $db_user, $db_pass, $pid_schema, $cgap_schema) =
(DB_INST, DB_USER, DB_PASS, SCHEMA, "cgap");
print "Content-type: text/html\n\n";
$geneid =~ s/\s+//g;
if ($geneid !~ /^\d+$/) {
print STDERR "illegal value for parameter geneid";
exit;
}
my $db = DBI->connect("DBI:Oracle:" . $db_inst, $db_user, $db_pass);
if (not $db or $db->err()) {
print STDERR "Cannot connect to " . $db_user . "@" . $db_inst . "\n";
exit;
}
my ($lv, $pw);
my ($mol2name, $mol2ext_id);
my $mols = FindMolIdsForGene($db, $geneid);
if (keys %{ $mols } > 0) {
($mol2name, $mol2ext_id) = FindNamesForMols($db, $mols);
} else {
print "No entries for Gene id = $geneid\n";
}
$db->disconnect();
print FormatOutput($mols, $mol2name, $mol2ext_id);
exit;
###################
if (keys %{ $mols } > 0) {
$lv = new PWLabel($db, $pid_schema);
$pw = new Pathway($lv);
FindReactionsForMolId($db, $lv, $pw, [ keys %{ $mols } ]);
if (@{ $pw->Atoms() } > 0) {
# EquationOutput();
my $eq = new EquationOutput($pw, $lv);
$eq->EquationOutput();
print @{ $eq->Lines() };
print "\n";
} else {
print "No entries for Gene id = $geneid\n";
}
} else {
print "No entries for Gene id = $geneid\n";
}
$db->disconnect();
######################################################################
sub numerically { $a <=> $b; }
######################################################################
sub MOLPAGE_URL {
my ($molid) = @_;
# return "http://pid.nci.nih.gov/search/MoleculePage?molid=$molid";
return "/search/MoleculePage?molid=$molid";
}
######################################################################
sub ATOMPAGE_URL {
my ($atomid) = @_;
# return "http://pid.nci.nih.gov/search/InteractionPage?atomid=$atomid";
return "/search/InteractionPage?atomid=$atomid";
}
######################################################################
sub FormatOutput {
my ($mols, $mol2name, $mol2ext_id) = @_;
my @lines;
for my $mol (keys %{ $mols }) {
my (@lls, @ups, @names);
for my $idtype (keys %{ $$mol2ext_id{$mol} }) {
for my $id (keys %{ $$mol2ext_id{$mol}{$idtype} }) {
if ($idtype eq "LL") {
push @lls, "Entrez Gene: $id";
} elsif ($idtype eq "UP") {
push @ups, "UniProt: $id";
}
}
}
for my $nametype (keys %{ $$mol2name{$mol} }) {
for my $name (keys %{ $$mol2name{$mol}{$nametype} }) {
push @names, $name;
}
}
push @lines, "<a href=\"" . MOLPAGE_URL($mol) . "\">" .
join(", ", @names, @lls, @ups) . "</a> ";
}
return join("<br>\n", @lines, "");
}
######################################################################
sub FindReactionsForMolId {
my ($db, $lv, $pw, $mols) = @_;
use constant SOURCE_LIST => "5";
use constant EVIDENCE_CODE_LIST => "";
use constant INCLUDE_COMPLEX_USES => "1";
my $pdb = new PathwayDB($db, $pid_schema,
SOURCE_LIST,
EVIDENCE_CODE_LIST, $pw, $lv);
$pdb->AtomsOfMols(join(",", @{ $mols }), INCLUDE_COMPLEX_USES);
$pw->MergeMolecules();
$pw->BuildMolInstCache();
$pw->BuildGenericLabelCache();
$pw->PruneDuplicateAtoms();
$pw->IdentifyMacroProcesses();
}
######################################################################
sub FindNamesForMols {
my ($db, $mols) = @_;
my $mollist = join(",", keys %{ $mols });
my (%mol2name, %mol2ext_id);
my ($sql, $stm);
my ($molid, $extid, $id_type, $name_type, $name);
$sql = qq!
select
e.mol_id,
e.id_type,
e.ext_mol_id
from
$pid_schema.pw_ext_mol_id e
where
e.mol_id in ($mollist)
!;
$stm = $db->prepare($sql);
if(not $stm) {
print STDERR "prepare failed: $sql\n";
return;
}
if(!$stm->execute()) {
print STDERR "execute failed: $sql\n";
return;
}
while (($molid, $id_type, $extid) = $stm->fetchrow_array()) {
$mol2ext_id{$molid}{$id_type}{$extid} = 1;
}
$sql = qq!
select
n.mol_id,
n.name_type,
n.mol_name
from
$pid_schema.pw_mol_name n
where
n.mol_id in ($mollist)
!;
$stm = $db->prepare($sql);
if(not $stm) {
print STDERR "prepare failed: $sql\n";
return;
}
if(!$stm->execute()) {
print STDERR "execute failed: $sql\n";
return;
}
while (($molid, $name_type, $name) = $stm->fetchrow_array()) {
$mol2name{$molid}{$name_type}{$name} = 1;
}
return (\%mol2name, \%mol2ext_id);
}
######################################################################
sub FindMolIdsForGene {
my ($db, $geneid) = @_;
my ($sql, $stm);
my ($molid, $extid);
my (%mols);
## Find direct matches of ext ids
$sql = qq!
select
e.mol_id,
e.ext_mol_id
from
$pid_schema.pw_ext_mol_id e,
$pid_schema.pw_mol m
where
e.ext_mol_id = '$geneid'
and e.mol_id = m.mol_id
and m.basic_mol_type = 'PR'
!;
$stm = $db->prepare($sql);
if(not $stm) {
print STDERR "prepare failed: $sql\n";
return;
}
if(!$stm->execute()) {
print STDERR "execute failed: $sql\n";
return;
}
while (($molid, $extid) = $stm->fetchrow_array()) {
$mols{$molid} = 1;
}
## Find matches of gene ids to proteins in PID
$sql = qq!
select
e.mol_id,
g.ll_id
from
$pid_schema.pw_ext_mol_id e,
$pid_schema.pw_mol m,
$cgap_schema.ll2sp s,
$cgap_schema.sp_primary p,
$cgap_schema.ll_gene g
where
p.sp_id_or_secondary = e.ext_mol_id
and p.sp_id_or_secondary = s.sp_primary
and s.organism = 'Hs'
and s.ll_id = g.ll_id
and g.ll_id ='$geneid'
and e.mol_id = m.mol_id
and m.basic_mol_type = 'PR'
!;
$stm = $db->prepare($sql);
if(not $stm) {
print STDERR "prepare failed: $sql\n";
return;
}
if(!$stm->execute()) {
print STDERR "execute failed: $sql\n";
return;
}
while (($molid, $extid) = $stm->fetchrow_array()) {
$mols{$molid} = 1;
}
return \%mols;
}