A
- the type of the allele the likelihood makes reference to.
Note: this class uses FastUtil collections for speed.public class ReadLikelihoods<A extends htsjdk.variant.variantcontext.Allele> extends java.lang.Object implements SampleList, AlleleList<A>
Modifier and Type | Class and Description |
---|---|
class |
ReadLikelihoods.BestAllele
Contains information about the best allele for a read search result.
|
AlleleList.ActualPermutation<A extends htsjdk.variant.variantcontext.Allele>, AlleleList.NonPermutation<A extends htsjdk.variant.variantcontext.Allele>
Modifier and Type | Field and Description |
---|---|
protected AlleleList<A> |
alleles
Allele list
|
protected GATKRead[][] |
readsBySampleIndex
Reads by sample index.
|
protected SampleList |
samples
Sample list
|
protected double[][][] |
valuesBySampleIndex
Indexed per sample, allele and finally read (within sample).
|
EMPTY_LIST
EMPTY_LIST
Constructor and Description |
---|
ReadLikelihoods(SampleList samples,
AlleleList<A> alleles,
java.util.Map<java.lang.String,java.util.List<GATKRead>> reads)
Constructs a new read-likelihood collection.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addMissingAlleles(java.util.Collection<A> candidateAlleles,
double defaultLikelihood)
Add alleles that are missing in the read-likelihoods collection giving all reads a default
likelihood value.
|
void |
addNonReferenceAllele(A nonRefAllele)
Adds the non-reference allele to the read-likelihood collection setting each read likelihood to the second
best found (or best one if only one allele has likelihood).
|
void |
addReads(java.util.Map<java.lang.String,java.util.List<GATKRead>> readsBySample,
double initialLikelihood)
Add more reads to the collection.
|
java.util.List<A> |
alleles()
Returns the samples in this read-likelihood collection.
|
java.util.Collection<ReadLikelihoods.BestAllele> |
bestAlleles()
Returns the collection of best allele estimates for the reads based on the read-likelihoods.
|
java.util.Collection<ReadLikelihoods.BestAllele> |
bestAlleles(java.lang.String sample)
Returns the collection of best allele estimates for one sample's reads based on the read-likelihoods.
|
void |
changeReads(java.util.Map<GATKRead,GATKRead> readRealignments) |
void |
contaminationDownsampling(java.util.Map<java.lang.String,java.lang.Double> perSampleDownsamplingFraction)
Downsamples reads based on contamination fractions making sure that all alleles are affected proportionally.
|
void |
filterPoorlyModeledReads(double maximumErrorPerBase)
Removes those read that the best possible likelihood given any allele is just too low.
|
void |
filterToOnlyOverlappingUnclippedReads(SimpleInterval location)
Remove those reads that do not overlap certain genomic location.
|
A |
getAllele(int alleleIndex)
Returns the allele given its index.
|
java.lang.String |
getSample(int sampleIndex)
Returns sample name given its index.
|
java.util.Map<java.lang.String,java.util.List<PileupElement>> |
getStratifiedPileups(htsjdk.samtools.util.Locatable loc)
Collect a map stratified per-sample of the base pileups at the provided Location
NOTE: Since we shouldn't need to use the pileup if we have more reliable liklihoods, we want to discourage their use
|
boolean |
hasFilledLikelihoods()
Is this container expected to have the per-allele liklihoods calculations filled in.
|
int |
indexOfAllele(A allele)
Returns the index of an allele within the likelihood collection.
|
int |
indexOfSample(java.lang.String sample)
Returns the index of a sample within the likelihood collection.
|
<B extends htsjdk.variant.variantcontext.Allele> |
marginalize(java.util.Map<B,java.util.List<A>> newToOldAlleleMap)
Perform marginalization from an allele set to another (smaller one) taking the maximum value
for each read in the original allele subset.
|
<B extends htsjdk.variant.variantcontext.Allele> |
marginalize(java.util.Map<B,java.util.List<A>> newToOldAlleleMap,
htsjdk.samtools.util.Locatable overlap)
Perform marginalization from an allele set to another (smaller one) taking the maximum value
for each read in the original allele subset.
|
void |
normalizeLikelihoods(boolean bestToZero,
double maximumLikelihoodDifferenceCap)
Adjusts likelihoods so that for each read, the best allele likelihood is 0 and caps the minimum likelihood
of any allele for each read based on the maximum alternative allele likelihood.
|
int |
numberOfAlleles()
Returns number of alleles in the collection.
|
int |
numberOfSamples()
Number of samples included in the likelihood collection.
|
int |
readCount()
Returns the total number of reads in the read-likelihood collection.
|
void |
removeSampleReads(int sampleIndex,
java.util.Collection<GATKRead> readsToRemove,
int alleleCount) |
LikelihoodMatrix<A> |
sampleMatrix(int sampleIndex)
Returns a read vs allele likelihood matrix corresponding to a sample.
|
int |
sampleReadCount(int sampleIndex)
Returns the number of reads that belong to a sample in the read-likelihood collection.
|
java.util.List<GATKRead> |
sampleReads(int sampleIndex)
Returns the reads that belong to a sample sorted by their index (within that sample).
|
java.util.List<java.lang.String> |
samples()
Returns the samples in this read-likelihood collection.
|
static boolean |
unclippedReadOverlapsRegion(GATKRead read,
htsjdk.samtools.util.Locatable region) |
void |
updateNonRefAlleleLikelihoods()
Updates the likelihoods of the non-ref allele, if present, considering all non-symbolic alleles avaialble.
|
void |
updateNonRefAlleleLikelihoods(AlleleList<A> allelesToConsider)
Updates the likelihood of the NonRef allele (if present) based on the likelihoods of a set of non-symbolic
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
asListOfSamples, asSetOfSamples, emptySampleList, equals, singletonSampleList
asListOfAlleles, containsAllele, emptyAlleleList, equals, indexOfReference, permutation
protected final GATKRead[][] readsBySampleIndex
protected final double[][][] valuesBySampleIndex
valuesBySampleIndex[s][a][r] == lnLk(R_r | A_a) where R_r comes from Sample s.
protected final SampleList samples
protected AlleleList<A extends htsjdk.variant.variantcontext.Allele> alleles
public ReadLikelihoods(SampleList samples, AlleleList<A> alleles, java.util.Map<java.lang.String,java.util.List<GATKRead>> reads)
The initial likelihoods for all allele-read combinations are 0.
samples
- all supported samples in the collection.alleles
- all supported alleles in the collection.reads
- reads stratified per sample.java.lang.IllegalArgumentException
- if any of allele
, samples
or reads
is null
,
or if they contain null values.public boolean hasFilledLikelihoods()
public int indexOfSample(java.lang.String sample)
indexOfSample
in interface SampleList
sample
- the query sample.java.lang.IllegalArgumentException
- if sample
is null
.public int numberOfSamples()
numberOfSamples
in interface SampleList
public java.lang.String getSample(int sampleIndex)
getSample
in interface SampleList
sampleIndex
- query index.null
.java.lang.IllegalArgumentException
- if sampleIndex
is negative.public int indexOfAllele(A allele)
indexOfAllele
in interface AlleleList<A extends htsjdk.variant.variantcontext.Allele>
allele
- the query allele.java.lang.IllegalArgumentException
- if allele
is null
.public int numberOfAlleles()
numberOfAlleles
in interface AlleleList<A extends htsjdk.variant.variantcontext.Allele>
public A getAllele(int alleleIndex)
getAllele
in interface AlleleList<A extends htsjdk.variant.variantcontext.Allele>
alleleIndex
- the allele index.null
.java.lang.IllegalArgumentException
- the allele index is null
.public java.util.List<GATKRead> sampleReads(int sampleIndex)
sampleIndex
- the requested sample.null
but perhaps a zero-length array if there is no reads in sample. No element in
the array will be null.public LikelihoodMatrix<A> sampleMatrix(int sampleIndex)
sampleIndex
- target sample.null
java.lang.IllegalArgumentException
- if sampleIndex
is not null.public void normalizeLikelihoods(boolean bestToZero, double maximumLikelihoodDifferenceCap)
bestToZero
- set the best likelihood to 0, others will be subtracted the same amount.maximumLikelihoodDifferenceCap
- maximum difference between the best alternative allele likelihood
and any other likelihood.java.lang.IllegalArgumentException
- if maximumDifferenceWithBestAlternative
is not 0 or less.public java.util.List<java.lang.String> samples()
Samples are sorted by their index in the collection.
The returned list is an unmodifiable view on the read-likelihoods sample list.
null
.public java.util.List<A> alleles()
Samples are sorted by their index in the collection.
The returned list is an unmodifiable. It will not be updated if the collection allele list changes.
null
.public boolean addMissingAlleles(java.util.Collection<A> candidateAlleles, double defaultLikelihood)
candidateAlleles
- the potentially missing alleles.defaultLikelihood
- the default read likelihood value for that allele.true
iff the the read-likelihood collection was modified by the addition of the input alleles.
So if all the alleles in the input collection were already present in the read-likelihood collection this method
will return false
.java.lang.IllegalArgumentException
- if candidateAlleles
is null
or there is more than
one missing allele that is a reference or there is one but the collection already has
a reference allele.public <B extends htsjdk.variant.variantcontext.Allele> ReadLikelihoods<B> marginalize(java.util.Map<B,java.util.List<A>> newToOldAlleleMap)
newToOldAlleleMap
- map where the keys are the new alleles and the value list the original
alleles that correspond to the new one.null
. The result will have the requested set of new alleles (keys in newToOldAlleleMap
, and
the same set of samples and reads as the original.java.lang.IllegalArgumentException
- is newToOldAlleleMap
is null
or contains null
values,
or its values contain reference to non-existing alleles in this read-likelihood collection. Also no new allele
can have zero old alleles mapping nor two new alleles can make reference to the same old allele.public <B extends htsjdk.variant.variantcontext.Allele> ReadLikelihoods<B> marginalize(java.util.Map<B,java.util.List<A>> newToOldAlleleMap, htsjdk.samtools.util.Locatable overlap)
newToOldAlleleMap
- map where the keys are the new alleles and the value list the original
alleles that correspond to the new one.overlap
- if not null
, only reads that overlap the location (with unclipping) will be present in
the output read-collection.null
. The result will have the requested set of new alleles (keys in newToOldAlleleMap
, and
the same set of samples and reads as the original.java.lang.IllegalArgumentException
- is newToOldAlleleMap
is null
or contains null
values,
or its values contain reference to non-existing alleles in this read-likelihood collection. Also no new allele
can have zero old alleles mapping nor two new alleles can make reference to the same old allele.public static boolean unclippedReadOverlapsRegion(GATKRead read, htsjdk.samtools.util.Locatable region)
public void filterPoorlyModeledReads(double maximumErrorPerBase)
This is determined by a maximum error per read-base against the best likelihood possible.
maximumErrorPerBase
- the minimum acceptable error rate per read base, must be
a positive number.java.lang.IllegalStateException
- is not supported for read-likelihood that do not contain alleles.java.lang.IllegalArgumentException
- if maximumErrorPerBase
is negative.public void addReads(java.util.Map<java.lang.String,java.util.List<GATKRead>> readsBySample, double initialLikelihood)
readsBySample
- reads to add.initialLikelihood
- the likelihood for the new entries.java.lang.IllegalArgumentException
- if readsBySample
is null
or readsBySample
contains
null
reads, or readsBySample
contains read that are already present in the read-likelihood
collection.public void addNonReferenceAllele(A nonRefAllele)
Nothing will happen if the read-likelihoods collection already includes the non-ref allele
Implementation note: even when strictly speaking we do not need to demand the calling code to pass
the reference the non-ref allele, we still demand it in order to lead the
the calling code to use the right generic type for this likelihoods
collection Allele
.
nonRefAllele
- the non-ref allele.java.lang.IllegalArgumentException
- if nonRefAllele
is anything but the designated <NON_REF>
symbolic allele Allele.NON_REF_ALLELE
.public void updateNonRefAlleleLikelihoods()
public void updateNonRefAlleleLikelihoods(AlleleList<A> allelesToConsider)
This method does
allelesToConsider
- public void contaminationDownsampling(java.util.Map<java.lang.String,java.lang.Double> perSampleDownsamplingFraction)
perSampleDownsamplingFraction
- contamination sample map where the sample name are the keys and the
fractions are the values.java.lang.IllegalArgumentException
- if perSampleDownsamplingFraction
is null
.public java.util.Collection<ReadLikelihoods.BestAllele> bestAlleles()
null
, one element per read in the read-likelihoods collection.java.lang.IllegalStateException
- if there is no alleles.public java.util.Collection<ReadLikelihoods.BestAllele> bestAlleles(java.lang.String sample)
null
, one element per read in the read-likelihoods collection.java.lang.IllegalStateException
- if there is no alleles.public int readCount()
null
public int sampleReadCount(int sampleIndex)
sampleIndex
- the query sample index.java.lang.IllegalArgumentException
- if sampleIndex
is not a valid sample index.public void filterToOnlyOverlappingUnclippedReads(SimpleInterval location)
This method modifies the current read-likelihoods collection.
location
- the target location.java.lang.IllegalArgumentException
- the location cannot be null
nor unmapped.public void removeSampleReads(int sampleIndex, java.util.Collection<GATKRead> readsToRemove, int alleleCount)
public java.util.Map<java.lang.String,java.util.List<PileupElement>> getStratifiedPileups(htsjdk.samtools.util.Locatable loc)
loc
- reference location to construct pileups for