Package htsjdk.variant.variantcontext
Class VariantContextUtils
- java.lang.Object
-
- htsjdk.variant.variantcontext.VariantContextUtils
-
public class VariantContextUtils extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classVariantContextUtils.JexlVCMatchExpA simple but common wrapper for matchingVariantContextobjects using JEXL expressions
-
Constructor Summary
Constructors Constructor Description VariantContextUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doublecalculateAltAlleleFrequency(VariantContext vc)Computes the alternate allele frequency at the providedVariantContextby dividing its "AN" by its "AC".static voidcalculateChromosomeCounts(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 voidcalculateChromosomeCounts(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()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 tagsstatic 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 tagsstatic intcomputeEndFromAlleles(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 casesstatic Set<String>genotypeNames(Collection<Genotype> genotypes)static VCFCompoundHeaderLinegetMetaDataForField(VCFHeader header, String field)static intgetSize(VariantContext vc)static List<VariantContextUtils.JexlVCMatchExp>initializeMatchExps(String[] names, String[] exps)Method for creating JexlVCMatchExp from input walker arguments names and exps.static List<VariantContextUtils.JexlVCMatchExp>initializeMatchExps(List<String> names, List<String> exps)Method for creating JexlVCMatchExp from input walker arguments names and exps.static List<VariantContextUtils.JexlVCMatchExp>initializeMatchExps(Map<String,String> names_and_exps)Method for creating JexlVCMatchExp from input walker arguments mapping from names to exps.static booleanisTransition(VariantContext vc)Answers if the provided variant is transitional (otherwise, it's transversional).static booleanmatch(VariantContext vc, Genotype g, VariantContextUtils.JexlVCMatchExp exp)Returns true ifexpmatchvc,g.static booleanmatch(VariantContext vc, Genotype g, VariantContextUtils.JexlVCMatchExp exp, JexlMissingValueTreatment howToTreatMissingValues)Returns true ifexpmatchvc,g.static Map<VariantContextUtils.JexlVCMatchExp,Boolean>match(VariantContext vc, Genotype g, Collection<VariantContextUtils.JexlVCMatchExp> exps)Matches eachVariantContextUtils.JexlVCMatchExpexp against the data contained invc,g, and returns a map from these expressions totrue(if they matched) orfalse(if they didn't).static Map<VariantContextUtils.JexlVCMatchExp,Boolean>match(VariantContext vc, Genotype g, Collection<VariantContextUtils.JexlVCMatchExp> exps, JexlMissingValueTreatment howToTreatMissingValues)Matches eachVariantContextUtils.JexlVCMatchExpexp against the data contained invc,g, and returns a map from these expressions totrue(if they matched) orfalse(if they didn't).static booleanmatch(VariantContext vc, VariantContextUtils.JexlVCMatchExp exp)Returns true ifexpmatchvc.static Map<VariantContextUtils.JexlVCMatchExp,Boolean>match(VariantContext vc, Collection<VariantContextUtils.JexlVCMatchExp> exps)Matches eachVariantContextUtils.JexlVCMatchExpexp against the data contained invc, and returns a map from these expressions totrue(if they matched) orfalse(if they didn't).static VariantContextsitesOnlyVariantContext(VariantContext vc)Returns a newly allocated VC that is the same as VC, but without genotypesstatic Collection<VariantContext>sitesOnlyVariantContexts(Collection<VariantContext> vcs)Returns a newly allocated list of VC, where each VC is the same as the input VCs, but without genotypes
-
-
-
Field Detail
-
engine
public static final Lazy<org.apache.commons.jexl2.JexlEngine> engine
Use aLazyJexlEngineinstance to avoid class-loading issues. (Applications that access this class are otherwise forced to build aJexlEngineinstance, which depends on some apache logging libraries that mightn't be packaged.)
-
-
Method Detail
-
calculateAltAlleleFrequency
public static double calculateAltAlleleFrequency(VariantContext vc)
Computes the alternate allele frequency at the providedVariantContextby 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
public static final VCFCompoundHeaderLine getMetaDataForField(VCFHeader header, String field)
-
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
public static boolean match(VariantContext vc, VariantContextUtils.JexlVCMatchExp exp)
- 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.JexlVCMatchExpexp 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 toVariantContextrecords. Use the variousinitializeMatchExps()'s to create the list ofVariantContextUtils.JexlVCMatchExpexpressions. 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
public static boolean match(VariantContext vc, Genotype g, VariantContextUtils.JexlVCMatchExp exp)
- 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.JexlVCMatchExpexp 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 toVariantContextrecords. Use the variousinitializeMatchExps()'s to create the list ofVariantContextUtils.JexlVCMatchExpexpressions. 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.JexlVCMatchExpexp 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 toVariantContextrecords. Use the variousinitializeMatchExps()'s to create the list ofVariantContextUtils.JexlVCMatchExpexpressions.- 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
public static boolean isTransition(VariantContext vc) throws IllegalArgumentException
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
public static VariantContext sitesOnlyVariantContext(VariantContext vc)
Returns a newly allocated VC that is the same as VC, but without genotypes- Parameters:
vc- variant context- Returns:
- new VC without genotypes
-
sitesOnlyVariantContexts
public static Collection<VariantContext> sitesOnlyVariantContexts(Collection<VariantContext> vcs)
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
public static int getSize(VariantContext vc)
-
genotypeNames
public static Set<String> genotypeNames(Collection<Genotype> genotypes)
-
computeEndFromAlleles
public static 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 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
-
-