Skip to content

Commit

Permalink
fetch missing patient clinical data for violin plot
Browse files Browse the repository at this point in the history
  • Loading branch information
onursumer committed Oct 18, 2024
1 parent 38a398d commit a3fdb32
Showing 1 changed file with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@InternalApi
@RestController()
Expand Down Expand Up @@ -354,12 +355,20 @@ public ResponseEntity<ClinicalViolinPlotData> fetchClinicalDataViolinPlots(
.stream()
.filter(clinicalData -> !clinicalData.getAttrValue().isEmpty())
.toList();

List<ClinicalData> patientClinicalDataList = studyViewColumnarService.getPatientClinicalData(interceptedStudyViewFilter, List.of(numericalAttributeId, categoricalAttributeId))
.stream()
.filter(clinicalData -> !clinicalData.getAttrValue().isEmpty())
.toList();

// Only mutation count can use log scale
boolean useLogScale = logScale && numericalAttributeId.equals("MUTATION_COUNT");

ClinicalViolinPlotData result = violinPlotService.getClinicalViolinPlotData(
sampleClinicalDataList,
Stream.concat(
sampleClinicalDataList.stream(),
convertPatientClinicalDataToSampleClinicalData(patientClinicalDataList, filteredSamples).stream()
).toList(),
filteredSamples,
axisStart,
axisEnd,
Expand All @@ -371,6 +380,48 @@ public ResponseEntity<ClinicalViolinPlotData> fetchClinicalDataViolinPlots(
return new ResponseEntity<>(result, HttpStatus.OK);
}

// TODO move this to a utility class?
private 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;
}

@Hidden
@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
@PostMapping(value = "/column-store/genomic-data-counts/fetch", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down

0 comments on commit a3fdb32

Please sign in to comment.