use of com.hartwig.hmftools.patientdb.data.Patient in project hmftools by hartwigmedical.
the class PatientReader method read.
@NotNull
public Patient read(@NotNull final EcrfPatient ecrfPatient, @NotNull final List<SampleData> sequencedSamples) throws IOException {
LOGGER.info("Reading patient " + ecrfPatient.patientId() + " with samples: " + sequencedSamples);
final BaselineData baselineData = cpctPatientReader.read(ecrfPatient);
final PreTreatmentData preTreatmentData = preTreatmentReader.read(ecrfPatient);
final List<BiopsyData> clinicalBiopsies = BiopsyReader.read(ecrfPatient);
final List<BiopsyTreatmentData> treatments = biopsyTreatmentReader.read(ecrfPatient);
final List<BiopsyTreatmentResponseData> treatmentResponses = BiopsyTreatmentResponseReader.read(ecrfPatient);
final List<TumorMarkerData> tumorMarkers = TumorMarkerReader.read(ecrfPatient);
final MatchResult<BiopsyData> matchedBiopsies = BiopsyMatcher.matchBiopsiesToTumorSamples(ecrfPatient.patientId(), sequencedSamples, clinicalBiopsies);
final MatchResult<BiopsyTreatmentData> matchedTreatments = TreatmentMatcher.matchTreatmentsToBiopsies(ecrfPatient.patientId(), clinicalBiopsies, treatments);
final MatchResult<BiopsyTreatmentResponseData> matchedResponses = TreatmentResponseMatcher.matchTreatmentResponsesToTreatments(ecrfPatient.patientId(), treatments, treatmentResponses);
final List<ValidationFinding> findings = Lists.newArrayList();
findings.addAll(matchedBiopsies.findings());
findings.addAll(matchedTreatments.findings());
findings.addAll(matchedResponses.findings());
return new Patient(ecrfPatient.patientId(), baselineData, preTreatmentData, sequencedSamples, matchedBiopsies.values(), matchedTreatments.values(), matchedResponses.values(), tumorMarkers, findings);
}
use of com.hartwig.hmftools.patientdb.data.Patient 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.Patient in project hmftools by hartwigmedical.
the class LoadClinicalData method writeClinicalData.
private static void writeClinicalData(@NotNull final Options clinicalOptions, @NotNull final CommandLine cmd, @NotNull final List<RunContext> runContexts, @NotNull final DatabaseAccess dbAccess) throws IOException, XMLStreamException {
final String ecrfFilePath = cmd.getOptionValue(ECRF_FILE);
final String limsJson = cmd.getOptionValue(LIMS_JSON);
final String preLIMSArrivalDatesCsv = cmd.getOptionValue(PRE_LIMS_ARRIVAL_DATES_CSV);
final String formStatusCsv = cmd.getOptionValue(FORM_STATUS_CSV);
final String csvOutputDir = cmd.getOptionValue(CSV_OUT_DIR);
final Optional<String> cancerTypesLink = Optional.ofNullable(cmd.getOptionValue(CANCER_TYPES_LINK));
final Optional<String> portalDataLink = Optional.ofNullable(cmd.getOptionValue(PORTAL_DATA_LINK));
if (Utils.anyNull(ecrfFilePath, limsJson, preLIMSArrivalDatesCsv, formStatusCsv, csvOutputDir)) {
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("patient-db", clinicalOptions);
} else {
LOGGER.info("Clearing database...");
dbAccess.clearClinicalTables();
LOGGER.info("Cleared database, loading samples from LIMS...");
Lims lims = LimsFactory.fromLimsJsonWithPreLIMSArrivalDates(limsJson, preLIMSArrivalDatesCsv);
Map<String, List<SampleData>> samplesPerPatient = readSamplesPerPatient(lims, runContexts);
LOGGER.info("Loaded samples for {} patients from LIMS, loading ecrf...", samplesPerPatient.size());
FormStatusModel formStatusModel = FormStatusReader.buildModelFromCsv(formStatusCsv);
CpctEcrfModel ecrfModel = CpctEcrfModel.loadFromXML(ecrfFilePath, formStatusModel);
TreatmentCurator treatmentCurator = TreatmentCurator.fromProductionResource();
TumorLocationCurator tumorLocationCurator = TumorLocationCurator.fromProductionResource();
PatientReader patientReader = new PatientReader(ecrfModel, treatmentCurator, tumorLocationCurator);
final Map<String, Patient> readPatients = readEcrfPatients(patientReader, ecrfModel.patients(), samplesPerPatient);
LOGGER.info("Loaded {} patients from ecrf", readPatients.size());
DumpClinicalData.writeClinicalDumps(csvOutputDir, readPatients.values(), cancerTypesLink, portalDataLink);
LOGGER.info("Writing clinical data for {} sequenced patients.", readPatients.size());
for (final String patientIdentifier : samplesPerPatient.keySet()) {
final Patient patient = readPatients.get(patientIdentifier);
if (patient == null) {
if (patientIdentifier.startsWith("CPCT")) {
LOGGER.error("Could not find patient with id: " + patientIdentifier + " in ecrf file.");
}
dbAccess.writeSampleClinicalData(patientIdentifier, samplesPerPatient.get(patientIdentifier));
} else {
dbAccess.writeFullClinicalData(patient);
final List<ValidationFinding> findings = PatientValidator.validatePatient(patient);
dbAccess.writeValidationFindings(findings);
dbAccess.writeValidationFindings(patient.matchFindings());
}
}
dbAccess.writeValidationFindings(CurationValidator.validateTreatmentCurator(treatmentCurator));
dbAccess.writeValidationFindings(CurationValidator.validateTumorLocationCurator(tumorLocationCurator));
LOGGER.info("Done!");
}
}
Aggregations