Skip to content

Commit

Permalink
move clinical data bin related SQL queries to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
onursumer committed Jun 21, 2024
1 parent 0d7c083 commit b436b2b
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="org.cbioportal.persistence.mybatisclickhouse.StudyViewMapper">
<sql id="sampleClinicalDataFromStudyViewFilter">
<where>
sample_unique_id IN (
<include refid="sampleUniqueIdsFromStudyViewFilter"/>
<if test="applyPatientIdFilters == true">
INTERSECT <include refid="getSampleIdsFromPatientIds"/>
</if>
)
</where>
<if test="attributeIds != null and !attributeIds.isEmpty()">
AND attribute_name IN
<foreach item="attributeId" collection="attributeIds" open="(" separator="," close=")">
#{attributeId}
</foreach>
</if>
</sql>

<sql id="patientClinicalDataFromStudyViewFilter">
<where>
patient_unique_id IN (
<include refid="getPatientIdsFromSampleIdFilters"/>
<if test="applyPatientIdFilters == true">
INTERSECT <include refid="patientUniqueIdsFromStudyViewFilter"/>
</if>
)
</where>
<if test="attributeIds != null and !attributeIds.isEmpty()">
AND attribute_name IN
<foreach item="attributeId" collection="attributeIds" open="(" separator="," close=")">
#{attributeId}
</foreach>
</if>
</sql>

<!-- TODO only fetching from sample_clinical_attribute_numeric, need to support sample_clinical_attribute_categorical as well -->
<select id="getSampleCountWithoutClinicalData" resultType="Long">
SELECT
COUNT (DISTINCT sample_unique_id)
FROM sample_mv
<where>
sample_unique_id IN ( <include refid="sampleUniqueIdsFromStudyViewFilter"/>)
<if test="applyPatientIdFilters == true">
AND patient_unique_id IN (<include refid="patientUniqueIdsFromStudyViewFilter"/>)
</if>
AND sample_unique_id NOT IN (
SELECT
sample_unique_id
FROM sample_clinical_attribute_numeric_view
<include refid="sampleClinicalDataFromStudyViewFilter"/>
)
</where>
</select>

<select id="getSampleClinicalDataFromStudyViewFilter" resultType="org.cbioportal.model.ClinicalData">
SELECT
sample_unique_id as sampleId,
patient_unique_id as patientId,
attribute_name as attrId,
attribute_value as attrValue,
cancer_study_identifier as studyId
FROM sample_clinical_attribute_numeric_view
<include refid="sampleClinicalDataFromStudyViewFilter"/>
</select>

<!-- TODO only fetching from patient_clinical_attribute_numeric, need to support patient_clinical_attribute_categorical as well -->
<select id="getPatientCountWithoutClinicalData" resultType="Long">
SELECT
COUNT (DISTINCT patient_unique_id)
FROM sample_mv
<where>
patient_unique_id IN (
<include refid="getPatientIdsFromSampleIdFilters"/>
<if test="applyPatientIdFilters == true">
INTERSECT <include refid="patientUniqueIdsFromStudyViewFilter"/>
</if>
)
AND patient_unique_id NOT IN (
SELECT
patient_unique_id
FROM patient_clinical_attribute_numeric_view
<include refid="patientClinicalDataFromStudyViewFilter"/>
)
</where>
</select>

<select id="getPatientClinicalDataFromStudyViewFilter" resultType="org.cbioportal.model.ClinicalData">
SELECT
patient_unique_id as patientId,
attribute_name as attrId,
attribute_value as attrValue,
cancer_study_identifier as studyId
FROM patient_clinical_attribute_numeric_view
<include refid="patientClinicalDataFromStudyViewFilter"/>
</select>
</mapper>

Original file line number Diff line number Diff line change
Expand Up @@ -61,102 +61,7 @@
GROUP BY hugo_gene_symbol, alteration, cytoband
ORDER BY totalCount DESC;
</select>

<sql id="sampleClinicalDataFromStudyViewFilter">
<where>
sample_unique_id IN (
<include refid="sampleUniqueIdsFromStudyViewFilter"/>
<if test="applyPatientIdFilters == true">
INTERSECT <include refid="getSampleIdsFromPatientIds"/>
</if>
)
</where>
<if test="attributeIds != null and !attributeIds.isEmpty()">
AND attribute_name IN
<foreach item="attributeId" collection="attributeIds" open="(" separator="," close=")">
#{attributeId}
</foreach>
</if>
</sql>

<sql id="patientClinicalDataFromStudyViewFilter">
<where>
patient_unique_id IN (
<include refid="getPatientIdsFromSampleIdFilters"/>
<if test="applyPatientIdFilters == true">
INTERSECT <include refid="patientUniqueIdsFromStudyViewFilter"/>
</if>
)
</where>
<if test="attributeIds != null and !attributeIds.isEmpty()">
AND attribute_name IN
<foreach item="attributeId" collection="attributeIds" open="(" separator="," close=")">
#{attributeId}
</foreach>
</if>
</sql>

<!-- TODO only fetching from sample_clinical_attribute_numeric, need to support sample_clinical_attribute_categorical as well -->
<select id="getSampleCountWithoutClinicalData" resultType="Long">
SELECT
COUNT (DISTINCT sample_unique_id)
FROM sample_view
<where>
sample_unique_id IN ( <include refid="sampleUniqueIdsFromStudyViewFilter"/>)
<if test="applyPatientIdFilters == true">
AND patient_unique_id IN (<include refid="patientUniqueIdsFromStudyViewFilter"/>)
</if>
AND sample_unique_id NOT IN (
SELECT
sample_unique_id
FROM sample_clinical_attribute_numeric_view
<include refid="sampleClinicalDataFromStudyViewFilter"/>
)
</where>
</select>

<select id="getSampleClinicalDataFromStudyViewFilter" resultType="org.cbioportal.model.ClinicalData">
SELECT
sample_unique_id as sampleId,
patient_unique_id as patientId,
attribute_name as attrId,
attribute_value as attrValue,
cancer_study_identifier as studyId
FROM sample_clinical_attribute_numeric_view
<include refid="sampleClinicalDataFromStudyViewFilter"/>
</select>

<!-- TODO only fetching from patient_clinical_attribute_numeric, need to support patient_clinical_attribute_categorical as well -->
<select id="getPatientCountWithoutClinicalData" resultType="Long">
SELECT
COUNT (DISTINCT patient_unique_id)
FROM sample_view
<where>
patient_unique_id IN (
<include refid="getPatientIdsFromSampleIdFilters"/>
<if test="applyPatientIdFilters == true">
INTERSECT <include refid="patientUniqueIdsFromStudyViewFilter"/>
</if>
)
AND patient_unique_id NOT IN (
SELECT
patient_unique_id
FROM patient_clinical_attribute_numeric_view
<include refid="patientClinicalDataFromStudyViewFilter"/>
)
</where>
</select>

<select id="getPatientClinicalDataFromStudyViewFilter" resultType="org.cbioportal.model.ClinicalData">
SELECT
patient_unique_id as patientId,
attribute_name as attrId,
attribute_value as attrValue,
cancer_study_identifier as studyId
FROM patient_clinical_attribute_numeric_view
<include refid="patientClinicalDataFromStudyViewFilter"/>
</select>

<!-- for /clinical-data-counts/fetch (returns ClinicalData) which will then be converted to clinicalDataCountItems -->
<select id="getClinicalDataCounts" resultType="org.cbioportal.model.ClinicalDataCount">
<include refid="getCategoricalClinicalDataCountsQuerySample">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public SqlSessionFactoryBean sqlColumnarSessionFactory(ResourceLoader resourceLo
var studyViewMapperResource = resourceLoader.getResource("classpath:org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.xml") ;
var studyViewFilterMapperResource = resourceLoader.getResource("classpath:org/cbioportal/persistence/mybatisclickhouse/StudyViewFilterMapper.xml");
var alterationFilterMapperResource = resourceLoader.getResource("classpath:org/cbioportal/persistence/mybatisclickhouse/StudyViewAlterationFilterMapper.xml");
var clinicalDataBinMapperResource = resourceLoader.getResource("classpath:org/cbioportal/persistence/mybatisclickhouse/StudyViewAlterationFilterMapper.xml");
sessionFactory.setMapperLocations(
studyViewMapperResource,studyViewFilterMapperResource, alterationFilterMapperResource
studyViewMapperResource,studyViewFilterMapperResource, alterationFilterMapperResource, clinicalDataBinMapperResource
);
return sessionFactory;
}
Expand Down

0 comments on commit b436b2b

Please sign in to comment.