Skip to content

Commit 000498c

Browse files
onursumeralisman
authored andcommitted
improve molecular data query (#11669)
1 parent de029ad commit 000498c

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

src/main/resources/org/cbioportal/legacy/persistence/mybatis/MolecularDataMapper.xml

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,44 @@
33

44
<mapper namespace="org.cbioportal.legacy.persistence.mybatis.MolecularDataMapper">
55

6+
<sql id="filterBySingleMolecularProfileId">
7+
genetic_alteration.genetic_profile_id = (
8+
SELECT gp.genetic_profile_id
9+
FROM genetic_profile gp
10+
WHERE gp.stable_id = #{molecularProfileId}
11+
)
12+
</sql>
13+
14+
<sql id="filterByEntrezGeneIds">
15+
genetic_alteration.genetic_entity_id IN (
16+
SELECT g.genetic_entity_id
17+
FROM gene g
18+
WHERE g.entrez_gene_id IN
19+
<foreach item="item" collection="entrezGeneIds" open="(" separator="," close=")">#{item}</foreach>
20+
)
21+
</sql>
22+
23+
<sql id="whereInSingleMolecularProfile">
24+
<where>
25+
<include refid="filterBySingleMolecularProfileId"/>
26+
<if test="entrezGeneIds != null and !entrezGeneIds.isEmpty()">
27+
AND <include refid="filterByEntrezGeneIds"/>
28+
</if>
29+
</where>
30+
</sql>
31+
632
<sql id="whereInMultipleMolecularProfiles">
733
<where>
834
<if test="molecularProfileIds != null and !molecularProfileIds.isEmpty()">
9-
genetic_profile.stable_id IN
10-
<foreach item="item" collection="molecularProfileIds" open="(" separator="," close=")">#{item}</foreach>
35+
genetic_alteration.genetic_profile_id IN (
36+
SELECT gp.genetic_profile_id
37+
FROM genetic_profile gp
38+
WHERE gp.stable_id IN
39+
<foreach item="item" collection="molecularProfileIds" open="(" separator="," close=")">#{item}</foreach>
40+
)
1141
</if>
1242
<if test="entrezGeneIds != null and !entrezGeneIds.isEmpty()">
13-
AND gene.entrez_gene_id IN
14-
<foreach item="item" collection="entrezGeneIds" open="(" separator="," close=")">#{item}</foreach>
43+
AND <include refid="filterByEntrezGeneIds"/>
1544
</if>
1645
</where>
1746
</sql>
@@ -44,13 +73,7 @@
4473
FROM genetic_alteration
4574
INNER JOIN genetic_profile ON genetic_alteration.genetic_profile_id = genetic_profile.genetic_profile_id
4675
INNER JOIN gene ON genetic_alteration.genetic_entity_id = gene.genetic_entity_id
47-
<where>
48-
genetic_profile.stable_id = #{molecularProfileId}
49-
<if test="entrezGeneIds != null and !entrezGeneIds.isEmpty()">
50-
AND gene.entrez_gene_id IN
51-
<foreach item="item" collection="entrezGeneIds" open="(" separator="," close=")">#{item}</foreach>
52-
</if>
53-
</where>
76+
<include refid="whereInSingleMolecularProfile"/>
5477
</select>
5578

5679
<!-- This routine is a copy of getGeneMolecularAlterations above. This copy is necessary because
@@ -72,13 +95,7 @@
7295
FROM genetic_alteration
7396
INNER JOIN genetic_profile ON genetic_alteration.genetic_profile_id = genetic_profile.genetic_profile_id
7497
INNER JOIN gene ON genetic_alteration.genetic_entity_id = gene.genetic_entity_id
75-
<where>
76-
genetic_profile.stable_id = #{molecularProfileId}
77-
<if test="entrezGeneIds != null and !entrezGeneIds.isEmpty()">
78-
AND gene.entrez_gene_id IN
79-
<foreach item="item" collection="entrezGeneIds" open="(" separator="," close=")">#{item}</foreach>
80-
</if>
81-
</where>
98+
<include refid="whereInSingleMolecularProfile"/>
8299
</select>
83100

84101
<!-- This routine is an abbreviated copy of getGeneMolecularAlterationsIter above. The two should be kept in sync. -->
@@ -90,7 +107,7 @@
90107
INNER JOIN genetic_profile ON genetic_alteration.genetic_profile_id = genetic_profile.genetic_profile_id
91108
INNER JOIN gene ON genetic_alteration.genetic_entity_id = gene.genetic_entity_id
92109
<where>
93-
genetic_profile.stable_id = #{molecularProfileId}
110+
<include refid="filterBySingleMolecularProfileId"/>
94111
</where>
95112
</select>
96113

@@ -124,7 +141,7 @@
124141
INNER JOIN genetic_profile ON genetic_alteration.genetic_profile_id = genetic_profile.genetic_profile_id
125142
INNER JOIN geneset ON genetic_alteration.genetic_entity_id = geneset.genetic_entity_id
126143
<where>
127-
genetic_profile.stable_id = #{molecularProfileId}
144+
<include refid="filterBySingleMolecularProfileId"/>
128145
<if test="genesetIds != null and genesetIds">
129146
AND geneset.external_id IN
130147
<foreach item="item" collection="genesetIds" open="(" separator="," close=")">#{item}</foreach>
@@ -147,7 +164,7 @@
147164
INNER JOIN genetic_profile ON genetic_alteration.genetic_profile_id = genetic_profile.genetic_profile_id
148165
INNER JOIN genetic_entity ON genetic_alteration.genetic_entity_id = genetic_entity.id
149166
<where>
150-
genetic_profile.stable_id = #{molecularProfileId}
167+
<include refid="filterBySingleMolecularProfileId"/>
151168
<if test="stableIds != null and stableIds">
152169
AND genetic_entity.stable_id IN
153170
<foreach item="item" collection="stableIds" open="(" separator="," close=")">#{item}</foreach>
@@ -175,7 +192,7 @@
175192
INNER JOIN genetic_profile ON genetic_alteration.genetic_profile_id = genetic_profile.genetic_profile_id
176193
INNER JOIN genetic_entity ON genetic_alteration.genetic_entity_id = genetic_entity.id
177194
<where>
178-
genetic_profile.stable_id = #{molecularProfileId}
195+
<include refid="filterBySingleMolecularProfileId"/>
179196
<if test="stableIds != null and stableIds">
180197
AND genetic_entity.stable_id IN
181198
<foreach item="item" collection="stableIds" open="(" separator="," close=")">#{item}</foreach>

0 commit comments

Comments
 (0)