Search in sources :

Example 1 with GenomeRegion

use of com.hartwig.hmftools.common.region.GenomeRegion in project hmftools by hartwigmedical.

the class ConsequenceDeterminerTest method worksAsExpected.

@Test
public void worksAsExpected() {
    final SortedSetMultimap<String, GenomeRegion> regionMap = TreeMultimap.create();
    GenomeRegion testRegion = GenomeRegionFactory.create(CHROMOSOME, POSITION - 10, POSITION + 10);
    regionMap.put(testRegion.chromosome(), testRegion);
    final Slicer slicer = SlicerFactory.fromRegions(regionMap);
    final Map<String, HmfGenomeRegion> transcriptMap = Maps.newHashMap();
    transcriptMap.put(TRANSCRIPT, hmfRegion());
    final ConsequenceDeterminer determiner = new ConsequenceDeterminer(slicer, transcriptMap);
    final VariantConsequence rightConsequence = VariantConsequence.MISSENSE_VARIANT;
    final VariantConsequence wrongConsequence = VariantConsequence.OTHER;
    final ImmutableVariantAnnotation.Builder annotationBuilder = createVariantAnnotationBuilder().featureID(TRANSCRIPT).featureType(ConsequenceDeterminer.FEATURE_TYPE_TRANSCRIPT).gene(GENE).hgvsCoding(HGVS_CODING).hgvsProtein(HGVS_PROTEIN);
    final VariantAnnotation rightAnnotation = annotationBuilder.consequences(Lists.newArrayList(rightConsequence)).build();
    final VariantAnnotation wrongAnnotation = annotationBuilder.consequences(Lists.newArrayList(wrongConsequence)).build();
    final ImmutableSomaticVariantImpl.Builder variantBuilder = SomaticVariantTestBuilderFactory.create().chromosome(CHROMOSOME).ref(REF).alt(ALT).cosmicID(COSMIC_ID).totalReadCount(TOTAL_READ_COUNT).alleleReadCount(ALLELE_READ_COUNT);
    final SomaticVariant rightVariant = variantBuilder.position(POSITION).annotations(Lists.newArrayList(rightAnnotation)).build();
    final SomaticVariant wrongConsequenceVariant = variantBuilder.position(POSITION).annotations(Lists.newArrayList(wrongAnnotation)).build();
    final SomaticVariant wrongPositionVariant = variantBuilder.position(WRONG_POSITION).annotations(Lists.newArrayList(rightAnnotation)).build();
    final List<VariantReport> findings = determiner.run(Lists.newArrayList(rightVariant, wrongConsequenceVariant, wrongPositionVariant)).findings();
    assertEquals(1, findings.size());
    final VariantReport report = findings.get(0);
    assertEquals(GENE, report.gene());
    assertEquals(CHROMOSOME + ":" + POSITION, report.variant().chromosomePosition());
    assertEquals(REF, report.variant().ref());
    assertEquals(ALT, report.variant().alt());
    assertEquals(TRANSCRIPT + "." + TRANSCRIPT_VERSION, report.transcript());
    assertEquals(HGVS_CODING, report.hgvsCoding());
    assertEquals(HGVS_PROTEIN, report.hgvsProtein());
    assertEquals(rightConsequence.readableSequenceOntologyTerm(), report.consequence());
    assertEquals(COSMIC_ID, report.cosmicID());
    assertEquals(TOTAL_READ_COUNT, report.totalReadCount());
    assertEquals(ALLELE_READ_COUNT, report.alleleReadCount());
}
Also used : SomaticVariant(com.hartwig.hmftools.common.variant.SomaticVariant) Slicer(com.hartwig.hmftools.common.slicing.Slicer) ImmutableVariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.ImmutableVariantAnnotation) VariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation) VariantConsequence(com.hartwig.hmftools.common.variant.VariantConsequence) HmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion) ImmutableHmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.ImmutableHmfGenomeRegion) GenomeRegion(com.hartwig.hmftools.common.region.GenomeRegion) HmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion) ImmutableHmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.ImmutableHmfGenomeRegion) ImmutableSomaticVariantImpl(com.hartwig.hmftools.common.variant.ImmutableSomaticVariantImpl) ImmutableVariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.ImmutableVariantAnnotation) Test(org.junit.Test)

Example 2 with GenomeRegion

use of com.hartwig.hmftools.common.region.GenomeRegion in project hmftools by hartwigmedical.

the class LineElementAnnotator method loadLineElementsFile.

public void loadLineElementsFile(final String filename) {
    if (filename.isEmpty())
        return;
    try {
        BufferedReader fileReader = new BufferedReader(new FileReader(filename));
        String line;
        while ((line = fileReader.readLine()) != null) {
            if (line.contains("Chromosome"))
                continue;
            // parse CSV data
            String[] items = line.split(",");
            if (items.length < 4)
                continue;
            final GenomeRegion genomeRegion = GenomeRegionFactory.create(items[0], Long.parseLong(items[1]), Long.parseLong(items[2]));
            if (items[3].equals(CSV_LE_TYPE_IDENTIFIED))
                mIdentifiedLineElements.add(genomeRegion);
            else
                mKnownLineElements.add(genomeRegion);
        // LOGGER.debug("loaded line element: chr({}) pos({}-{})",
        // genomeRegion.chromosome(), genomeRegion.start(), genomeRegion.end());
        }
        LOGGER.debug("loaded {} known line elements, {} identified", mKnownLineElements.size(), mIdentifiedLineElements.size());
    } catch (IOException exception) {
        LOGGER.error("Failed to read line element CSV file({})", filename);
    }
}
Also used : GenomeRegion(com.hartwig.hmftools.common.region.GenomeRegion) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException)

Example 3 with GenomeRegion

use of com.hartwig.hmftools.common.region.GenomeRegion in project hmftools by hartwigmedical.

the class LoadSomaticVariants method main.

public static void main(@NotNull final String[] args) throws ParseException, IOException, SQLException {
    final Options options = createBasicOptions();
    final CommandLine cmd = createCommandLine(args, options);
    final String vcfFileLocation = cmd.getOptionValue(VCF_FILE);
    final String highConfidenceBed = cmd.getOptionValue(HIGH_CONFIDENCE_BED);
    final String fastaFileLocation = cmd.getOptionValue(REF_GENOME);
    final String sample = cmd.getOptionValue(SAMPLE);
    final DatabaseAccess dbAccess = databaseAccess(cmd);
    final CompoundFilter filter = new CompoundFilter(true);
    if (cmd.hasOption(PASS_FILTER)) {
        filter.add(new PassingVariantFilter());
    }
    if (cmd.hasOption(SOMATIC_FILTER)) {
        filter.add(new SomaticFilter());
    }
    LOGGER.info("Reading somatic VCF File");
    final List<SomaticVariant> variants = SomaticVariantFactory.filteredInstance(filter).fromVCFFile(sample, vcfFileLocation);
    LOGGER.info("Reading high confidence bed file");
    final Multimap<String, GenomeRegion> highConfidenceRegions = BEDFileLoader.fromBedFile(highConfidenceBed);
    LOGGER.info("Loading indexed fasta reference file");
    IndexedFastaSequenceFile indexedFastaSequenceFile = new IndexedFastaSequenceFile(new File(fastaFileLocation));
    LOGGER.info("Querying purple database");
    final PurityContext purityContext = dbAccess.readPurityContext(sample);
    if (purityContext == null) {
        LOGGER.warn("Unable to retrieve purple data. Enrichment may be incomplete.");
    }
    final PurityAdjuster purityAdjuster = purityContext == null ? new PurityAdjuster(Gender.FEMALE, 1, 1) : new PurityAdjuster(purityContext.gender(), purityContext.bestFit().purity(), purityContext.bestFit().normFactor());
    final Multimap<String, PurpleCopyNumber> copyNumbers = Multimaps.index(dbAccess.readCopynumbers(sample), PurpleCopyNumber::chromosome);
    final Multimap<String, FittedRegion> copyNumberRegions = Multimaps.index(dbAccess.readCopyNumberRegions(sample), FittedRegion::chromosome);
    LOGGER.info("Incorporating purple purity");
    final PurityAdjustedSomaticVariantFactory purityAdjustmentFactory = new PurityAdjustedSomaticVariantFactory(purityAdjuster, copyNumbers, copyNumberRegions);
    final List<PurityAdjustedSomaticVariant> purityAdjustedVariants = purityAdjustmentFactory.create(variants);
    final double clonalPloidy = ClonalityCutoffKernel.clonalCutoff(purityAdjustedVariants);
    LOGGER.info("Enriching variants");
    final EnrichedSomaticVariantFactory enrichedSomaticVariantFactory = new EnrichedSomaticVariantFactory(highConfidenceRegions, indexedFastaSequenceFile, new ClonalityFactory(purityAdjuster, clonalPloidy), CanonicalTranscriptFactory.create(HmfGenePanelSupplier.allGeneList()));
    final List<EnrichedSomaticVariant> enrichedVariants = enrichedSomaticVariantFactory.enrich(purityAdjustedVariants);
    LOGGER.info("Persisting variants to database");
    dbAccess.writeSomaticVariants(sample, enrichedVariants);
    LOGGER.info("Complete");
}
Also used : Options(org.apache.commons.cli.Options) EnrichedSomaticVariant(com.hartwig.hmftools.common.variant.EnrichedSomaticVariant) PassingVariantFilter(htsjdk.variant.variantcontext.filter.PassingVariantFilter) FittedRegion(com.hartwig.hmftools.common.purple.region.FittedRegion) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) DatabaseAccess(com.hartwig.hmftools.patientdb.dao.DatabaseAccess) SomaticFilter(com.hartwig.hmftools.common.variant.filter.SomaticFilter) PurityAdjuster(com.hartwig.hmftools.common.purple.PurityAdjuster) PurityAdjustedSomaticVariant(com.hartwig.hmftools.common.variant.PurityAdjustedSomaticVariant) SomaticVariant(com.hartwig.hmftools.common.variant.SomaticVariant) EnrichedSomaticVariant(com.hartwig.hmftools.common.variant.EnrichedSomaticVariant) PurityAdjustedSomaticVariantFactory(com.hartwig.hmftools.common.variant.PurityAdjustedSomaticVariantFactory) CompoundFilter(htsjdk.variant.variantcontext.filter.CompoundFilter) PurityAdjustedSomaticVariant(com.hartwig.hmftools.common.variant.PurityAdjustedSomaticVariant) CommandLine(org.apache.commons.cli.CommandLine) GenomeRegion(com.hartwig.hmftools.common.region.GenomeRegion) PurityContext(com.hartwig.hmftools.common.purple.purity.PurityContext) EnrichedSomaticVariantFactory(com.hartwig.hmftools.common.variant.EnrichedSomaticVariantFactory) ClonalityFactory(com.hartwig.hmftools.common.variant.ClonalityFactory) File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile)

Example 4 with GenomeRegion

use of com.hartwig.hmftools.common.region.GenomeRegion in project hmftools by hartwigmedical.

the class GCAccumulatorTest method testExcludeFromBothEnds.

@Test
public void testExcludeFromBothEnds() {
    final GenomeRegion region = GenomeRegionFactory.create(CHROMOSOME, 1100, 2999);
    final GCAccumulator victim = new GCAccumulator(region);
    final GenomeRegionSelector<GCProfile> selector = selector(profile(1001, 0.90), profile(2001, 0.91));
    selector.select(region, victim);
    assertEquals(0, victim.averageGCContent(), EPSILON);
}
Also used : GenomeRegion(com.hartwig.hmftools.common.region.GenomeRegion) ImmutableGCProfile(com.hartwig.hmftools.common.gc.ImmutableGCProfile) GCProfile(com.hartwig.hmftools.common.gc.GCProfile) Test(org.junit.Test)

Example 5 with GenomeRegion

use of com.hartwig.hmftools.common.region.GenomeRegion in project hmftools by hartwigmedical.

the class GCAccumulatorTest method testStandard.

@Test
public void testStandard() {
    final GenomeRegion region = GenomeRegionFactory.create(CHROMOSOME, 1001, 10000);
    final GCAccumulator victim = new GCAccumulator(region);
    final GenomeRegionSelector<GCProfile> selector = selector(profile(1001, 0.30), profile(4001, 0.31), profile(9001, 0.35));
    selector.select(region, victim);
    assertEquals(0.32, victim.averageGCContent(), EPSILON);
}
Also used : GenomeRegion(com.hartwig.hmftools.common.region.GenomeRegion) ImmutableGCProfile(com.hartwig.hmftools.common.gc.ImmutableGCProfile) GCProfile(com.hartwig.hmftools.common.gc.GCProfile) Test(org.junit.Test)

Aggregations

GenomeRegion (com.hartwig.hmftools.common.region.GenomeRegion)13 Test (org.junit.Test)6 GCProfile (com.hartwig.hmftools.common.gc.GCProfile)5 ImmutableGCProfile (com.hartwig.hmftools.common.gc.ImmutableGCProfile)5 Slicer (com.hartwig.hmftools.common.slicing.Slicer)2 SomaticVariant (com.hartwig.hmftools.common.variant.SomaticVariant)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 NotNull (org.jetbrains.annotations.NotNull)2 CobaltRatio (com.hartwig.hmftools.common.cobalt.CobaltRatio)1 ImmutablePCFPosition (com.hartwig.hmftools.common.pcf.ImmutablePCFPosition)1 PCFPosition (com.hartwig.hmftools.common.pcf.PCFPosition)1 PurityAdjuster (com.hartwig.hmftools.common.purple.PurityAdjuster)1 PurpleCopyNumber (com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber)1 PurityContext (com.hartwig.hmftools.common.purple.purity.PurityContext)1 FittedRegion (com.hartwig.hmftools.common.purple.region.FittedRegion)1 HmfGenomeRegion (com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion)1 ImmutableHmfGenomeRegion (com.hartwig.hmftools.common.region.hmfslicer.ImmutableHmfGenomeRegion)1 ClonalityFactory (com.hartwig.hmftools.common.variant.ClonalityFactory)1