use of com.hartwig.hmftools.patientdb.data.SampleData in project hmftools by hartwigmedical.
the class BiopsyMatcher method matchBiopsiesToTumorSamples.
@NotNull
public static MatchResult<BiopsyData> matchBiopsiesToTumorSamples(@NotNull final String patientId, @NotNull final List<SampleData> sequencedBiopsies, @NotNull final List<BiopsyData> clinicalBiopsies) {
final List<BiopsyData> matchedBiopsies = Lists.newArrayList();
final List<ValidationFinding> findings = Lists.newArrayList();
if (clinicalBiopsies.size() < sequencedBiopsies.size()) {
findings.add(biopsyMatchFinding(patientId, "less ecrf biopsies than biopsies sequenced.", "ecrf biopsies: " + clinicalBiopsies.size() + "; sequenced: " + sequencedBiopsies.size()));
}
List<BiopsyData> remainingBiopsies = clinicalBiopsies;
for (final SampleData sequencedBiopsy : sequencedBiopsies) {
final Map<Boolean, List<BiopsyData>> partitions = remainingBiopsies.stream().collect(Collectors.partitioningBy(clinicalBiopsy -> isPossibleMatch(sequencedBiopsy, clinicalBiopsy)));
final List<BiopsyData> possibleMatches = partitions.get(true);
if (possibleMatches.size() == 1 && possibleMatches.get(0).date() != null) {
final BiopsyData clinicalBiopsy = possibleMatches.get(0);
matchedBiopsies.add(ImmutableBiopsyData.builder().from(clinicalBiopsy).sampleId(sequencedBiopsy.sampleId()).build());
if (hasMismatchOnSamplingDate(sequencedBiopsy, clinicalBiopsy)) {
findings.add(biopsyMatchFinding(patientId, "sampling date does not equal biopsy date in matched biopsy", "sampling date: " + sequencedBiopsy.samplingDate() + "; ecrf biopsy date: " + clinicalBiopsy.date()));
}
remainingBiopsies = partitions.get(false);
} else if (possibleMatches.size() == 0 || (possibleMatches.size() == 1 && possibleMatches.get(0).date() == null)) {
findings.add(biopsyMatchFinding(patientId, "could not match any clinical biopsy with sequenced sample.", "sample: " + sampleDataToString(sequencedBiopsy) + "; ecrf biopsies: " + clinicalBiopsies.stream().map(BiopsyData::date).collect(Collectors.toList()) + ". match criteria: " + getMatchDateCriteria(sequencedBiopsy)));
// MIVO: abort finding new matches if we can't match one sequenced biopsy
return new MatchResult<>(clinicalBiopsies, findings);
} else if (possibleMatches.size() > 1) {
findings.add(biopsyMatchFinding(patientId, "more than 1 possible clinical biopsy match for sequenced sample.", "sample: " + sampleDataToString(sequencedBiopsy) + "; ecrf biopsies: " + clinicalBiopsies.stream().map(BiopsyData::date).collect(Collectors.toList()) + ". match criteria: " + getMatchDateCriteria(sequencedBiopsy)));
// MIVO: abort finding new matches if we can't match one sequenced biopsy
return new MatchResult<>(clinicalBiopsies, findings);
}
}
matchedBiopsies.addAll(remainingBiopsies);
return new MatchResult<>(matchedBiopsies, findings);
}
use of com.hartwig.hmftools.patientdb.data.SampleData in project hmftools by hartwigmedical.
the class LimsSampleReader method read.
@NotNull
public List<SampleData> read(@NotNull final List<String> sampleIds) {
final List<SampleData> limsBiopsies = Lists.newArrayList();
sampleIds.forEach(sampleId -> {
final LocalDate arrivalDate = lims.arrivalDateForSample(sampleId);
if (arrivalDate != null) {
limsBiopsies.add(ImmutableSampleData.of(sampleId, arrivalDate, lims.samplingDateForSample(sampleId), lims.dnaNanogramsForSample(sampleId), lims.tumorPercentageForSample(sampleId)));
}
});
return limsBiopsies;
}
use of com.hartwig.hmftools.patientdb.data.SampleData in project hmftools by hartwigmedical.
the class LoadClinicalData method readEcrfPatients.
@NotNull
private static Map<String, Patient> readEcrfPatients(@NotNull final PatientReader reader, @NotNull final Iterable<EcrfPatient> patients, @NotNull final Map<String, List<SampleData>> samplesPerPatient) throws IOException {
final Map<String, Patient> patientMap = Maps.newHashMap();
for (final EcrfPatient ecrfPatient : patients) {
List<SampleData> samples = samplesPerPatient.get(ecrfPatient.patientId());
if (samples != null && samples.size() > 0) {
final Patient patient = reader.read(ecrfPatient, samples);
patientMap.put(patient.patientIdentifier(), patient);
}
}
return patientMap;
}
use of com.hartwig.hmftools.patientdb.data.SampleData in project hmftools by hartwigmedical.
the class LoadClinicalData method readSamplesPerPatient.
@NotNull
private static Map<String, List<SampleData>> readSamplesPerPatient(@NotNull Lims lims, @NotNull List<RunContext> runContexts) {
LimsSampleReader sampleReader = new LimsSampleReader(lims);
final Set<String> sequencedPatientIdentifiers = Utils.sequencedPatientIds(runContexts).stream().filter(identifier -> identifier.startsWith("CPCT") || identifier.startsWith("DRUP")).collect(Collectors.toSet());
Map<String, List<SampleData>> samplesPerPatient = Maps.newHashMap();
for (String patientIdentifier : sequencedPatientIdentifiers) {
List<String> sampleIds = getTumorSamplesForPatient(patientIdentifier, runContexts);
samplesPerPatient.put(patientIdentifier, sampleReader.read(sampleIds));
}
return samplesPerPatient;
}
Aggregations