-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fetch missing patient clinical data for violin plot
- Loading branch information
Showing
2 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/org/cbioportal/web/columnar/util/ClinicalDataViolinPlotUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.cbioportal.web.columnar.util; | ||
|
||
import org.cbioportal.model.ClinicalData; | ||
import org.cbioportal.model.Sample; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class ClinicalDataViolinPlotUtil { | ||
public static List<ClinicalData> filterNonEmptyClinicalData(List<ClinicalData> clinicalData) { | ||
return clinicalData | ||
.stream() | ||
.filter(data -> !data.getAttrValue().isEmpty()) | ||
.toList(); | ||
} | ||
|
||
public static List<ClinicalData> convertPatientClinicalDataToSampleClinicalData( | ||
List<ClinicalData> patientClinicalDataList, | ||
List<Sample> filteredSamples | ||
) { | ||
List<ClinicalData> sampleClinicalDataList = new ArrayList<>(); | ||
|
||
Map<String, Map<String, List<Sample>>> patientToSamples = filteredSamples | ||
.stream() | ||
.collect(Collectors.groupingBy( | ||
s -> s.getCancerStudyIdentifier() + "_" + s.getPatientStableId(), | ||
Collectors.groupingBy(Sample::getCancerStudyIdentifier) | ||
)); | ||
|
||
// put all clinical data into sample form | ||
for (ClinicalData d: patientClinicalDataList) { | ||
List<Sample> samplesForPatient = patientToSamples.get(d.getPatientId()).get(d.getStudyId()); | ||
if (samplesForPatient != null) { | ||
for (Sample s: samplesForPatient) { | ||
ClinicalData newData = new ClinicalData(); | ||
|
||
newData.setInternalId(s.getInternalId()); | ||
newData.setAttrId(d.getAttrId()); | ||
newData.setPatientId(d.getPatientId()); | ||
newData.setStudyId(d.getStudyId()); | ||
newData.setAttrValue(d.getAttrValue()); | ||
newData.setSampleId(s.getCancerStudyIdentifier() + "_" + s.getStableId()); | ||
|
||
sampleClinicalDataList.add(newData); | ||
} | ||
} else { | ||
// TODO ignoring for now rather than throwing an error | ||
// patient has no samples - this shouldn't happen and could affect the integrity | ||
// of the data analysis | ||
// return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
return sampleClinicalDataList; | ||
} | ||
} |