|
3 | 3 |
|
4 | 4 | <mapper namespace="org.cbioportal.legacy.persistence.mybatis.MolecularDataMapper"> |
5 | 5 |
|
| 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 | + |
6 | 32 | <sql id="whereInMultipleMolecularProfiles"> |
7 | 33 | <where> |
8 | 34 | <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 | + ) |
11 | 41 | </if> |
12 | 42 | <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"/> |
15 | 44 | </if> |
16 | 45 | </where> |
17 | 46 | </sql> |
|
44 | 73 | FROM genetic_alteration |
45 | 74 | INNER JOIN genetic_profile ON genetic_alteration.genetic_profile_id = genetic_profile.genetic_profile_id |
46 | 75 | 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"/> |
54 | 77 | </select> |
55 | 78 |
|
56 | 79 | <!-- This routine is a copy of getGeneMolecularAlterations above. This copy is necessary because |
|
72 | 95 | FROM genetic_alteration |
73 | 96 | INNER JOIN genetic_profile ON genetic_alteration.genetic_profile_id = genetic_profile.genetic_profile_id |
74 | 97 | 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"/> |
82 | 99 | </select> |
83 | 100 |
|
84 | 101 | <!-- This routine is an abbreviated copy of getGeneMolecularAlterationsIter above. The two should be kept in sync. --> |
|
90 | 107 | INNER JOIN genetic_profile ON genetic_alteration.genetic_profile_id = genetic_profile.genetic_profile_id |
91 | 108 | INNER JOIN gene ON genetic_alteration.genetic_entity_id = gene.genetic_entity_id |
92 | 109 | <where> |
93 | | - genetic_profile.stable_id = #{molecularProfileId} |
| 110 | + <include refid="filterBySingleMolecularProfileId"/> |
94 | 111 | </where> |
95 | 112 | </select> |
96 | 113 |
|
|
124 | 141 | INNER JOIN genetic_profile ON genetic_alteration.genetic_profile_id = genetic_profile.genetic_profile_id |
125 | 142 | INNER JOIN geneset ON genetic_alteration.genetic_entity_id = geneset.genetic_entity_id |
126 | 143 | <where> |
127 | | - genetic_profile.stable_id = #{molecularProfileId} |
| 144 | + <include refid="filterBySingleMolecularProfileId"/> |
128 | 145 | <if test="genesetIds != null and genesetIds"> |
129 | 146 | AND geneset.external_id IN |
130 | 147 | <foreach item="item" collection="genesetIds" open="(" separator="," close=")">#{item}</foreach> |
|
147 | 164 | INNER JOIN genetic_profile ON genetic_alteration.genetic_profile_id = genetic_profile.genetic_profile_id |
148 | 165 | INNER JOIN genetic_entity ON genetic_alteration.genetic_entity_id = genetic_entity.id |
149 | 166 | <where> |
150 | | - genetic_profile.stable_id = #{molecularProfileId} |
| 167 | + <include refid="filterBySingleMolecularProfileId"/> |
151 | 168 | <if test="stableIds != null and stableIds"> |
152 | 169 | AND genetic_entity.stable_id IN |
153 | 170 | <foreach item="item" collection="stableIds" open="(" separator="," close=")">#{item}</foreach> |
|
175 | 192 | INNER JOIN genetic_profile ON genetic_alteration.genetic_profile_id = genetic_profile.genetic_profile_id |
176 | 193 | INNER JOIN genetic_entity ON genetic_alteration.genetic_entity_id = genetic_entity.id |
177 | 194 | <where> |
178 | | - genetic_profile.stable_id = #{molecularProfileId} |
| 195 | + <include refid="filterBySingleMolecularProfileId"/> |
179 | 196 | <if test="stableIds != null and stableIds"> |
180 | 197 | AND genetic_entity.stable_id IN |
181 | 198 | <foreach item="item" collection="stableIds" open="(" separator="," close=")">#{item}</foreach> |
|
0 commit comments