Class VariantContextBuilder


  • public class VariantContextBuilder
    extends Object

    Builder class for VariantContext.

    Some basic assumptions here:

    1. data isn't protectively copied. If you provide an attribute map to the build, and modify it later, the builder will see this and so will any resulting variant contexts. It's best not to modify collections provided to a builder.
    2. the system uses the standard builder model, allowing the simple construction idiom:
      builder.source("a").genotypes(gc).id("x").make() => VariantContext
    3. The best way to copy a VariantContext is:
      new VariantContextBuilder(vc).make() => a copy of VC
    4. validation of arguments is done at the during the final make() call, so a VariantContextBuilder can exist in an inconsistent state as long as those issues are resolved before the call to make() is issued.
    • Constructor Detail

      • VariantContextBuilder

        public VariantContextBuilder()
        Create an empty VariantContextBuilder where all values adopt their default values. Note that source, chr, start, stop, and alleles must eventually be filled in, or the resulting VariantContext will throw an error.
      • VariantContextBuilder

        public VariantContextBuilder​(String source,
                                     String contig,
                                     long start,
                                     long stop,
                                     Collection<Allele> alleles)
        Create an empty VariantContextBuilder where all values adopt their default values, but the bare min. of info (source, chr, start, stop, and alleles) have been provided to start.
      • VariantContextBuilder

        public VariantContextBuilder​(VariantContext parent)
        Returns a new builder based on parent -- the new VC will have all fields initialized to their corresponding values in parent. This is the best way to create a derived VariantContext
        Parameters:
        parent - Cannot be null
    • Method Detail

      • alleles

        public VariantContextBuilder alleles​(Collection<Allele> alleles)
        Tells this builder to use this collection of alleles for the resulting VariantContext
        Parameters:
        alleles -
        Returns:
        this builder
      • attributes

        public VariantContextBuilder attributes​(Map<String,​?> attributes)
        Tells this builder to use this map of attributes for the resulting VariantContext. The contents of the Map are copied to a new Map to ensure that modifications to the provided Map post-invocation don't affect the VariantContext and also to ensure additional attributes can be added in case the provided map doesn't support changes (e.g. UnmodifiableMap). Attributes can be null -> meaning there are no attributes. After calling this routine the builder assumes it can modify the attributes object here, if subsequent calls are made to set attribute values Value for each attribute must be of a type that implements Serializable or else serialization will fail.
        Parameters:
        attributes - a Map of attributes to replace any existing attributes with
      • attribute

        public VariantContextBuilder attribute​(String key,
                                               Object value)
        Puts the key -> value mapping into this builder's attributes
        Parameters:
        key - key for the attribute
        value - value for the attribute (must be of a type that implements Serializable or else serialization will fail)
      • rmAttribute

        public VariantContextBuilder rmAttribute​(String key)
        Removes key if present in the attributes
        Parameters:
        key - key to remove
        Returns:
      • rmAttributes

        public VariantContextBuilder rmAttributes​(List<String> keys)
        Removes list of keys if present in the attributes
        Parameters:
        keys - list of keys to remove
        Returns:
      • filters

        public VariantContextBuilder filters​(Set<String> filters)
        This builder's filters are set to this value filters can be null -> meaning there are no filters
        Parameters:
        filters -
      • passFilters

        public VariantContextBuilder passFilters()
        Tells this builder that the resulting VariantContext should have PASS filters
        Returns:
      • unfiltered

        public VariantContextBuilder unfiltered()
        Tells this builder that the resulting VariantContext be unfiltered
        Returns:
      • genotypes

        public VariantContextBuilder genotypes​(GenotypesContext genotypes)
        Tells this builder that the resulting VariantContext should use this genotype's GenotypeContext. Note that genotypes can be null -> meaning there are no genotypes
        Parameters:
        genotypes -
      • genotypes

        public VariantContextBuilder genotypes​(Collection<Genotype> genotypes)
        Tells this builder that the resulting VariantContext should use a GenotypeContext containing genotypes Note that genotypes can be null, meaning there are no genotypes
        Parameters:
        genotypes -
      • genotypes

        public VariantContextBuilder genotypes​(Genotype... genotypes)
        Tells this builder that the resulting VariantContext should use a GenotypeContext containing genotypes
        Parameters:
        genotypes -
      • noGenotypes

        public VariantContextBuilder noGenotypes()
        Tells this builder that the resulting VariantContext should not contain any GenotypeContext
      • id

        public VariantContextBuilder id​(String ID)
        Tells us that the resulting VariantContext should have ID
        Parameters:
        ID -
        Returns:
      • noID

        public VariantContextBuilder noID()
        Tells us that the resulting VariantContext should not have an ID
        Returns:
      • log10PError

        public VariantContextBuilder log10PError​(double log10PError)
        Tells us that the resulting VariantContext should have log10PError
        Parameters:
        log10PError -
        Returns:
      • source

        public VariantContextBuilder source​(String source)
        Tells us that the resulting VariantContext should have source field set to source
        Parameters:
        source -
        Returns:
      • loc

        public VariantContextBuilder loc​(String contig,
                                         long start,
                                         long stop)
        Tells us that the resulting VariantContext should have the specified location
        Parameters:
        contig -
        start -
        stop -
        Returns:
      • chr

        public VariantContextBuilder chr​(String contig)
        Tells us that the resulting VariantContext should have the specified contig chr
        Parameters:
        contig -
        Returns:
      • start

        public VariantContextBuilder start​(long start)
        Tells us that the resulting VariantContext should have the specified contig start
        Parameters:
        start -
        Returns:
      • stop

        public VariantContextBuilder stop​(long stop)
        Tells us that the resulting VariantContext should have the specified contig stop
        Parameters:
        stop -
        Returns:
      • computeEndFromAlleles

        public VariantContextBuilder computeEndFromAlleles​(List<Allele> alleles,
                                                           int start,
                                                           int endForSymbolicAlleles)
        Compute the end position for this VariantContext from the alleles themselves assigns this builder the stop position computed.
        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
      • isFullyDecoded

        public boolean isFullyDecoded()
        Returns:
        true if this builder contains fully decoded data See VariantContext for more information
      • fullyDecoded

        public VariantContextBuilder fullyDecoded​(boolean isFullyDecoded)
        Sets this builder's fully decoded state to true. A fully decoded builder indicates that all fields are represented by their proper java objects (e.g., Integer(10) not "10"). See VariantContext for more information
        Parameters:
        isFullyDecoded -
      • make

        public VariantContext make()
        Takes all of the builder data provided up to this point, and instantiates a freshly allocated VariantContext with all of the builder data. This VariantContext is validated as appropriate and if not failing QC (and throwing an exception) is returned. Note that this function can be called multiple times to create multiple VariantContexts from the same builder.