Skip to content

Commit

Permalink
add internal id to sample and clinical data SQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
onursumer committed Oct 30, 2024
1 parent a21ca53 commit 08fb470
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ public ClinicalViolinPlotData getClinicalViolinPlotData(
result.setRows(new ArrayList<>());

// collect filtered samples into a set for quick lookup
Set<String> samplesForSampleCountsIds =
Set<Integer> samplesForSampleCountsIds =
samplesForSampleCounts.stream()
.map(s -> s.getInternalId() == null ?
s.getCancerStudyIdentifier() + "_" + s.getStableId(): s.getInternalId().toString()
)
.map(Sample::getInternalId)
.collect(Collectors.toSet());

// clinicalDataMap is a map sampleId->studyId->data
Expand Down Expand Up @@ -216,14 +214,12 @@ public ClinicalViolinPlotData getClinicalViolinPlotData(

@SafeVarargs
private static int countFilteredSamples(
Set<String> filteredSampleIds,
Set<Integer> filteredSampleIds,
List<ClinicalData>... dataLists
) {
return (int) Arrays.stream(dataLists)
.flatMap(Collection::stream)
.map(c -> c.getInternalId() == null ?
c.getStudyId() + "_" + c.getSampleId() : c.getInternalId().toString()
)
.map(ClinicalData::getInternalId)
.filter(filteredSampleIds::contains)
.count();
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/resources/db-scripts/clickhouse/clickhouse.sql
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ WHERE

CREATE TABLE IF NOT EXISTS clinical_data_derived
(
internal_id Int,
sample_unique_id String,
patient_unique_id String,
attribute_name LowCardinality(String),
Expand All @@ -224,7 +225,8 @@ CREATE TABLE IF NOT EXISTS clinical_data_derived

-- Insert sample attribute data
INSERT INTO TABLE clinical_data_derived
SELECT sm.sample_unique_id AS sample_unique_id,
SELECT sm.internal_id AS internal_id,
sm.sample_unique_id AS sample_unique_id,
sm.patient_unique_id AS patient_unique_id,
cam.attr_id AS attribute_name,
ifNull(csamp.attr_value, '') AS attribute_value,
Expand All @@ -241,10 +243,11 @@ WHERE cam.patient_attribute = 0;

-- INSERT patient attribute data
INSERT INTO TABLE clinical_data_derived
SELECT '' AS sample_unique_id,
SELECT p.internal_id AS internal_id,
'' AS sample_unique_id,
concat(cs.cancer_study_identifier, '_', p.stable_id) AS patient_unique_id,
cam.attr_id AS attribute_name,
ifNull(clinpat.attr_value, '') AS attribute_value,
ifNull(clinpat.attr_value, '') AS attribute_value,
cs.cancer_study_identifier AS cancer_study_identifier,
'patient' AS type
FROM patient AS p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<!-- for /filtered-sample/fetch (returns Sample objects) -->
<select id="getFilteredSamples" resultType="org.cbioportal.model.Sample">
SELECT
internal_id as internalId,
patient_stable_id as patientStableId,
sample_stable_id as stableId,
cancer_study_identifier as cancerStudyIdentifier,
Expand Down Expand Up @@ -91,6 +92,7 @@

<select id="getSampleClinicalDataFromStudyViewFilter" resultType="org.cbioportal.model.ClinicalData">
SELECT
internal_id as internalId,
replaceOne(sample_unique_id, concat(cancer_study_identifier, '_'), '') as sampleId,
replaceOne(patient_unique_id, concat(cancer_study_identifier, '_'), '') as patientId,
attribute_name as attrId,
Expand All @@ -113,6 +115,7 @@

<select id="getPatientClinicalDataFromStudyViewFilter" resultType="org.cbioportal.model.ClinicalData">
SELECT
internal_id as internalId,
replaceOne(patient_unique_id, concat(cancer_study_identifier, '_'), '') as patientId,
attribute_name as attrId,
attribute_value as attrValue,
Expand Down

0 comments on commit 08fb470

Please sign in to comment.