Skip to content

Commit

Permalink
Filtering with NA for genomic-data-bin-counts
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhaoyuan committed Sep 23, 2024
1 parent 0d1d51f commit 5d2874c
Showing 1 changed file with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,10 @@
<foreach item="genomicDataFilter" collection="studyViewFilterHelper.studyViewFilter.genomicDataFilters" open="INTERSECT" separator="INTERSECT">
<choose>
<when test="genomicDataFilter.profileType == 'cna' or genomicDataFilter.profileType == 'gistic'">
<include refid="applyGenomicDataFilter"/>
<include refid="categoricalGenomicDataFilter"/>
</when>
<otherwise>
<include refid="numericalGenomicDataCountFilter">
<property name="unique_id" value="sample_unique_id"/>
<property name="table_name" value="genetic_alteration_derived"/>
</include>
<include refid="numericalGenomicDataFilter"/>
</otherwise>
</choose>
</foreach>
Expand Down Expand Up @@ -387,19 +384,27 @@
</foreach>
</sql>

<sql id="numericalGenomicDataCountFilter">
SELECT ${unique_id}
FROM ${table_name}
WHERE hugo_gene_symbol = '${genomicDataFilter.hugoGeneSymbol}' AND
profile_type='${genomicDataFilter.profileType}'
<foreach item="dataFilterValue" collection="genomicDataFilter.values" open=" AND ((" separator=") OR (" close="))">
<sql id="numericalGenomicDataFilter">
<!-- check if 'NA' is selected -->
<bind name="containsNA" value="false" />
<foreach item="dataFilterValue" collection="genomicDataFilter.values">
<if test="dataFilterValue.value == 'NA'">
<bind name="containsNA" value="true" />
</if>
</foreach>
<if test="containsNA">
SELECT DISTINCT sd.sample_unique_id
FROM sample_derived sd
LEFT JOIN (<include refid="selectAllGenomicNumericalSamples"/>) AS genomic_numerical_query ON sd.sample_unique_id = genomic_numerical_query.sample_unique_id
WHERE alteration_value IS null
UNION ALL
</if>
SELECT DISTINCT sd.sample_unique_id
FROM sample_derived sd
INNER JOIN (<include refid="selectAllGenomicNumericalSamples"/>) AS genomic_numerical_query ON sd.sample_unique_id = genomic_numerical_query.sample_unique_id
WHERE
<foreach item="dataFilterValue" collection="genomicDataFilter.values" open="((" separator=") OR (" close="))">
<trim prefix="" prefixOverrides="AND">
<if test="dataFilterValue.value eq 'NA'">
AND
<include refid="isAttributeValueNA">
<property name="attribute_value" value="alteration_value"/>
</include>
</if>
<if test="dataFilterValue.start != null and dataFilterValue.end == null">
AND match(alteration_value, '^>?=?[-+]?[0-9]*[.,]?[0-9]+$')
</if>
Expand Down Expand Up @@ -440,6 +445,17 @@
</trim>
</foreach>
</sql>

<sql id="selectAllGenomicNumericalSamples">
SELECT sample_unique_id, alteration_value
FROM genetic_alteration_derived comeonwhyisitnotworking
WHERE profile_type = #{genomicDataFilter.profileType}
AND hugo_gene_symbol = #{genomicDataFilter.hugoGeneSymbol}
AND cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterHelper.studyViewFilter.studyIds" open="(" separator="," close=")">
#{studyId}
</foreach>
</sql>

<!-- TODO: update the database scheme to include the data_type column -->
<sql id="numericalGenericAssayDataCountFilter">
Expand Down Expand Up @@ -577,7 +593,7 @@
</if>
</sql>

<sql id="applyGenomicDataFilter">
<sql id="categoricalGenomicDataFilter">
<!-- filter on study to reduce query size in preparation of the following LEFT JOIN -->
WITH cna_query AS (
SELECT sample_unique_id, alteration_value
Expand All @@ -597,9 +613,11 @@
<foreach item="studyId" collection="studyViewFilterHelper.studyViewFilter.studyIds" open="(" separator="," close=")">
#{studyId}
</foreach>
AND alteration_value IN
<foreach item="dataFilterValue" collection="genomicDataFilter.values" open="(" separator="," close=")">
#{dataFilterValue.value}
<foreach item="dataFilterValue" collection="genomicDataFilter.values" open="AND (" separator=" OR " close=")">
<choose>
<when test="dataFilterValue.value == 'NA'">alteration_value IS null</when>
<otherwise>alteration_value == #{dataFilterValue.value}</otherwise>
</choose>
</foreach>
</sql>
</mapper>

0 comments on commit 5d2874c

Please sign in to comment.