-
Notifications
You must be signed in to change notification settings - Fork 11
/
search.sql
43 lines (42 loc) · 1.49 KB
/
search.sql
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
CREATE function find_features(argOrgName varchar, argRefseq text, argSoType text, argFmin int, argFmax int) returns setof feature as $$
SELECT
feature.feature_id, feature.dbxref_id, feature.organism_id,
feature.name, feature.uniquename, feature.residues, feature.seqlen,
feature.md5checksum, feature.type_id, feature.is_analysis,
feature.is_obsolete, feature.timeaccessioned, feature.timelastmodified
FROM
feature, featureloc, cvterm
WHERE
-- Join conditions
feature.feature_id = featureloc.feature_id AND
feature.type_id = cvterm.cvterm_id AND
-- Actual conditions
-- only in organism
feature.organism_id = (select organism_id from organism where common_name=argOrgName)
AND
-- with queried seqid
(featureloc.srcfeature_id IN (SELECT feature_id FROM feature WHERE name = argRefseq))
AND
-- within queried region
(featureloc.fmin <= argFmax AND argFmin <= featureloc.fmax)
AND
-- top level only
cvterm.name = argSoType
$$ language sql stable;
CREATE function find_sequence(argOrgName varchar, argRefseq text, argFmin int, argFlen int) returns text as $$
SELECT
substring(
(
SELECT
residues
FROM
feature
WHERE
feature.organism_id = (select organism_id from organism where common_name=argOrgName)
AND
feature.name = argRefSeq
)
from argFmin for argFlen
) as "sequence"
;
$$ language sql stable;