Search in sources :

Example 1 with SampleData

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);
}
Also used : Config(com.hartwig.hmftools.patientdb.Config) FORM_BIOPS(com.hartwig.hmftools.patientdb.readers.BiopsyReader.FORM_BIOPS) BiopsyData(com.hartwig.hmftools.patientdb.data.BiopsyData) Collectors(java.util.stream.Collectors) ImmutableBiopsyData(com.hartwig.hmftools.patientdb.data.ImmutableBiopsyData) ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) FormStatusState(com.hartwig.hmftools.common.ecrf.formstatus.FormStatusState) List(java.util.List) Lists(com.google.common.collect.Lists) Duration(java.time.Duration) LocalDate(java.time.LocalDate) Map(java.util.Map) SampleData(com.hartwig.hmftools.patientdb.data.SampleData) NotNull(org.jetbrains.annotations.NotNull) SampleData(com.hartwig.hmftools.patientdb.data.SampleData) ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) List(java.util.List) BiopsyData(com.hartwig.hmftools.patientdb.data.BiopsyData) ImmutableBiopsyData(com.hartwig.hmftools.patientdb.data.ImmutableBiopsyData) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with SampleData

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;
}
Also used : ImmutableSampleData(com.hartwig.hmftools.patientdb.data.ImmutableSampleData) SampleData(com.hartwig.hmftools.patientdb.data.SampleData) LocalDate(java.time.LocalDate) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with SampleData

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;
}
Also used : SampleData(com.hartwig.hmftools.patientdb.data.SampleData) EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) Patient(com.hartwig.hmftools.patientdb.data.Patient) EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with SampleData

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;
}
Also used : FormStatusModel(com.hartwig.hmftools.common.ecrf.formstatus.FormStatusModel) FormStatusReader(com.hartwig.hmftools.common.ecrf.formstatus.FormStatusReader) Options(org.apache.commons.cli.Options) EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) HelpFormatter(org.apache.commons.cli.HelpFormatter) DefaultParser(org.apache.commons.cli.DefaultParser) SQLException(java.sql.SQLException) Lims(com.hartwig.hmftools.common.lims.Lims) Lists(com.google.common.collect.Lists) CurationValidator(com.hartwig.hmftools.patientdb.validators.CurationValidator) PatientReader(com.hartwig.hmftools.patientdb.readers.PatientReader) Map(java.util.Map) XMLStreamException(javax.xml.stream.XMLStreamException) LimsSampleReader(com.hartwig.hmftools.patientdb.readers.LimsSampleReader) RunsFolderReader(com.hartwig.hmftools.patientdb.readers.RunsFolderReader) CommandLine(org.apache.commons.cli.CommandLine) SampleData(com.hartwig.hmftools.patientdb.data.SampleData) TreatmentCurator(com.hartwig.hmftools.patientdb.curators.TreatmentCurator) CommandLineParser(org.apache.commons.cli.CommandLineParser) Patient(com.hartwig.hmftools.patientdb.data.Patient) Set(java.util.Set) IOException(java.io.IOException) LimsFactory(com.hartwig.hmftools.common.lims.LimsFactory) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) File(java.io.File) RunContext(com.hartwig.hmftools.common.context.RunContext) DatabaseAccess(com.hartwig.hmftools.patientdb.dao.DatabaseAccess) ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) PatientValidator(com.hartwig.hmftools.patientdb.validators.PatientValidator) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ParseException(org.apache.commons.cli.ParseException) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) LogManager(org.apache.logging.log4j.LogManager) TumorLocationCurator(com.hartwig.hmftools.patientdb.curators.TumorLocationCurator) CpctEcrfModel(com.hartwig.hmftools.common.ecrf.CpctEcrfModel) List(java.util.List) LimsSampleReader(com.hartwig.hmftools.patientdb.readers.LimsSampleReader) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SampleData (com.hartwig.hmftools.patientdb.data.SampleData)4 NotNull (org.jetbrains.annotations.NotNull)4 Lists (com.google.common.collect.Lists)2 EcrfPatient (com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient)2 ValidationFinding (com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding)2 Patient (com.hartwig.hmftools.patientdb.data.Patient)2 LocalDate (java.time.LocalDate)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Maps (com.google.common.collect.Maps)1 RunContext (com.hartwig.hmftools.common.context.RunContext)1 CpctEcrfModel (com.hartwig.hmftools.common.ecrf.CpctEcrfModel)1 FormStatusModel (com.hartwig.hmftools.common.ecrf.formstatus.FormStatusModel)1 FormStatusReader (com.hartwig.hmftools.common.ecrf.formstatus.FormStatusReader)1 FormStatusState (com.hartwig.hmftools.common.ecrf.formstatus.FormStatusState)1 Lims (com.hartwig.hmftools.common.lims.Lims)1 LimsFactory (com.hartwig.hmftools.common.lims.LimsFactory)1 Config (com.hartwig.hmftools.patientdb.Config)1 TreatmentCurator (com.hartwig.hmftools.patientdb.curators.TreatmentCurator)1