Package htsjdk.variant.variantcontext
Class GenotypeBuilder
java.lang.Object
htsjdk.variant.variantcontext.GenotypeBuilder
A builder class for genotypes
Provides convenience setter methods for all of the Genotype field
values. Setter methods can be used in any order, allowing you to
pass through states that wouldn't be allowed in the highly regulated
immutable Genotype class.
All fields default to meaningful MISSING values.
Call make() to actually create the corresponding Genotype object from
this builder. Can be called multiple times to create independent copies,
or with intervening sets to conveniently make similar Genotypes with
slight modifications.
Re-using the same GenotypeBuilder to build multiple Genotype objects via calls
to make() is dangerous, since reference types in the builder (eg., Collections/arrays)
don't get copied when making each Genotype. To safely re-use the same builder object
multiple times, use makeWithShallowCopy() instead of make().
- Since:
- 06/12
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a empty builder.Create a new builder starting with the values in Genotype gGenotypeBuilder
(String sampleName) Create a builder using sampleName.GenotypeBuilder
(String sampleName, List<Allele> alleles) Make a builder using sampleName and alleles for starting values -
Method Summary
Modifier and TypeMethodDescriptionAD
(int[] AD) This genotype has this AD valueSet this genotype's allelesThis genotype has this attribute key / value pair.attributes
(Map<String, Object> attributes) This genotype has these attributes.Copy all of the values for this builder from Genotype gstatic Genotype
protected static Genotype
static Genotype
static Genotype
createMissing
(String sampleName, int ploidy) Create a new Genotype object for a sample that's missing from the VC (i.e., in the output header).DP
(int DP) This genotype has this DP valueMost efficient version of setting filters -- just set the filters string to filtersvarargs version of #filtersTells this builder to make a Genotype object that has had filters applied, which may be empty (passes) or have some value indicating the reasons why it's been filtered.GQ
(int GQ) log10PError
(double pLog10Error) Set the GQ with a log10PError valuemake()
Create a new Genotype object using the values set in this builder.Create a new Genotype object using the values set in this builder, and perform a shallow copy of reference types to allow safer re-use of this builder After creation the values in this builder can be modified and more Genotypes created.maxAttributes
(int i) Tell's this builder that we have at most these number of attributesSet this genotype's namenoAD()
This genotype has no AD valueTells this builder to remove all extended attributesnoDP()
This genotype has no DP valuenoGQ()
This genotype has no GQ valuenoPL()
This genotype has no PL valuephased
(boolean phased) Is this genotype phased?PL
(double[] GLs) This genotype has this PL value, converted from double[].PL
(int[] PL) This genotype has this PL value, as int[].final void
reset
(boolean keepSampleName) Reset all of the builder attributes to their defaults.This genotype is unfiltered
-
Constructor Details
-
GenotypeBuilder
public GenotypeBuilder()Create a empty builder. Both a sampleName and alleles must be provided before trying to make a Genotype from this builder. -
GenotypeBuilder
Create a builder using sampleName. Alleles must be provided before trying to make a Genotype from this builder.- Parameters:
sampleName
-
-
GenotypeBuilder
Make a builder using sampleName and alleles for starting values- Parameters:
sampleName
-alleles
-
-
GenotypeBuilder
Create a new builder starting with the values in Genotype g- Parameters:
g
-
-
-
Method Details
-
create
-
create
-
create
-
createMissing
Create a new Genotype object for a sample that's missing from the VC (i.e., in the output header). Defaults to a diploid no call genotype ./.- Parameters:
sampleName
- the name of this sample- Returns:
- an initialized Genotype with sampleName that's a diploid ./. no call genotype
-
copy
Copy all of the values for this builder from Genotype g- Parameters:
g
-- Returns:
-
reset
public final void reset(boolean keepSampleName) Reset all of the builder attributes to their defaults. After this function you must provide sampleName and alleles before trying to make more Genotypes. -
make
Create a new Genotype object using the values set in this builder. After creation the values in this builder can be modified and more Genotypes created, althrough the contents of array values like PL should never be modified inline as they are not copied for efficiency reasons. Note: if attributes are added via this builder after a call to make(), the new Genotype will be modified. UsemakeWithShallowCopy()
to safely re-use the same builder object multiple times.- Returns:
- a newly minted Genotype object with values provided from this builder
-
makeWithShallowCopy
Create a new Genotype object using the values set in this builder, and perform a shallow copy of reference types to allow safer re-use of this builder After creation the values in this builder can be modified and more Genotypes created.- Returns:
- a newly minted Genotype object with values provided from this builder
-
name
Set this genotype's name- Parameters:
sampleName
-- Returns:
-
alleles
Set this genotype's alleles- Parameters:
alleles
-- Returns:
-
phased
Is this genotype phased?- Parameters:
phased
-- Returns:
-
GQ
-
log10PError
Set the GQ with a log10PError value- Parameters:
pLog10Error
-- Returns:
-
noGQ
This genotype has no GQ value- Returns:
-
noAD
This genotype has no AD value- Returns:
-
noDP
This genotype has no DP value- Returns:
-
noPL
This genotype has no PL value- Returns:
-
DP
This genotype has this DP value- Returns:
-
AD
This genotype has this AD value- Returns:
-
PL
This genotype has this PL value, as int[]. FAST- Returns:
-
PL
This genotype has this PL value, converted from double[]. SLOW- Returns:
-
attributes
This genotype has these attributes. Attributes are added to previous ones. Cannot contain inline attributes (DP, AD, GQ, PL). Note: this is not checked- Returns:
-
noAttributes
Tells this builder to remove all extended attributes- Returns:
-
attribute
This genotype has this attribute key / value pair. Cannot contain inline attributes (DP, AD, GQ, PL). Note: this is not checked- Returns:
-
filters
Tells this builder to make a Genotype object that has had filters applied, which may be empty (passes) or have some value indicating the reasons why it's been filtered.- Parameters:
filters
- non-null list of filters. empty list => PASS- Returns:
- this builder
-
filters
varargs version of #filters- Parameters:
filters
-- Returns:
-
filter
Most efficient version of setting filters -- just set the filters string to filters- Parameters:
filter
- if filters == null or filters.equals("PASS") => genotype is PASS- Returns:
-
unfiltered
This genotype is unfiltered- Returns:
-
maxAttributes
Tell's this builder that we have at most these number of attributes- Returns:
-