Skip to content

Commit

Permalink
Merge pull request #23 from TheJacksonLaboratory/G3-457-view-similar-…
Browse files Browse the repository at this point in the history
…genesets-button-broken

Reverting change to get_genesets_by_hom_id
  • Loading branch information
bergsalex authored Sep 24, 2024
2 parents 1c12d28 + 147559e commit 49ed317
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 33 deletions.
11 changes: 11 additions & 0 deletions deploy/k8s/base/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: geneweaver-legacy-ingress
annotations:
# Set the read and send timeouts for long connections
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" # 1 hour, adjust as needed
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" # 1 hour, adjust as needed
# Optional: Prevent connection closing during idle time
nginx.ingress.kubernetes.io/proxy-buffering: "off" # Ensure SSE is not buffered
nginx.ingress.kubernetes.io/keep-alive: "75s" # Adjust keep-alive duration
1 change: 1 addition & 0 deletions deploy/k8s/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ resources:
- service.yaml
- external-secrets.yaml
- persistent-volume-claim.yaml
- ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Kustomization
namespace: dev
resources:
- ../../base
- ingress.yaml
patchesStrategicMerge:
- persistent-volume-claim.yaml
- service.yaml
- ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ kind: Kustomization
namespace: sqa
resources:
- ../../base
- ingress.yaml
patchesStrategicMerge:
- persistent-volume-claim.yaml
- ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Kustomization
namespace: prod
resources:
- ../../base
- ingress.yaml
patchesStrategicMerge:
- persistent-volume-claim.yaml
- configmap.yaml
- ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Kustomization
namespace: stage
resources:
- ../../base
- ingress.yaml
patchesStrategicMerge:
- persistent-volume-claim.yaml
- configmap.yaml
- ingress.yaml
14 changes: 14 additions & 0 deletions migration/114-create-view-geneset2hom.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE MATERIALIZED VIEW extsrc.geneset2hom AS
SELECT g.gs_id, array_agg(h.hom_id) as hom_id_array
FROM extsrc.homology h
INNER JOIN extsrc.geneset_value gv ON
h.ode_gene_id = gv.ode_gene_id
INNER JOIN production.geneset g ON gv.gs_id = g.gs_id
WHERE g.gs_status NOT LIKE 'de%'
AND hom_id IN
(SELECT DISTINCT hom_id
FROM extsrc.homology)
GROUP BY g.gs_id;

CREATE INDEX geneset2hom_gs_id_index
ON extsrc.geneset2hom (gs_id);
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "geneweaver-legacy"
version = "1.4.5"
version = "1.4.6"
description = ""
authors = ["Alexander Berger <[email protected]>"]
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions src/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -3224,9 +3224,9 @@ def calculate_jaccard(gs_id, genesets):
"""
jaccards = {}
gs1 = geneweaverdb.get_geneset_hom_ids(gs_id)
gs2s = geneweaverdb.get_genesets_hom_ids(genesets)
for g in genesets:
gs2 = geneweaverdb.get_geneset_hom_ids(g)
jaccards[g] = jaccard(gs1, gs2)
jaccards[g] = jaccard(gs1, gs2s[g])
return jaccards


Expand Down
38 changes: 12 additions & 26 deletions src/geneweaverdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3620,18 +3620,20 @@ def get_similar_genesets(geneset_id, user_id, grp_by):
'''SELECT a.* FROM (
(SELECT geneset.*,jac_value,gic_value
FROM geneset, geneset_jaccard gj
WHERE gs_id=gs_id_right AND gs_id_left=408167
WHERE gs_id=gs_id_right AND gs_id_left=%(geneset_id)s
AND geneset_is_readable(%(user_id)s, gs_id)
AND gs_status NOT LIKE 'de%%'
ORDER BY gj.jac_value DESC LIMIT 500
)
UNION
(SELECT geneset.*,jac_value,gic_value
FROM geneset, geneset_jaccard gj
WHERE gs_id=gs_id_left AND gs_id_right=408167
WHERE gs_id=gs_id_left AND gs_id_right=%(geneset_id)s
AND geneset_is_readable(%(user_id)s, gs_id)
AND gs_status NOT LIKE 'de%%'
ORDER BY gj.jac_value DESC LIMIT 500
)
) AS a ORDER BY a.jac_value DESC LIMIT 1000''',
) AS a ORDER BY ''' + order_by + ''' a.jac_value DESC LIMIT 1000''',
{
'geneset_id': geneset_id,
'user_id': user_id,
Expand Down Expand Up @@ -3921,21 +3923,16 @@ def get_geneset_hom_ids(gs_id):

def get_genesets_by_hom_id(hom_ids):
"""
Find which genesets are associated with which arrays. postgres does not have an any to
any array comparision so I have to loop :(
Find which genesets are associated with which arrays.
:param hom_ids:
:return: list of genesets
"""
if not isinstance(hom_ids, list):
hom_ids = [hom_ids]

geneset_list = []
with PooledCursor() as cursor:
geneset_list = []
for h in hom_ids:
cursor.execute('SELECT geneset_array FROM extsrc.hom2geneset WHERE hom_id=ANY(%s)', (h,))
geneset_list.append(cursor.fetchone()[0])
list(set(geneset_list[0]))
return geneset_list
cursor.execute("SELECT geneset_array FROM extsrc.hom2geneset WHERE hom_id=ANY(%s)", (hom_ids,))
for result in cursor.fetchall():
geneset_list.extend(result[0])
return list(set(geneset_list))


def get_genesets_hom_ids(gs_ids):
Expand All @@ -3945,18 +3942,7 @@ def get_genesets_hom_ids(gs_ids):
"""
with PooledCursor() as cursor:
cursor.execute("""
SELECT
g.gs_id,
ARRAY_AGG(DISTINCT h.hom_id) AS hom_ids
FROM
extsrc.homology h
INNER JOIN extsrc.geneset_value gsv ON h.ode_gene_id = gsv.ode_gene_id
INNER JOIN production.geneset g ON gsv.gs_id = g.gs_id
WHERE
g.gs_status NOT LIKE 'de%%'
AND g.gs_id = ANY(%(gs_ids)s)
GROUP BY
g.gs_id;
SELECT gs_id, hom_id_array FROM extsrc.geneset2hom WHERE gs_id = ANY(%(gs_ids)s)
""", {"gs_ids": list(gs_ids)})
if cursor.rowcount == 0:
return {}
Expand Down

0 comments on commit 49ed317

Please sign in to comment.