Search in sources :

Example 1 with Lims

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());
}
Also used : ImmutableSampleReport(com.hartwig.hmftools.patientreporter.ImmutableSampleReport) SampleReport(com.hartwig.hmftools.patientreporter.SampleReport) StructuralVariantAnalysis(com.hartwig.hmftools.svannotation.analysis.StructuralVariantAnalysis) GeneDisruptionData(com.hartwig.hmftools.patientreporter.report.data.GeneDisruptionData) Lims(com.hartwig.hmftools.common.lims.Lims) VariantReport(com.hartwig.hmftools.patientreporter.variants.VariantReport) Alteration(com.hartwig.hmftools.patientreporter.report.data.Alteration) GeneFusionData(com.hartwig.hmftools.patientreporter.report.data.GeneFusionData) ImmutablePurpleAnalysis(com.hartwig.hmftools.patientreporter.copynumber.ImmutablePurpleAnalysis) PurpleAnalysis(com.hartwig.hmftools.patientreporter.copynumber.PurpleAnalysis) VariantAnalysis(com.hartwig.hmftools.patientreporter.variants.VariantAnalysis) StructuralVariantAnalysis(com.hartwig.hmftools.svannotation.analysis.StructuralVariantAnalysis) RunContext(com.hartwig.hmftools.common.context.RunContext) TumorLocationDoidMapping(com.hartwig.hmftools.common.ecrf.doid.TumorLocationDoidMapping) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Lims

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));
}
Also used : Lims(com.hartwig.hmftools.common.lims.Lims) CenterModel(com.hartwig.hmftools.common.center.CenterModel) PatientCancerTypes(com.hartwig.hmftools.common.ecrf.projections.PatientCancerTypes) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Lims

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);
}
Also used : Lims(com.hartwig.hmftools.common.lims.Lims) CenterModel(com.hartwig.hmftools.common.center.CenterModel) PatientCancerTypes(com.hartwig.hmftools.common.ecrf.projections.PatientCancerTypes) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Lims

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());
}
Also used : ImmutableSampleReport(com.hartwig.hmftools.patientreporter.ImmutableSampleReport) SampleReport(com.hartwig.hmftools.patientreporter.SampleReport) Lims(com.hartwig.hmftools.common.lims.Lims)

Example 5 with Lims

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!");
    }
}
Also used : FormStatusModel(com.hartwig.hmftools.common.ecrf.formstatus.FormStatusModel) TreatmentCurator(com.hartwig.hmftools.patientdb.curators.TreatmentCurator) Lims(com.hartwig.hmftools.common.lims.Lims) PatientReader(com.hartwig.hmftools.patientdb.readers.PatientReader) EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) Patient(com.hartwig.hmftools.patientdb.data.Patient) HelpFormatter(org.apache.commons.cli.HelpFormatter) TumorLocationCurator(com.hartwig.hmftools.patientdb.curators.TumorLocationCurator) ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) List(java.util.List) CpctEcrfModel(com.hartwig.hmftools.common.ecrf.CpctEcrfModel)

Aggregations

Lims (com.hartwig.hmftools.common.lims.Lims)6 NotNull (org.jetbrains.annotations.NotNull)4 CenterModel (com.hartwig.hmftools.common.center.CenterModel)2 RunContext (com.hartwig.hmftools.common.context.RunContext)2 CpctEcrfModel (com.hartwig.hmftools.common.ecrf.CpctEcrfModel)2 EcrfPatient (com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient)2 ValidationFinding (com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding)2 FormStatusModel (com.hartwig.hmftools.common.ecrf.formstatus.FormStatusModel)2 PatientCancerTypes (com.hartwig.hmftools.common.ecrf.projections.PatientCancerTypes)2 TreatmentCurator (com.hartwig.hmftools.patientdb.curators.TreatmentCurator)2 TumorLocationCurator (com.hartwig.hmftools.patientdb.curators.TumorLocationCurator)2 Patient (com.hartwig.hmftools.patientdb.data.Patient)2 PatientReader (com.hartwig.hmftools.patientdb.readers.PatientReader)2 ImmutableSampleReport (com.hartwig.hmftools.patientreporter.ImmutableSampleReport)2 SampleReport (com.hartwig.hmftools.patientreporter.SampleReport)2 List (java.util.List)2 HelpFormatter (org.apache.commons.cli.HelpFormatter)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 TumorLocationDoidMapping (com.hartwig.hmftools.common.ecrf.doid.TumorLocationDoidMapping)1