Skip to content
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
2 changes: 1 addition & 1 deletion src/main/resources/db-scripts/clickhouse/clickhouse.sql
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ CREATE TABLE clinical_event_derived
cancer_study_identifier LowCardinality(String)
)
ENGINE = MergeTree
ORDER BY (event_type, patient_unique_id, cancer_study_identifier);
ORDER BY (cancer_study_identifier, event_type, patient_unique_id);

INSERT INTO clinical_event_derived
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,15 @@
ced.cancer_study_identifier AS cancer_study_identifier
FROM clinical_event_derived ced
<where>
key = 'SAMPLE_ID'
AND (event_type ILIKE 'Sample Acquisition' OR event_type ILIKE 'SPECIMEN')
<if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()">
cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")">
#{studyId}
</foreach>
AND
</if>
(event_type ILIKE 'Sample Acquisition' OR event_type ILIKE 'SPECIMEN')
AND key = 'SAMPLE_ID'
</where>
GROUP BY patient_unique_id, ced.value, cancer_study_identifier
) ced
Expand All @@ -202,8 +209,16 @@
value AS treatment,
argMin(start_date, start_date) AS treatment_time_taken
FROM clinical_event_derived
WHERE lower(event_type) = 'treatment'
AND key = 'AGENT'
WHERE
<if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()">
cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")">
#{studyId}
</foreach>
AND
</if>
lower(event_type) = 'treatment'
AND key = 'AGENT'
GROUP BY patient_unique_id, value
) ced_inner ON ced_inner.patient_unique_id = ced.patient_unique_id
<where>
Expand Down Expand Up @@ -232,7 +247,14 @@
SELECT patient_unique_id
FROM clinical_event_derived
<where>
<foreach item="dataFilterValue" collection="clinicalEventFilter.values" open="(" separator=") OR (" close=")">
<if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()">
cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")">
#{studyId}
</foreach>
AND
</if>
<foreach item="dataFilterValue" collection="clinicalEventFilter.values" open="((" separator=") OR (" close="))">
event_type = #{dataFilterValue.value}
</foreach>
</where>
Expand All @@ -250,9 +272,19 @@
SELECT patient_unique_id
FROM clinical_event_derived
<where>
<foreach item="patientTreatmentFilter" collection="andedPatientTreatmentFilters.getFilters()" open="("
separator=") OR ("
close=")"> lower(event_type) = 'treatment'
<if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()">
cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")">
#{studyId}
</foreach>
AND
</if>
<foreach
item="patientTreatmentFilter"
collection="andedPatientTreatmentFilters.getFilters()"
open="((" separator=") OR (" close="))"
>
lower(event_type) = 'treatment'
AND key = 'AGENT'
AND value = #{patientTreatmentFilter.treatment}
</foreach>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
count(DISTINCT patient_unique_id) AS count
FROM clinical_event_derived
<where>
<if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()">
cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")">
#{studyId}
</foreach>
AND
</if>
lower(event_type) = 'treatment'
AND key = 'AGENT'
AND
Expand All @@ -34,6 +41,13 @@
patient_unique_id
FROM clinical_event_derived
<where>
<if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()">
cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")">
#{studyId}
</foreach>
AND
</if>
lower(event_type) = 'treatment'
AND key = 'AGENT'
AND
Expand All @@ -48,8 +62,15 @@
count(distinct ced.value) AS totalSamples
FROM clinical_event_derived ced
<where>
<if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()">
cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")">
#{studyId}
</foreach>
AND
</if>
(event_type ILIKE 'Sample Acquisition' OR event_type ILIKE 'SPECIMEN')
AND key = 'SAMPLE_ID'
AND (event_type ILIKE 'Sample Acquisition' OR event_type ILIKE 'SPECIMEN')
AND
concat(ced.cancer_study_identifier, '_', ced.value) IN ( <include refid="org.cbioportal.infrastructure.repository.clickhouse.studyview.ClickhouseStudyViewFilterMapper.sampleUniqueIdsFromStudyViewFilter"/>)
AND
Expand All @@ -58,6 +79,13 @@
patient_unique_id
FROM clinical_event_derived
<where>
<if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()">
cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")">
#{studyId}
</foreach>
AND
</if>
lower(event_type) = 'treatment'
AND key = 'AGENT'
AND
Expand Down Expand Up @@ -85,8 +113,15 @@
ced.cancer_study_identifier AS cancer_study_identifier
FROM clinical_event_derived ced
<where>
key = 'SAMPLE_ID'
AND (event_type ILIKE 'Sample Acquisition' OR event_type ILIKE 'SPECIMEN')
<if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()">
cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")">
#{studyId}
</foreach>
AND
</if>
(event_type ILIKE 'Sample Acquisition' OR event_type ILIKE 'SPECIMEN')
AND key = 'SAMPLE_ID'
</where>
GROUP BY patient_unique_id, ced.value, cancer_study_identifier
</sql>
Expand All @@ -98,6 +133,13 @@
argMin(start_date, start_date) AS treatment_time_taken
FROM clinical_event_derived
<where>
<if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()">
cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")">
#{studyId}
</foreach>
AND
</if>
lower(event_type) = 'treatment'
AND key = 'AGENT'
</where>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public void getPatientTreatments() {

@Test
public void getTotalSampleTreatmentCounts() {
// sample treatment counts without sample treatment filters

StudyViewFilter studyViewFilter = new StudyViewFilter();
studyViewFilter.setStudyIds(List.of(STUDY_TCGA_PUB));

Expand Down Expand Up @@ -126,6 +128,9 @@ public void getTotalSampleTreatmentCounts() {
.getTimeTaken()
.intValue());

// sample treatment counts with sample treatment filters

// PRE treatment test
SampleTreatmentFilter filter = new SampleTreatmentFilter();
filter.setTreatment("madeupanib");
filter.setTime(TemporalRelation.Pre);
Expand Down Expand Up @@ -155,5 +160,34 @@ public void getTotalSampleTreatmentCounts() {
assertEquals(0, totalSampleTreatmentCount);
assertEquals(0, sampleTreatmentCounts.size());
assertEquals(0, sampleTreatmentCountsWithSampleLists.size());

// POST treatment test
filter.setTime(TemporalRelation.Post);

totalSampleTreatmentCount =
mapper.getTotalSampleTreatmentCounts(
StudyViewFilterFactory.make(
studyViewFilter, null, studyViewFilter.getStudyIds(), null));

sampleTreatmentCounts =
mapper.getSampleTreatmentCounts(
StudyViewFilterFactory.make(studyViewFilter, null, studyViewFilter.getStudyIds(), null),
ProjectionType.SUMMARY.name());

sampleTreatmentCountsWithSampleLists =
mapper.getSampleTreatmentCounts(
StudyViewFilterFactory.make(studyViewFilter, null, studyViewFilter.getStudyIds(), null),
ProjectionType.DETAILED.name());

assertEquals(1, totalSampleTreatmentCount);
assertEquals(1, sampleTreatmentCounts.size());
assertEquals(1, sampleTreatmentCountsWithSampleLists.size());
assertEquals("madeupanib", sampleTreatmentCounts.getFirst().treatment());
assertEquals(1, sampleTreatmentCounts.getFirst().postSampleCount());
assertEquals(0, sampleTreatmentCounts.getFirst().preSampleCount());
assertEquals(1, sampleTreatmentCountsWithSampleLists.getFirst().postSampleCount());
assertEquals(0, sampleTreatmentCountsWithSampleLists.getFirst().preSampleCount());
assertEquals(1, sampleTreatmentCountsWithSampleLists.getFirst().postSamples().size());
assertEquals(0, sampleTreatmentCountsWithSampleLists.getFirst().preSamples().size());
}
}
Loading