use of com.hartwig.hmftools.common.lims.Lims in project hmftools by hartwigmedical.
the class PatientReporter method run.
@NotNull
public SequencedPatientReport run(@NotNull final String runDirectory, @Nullable final String comments) throws IOException {
final RunContext run = ProductionRunContextFactory.fromRunDirectory(runDirectory);
final GenomeAnalysis genomeAnalysis = analyseGenomeData(run.tumorSample(), runDirectory);
assert run.isSomaticRun() && run.tumorSample().equals(genomeAnalysis.sample());
final String tumorSample = genomeAnalysis.sample();
final VariantAnalysis variantAnalysis = genomeAnalysis.variantAnalysis();
final PurpleAnalysis purpleAnalysis = genomeAnalysis.purpleAnalysis();
final StructuralVariantAnalysis structuralVariantAnalysis = genomeAnalysis.structuralVariantAnalysis();
final List<GeneFusionData> reportableFusions = structuralVariantAnalysis.reportableFusions().stream().sorted(fusionComparator()).map(GeneFusionData::from).collect(Collectors.toList());
final List<GeneDisruptionData> reportableDisruptions = structuralVariantAnalysis.reportableDisruptions().stream().sorted(disruptionComparator(reporterData().panelGeneModel().transcriptMap())).map(GeneDisruptionData::from).collect(Collectors.toList());
final int passedVariantCount = variantAnalysis.passedVariants().size();
final int mutationalLoad = variantAnalysis.mutationalLoad();
final int consequentialVariantCount = variantAnalysis.consequentialVariants().size();
final int structuralVariantCount = structuralVariantAnalysis.annotations().size();
final String cancerType = PatientReporterHelper.extractCancerType(baseReporterData().patientsCancerTypes(), tumorSample);
final TumorLocationDoidMapping doidMapping = TumorLocationDoidMapping.fromResource("/tumor_location_doid_mapping.csv");
final List<Alteration> alterations = civicAnalyzer().run(variantAnalysis.findings(), purpleAnalysis.reportableGeneCopyNumbers(), reportableDisruptions, reportableFusions, reporterData().panelGeneModel(), doidMapping.doidsForTumorType(cancerType));
LOGGER.info(" Printing analysis results:");
LOGGER.info(" Number of passed variants : " + Integer.toString(passedVariantCount));
LOGGER.info(" Number of missense variants (mutational load) : " + Integer.toString(mutationalLoad));
LOGGER.info(" Number of consequential variants to report : " + Integer.toString(consequentialVariantCount));
LOGGER.info(" Determined copy number stats for " + Integer.toString(purpleAnalysis.genePanelSize()) + " genes which led to " + Integer.toString(purpleAnalysis.reportableGeneCopyNumbers().size()) + " copy numbers.");
LOGGER.info(" Number of unreported structural variants : " + Integer.toString(structuralVariantCount));
LOGGER.info(" Number of gene fusions to report : " + Integer.toString(reportableFusions.size()));
LOGGER.info(" Number of gene disruptions to report : " + Integer.toString(reportableDisruptions.size()));
LOGGER.info(" Number of CIViC alterations to report : " + alterations.size());
LOGGER.info(" Microsatellite analysis results: " + variantAnalysis.indelsPerMb() + " indels per MB");
final Lims lims = baseReporterData().limsModel();
final Double tumorPercentage = lims.tumorPercentageForSample(tumorSample);
final List<VariantReport> purpleEnrichedVariants = purpleAnalysis.enrichSomaticVariants(variantAnalysis.findings());
final String sampleRecipient = baseReporterData().centerModel().getAddresseeStringForSample(tumorSample);
final SampleReport sampleReport = ImmutableSampleReport.of(tumorSample, cancerType, tumorPercentage, lims.arrivalDateForSample(tumorSample), lims.arrivalDateForSample(run.refSample()), lims.labProceduresForSample(tumorSample), sampleRecipient);
return ImmutableSequencedPatientReport.of(sampleReport, purpleEnrichedVariants, mutationalLoad, variantAnalysis.indelsPerMb(), purpleAnalysis.reportableGeneCopyNumbers(), reportableDisruptions, reportableFusions, purpleAnalysis.purityString(), alterations, PatientReporterHelper.findCircosPlotPath(runDirectory, tumorSample), Optional.ofNullable(comments), baseReporterData().signaturePath());
}
use of com.hartwig.hmftools.common.lims.Lims in project hmftools by hartwigmedical.
the class PatientReporterApplication method buildBaseReporterData.
@NotNull
private static BaseReporterData buildBaseReporterData(@NotNull final CommandLine cmd) throws IOException {
LOGGER.info(" Loading ECRF CSV dump...");
final List<PatientCancerTypes> patientsCancerTypes = PatientCancerTypes.readRecords(cmd.getOptionValue(CANCER_TYPES_CSV));
LOGGER.info(" Loaded data for {} patients.", patientsCancerTypes.size());
LOGGER.info(" Loading LIMS database...");
final Lims lims = LimsFactory.fromLimsJson(cmd.getOptionValue(LIMS_JSON));
LOGGER.info(" Loaded data for {} samples.", lims.sampleCount());
final CenterModel centerModel = Center.readFromCSV(cmd.getOptionValue(CENTER_CSV));
return ImmutableBaseReporterData.of(patientsCancerTypes, lims, centerModel, cmd.getOptionValue(SIGNATURE));
}
use of com.hartwig.hmftools.common.lims.Lims in project hmftools by hartwigmedical.
the class PatientReporterTestUtil method testBaseReporterData.
@NotNull
public static BaseReporterData testBaseReporterData() throws IOException {
final String centerPath = Resources.getResource("center").getPath() + File.separator + "centers.csv";
final List<PatientCancerTypes> patientsCancerTypes = Lists.newArrayList();
final Lims lims = LimsFactory.empty();
final CenterModel centerModel = Center.readFromCSV(centerPath);
return ImmutableBaseReporterData.of(patientsCancerTypes, lims, centerModel, SIGNATURE_PATH);
}
use of com.hartwig.hmftools.common.lims.Lims in project hmftools by hartwigmedical.
the class NotSequenceableReporter method run.
public NotSequencedPatientReport run(@NotNull final String sample, @NotNull final NotSequenceableReason reason, @Nullable final String comments) {
final NotSequenceableStudy study = NotSequenceableStudy.fromSample(sample);
assert study != null;
final String cancerType = PatientReporterHelper.extractCancerType(baseReporterData().patientsCancerTypes(), sample);
final Lims lims = baseReporterData().limsModel();
final Double tumorPercentage = lims.tumorPercentageForSample(sample);
final String sampleRecipient = baseReporterData().centerModel().getAddresseeStringForSample(sample);
final SampleReport sampleReport = ImmutableSampleReport.of(sample, cancerType, tumorPercentage, lims.arrivalDateForSample(sample), null, lims.labProceduresForSample(sample), sampleRecipient);
return ImmutableNotSequencedPatientReport.of(sampleReport, reason, study, Optional.ofNullable(comments), baseReporterData().signaturePath());
}
use of com.hartwig.hmftools.common.lims.Lims 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