Package htsjdk.variant.variantcontext
Class VariantContextUtils
java.lang.Object
htsjdk.variant.variantcontext.VariantContextUtils
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A simple but common wrapper for matchingVariantContext
objects using JEXL expressions -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
Computes the alternate allele frequency at the providedVariantContext
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, Set<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()calculateChromosomeCounts
(VariantContext vc, Map<String, Object> attributes, boolean removeStaleValues) Update the attributes of the attributes map given the VariantContext to reflect the proper chromosome-based VCF tagscalculateChromosomeCounts
(VariantContext vc, Map<String, Object> attributes, boolean removeStaleValues, Set<String> founderIds) Update the attributes of the attributes map given the VariantContext to reflect the proper chromosome-based VCF tagsstatic int
computeEndFromAlleles
(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 casesgenotypeNames
(Collection<Genotype> genotypes) static final VCFCompoundHeaderLine
getMetaDataForField
(VCFHeader header, String field) static int
initializeMatchExps
(String[] names, String[] exps) Method for creating JexlVCMatchExp from input walker arguments names and exps.initializeMatchExps
(List<String> names, List<String> exps) Method for creating JexlVCMatchExp from input walker arguments names and exps.initializeMatchExps
(Map<String, String> names_and_exps) Method for creating JexlVCMatchExp from input walker arguments mapping from names to exps.static boolean
Answers if the provided variant is transitional (otherwise, it's transversional).static boolean
Returns true ifexp
matchvc
,g
.static boolean
match
(VariantContext vc, Genotype g, VariantContextUtils.JexlVCMatchExp exp, JexlMissingValueTreatment howToTreatMissingValues) Returns true ifexp
matchvc
,g
.match
(VariantContext vc, Genotype g, Collection<VariantContextUtils.JexlVCMatchExp> exps) Matches eachVariantContextUtils.JexlVCMatchExp
exp against the data contained invc
,g
, and returns a map from these expressions totrue
(if they matched) orfalse
(if they didn't).match
(VariantContext vc, Genotype g, Collection<VariantContextUtils.JexlVCMatchExp> exps, JexlMissingValueTreatment howToTreatMissingValues) Matches eachVariantContextUtils.JexlVCMatchExp
exp against the data contained invc
,g
, and returns a map from these expressions totrue
(if they matched) orfalse
(if they didn't).static boolean
Returns true ifexp
matchvc
.Matches eachVariantContextUtils.JexlVCMatchExp
exp against the data contained invc
, and returns a map from these expressions totrue
(if they matched) orfalse
(if they didn't).static VariantContext
Returns a newly allocated VC that is the same as VC, but without genotypesstatic Collection<VariantContext>
Returns a newly allocated list of VC, where each VC is the same as the input VCs, but without genotypes
-
Field Details
-
engine
Use aLazy
JexlEngine
instance to avoid class-loading issues. (Applications that access this class are otherwise forced to build aJexlEngine
instance, which depends on some apache logging libraries that mightn't be packaged.)
-
-
Constructor Details
-
VariantContextUtils
public VariantContextUtils()
-
-
Method Details
-
calculateAltAlleleFrequency
Computes the alternate allele frequency at the providedVariantContext
by dividing its "AN" by its "AC".- Parameters:
vc
- The variant whose alternate allele frequency is computed- Returns:
- The alternate allele frequency in [0, 1]
- Throws:
AssertionError
- When either annotation is missing, or when the compuated frequency is outside the expected range
-
calculateChromosomeCounts
public static Map<String,Object> calculateChromosomeCounts(VariantContext vc, Map<String, Object> attributes, boolean removeStaleValues) Update the attributes of the attributes map given the VariantContext to reflect the proper chromosome-based VCF tags- Parameters:
vc
- the VariantContextattributes
- the attributes map to populate; must not be null; may contain old valuesremoveStaleValues
- should we remove stale values from the mapping?- Returns:
- the attributes map provided as input, returned for programming convenience
-
calculateChromosomeCounts
public static Map<String,Object> calculateChromosomeCounts(VariantContext vc, Map<String, Object> attributes, boolean removeStaleValues, Set<String> founderIds) Update the attributes of the attributes map given the VariantContext to reflect the proper chromosome-based VCF tags- Parameters:
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 individuals- Returns:
- the attributes map provided as input, returned for programming convenience
-
calculateChromosomeCounts
public 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()- Parameters:
builder
- the VariantContextBuilder we are updatingremoveStaleValues
- should we remove stale values from the mapping?
-
calculateChromosomeCounts
public static void calculateChromosomeCounts(VariantContextBuilder builder, boolean removeStaleValues, Set<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()- Parameters:
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?
-
getMetaDataForField
-
initializeMatchExps
public static List<VariantContextUtils.JexlVCMatchExp> initializeMatchExps(String[] names, String[] exps) Method for creating JexlVCMatchExp from input walker arguments names and exps. These two arrays contain the name associated with each JEXL expression. initializeMatchExps will parse each expression and return a list of JexlVCMatchExp, in order, that correspond to the names and exps. These are suitable input to match() below.- Parameters:
names
- namesexps
- expressions- Returns:
- list of matches
-
initializeMatchExps
public static List<VariantContextUtils.JexlVCMatchExp> initializeMatchExps(List<String> names, List<String> exps) Method for creating JexlVCMatchExp from input walker arguments names and exps. These two lists contain the name associated with each JEXL expression. initializeMatchExps will parse each expression and return a list of JexlVCMatchExp, in order, that correspond to the names and exps. These are suitable input to match() below.- Parameters:
names
- namesexps
- expressions- Returns:
- list of matches
-
initializeMatchExps
public static List<VariantContextUtils.JexlVCMatchExp> initializeMatchExps(Map<String, String> names_and_exps) Method for creating JexlVCMatchExp from input walker arguments mapping from names to exps. These two arrays contain the name associated with each JEXL expression. initializeMatchExps will parse each expression and return a list of JexlVCMatchExp, in order, that correspond to the names and exps. These are suitable input to match() below.- Parameters:
names_and_exps
- mapping of names to expressions- Returns:
- list of matches
-
match
- Parameters:
vc
- variant contextexp
- expression- Returns:
- true if there is a match
-
match
public static Map<VariantContextUtils.JexlVCMatchExp,Boolean> match(VariantContext vc, Collection<VariantContextUtils.JexlVCMatchExp> exps) Matches eachVariantContextUtils.JexlVCMatchExp
exp against the data contained invc
, and returns a map from these expressions totrue
(if they matched) orfalse
(if they didn't). This the best way to apply JEXL expressions toVariantContext
records. Use the variousinitializeMatchExps()
's to create the list ofVariantContextUtils.JexlVCMatchExp
expressions. Expressions that contain literals not available in the VariantContext or Genotype will be treated as not matching- Parameters:
vc
- variant contextexps
- expressions- Returns:
- true if there is a match
-
match
- Parameters:
vc
- variant contextg
- genotypeexp
- expression- Returns:
- true if there is a match
-
match
public static boolean match(VariantContext vc, Genotype g, VariantContextUtils.JexlVCMatchExp exp, JexlMissingValueTreatment howToTreatMissingValues) - Parameters:
vc
- variant contextg
- genotypeexp
- expressionhowToTreatMissingValues
- what to do if the jexl expression contains literals that aren't in the context- Returns:
- true if there is a match
-
match
public static Map<VariantContextUtils.JexlVCMatchExp,Boolean> match(VariantContext vc, Genotype g, Collection<VariantContextUtils.JexlVCMatchExp> exps) Matches eachVariantContextUtils.JexlVCMatchExp
exp against the data contained invc
,g
, and returns a map from these expressions totrue
(if they matched) orfalse
(if they didn't). This the best way to apply JEXL expressions toVariantContext
records. Use the variousinitializeMatchExps()
's to create the list ofVariantContextUtils.JexlVCMatchExp
expressions. Expressions that contain literals not available in the VariantContext or Genotype will be treated as not matching- Parameters:
vc
- variant contextg
- genotypeexps
- expressions- Returns:
- true if there is a match
-
match
public static Map<VariantContextUtils.JexlVCMatchExp,Boolean> match(VariantContext vc, Genotype g, Collection<VariantContextUtils.JexlVCMatchExp> exps, JexlMissingValueTreatment howToTreatMissingValues) Matches eachVariantContextUtils.JexlVCMatchExp
exp against the data contained invc
,g
, and returns a map from these expressions totrue
(if they matched) orfalse
(if they didn't). This the best way to apply JEXL expressions toVariantContext
records. Use the variousinitializeMatchExps()
's to create the list ofVariantContextUtils.JexlVCMatchExp
expressions.- Parameters:
vc
- variant contextg
- genotypeexps
- expressionshowToTreatMissingValues
- what to do if the jexl expression contains literals that aren't in the context- Returns:
- true if there is a match
-
isTransition
Answers if the provided variant is transitional (otherwise, it's transversional). Transitions: A->G G->A C->T T->C Transversions: A->C A->T C->A C->G G->C G->T T->A T->G- Parameters:
vc
- a biallelic polymorphic SNP- Returns:
- true if a transition and false if transversion
- Throws:
IllegalArgumentException
- if vc is monomorphic, not a SNP or not bi-allelic.
-
sitesOnlyVariantContext
Returns a newly allocated VC that is the same as VC, but without genotypes- Parameters:
vc
- variant context- Returns:
- new VC without genotypes
-
sitesOnlyVariantContexts
Returns a newly allocated list of VC, where each VC is the same as the input VCs, but without genotypes- Parameters:
vcs
- collection of VCs- Returns:
- new VCs without genotypes
-
getSize
-
genotypeNames
-
computeEndFromAlleles
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- Parameters:
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- Returns:
- this builder
-