Search in sources :

Example 6 with SampleList

use of org.broadinstitute.hellbender.utils.genotyper.SampleList in project gatk-protected by broadinstitute.

the class OrientationBiasFilterer method createVCFHeader.

/** Ingest the current VCF header and update it with the information necessary for the Orientation Bias filter to run.
     *
     * @param inputVCFHeader original header.  Never {@code null}
     * @param commandLine The command line used to run this tool.
     * @param transitions  Never {@code null}
     * @return updated VCF Header
     */
public static VCFHeader createVCFHeader(final VCFHeader inputVCFHeader, final String commandLine, final List<String> transitions) {
    Utils.nonNull(inputVCFHeader);
    Utils.nonNull(transitions);
    // Setup header for output file
    final Set<VCFHeaderLine> headerLines = new LinkedHashSet<>(inputVCFHeader.getMetaDataInInputOrder());
    headerLines.add(new VCFFormatHeaderLine(OrientationBiasFilterConstants.PRE_ADAPTER_METRIC_FIELD_NAME, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Measure (across entire bam file) of orientation bias for a given REF/ALT error."));
    headerLines.add(new VCFFormatHeaderLine(OrientationBiasFilterConstants.PRE_ADAPTER_METRIC_RC_FIELD_NAME, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Measure (across entire bam file) of orientation bias for the complement of a given REF/ALT error."));
    headerLines.add(new VCFFormatHeaderLine(OrientationBiasFilterConstants.P_ARTIFACT_FIELD_NAME, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Orientation bias p value for the given REF/ALT artifact or its complement."));
    headerLines.add(new VCFFormatHeaderLine(OrientationBiasFilterConstants.FOB, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Fraction of alt reads indicating orientation bias error (taking into account artifact mode complement)."));
    headerLines.add(new VCFFormatHeaderLine(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_ARTIFACT_MODE, VCFHeaderLineCount.A, VCFHeaderLineType.String, "Whether the variant can be one of the given REF/ALT artifact modes."));
    headerLines.add(new VCFFormatHeaderLine(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_RC_ARTIFACT_MODE, VCFHeaderLineCount.A, VCFHeaderLineType.String, "Whether the variant can be one of the given REF/ALT artifact mode complements."));
    headerLines.add(new VCFFormatHeaderLine(VCFConstants.GENOTYPE_FILTER_KEY, 1, VCFHeaderLineType.String, "Genotype-level filter"));
    headerLines.add(new VCFFilterHeaderLine(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_CUT, "Orientation bias (in one of the specified artifact mode(s) or complement) seen in one or more samples."));
    headerLines.add(new VCFSimpleHeaderLine("orientation_bias_artifact_modes", String.join("|", transitions), "The artifact modes that were used for orientation bias artifact filtering for this VCF"));
    headerLines.add(new VCFHeaderLine("command", commandLine));
    final SampleList samples = new IndexedSampleList(inputVCFHeader.getGenotypeSamples());
    final Set<String> sampleNameSet = samples.asSetOfSamples();
    return new VCFHeader(headerLines, sampleNameSet);
}
Also used : IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList)

Example 7 with SampleList

use of org.broadinstitute.hellbender.utils.genotyper.SampleList in project gatk-protected by broadinstitute.

the class RandomLikelihoodCalculationEngineUnitTest method testComputeLikelihoods.

@Test
public void testComputeLikelihoods() {
    final ReadLikelihoodCalculationEngine lce = new RandomLikelihoodCalculationEngine();
    final Map<String, List<GATKRead>> perSampleReadList = new HashMap<>();
    final int n = 10;
    final GATKRead read1 = ArtificialReadUtils.createArtificialRead(TextCigarCodec.decode(n + "M"));
    read1.setMappingQuality(60);
    final String sample1 = "sample1";
    perSampleReadList.put(sample1, Arrays.asList(read1));
    final SampleList samples = new IndexedSampleList(sample1);
    final AssemblyResultSet assemblyResultSet = new AssemblyResultSet();
    final byte[] bases = Strings.repeat("A", n + 1).getBytes();
    final Haplotype hap1 = new Haplotype(bases, true);
    hap1.setGenomeLocation(read1);
    assemblyResultSet.add(hap1);
    final byte[] basesModified = bases;
    //different bases
    basesModified[5] = 'C';
    final Haplotype hap2 = new Haplotype(basesModified, false);
    //use same loc
    hap2.setGenomeLocation(read1);
    assemblyResultSet.add(hap2);
    final ReadLikelihoods<Haplotype> likes = lce.computeReadLikelihoods(assemblyResultSet, samples, perSampleReadList);
    final LikelihoodMatrix<Haplotype> mtx = likes.sampleMatrix(0);
    Assert.assertEquals(mtx.numberOfAlleles(), 2);
    Assert.assertEquals(mtx.numberOfReads(), 1);
    final double v1 = mtx.get(0, 0);
    final double v2 = mtx.get(1, 0);
    Assert.assertTrue(v1 < 0);
    Assert.assertTrue(v2 < 0);
    lce.close();
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) HashMap(java.util.HashMap) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) List(java.util.List) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) Test(org.testng.annotations.Test)

Example 8 with SampleList

use of org.broadinstitute.hellbender.utils.genotyper.SampleList in project gatk-protected by broadinstitute.

the class ReadPositionUnitTest method test.

@Test
public void test() {
    final SAMFileHeader SAM_HEADER = ArtificialReadUtils.createArtificialSamHeader(10, 0, 1000);
    final List<Allele> alleles = Arrays.asList(Allele.create((byte) 'A', true), Allele.create((byte) 'C', false));
    final AlleleList<Allele> alleleList = new IndexedAlleleList<>(alleles);
    final int chromosomeIndex = 5;
    // variant is a SNP at position 20
    final int variantSite = 20;
    final VariantContext vc = new VariantContextBuilder("source", Integer.toString(chromosomeIndex), variantSite, variantSite, alleles).make();
    final SampleList sampleList = new IndexedSampleList("SAMPLE");
    //7 length-12 reads
    final Map<String, List<GATKRead>> readMap = new LinkedHashMap<>();
    final List<GATKRead> reads = new ArrayList<>();
    final int[] positionsOfSiteWithinReads = new int[] { 1, 2, 2, 3, 10, 10, 11 };
    final int[] alignmentStarts = Arrays.stream(positionsOfSiteWithinReads).map(n -> variantSite - n).toArray();
    for (int r = 0; r < positionsOfSiteWithinReads.length; r++) {
        final GATKRead read = ArtificialReadUtils.createArtificialRead(SAM_HEADER, "RRR00" + r, chromosomeIndex, alignmentStarts[r], "ACGTACGTACGT".getBytes(), new byte[] { 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 }, "12M");
        read.setMappingQuality(60);
        reads.add(read);
    }
    readMap.put("SAMPLE", reads);
    final ReadLikelihoods<Allele> likelihoods = new ReadLikelihoods<>(sampleList, alleleList, readMap);
    //we will make the first four reads ref (median position = 2) and the last three alt (median position 10, hence
    // median distance from end = 1)
    final LikelihoodMatrix<Allele> matrix = likelihoods.sampleMatrix(0);
    // log likelihoods are initialized to 0, so we can "turn on" a read for a particular allele by setting the
    // (allele, read) entry to 10
    matrix.set(0, 0, 10);
    matrix.set(0, 1, 10);
    matrix.set(0, 2, 10);
    matrix.set(0, 3, 10);
    matrix.set(1, 4, 10);
    matrix.set(1, 5, 10);
    matrix.set(1, 6, 10);
    final ReadPosition rp = new ReadPosition();
    final GenotypeBuilder gb = new GenotypeBuilder(DUMMY_GENOTYPE);
    rp.annotate(null, vc, DUMMY_GENOTYPE, gb, likelihoods);
    final Genotype g = gb.make();
    final int[] medianRefAndAltPositions = (int[]) g.getExtendedAttribute(ReadPosition.KEY);
    Assert.assertEquals(medianRefAndAltPositions[0], 2);
    Assert.assertEquals(medianRefAndAltPositions[1], 1);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) java.util(java.util) ArtificialReadUtils(org.broadinstitute.hellbender.utils.read.ArtificialReadUtils) Assert(org.testng.Assert) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) Test(org.testng.annotations.Test) htsjdk.variant.variantcontext(htsjdk.variant.variantcontext) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMFileHeader(htsjdk.samtools.SAMFileHeader) org.broadinstitute.hellbender.utils.genotyper(org.broadinstitute.hellbender.utils.genotyper) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 9 with SampleList

use of org.broadinstitute.hellbender.utils.genotyper.SampleList in project gatk-protected by broadinstitute.

the class ReferenceConfidenceModelUnitTest method splitReadsBySample.

public static Map<String, List<GATKRead>> splitReadsBySample(final SampleList samplesList, final Collection<GATKRead> reads, final SAMFileHeader header) {
    final Map<String, List<GATKRead>> returnMap = new HashMap<>();
    final int sampleCount = samplesList.numberOfSamples();
    for (int i = 0; i < sampleCount; i++) {
        returnMap.put(samplesList.getSample(i), new ArrayList<>());
    }
    for (final GATKRead read : reads) {
        returnMap.get(ReadUtils.getSampleName(read, header)).add(read);
    }
    return returnMap;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) IndexedAlleleList(org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList)

Example 10 with SampleList

use of org.broadinstitute.hellbender.utils.genotyper.SampleList in project gatk by broadinstitute.

the class HaplotypeBAMWriterUnitTest method generateReadLikelihoods.

private ReadLikelihoods<Haplotype> generateReadLikelihoods(final int[] readCount) {
    final AlleleList<Haplotype> haplotypeList = generateHaplotypeList();
    final SampleList sampleList = generateSampleList(readCount.length);
    final Map<String, List<GATKRead>> readSamples = new LinkedHashMap<>(readCount.length);
    for (int i = 0; i < readCount.length; i++) {
        readSamples.put(sampleList.getSample(i), generateReadsList(i, readCount[i]));
    }
    return new ReadLikelihoods<>(sampleList, haplotypeList, readSamples);
}
Also used : ArrayList(java.util.ArrayList) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) List(java.util.List) AlleleList(org.broadinstitute.hellbender.utils.genotyper.AlleleList) IndexedAlleleList(org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) ReadLikelihoods(org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

SampleList (org.broadinstitute.hellbender.utils.genotyper.SampleList)15 IndexedSampleList (org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList)10 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)9 Test (org.testng.annotations.Test)8 List (java.util.List)4 Haplotype (org.broadinstitute.hellbender.utils.haplotype.Haplotype)4 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)4 IndexedAlleleList (org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList)3 SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 htsjdk.variant.variantcontext (htsjdk.variant.variantcontext)2 File (java.io.File)2 java.util (java.util)2 HashMap (java.util.HashMap)2 PairHMMNativeArguments (org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments)2 GeneralPloidyFailOverAFCalculatorProvider (org.broadinstitute.hellbender.tools.walkers.genotyper.afcalc.GeneralPloidyFailOverAFCalculatorProvider)2 org.broadinstitute.hellbender.utils.genotyper (org.broadinstitute.hellbender.utils.genotyper)2 ArtificialReadUtils (org.broadinstitute.hellbender.utils.read.ArtificialReadUtils)2 Assert (org.testng.Assert)2 Allele (htsjdk.variant.variantcontext.Allele)1 ArrayList (java.util.ArrayList)1