Package htsjdk.variant.variantcontext
Class VariantContextBuilder
java.lang.Object
htsjdk.variant.variantcontext.VariantContextBuilder
Builder class for VariantContext
.
Some basic assumptions here:
- 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.
- the system uses the standard builder model, allowing the simple construction idiom:
builder.source("a").genotypes(gc).id("x").make()
=>VariantContext
- The best way to copy a VariantContext is:
new VariantContextBuilder(vc).make()
=> a copy of VC - validation of arguments is done at the during the final
make()
call, so aVariantContextBuilder
can exist in an inconsistent state as long as those issues are resolved before the call tomake()
is issued.
-
Constructor Summary
ConstructorDescriptionCreate an empty VariantContextBuilder where all values adopt their default values.VariantContextBuilder
(VariantContext parent) Returns a new builder based on parent -- the new VC will have all fields initialized to their corresponding values in parent.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. -
Method Summary
Modifier and TypeMethodDescriptionalleles
(Collection<Allele> alleles) Tells this builder to use this collection of alleles for the resulting VariantContextPuts the key -> value mapping into this builder's attributesattributes
(Map<String, ?> attributes) Tells this builder to use this map of attributes for the resultingVariantContext
.Tells us that the resulting VariantContext should have the specified contig chrcomputeEndFromAlleles
(List<Allele> alleles, int start) 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.copy()
Adds the given filter to the list of filtersfilters
This builder's filters are set to this value filters can benull
-> meaning there are no filtersfullyDecoded
(boolean isFullyDecoded) Sets this builder's fully decoded state to true.Tells this builder that the resultingVariantContext
should use aGenotypeContext
containing genotypesgenotypes
(GenotypesContext genotypes) Tells this builder that the resultingVariantContext
should use this genotype'sGenotypeContext
.genotypes
(Collection<Genotype> genotypes) Tells this builder that the resultingVariantContext
should use aGenotypeContext
containing genotypes Note that genotypes can benull
, meaning there are no genotypesgenotypesNoValidation
(GenotypesContext genotypes) Getter for attributes (DANGEROUS!!! DOES NOT MAKE A COPY!!!)Getter for contigGetter for filters (DANGEROUS!!! DOES NOT MAKE A COPY!!!)Getter for genotypes (DANGEROUS!!! DOES NOT MAKE A COPY!!!)getID()
Getter for id of variantlong
getStart()
Getter for start positionlong
getStop()
Getter for stop positionTells us that the resulting VariantContext should have IDboolean
Tells us that the resulting VariantContext should have the specified locationlog10PError
(double log10PError) Tells us that the resulting VariantContext should have log10PErrormake()
Takes all of the builder data provided up to this point, and instantiates a freshly allocated VariantContext with all of the builder data.make
(boolean leaveModifyableAsIs) Tells this builder that the resulting VariantContext should not contain any GenotypeContextnoID()
Tells us that the resulting VariantContext should not have an IDTells this builder that the resulting VariantContext should have PASS filtersputAttributes
(Map<String, ?> attributes) Tells this builder to put this map of attributes into the resultingVariantContext
.rmAttribute
(String key) Removes key if present in the attributesrmAttributes
(List<String> keys) Removes list of keys if present in the attributesTells us that the resulting VariantContext should have source field set to sourcestart
(long start) Tells us that the resulting VariantContext should have the specified contig startstop
(long stop) Tells us that the resulting VariantContext should have the specified contig stopTells this builder that the resulting VariantContext be unfiltered
-
Constructor Details
-
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
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
-
VariantContextBuilder
-
-
Method Details
-
getContig
Getter for contig- Returns:
- the current contig
-
getStart
public long getStart()Getter for start position- Returns:
- the current start position
-
getStop
public long getStop()Getter for stop position- Returns:
- the current stop position
-
getID
Getter for id of variant- Returns:
- the current variant id
-
getGenotypes
Getter for genotypes (DANGEROUS!!! DOES NOT MAKE A COPY!!!)- Returns:
- the current GenotypeContext
-
getFilters
Getter for filters (DANGEROUS!!! DOES NOT MAKE A COPY!!!)- Returns:
- the current set of filters
-
getAttributes
Getter for attributes (DANGEROUS!!! DOES NOT MAKE A COPY!!!)- Returns:
- the current map of attributes
-
copy
-
alleles
Tells this builder to use this collection of alleles for the resulting VariantContext- Parameters:
alleles
- a Collection of alleles to set as the alleles of this builder- Returns:
- this builder
-
alleles
-
alleles
-
getAlleles
-
attributes
Tells this builder to use this map of attributes for the resultingVariantContext
. 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 benull
-> 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 implementsSerializable
or else serialization will fail.- Parameters:
attributes
- a Map of attributes to replace existing attributes with
-
putAttributes
Tells this builder to put this map of attributes into the resultingVariantContext
. The contents of the Map are copied to the current Map (or a new one is created if null) 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 implementsSerializable
or else serialization will fail.- Parameters:
attributes
- a Map of attributes to complement any existing attributes with, overwriting any that share the same key.
-
attribute
Puts the key -> value mapping into this builder's attributes- Parameters:
key
- key for the attributevalue
- value for the attribute (must be of a type that implementsSerializable
or else serialization will fail)
-
rmAttribute
Removes key if present in the attributes- Parameters:
key
- key to remove- Returns:
- this builder
-
rmAttributes
Removes list of keys if present in the attributes- Parameters:
keys
- list of keys to remove- Returns:
- this builder
-
filters
This builder's filters are set to this value filters can benull
-> meaning there are no filters- Parameters:
filters
- Set of strings to set as the filters for this builder This set will be copied so that external set can be safely changed.- Returns:
- this builder
-
filters
filters
- Parameters:
filters
- Strings to set as the filters for this builder- Returns:
- this builder
-
filter
Adds the given filter to the list of filters- Parameters:
filter
-- Returns:
-
passFilters
Tells this builder that the resulting VariantContext should have PASS filters- Returns:
- this builder
-
unfiltered
Tells this builder that the resulting VariantContext be unfiltered- Returns:
- this builder
-
genotypes
Tells this builder that the resultingVariantContext
should use this genotype'sGenotypeContext
. Note that this method will call the immutable method on the provided genotypes object to ensure that the user will not modify it further. Note that genotypes can benull
-> meaning there are no genotypes- Parameters:
genotypes
- GenotypeContext to use in this builder- Returns:
- this builder
-
genotypesNoValidation
-
genotypes
Tells this builder that the resultingVariantContext
should use aGenotypeContext
containing genotypes Note that genotypes can benull
, meaning there are no genotypes- Parameters:
genotypes
- Collection of genotypes to set as genotypes for this builder
-
genotypes
Tells this builder that the resultingVariantContext
should use aGenotypeContext
containing genotypes- Parameters:
genotypes
- genotypes to set as genotypes for this builder
-
noGenotypes
Tells this builder that the resulting VariantContext should not contain any GenotypeContext -
id
Tells us that the resulting VariantContext should have ID- Parameters:
ID
- id of variant- Returns:
- this builder
-
noID
Tells us that the resulting VariantContext should not have an ID- Returns:
- this builder
-
log10PError
Tells us that the resulting VariantContext should have log10PError- Parameters:
log10PError
- value of QUAL field for this builder- Returns:
- this builder
-
source
Tells us that the resulting VariantContext should have source field set to source- Parameters:
source
- string describing the source of the variant- Returns:
- this builder
-
loc
Tells us that the resulting VariantContext should have the specified location- Parameters:
contig
- the contig the variant is on (must be in the dictionary)start
- the start position of the variantstop
- the end position of the variant- Returns:
- this builder
-
chr
Tells us that the resulting VariantContext should have the specified contig chr- Parameters:
contig
- the contig of the variant- Returns:
- this builder
-
start
Tells us that the resulting VariantContext should have the specified contig start- Parameters:
start
- the start position of the variant- Returns:
- this builder
-
stop
Tells us that the resulting VariantContext should have the specified contig stop- Parameters:
stop
- the stop position of the variant- Returns:
- this builder
-
computeEndFromAlleles
- See Also:
-
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 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
-
isFullyDecoded
public boolean isFullyDecoded()- Returns:
- true if this builder contains fully decoded data See VariantContext for more information
-
fullyDecoded
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
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. -
make
-