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);
}
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();
}
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);
}
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;
}
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);
}
Aggregations