Search in sources :

Example 11 with StructuralVariant

use of com.hartwig.hmftools.common.variant.structural.StructuralVariant in project hmftools by hartwigmedical.

the class StructuralVariantLegsFactory method create.

@NotNull
static List<StructuralVariantLegs> create(@NotNull final List<StructuralVariant> variants) {
    final List<ModifiableStructuralVariantLegs> result = createLegs(false, variants);
    final Multimap<GenomePosition, ModifiableStructuralVariantLegs> duplicates = findDuplicates(result);
    for (GenomePosition duplicatePosition : duplicates.keySet()) {
        final StructuralVariantLeg approvedLeg = reduce(duplicatePosition, duplicates.get(duplicatePosition));
        boolean match = false;
        for (ModifiableStructuralVariantLegs legs : duplicates.get(duplicatePosition)) {
            Optional<StructuralVariantLeg> start = legs.start();
            if (start.filter(x -> isDuplicate(duplicatePosition, x)).isPresent()) {
                assert start.isPresent();
                if (start.get().equals(approvedLeg)) {
                    match = true;
                } else {
                    legs.setStart(Optional.empty());
                }
            }
            Optional<StructuralVariantLeg> end = legs.end();
            if (end.filter(x -> isDuplicate(duplicatePosition, x)).isPresent()) {
                assert end.isPresent();
                if (end.get().equals(approvedLeg)) {
                    match = true;
                } else {
                    legs.setEnd(Optional.empty());
                }
            }
        }
        if (!match) {
            result.add(ModifiableStructuralVariantLegs.create().setStart(approvedLeg).setEnd(Optional.empty()));
        }
    }
    return new ArrayList<>(result);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap) Collection(java.util.Collection) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) ArrayList(java.util.ArrayList) List(java.util.List) Lists(com.google.common.collect.Lists) GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) Doubles(com.hartwig.hmftools.common.numeric.Doubles) ImmutableStructuralVariantLegImpl(com.hartwig.hmftools.common.variant.structural.ImmutableStructuralVariantLegImpl) Optional(java.util.Optional) StructuralVariantType(com.hartwig.hmftools.common.variant.structural.StructuralVariantType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) GenomePositions(com.hartwig.hmftools.common.position.GenomePositions) StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with StructuralVariant

use of com.hartwig.hmftools.common.variant.structural.StructuralVariant in project hmftools by hartwigmedical.

the class PatientReporter method analyseGenomeData.

@NotNull
private GenomeAnalysis analyseGenomeData(@NotNull final String sample, @NotNull final String runDirectory) throws IOException {
    LOGGER.info(" Loading somatic snv and indels...");
    final List<SomaticVariant> variants = PatientReporterHelper.loadPassedSomaticVariants(sample, runDirectory);
    LOGGER.info("  " + variants.size() + " somatic passed snps, mnps and indels loaded for sample " + sample);
    LOGGER.info(" Analyzing somatic snp/mnp and indels....");
    final VariantAnalysis variantAnalysis = variantAnalyzer().run(variants);
    LOGGER.info(" Loading purity numbers...");
    final PurityContext context = PatientReporterHelper.loadPurity(runDirectory, sample);
    if (context.status().equals(FittedPurityStatus.NO_TUMOR)) {
        LOGGER.warn("PURPLE DID NOT DETECT A TUMOR. Proceed with utmost caution!");
    }
    final FittedPurity purity = context.bestFit();
    final FittedPurityScore purityScore = context.score();
    final List<PurpleCopyNumber> purpleCopyNumbers = PatientReporterHelper.loadPurpleCopyNumbers(runDirectory, sample);
    final List<GeneCopyNumber> panelGeneCopyNumbers = PatientReporterHelper.loadPurpleGeneCopyNumbers(runDirectory, sample).stream().filter(x -> reporterData().panelGeneModel().panel().contains(x.gene())).collect(Collectors.toList());
    LOGGER.info("  " + purpleCopyNumbers.size() + " purple copy number regions loaded for sample " + sample);
    LOGGER.info(" Analyzing purple somatic copy numbers...");
    final PurpleAnalysis purpleAnalysis = ImmutablePurpleAnalysis.builder().gender(context.gender()).status(context.status()).fittedPurity(purity).fittedScorePurity(purityScore).copyNumbers(purpleCopyNumbers).panelGeneCopyNumbers(panelGeneCopyNumbers).build();
    final Path structuralVariantVCF = PatientReporterHelper.findStructuralVariantVCF(runDirectory);
    LOGGER.info(" Loading structural variants...");
    final List<StructuralVariant> structuralVariants = StructuralVariantFileLoader.fromFile(structuralVariantVCF.toString(), true);
    LOGGER.info(" Enriching structural variants with purple data.");
    final List<EnrichedStructuralVariant> enrichedStructuralVariants = purpleAnalysis.enrichStructuralVariants(structuralVariants);
    LOGGER.info(" Analysing structural variants...");
    final StructuralVariantAnalysis structuralVariantAnalysis = structuralVariantAnalyzer().run(enrichedStructuralVariants, false);
    return ImmutableGenomeAnalysis.of(sample, variantAnalysis, purpleAnalysis, structuralVariantAnalysis);
}
Also used : ProductionRunContextFactory(com.hartwig.hmftools.common.context.ProductionRunContextFactory) StructuralVariantAnalyzer(com.hartwig.hmftools.svannotation.analysis.StructuralVariantAnalyzer) ImmutableSampleReport(com.hartwig.hmftools.patientreporter.ImmutableSampleReport) ImmutablePurpleAnalysis(com.hartwig.hmftools.patientreporter.copynumber.ImmutablePurpleAnalysis) HmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion) SampleReport(com.hartwig.hmftools.patientreporter.SampleReport) HmfReporterData(com.hartwig.hmftools.patientreporter.HmfReporterData) AlterationAnalyzer(com.hartwig.hmftools.patientreporter.civic.AlterationAnalyzer) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) GeneFusionData(com.hartwig.hmftools.patientreporter.report.data.GeneFusionData) VariantAnalyzer(com.hartwig.hmftools.patientreporter.variants.VariantAnalyzer) Lims(com.hartwig.hmftools.common.lims.Lims) Value(org.immutables.value.Value) Map(java.util.Map) Alteration(com.hartwig.hmftools.patientreporter.report.data.Alteration) Path(java.nio.file.Path) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) EnrichedStructuralVariant(com.hartwig.hmftools.common.variant.structural.EnrichedStructuralVariant) GeneDisruptionData(com.hartwig.hmftools.patientreporter.report.data.GeneDisruptionData) GeneDisruption(com.hartwig.hmftools.svannotation.annotations.GeneDisruption) SomaticVariant(com.hartwig.hmftools.common.variant.SomaticVariant) VariantReport(com.hartwig.hmftools.patientreporter.variants.VariantReport) ImmutableSequencedPatientReport(com.hartwig.hmftools.patientreporter.ImmutableSequencedPatientReport) PurpleAnalysis(com.hartwig.hmftools.patientreporter.copynumber.PurpleAnalysis) SequencedPatientReport(com.hartwig.hmftools.patientreporter.SequencedPatientReport) FittedPurityScore(com.hartwig.hmftools.common.purple.purity.FittedPurityScore) IOException(java.io.IOException) VariantAnalysis(com.hartwig.hmftools.patientreporter.variants.VariantAnalysis) BaseReporterData(com.hartwig.hmftools.patientreporter.BaseReporterData) Collectors(java.util.stream.Collectors) Transcript(com.hartwig.hmftools.svannotation.annotations.Transcript) RunContext(com.hartwig.hmftools.common.context.RunContext) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) TumorLocationDoidMapping(com.hartwig.hmftools.common.ecrf.doid.TumorLocationDoidMapping) Logger(org.apache.logging.log4j.Logger) PurityContext(com.hartwig.hmftools.common.purple.purity.PurityContext) GeneFusion(com.hartwig.hmftools.svannotation.annotations.GeneFusion) Optional(java.util.Optional) FittedPurity(com.hartwig.hmftools.common.purple.purity.FittedPurity) GeneCopyNumber(com.hartwig.hmftools.common.gene.GeneCopyNumber) StructuralVariantAnalysis(com.hartwig.hmftools.svannotation.analysis.StructuralVariantAnalysis) Comparator(java.util.Comparator) StructuralVariantFileLoader(com.hartwig.hmftools.common.variant.structural.StructuralVariantFileLoader) NotNull(org.jetbrains.annotations.NotNull) LogManager(org.apache.logging.log4j.LogManager) FittedPurityStatus(com.hartwig.hmftools.common.purple.purity.FittedPurityStatus) Path(java.nio.file.Path) SomaticVariant(com.hartwig.hmftools.common.variant.SomaticVariant) EnrichedStructuralVariant(com.hartwig.hmftools.common.variant.structural.EnrichedStructuralVariant) StructuralVariantAnalysis(com.hartwig.hmftools.svannotation.analysis.StructuralVariantAnalysis) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) EnrichedStructuralVariant(com.hartwig.hmftools.common.variant.structural.EnrichedStructuralVariant) GeneCopyNumber(com.hartwig.hmftools.common.gene.GeneCopyNumber) PurityContext(com.hartwig.hmftools.common.purple.purity.PurityContext) 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) FittedPurity(com.hartwig.hmftools.common.purple.purity.FittedPurity) FittedPurityScore(com.hartwig.hmftools.common.purple.purity.FittedPurityScore) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with StructuralVariant

use of com.hartwig.hmftools.common.variant.structural.StructuralVariant in project hmftools by hartwigmedical.

the class SvVCFAnnotator method generateFilteredSVFile.

private void generateFilteredSVFile(final List<StructuralVariant> variants, final String sampleId) {
    try {
        if (mFileWriter == null) {
            String outputFileName = mOutputPath;
            if (!outputFileName.endsWith("/"))
                outputFileName += "/";
            outputFileName += "svs_incl_filtered.csv";
            Path outputFile = Paths.get(outputFileName);
            mFileWriter = Files.newBufferedWriter(outputFile);
            mFileWriter.write("SampleId,SvId,Type,ChrStart,PosStart,OrientStart,ChrEnd,PosEnd,OrientEnd,Filters\n");
        }
        for (final StructuralVariant var : variants) {
            String filtersStr = var.filters();
            if (filtersStr.equals("PASS") || filtersStr.equals("[]") || filtersStr.isEmpty()) {
                LOGGER.debug("var({}) was a PASS", var.id());
                filtersStr = "PASS";
            } else {
                // make tokenisable for further searches
                LOGGER.debug("var({}) has filters: {}", var.id(), var.filters());
                if (filtersStr.charAt(0) == '[')
                    filtersStr = filtersStr.substring(1);
                if (filtersStr.charAt(filtersStr.length() - 1) == ']')
                    filtersStr = filtersStr.substring(0, filtersStr.length() - 1);
                if (!filtersStr.isEmpty())
                    filtersStr = filtersStr.replace(",", ";");
            }
            mFileWriter.write(String.format("%s,%s,%s,%s,%d,%d,%s,%d,%d,%s", sampleId, var.id(), var.type(), var.chromosome(true), var.position(true), var.orientation(true), var.chromosome(false), var.position(false), var.orientation(false), filtersStr));
            mFileWriter.newLine();
        }
    } catch (final IOException e) {
        LOGGER.error("error writing to outputFile");
    }
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant)

Example 14 with StructuralVariant

use of com.hartwig.hmftools.common.variant.structural.StructuralVariant in project hmftools by hartwigmedical.

the class StructuralVariantLegsFactoryTest method testSameVAF.

@Test
public void testSameVAF() {
    final StructuralVariant first = sv(100, 200, StructuralVariantType.INV, 0.25, 0.25);
    final StructuralVariant second = sv(200, 300, StructuralVariantType.BND, 0.25, 0.25);
    final List<StructuralVariant> variants = Lists.newArrayList(first, second);
    final List<StructuralVariantLegs> legs = StructuralVariantLegsFactory.create(variants);
    assertEquals(2, legs.size());
    assertTrue(legs.get(0).start().isPresent());
    assertTrue(legs.get(0).end().isPresent());
    assertTrue(legs.get(1).start().isPresent());
    assertTrue(legs.get(1).end().isPresent());
    assertLeg(1, 0.25, legs.get(0).start().get());
    assertLeg(1, 0.25, legs.get(0).end().get());
    assertLeg(1, 0.25, legs.get(1).start().get());
    assertLeg(1, 0.25, legs.get(1).end().get());
}
Also used : StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) Test(org.junit.Test) PurpleDatamodelTest(com.hartwig.hmftools.common.purple.PurpleDatamodelTest)

Example 15 with StructuralVariant

use of com.hartwig.hmftools.common.variant.structural.StructuralVariant in project hmftools by hartwigmedical.

the class StructuralVariantPositionFactoryTest method excludeInserts.

@Test
public void excludeInserts() {
    final StructuralVariant variant = PurpleDatamodelTest.createStructuralVariant("1", 1001, "1", 1001, StructuralVariantType.INS).build();
    assertEquals(0, ClusterVariantLegFactory.create(Lists.newArrayList(variant)).size());
}
Also used : StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) PurpleDatamodelTest(com.hartwig.hmftools.common.purple.PurpleDatamodelTest) Test(org.junit.Test)

Aggregations

StructuralVariant (com.hartwig.hmftools.common.variant.structural.StructuralVariant)15 PurpleDatamodelTest (com.hartwig.hmftools.common.purple.PurpleDatamodelTest)7 Test (org.junit.Test)7 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 NotNull (org.jetbrains.annotations.NotNull)4 StructuralVariantLeg (com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 EnrichedStructuralVariant (com.hartwig.hmftools.common.variant.structural.EnrichedStructuralVariant)2 Optional (java.util.Optional)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ListMultimap (com.google.common.collect.ListMultimap)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 ProductionRunContextFactory (com.hartwig.hmftools.common.context.ProductionRunContextFactory)1 RunContext (com.hartwig.hmftools.common.context.RunContext)1 CosmicFusionModel (com.hartwig.hmftools.common.cosmic.fusions.CosmicFusionModel)1 TumorLocationDoidMapping (com.hartwig.hmftools.common.ecrf.doid.TumorLocationDoidMapping)1