Skip to content

Commit

Permalink
make clinical data sample/patient ids match legacy ids, and use stabl…
Browse files Browse the repository at this point in the history
…e ids to count samples when internal id is null
  • Loading branch information
onursumer committed Oct 25, 2024
1 parent 2f99479 commit c028f13
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public DensityPlotData getDensityPlotData(List<ClinicalData> sampleClinicalData,
result.setBins(new ArrayList<>());

Map<String, List<ClinicalData>> clinicalDataGroupedBySampleId = sampleClinicalData.stream().
collect(Collectors.groupingBy(ClinicalData::getSampleId));
collect(Collectors.groupingBy(c -> c.getStudyId() + "_" + c.getSampleId()));

List<ClinicalData> extractedXYClinicalData = clinicalDataGroupedBySampleId.entrySet().stream()
.filter(entry -> entry.getValue().size() == 2 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public ClinicalViolinPlotData getClinicalViolinPlotData(
result.setRows(new ArrayList<>());

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

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

@SafeVarargs
private static int countFilteredSamples(
Set<Integer> filteredSampleIds,
Set<String> filteredSampleIds,
List<ClinicalData>... dataLists
) {
return (int) Arrays.stream(dataLists)
.flatMap(Collection::stream)
.map(ClinicalData::getInternalId)
.map(c -> c.getInternalId() == null ?
c.getStudyId() + "_" + c.getSampleId() : c.getInternalId().toString()
)
.filter(filteredSampleIds::contains)
.count();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static List<ClinicalData> convertPatientClinicalDataToSampleClinicalData(
Map<String, Map<String, List<Sample>>> patientToSamples = samplesWithoutNumericalFilter
.stream()
.collect(Collectors.groupingBy(
s -> s.getCancerStudyIdentifier() + "_" + s.getPatientStableId(),
Sample::getPatientStableId,
Collectors.groupingBy(Sample::getCancerStudyIdentifier)
));

Expand All @@ -41,7 +41,7 @@ public static List<ClinicalData> convertPatientClinicalDataToSampleClinicalData(
newData.setPatientId(d.getPatientId());
newData.setStudyId(d.getStudyId());
newData.setAttrValue(d.getAttrValue());
newData.setSampleId(s.getCancerStudyIdentifier() + "_" + s.getStableId());
newData.setSampleId(s.getStableId());

sampleClinicalDataList.add(newData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@

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

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

0 comments on commit c028f13

Please sign in to comment.