Class VariantContextUtils


  • public class VariantContextUtils
    extends Object
    • Field Detail

      • engine

        public static final Lazy<org.apache.commons.jexl2.JexlEngine> engine
        Use a 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.)
    • Constructor Detail

      • VariantContextUtils

        public VariantContextUtils()
    • Method Detail

      • calculateAltAlleleFrequency

        public static double calculateAltAlleleFrequency​(VariantContext vc)
        Computes the alternate allele frequency at the provided VariantContext 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 VariantContext
        attributes - the attributes map to populate; must not be null; may contain old values
        removeStaleValues - 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 VariantContext
        attributes - the attributes map to populate; must not be null; may contain old values
        removeStaleValues - 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 updating
        removeStaleValues - 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 updating
        founderIds - - 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 individuals
        removeStaleValues - should we remove stale values from the mapping?
      • 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 - names
        exps - 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 - names
        exps - 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
      • 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
      • 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 one
        start - the known start position of this event
        endForSymbolicAlleles - 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