public class VariantContextUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
VariantContextUtils.JexlVCMatchExp
A simple but common wrapper for matching
VariantContext objects using JEXL expressions |
Modifier and Type | Field and Description |
---|---|
static Lazy<org.apache.commons.jexl2.JexlEngine> |
engine
Use a
Lazy JexlEngine instance to avoid class-loading issues. |
Constructor and Description |
---|
VariantContextUtils() |
Modifier and Type | Method and Description |
---|---|
static double |
calculateAltAlleleFrequency(VariantContext vc)
Computes the alternate allele frequency at the provided
VariantContext by dividing its "AN" by its "AC". |
static void |
calculateChromosomeCounts(VariantContextBuilder builder,
boolean removeStaleValues)
Update the attributes of the attributes map in the VariantContextBuilder to reflect the proper
chromosome-based VCF tags based on the current VC produced by builder.make()
|
static void |
calculateChromosomeCounts(VariantContextBuilder builder,
boolean removeStaleValues,
java.util.Set<java.lang.String> founderIds)
Update the attributes of the attributes map in the VariantContextBuilder to reflect the proper
chromosome-based VCF tags based on the current VC produced by builder.make()
|
static java.util.Map<java.lang.String,java.lang.Object> |
calculateChromosomeCounts(VariantContext vc,
java.util.Map<java.lang.String,java.lang.Object> attributes,
boolean removeStaleValues)
Update the attributes of the attributes map given the VariantContext to reflect the
proper chromosome-based VCF tags
|
static java.util.Map<java.lang.String,java.lang.Object> |
calculateChromosomeCounts(VariantContext vc,
java.util.Map<java.lang.String,java.lang.Object> attributes,
boolean removeStaleValues,
java.util.Set<java.lang.String> founderIds)
Update the attributes of the attributes map given the VariantContext to reflect the
proper chromosome-based VCF tags
|
static int |
computeEndFromAlleles(java.util.List<Allele> alleles,
int start,
int endForSymbolicAlleles)
Compute the end position for this VariantContext from the alleles themselves
In the trivial case this is a single BP event and end = start (open intervals)
In general the end is start + ref length - 1, handling the case where ref length == 0
However, if alleles contains a symbolic allele then we use endForSymbolicAllele in all cases
|
static java.util.Set<java.lang.String> |
genotypeNames(java.util.Collection<Genotype> genotypes) |
static VCFCompoundHeaderLine |
getMetaDataForField(VCFHeader header,
java.lang.String field) |
static int |
getSize(VariantContext vc) |
static java.util.List<VariantContextUtils.JexlVCMatchExp> |
initializeMatchExps(java.util.List<java.lang.String> names,
java.util.List<java.lang.String> exps)
Method for creating JexlVCMatchExp from input walker arguments names and exps.
|
static java.util.List<VariantContextUtils.JexlVCMatchExp> |
initializeMatchExps(java.util.Map<java.lang.String,java.lang.String> names_and_exps)
Method for creating JexlVCMatchExp from input walker arguments mapping from names to exps.
|
static java.util.List<VariantContextUtils.JexlVCMatchExp> |
initializeMatchExps(java.lang.String[] names,
java.lang.String[] exps)
Method for creating JexlVCMatchExp from input walker arguments names and exps.
|
static boolean |
isTransition(VariantContext vc)
Answers if the provided variant is transitional (otherwise, it's transversional).
|
static java.util.Map<VariantContextUtils.JexlVCMatchExp,java.lang.Boolean> |
match(VariantContext vc,
java.util.Collection<VariantContextUtils.JexlVCMatchExp> exps)
Matches each
VariantContextUtils.JexlVCMatchExp exp against the data contained in vc ,
and returns a map from these expressions to true (if they matched) or false (if they didn't). |
static java.util.Map<VariantContextUtils.JexlVCMatchExp,java.lang.Boolean> |
match(VariantContext vc,
Genotype g,
java.util.Collection<VariantContextUtils.JexlVCMatchExp> exps)
Matches each
VariantContextUtils.JexlVCMatchExp exp against the data contained in vc , g ,
and returns a map from these expressions to true (if they matched) or false (if they didn't). |
static java.util.Map<VariantContextUtils.JexlVCMatchExp,java.lang.Boolean> |
match(VariantContext vc,
Genotype g,
java.util.Collection<VariantContextUtils.JexlVCMatchExp> exps,
JexlMissingValueTreatment howToTreatMissingValues)
Matches each
VariantContextUtils.JexlVCMatchExp exp against the data contained in vc , g ,
and returns a map from these expressions to true (if they matched) or false (if they didn't). |
static boolean |
match(VariantContext vc,
Genotype g,
VariantContextUtils.JexlVCMatchExp exp)
Returns true if
exp match vc , g . |
static boolean |
match(VariantContext vc,
Genotype g,
VariantContextUtils.JexlVCMatchExp exp,
JexlMissingValueTreatment howToTreatMissingValues)
Returns true if
exp match vc , g . |
static boolean |
match(VariantContext vc,
VariantContextUtils.JexlVCMatchExp exp)
Returns true if
exp match vc . |
static VariantContext |
sitesOnlyVariantContext(VariantContext vc)
Returns a newly allocated VC that is the same as VC, but without genotypes
|
static java.util.Collection<VariantContext> |
sitesOnlyVariantContexts(java.util.Collection<VariantContext> vcs)
Returns a newly allocated list of VC, where each VC is the same as the input VCs, but without genotypes
|
public static final Lazy<org.apache.commons.jexl2.JexlEngine> engine
Lazy
JexlEngine
instance to avoid class-loading issues. (Applications that access this class are otherwise
forced to build a JexlEngine
instance, which depends on some apache logging libraries that mightn't be packaged.)public static double calculateAltAlleleFrequency(VariantContext vc)
VariantContext
by dividing its "AN" by its "AC".vc
- The variant whose alternate allele frequency is computedjava.lang.AssertionError
- When either annotation is missing, or when the compuated frequency is outside the expected rangepublic static java.util.Map<java.lang.String,java.lang.Object> calculateChromosomeCounts(VariantContext vc, java.util.Map<java.lang.String,java.lang.Object> attributes, boolean removeStaleValues)
vc
- the VariantContextattributes
- the attributes map to populate; must not be null; may contain old valuesremoveStaleValues
- should we remove stale values from the mapping?public static java.util.Map<java.lang.String,java.lang.Object> calculateChromosomeCounts(VariantContext vc, java.util.Map<java.lang.String,java.lang.Object> attributes, boolean removeStaleValues, java.util.Set<java.lang.String> founderIds)
vc
- the VariantContextattributes
- the attributes map to populate; must not be null; may contain old valuesremoveStaleValues
- should we remove stale values from the mapping?founderIds
- - Set of founders Ids to take into account. AF and FC will be calculated over the founders.
If empty or null, counts are generated for all samples as unrelated individualspublic static void calculateChromosomeCounts(VariantContextBuilder builder, boolean removeStaleValues)
builder
- the VariantContextBuilder we are updatingremoveStaleValues
- should we remove stale values from the mapping?public static void calculateChromosomeCounts(VariantContextBuilder builder, boolean removeStaleValues, java.util.Set<java.lang.String> founderIds)
builder
- the VariantContextBuilder we are updatingfounderIds
- - Set of founders to take into account. AF and FC will be calculated over the founders only.
If empty or null, counts are generated for all samples as unrelated individualsremoveStaleValues
- should we remove stale values from the mapping?public static final VCFCompoundHeaderLine getMetaDataForField(VCFHeader header, java.lang.String field)
public static java.util.List<VariantContextUtils.JexlVCMatchExp> initializeMatchExps(java.lang.String[] names, java.lang.String[] exps)
names
- namesexps
- expressionspublic static java.util.List<VariantContextUtils.JexlVCMatchExp> initializeMatchExps(java.util.List<java.lang.String> names, java.util.List<java.lang.String> exps)
names
- namesexps
- expressionspublic static java.util.List<VariantContextUtils.JexlVCMatchExp> initializeMatchExps(java.util.Map<java.lang.String,java.lang.String> names_and_exps)
names_and_exps
- mapping of names to expressionspublic static boolean match(VariantContext vc, VariantContextUtils.JexlVCMatchExp exp)
vc
- variant contextexp
- expressionpublic static java.util.Map<VariantContextUtils.JexlVCMatchExp,java.lang.Boolean> match(VariantContext vc, java.util.Collection<VariantContextUtils.JexlVCMatchExp> exps)
VariantContextUtils.JexlVCMatchExp
exp against the data contained in vc
,
and returns a map from these expressions to true
(if they matched) or false
(if they didn't).
This the best way to apply JEXL expressions to VariantContext
records.
Use the various initializeMatchExps()
's to create the list of VariantContextUtils.JexlVCMatchExp
expressions.
Expressions that contain literals not available in the VariantContext or Genotype will be treated as not matchingvc
- variant contextexps
- expressionspublic static boolean match(VariantContext vc, Genotype g, VariantContextUtils.JexlVCMatchExp exp)
vc
- variant contextg
- genotypeexp
- expressionpublic static boolean match(VariantContext vc, Genotype g, VariantContextUtils.JexlVCMatchExp exp, JexlMissingValueTreatment howToTreatMissingValues)
vc
- variant contextg
- genotypeexp
- expressionhowToTreatMissingValues
- what to do if the jexl expression contains literals that aren't in the contextpublic static java.util.Map<VariantContextUtils.JexlVCMatchExp,java.lang.Boolean> match(VariantContext vc, Genotype g, java.util.Collection<VariantContextUtils.JexlVCMatchExp> exps)
VariantContextUtils.JexlVCMatchExp
exp against the data contained in vc
, g
,
and returns a map from these expressions to true
(if they matched) or false
(if they didn't).
This the best way to apply JEXL expressions to VariantContext
records.
Use the various initializeMatchExps()
's to create the list of VariantContextUtils.JexlVCMatchExp
expressions.
Expressions that contain literals not available in the VariantContext or Genotype will be treated as not matchingvc
- variant contextg
- genotypeexps
- expressionspublic static java.util.Map<VariantContextUtils.JexlVCMatchExp,java.lang.Boolean> match(VariantContext vc, Genotype g, java.util.Collection<VariantContextUtils.JexlVCMatchExp> exps, JexlMissingValueTreatment howToTreatMissingValues)
VariantContextUtils.JexlVCMatchExp
exp against the data contained in vc
, g
,
and returns a map from these expressions to true
(if they matched) or false
(if they didn't).
This the best way to apply JEXL expressions to VariantContext
records.
Use the various initializeMatchExps()
's to create the list of VariantContextUtils.JexlVCMatchExp
expressions.vc
- variant contextg
- genotypeexps
- expressionshowToTreatMissingValues
- what to do if the jexl expression contains literals that aren't in the contextpublic static boolean isTransition(VariantContext vc) throws java.lang.IllegalArgumentException
vc
- a biallelic polymorphic SNPjava.lang.IllegalArgumentException
- if vc is monomorphic, not a SNP or not bi-allelic.public static VariantContext sitesOnlyVariantContext(VariantContext vc)
vc
- variant contextpublic static java.util.Collection<VariantContext> sitesOnlyVariantContexts(java.util.Collection<VariantContext> vcs)
vcs
- collection of VCspublic static int getSize(VariantContext vc)
public static java.util.Set<java.lang.String> genotypeNames(java.util.Collection<Genotype> genotypes)
public static int computeEndFromAlleles(java.util.List<Allele> alleles, int start, int endForSymbolicAlleles)
alleles
- the list of alleles to consider. The reference allele must be the first onestart
- the known start position of this eventendForSymbolicAlleles
- the end position to use if any of the alleles is symbolic. Can be -1
if no is expected but will throw an error if one is found