Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for non-numerical values in numerical data count filter #11216

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,74 @@
</foreach>
</sql>

<sql id="applyNumericalDataFilter">
<foreach item="dataFilterValue" collection="${data_filter_collection}" open="((" separator=") OR (" close="))">
<trim prefix="" prefixOverrides="AND">
<!-- Special case: NA -->
<if test="dataFilterValue.value eq 'NA'">
AND
<include refid="isAttributeValueNA">
<property name="attribute_value" value="${attribute_value}"/>
</include>
</if>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't need to handle NA here if this SQL is used as the non-NA part? Just curious, it's also fine to have it here. And I think it's also possible to include the NA part as a whole SQL but this is great progress already. Appreciate it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this NA part was implemented before we added the additional logic for NA.

You're right. We should probably move the NA filter logic into this same SQL as well. Might be better to deal with it in a separate PR tough.

<!--
Special case: Non-numerical value within numerical filter collection.
Even if the data type is numerical we can still have non-numerical values
such as "UNKNOWN", "NOT COLLECTED", "NOT RELEASED", etc.
-->
<if test="dataFilterValue.value != null">
AND
${attribute_value} ILIKE #{dataFilterValue.value}
</if>
<!--
Special case: Numerical range values such as <18, >=90, etc.
We need to make sure to treat these values as numerical for filtering purposes.
-->
<if test="dataFilterValue.start != null and dataFilterValue.end == null">
AND match(${attribute_value}, '^>?=?[-+]?[0-9]*[.,]?[0-9]+$')
</if>
<if test="dataFilterValue.start == null and dataFilterValue.end != null">
AND match(${attribute_value}, '^&lt;?=?[-+]?[0-9]*[.,]?[0-9]+$')
</if>
<if test="dataFilterValue.start != null and dataFilterValue.end != null">
AND match(${attribute_value}, '^[-+]?[0-9]*[.,]?[0-9]+$')
</if>
<!--
Actual filtering of values that fall within the range of (start, end].
Note that start value is exclusive, but end value is inclusive.
-->
<if test="dataFilterValue.start != null or dataFilterValue.end != null">
<choose>
<when test="dataFilterValue.start == dataFilterValue.end">
AND abs(
minus(
<include refid="castStringValueToFloat">
<property name="attribute_value" value="${attribute_value}"/>
</include>,
cast(#{dataFilterValue.start} as float)
)
) &lt; exp(-11)
</when>
<otherwise>
<if test="dataFilterValue.start != null">
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="${attribute_value}"/>
</include> &gt; cast(#{dataFilterValue.start} as float)
</if>
<if test="dataFilterValue.end != null">
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="${attribute_value}"/>
</include> &lt;= cast(#{dataFilterValue.end} as float)
</if>
</otherwise>
</choose>
</if>
</trim>
</foreach>
</sql>

<sql id="applyClinicalDataCountFilter">
<foreach item="clinicalDataFilter"
collection="studyViewFilterHelper.studyViewFilter.clinicalDataFilters"
Expand All @@ -288,11 +356,11 @@
</include>
</when>
<otherwise>
<include refid="numericalClinicalDataCountFilter">
<property name="unique_id" value="sample_unique_id"/>
<property name="table_name" value="clinical_data_derived"/>
<property name="type" value="sample"/>
</include>
<include refid="numericalClinicalDataCountFilter">
<property name="unique_id" value="sample_unique_id"/>
<property name="table_name" value="clinical_data_derived"/>
<property name="type" value="sample"/>
</include>
</otherwise>
</choose>

Expand Down Expand Up @@ -362,57 +430,15 @@

<!-- if non-NA is selected, prepare non-NA samples -->
<if test="userSelectsNumericalValue">
SELECT ${unique_id}
FROM ${table_name}
WHERE attribute_name = #{clinicalDataFilter.attributeId} AND
type='${type}'
<foreach item="dataFilterValue" collection="clinicalDataFilter.values" open=" AND ((" separator=") OR (" close="))">
<trim prefix="" prefixOverrides="AND">
<if test="dataFilterValue.value eq 'NA'">
AND
<include refid="isAttributeValueNA">
<property name="attribute_value" value="attribute_value"/>
</include>
</if>
<if test="dataFilterValue.start != null and dataFilterValue.end == null">
AND match(attribute_value, '^>?=?[-+]?[0-9]*[.,]?[0-9]+$')
</if>
<if test="dataFilterValue.start == null and dataFilterValue.end != null">
AND match(attribute_value, '^&lt;?=?[-+]?[0-9]*[.,]?[0-9]+$')
</if>
<if test="dataFilterValue.start != null and dataFilterValue.end != null">
AND match(attribute_value, '^[-+]?[0-9]*[.,]?[0-9]+$')
</if>
<if test="dataFilterValue.start != null or dataFilterValue.end != null">
<choose>
<when test="dataFilterValue.start == dataFilterValue.end">
AND abs(
minus(
<include refid="castStringValueToFloat">
<property name="attribute_value" value="attribute_value"/>
</include>,
cast(#{dataFilterValue.start} as float)
)
) &lt; exp(-11)
</when>
<otherwise>
<if test="dataFilterValue.start != null">
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="attribute_value"/>
</include> &gt; cast(#{dataFilterValue.start} as float)
</if>
<if test="dataFilterValue.end != null">
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="attribute_value"/>
</include> &lt;= cast(#{dataFilterValue.end} as float)
</if>
</otherwise>
</choose>
</if>
</trim>
</foreach>
SELECT ${unique_id}
FROM ${table_name}
WHERE attribute_name = #{clinicalDataFilter.attributeId} AND
type='${type}'
AND
<include refid="applyNumericalDataFilter">
<property name="attribute_value" value="attribute_value"/>
<property name="data_filter_collection" value="clinicalDataFilter.values"/>
</include>
</if>
)
</sql>
Expand Down Expand Up @@ -452,11 +478,7 @@
</include> = 'NA'
</when>
<otherwise>
(
<include refid="normalizeAttributeValue">
<property name="attribute_value" value="attribute_value"/>
</include>
) ILIKE #{dataFilterValue.value}
attribute_value ILIKE #{dataFilterValue.value}
</otherwise>
</choose>
</foreach>
Expand Down Expand Up @@ -494,47 +516,10 @@
SELECT DISTINCT sample_unique_id
FROM (<include refid="selectAllNumericalGeneticAlterations"/>) AS genomic_numerical_query
WHERE
<foreach item="dataFilterValue" collection="genomicDataFilter.values" open="((" separator=") OR (" close="))">
<trim prefix="" prefixOverrides="AND">
<if test="dataFilterValue.start != null and dataFilterValue.end == null">
AND match(alteration_value, '^>?=?[-+]?[0-9]*[.,]?[0-9]+$')
</if>
<if test="dataFilterValue.start == null and dataFilterValue.end != null">
AND match(alteration_value, '^&lt;?=?[-+]?[0-9]*[.,]?[0-9]+$')
</if>
<if test="dataFilterValue.start != null and dataFilterValue.end != null">
AND match(alteration_value, '^[-+]?[0-9]*[.,]?[0-9]+$')
</if>
<if test="dataFilterValue.start != null or dataFilterValue.end != null">
<choose>
<when test="dataFilterValue.start == dataFilterValue.end">
AND abs(
minus(
<include refid="castStringValueToFloat">
<property name="attribute_value" value="alteration_value"/>
</include>,
cast(#{dataFilterValue.start} as float)
)
) &lt; exp(-11)
</when>
<otherwise>
<if test="dataFilterValue.start != null">
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="alteration_value"/>
</include> &gt; cast(#{dataFilterValue.start} as float)
</if>
<if test="dataFilterValue.end != null">
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="alteration_value"/>
</include> &lt;= cast(#{dataFilterValue.end} as float)
</if>
</otherwise>
</choose>
</if>
</trim>
</foreach>
<include refid="applyNumericalDataFilter">
<property name="attribute_value" value="alteration_value"/>
<property name="data_filter_collection" value="genomicDataFilter.values"/>
</include>
</if>
</sql>

Expand Down Expand Up @@ -596,53 +581,11 @@
<include refid="normalizeAttributeValue">
<property name="attribute_value" value="value"/>
</include> != 'NA'
<foreach item="dataFilterValue" collection="genericAssayDataFilter.values" open=" AND ((" separator=") OR (" close="))">
<trim prefix="" prefixOverrides="AND">
<if test="dataFilterValue.value eq 'NA'">
AND
<include refid="isAttributeValueNA">
<property name="attribute_value" value="value"/>
</include>
</if>
<if test="dataFilterValue.start != null and dataFilterValue.end == null">
AND match(value, '^>?=?[-+]?[0-9]*[.,]?[0-9]+$')
</if>
<if test="dataFilterValue.start == null and dataFilterValue.end != null">
AND match(value, '^&lt;?=?[-+]?[0-9]*[.,]?[0-9]+$')
</if>
<if test="dataFilterValue.start != null and dataFilterValue.end != null">
AND match(value, '^[-+]?[0-9]*[.,]?[0-9]+$')
</if>
<if test="dataFilterValue.start != null or dataFilterValue.end != null">
<choose>
<when test="dataFilterValue.start == dataFilterValue.end">
AND abs(
minus(
<include refid="castStringValueToFloat">
<property name="attribute_value" value="value"/>
</include>,
cast(#{dataFilterValue.start} as float)
)
) &lt; exp(-11)
</when>
<otherwise>
<if test="dataFilterValue.start != null">
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="value"/>
</include> &gt; cast(#{dataFilterValue.start} as float)
</if>
<if test="dataFilterValue.end != null">
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="value"/>
</include> &lt;= cast(#{dataFilterValue.end} as float)
</if>
</otherwise>
</choose>
</if>
</trim>
</foreach>
AND
<include refid="applyNumericalDataFilter">
<property name="attribute_value" value="value"/>
<property name="data_filter_collection" value="genericAssayDataFilter.values"/>
</include>
</if>
</sql>

Expand All @@ -662,11 +605,7 @@
</include> = 'NA'
</when>
<otherwise>
(
<include refid="normalizeAttributeValue">
<property name="attribute_value" value="value"/>
</include>
) ILIKE #{dataFilterValue.value}
value ILIKE #{dataFilterValue.value}
</otherwise>
</choose>
</foreach>
Expand Down
Loading
Loading