Package htsjdk.variant.variantcontext
Class GenotypeBuilder
- java.lang.Object
-
- htsjdk.variant.variantcontext.GenotypeBuilder
-
public final class GenotypeBuilder extends Object
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
Constructors Constructor Description GenotypeBuilder()
Create a empty builder.GenotypeBuilder(Genotype g)
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GenotypeBuilder
AD(int[] AD)
This genotype has this AD valueGenotypeBuilder
alleles(List<Allele> alleles)
Set this genotype's allelesGenotypeBuilder
attribute(String key, Object value)
This genotype has this attribute key / value pair.GenotypeBuilder
attributes(Map<String,Object> attributes)
This genotype has these attributes.GenotypeBuilder
copy(Genotype g)
Copy all of the values for this builder from Genotype gstatic Genotype
create(String sampleName, List<Allele> alleles)
protected static Genotype
create(String sampleName, List<Allele> alleles, double[] gls)
static Genotype
create(String sampleName, List<Allele> alleles, Map<String,Object> attributes)
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).GenotypeBuilder
DP(int DP)
This genotype has this DP valueGenotypeBuilder
filter(String filter)
Most efficient version of setting filters -- just set the filters string to filtersGenotypeBuilder
filters(String... filters)
varargs version of #filtersGenotypeBuilder
filters(List<String> 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.GenotypeBuilder
GQ(int GQ)
GenotypeBuilder
log10PError(double pLog10Error)
Set the GQ with a log10PError valueGenotype
make()
Create a new Genotype object using the values set in this builder.Genotype
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.GenotypeBuilder
maxAttributes(int i)
Tell's this builder that we have at most these number of attributesGenotypeBuilder
name(String sampleName)
Set this genotype's nameGenotypeBuilder
noAD()
This genotype has no AD valueGenotypeBuilder
noAttributes()
Tells this builder to remove all extended attributesGenotypeBuilder
noDP()
This genotype has no DP valueGenotypeBuilder
noGQ()
This genotype has no GQ valueGenotypeBuilder
noPL()
This genotype has no PL valueGenotypeBuilder
phased(boolean phased)
Is this genotype phased?GenotypeBuilder
PL(double[] GLs)
This genotype has this PL value, converted from double[].GenotypeBuilder
PL(int[] PL)
This genotype has this PL value, as int[].void
reset(boolean keepSampleName)
Reset all of the builder attributes to their defaults.GenotypeBuilder
unfiltered()
This genotype is unfiltered
-
-
-
Constructor Detail
-
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
public GenotypeBuilder(String sampleName)
Create a builder using sampleName. Alleles must be provided before trying to make a Genotype from this builder.- Parameters:
sampleName
-
-
GenotypeBuilder
public GenotypeBuilder(String sampleName, List<Allele> alleles)
Make a builder using sampleName and alleles for starting values- Parameters:
sampleName
-alleles
-
-
GenotypeBuilder
public GenotypeBuilder(Genotype g)
Create a new builder starting with the values in Genotype g- Parameters:
g
-
-
-
Method Detail
-
create
public static Genotype create(String sampleName, List<Allele> alleles, Map<String,Object> attributes)
-
createMissing
public 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). 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
public GenotypeBuilder copy(Genotype g)
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
public Genotype 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
public Genotype 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
public GenotypeBuilder name(String sampleName)
Set this genotype's name- Parameters:
sampleName
-- Returns:
-
alleles
public GenotypeBuilder alleles(List<Allele> alleles)
Set this genotype's alleles- Parameters:
alleles
-- Returns:
-
phased
public GenotypeBuilder phased(boolean phased)
Is this genotype phased?- Parameters:
phased
-- Returns:
-
GQ
public GenotypeBuilder GQ(int GQ)
-
log10PError
public GenotypeBuilder log10PError(double pLog10Error)
Set the GQ with a log10PError value- Parameters:
pLog10Error
-- Returns:
-
noGQ
public GenotypeBuilder noGQ()
This genotype has no GQ value- Returns:
-
noAD
public GenotypeBuilder noAD()
This genotype has no AD value- Returns:
-
noDP
public GenotypeBuilder noDP()
This genotype has no DP value- Returns:
-
noPL
public GenotypeBuilder noPL()
This genotype has no PL value- Returns:
-
DP
public GenotypeBuilder DP(int DP)
This genotype has this DP value- Returns:
-
AD
public GenotypeBuilder AD(int[] AD)
This genotype has this AD value- Returns:
-
PL
public GenotypeBuilder PL(int[] PL)
This genotype has this PL value, as int[]. FAST- Returns:
-
PL
public GenotypeBuilder PL(double[] GLs)
This genotype has this PL value, converted from double[]. SLOW- Returns:
-
attributes
public GenotypeBuilder attributes(Map<String,Object> 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
public GenotypeBuilder noAttributes()
Tells this builder to remove all extended attributes- Returns:
-
attribute
public GenotypeBuilder attribute(String key, Object value)
This genotype has this attribute key / value pair. Cannot contain inline attributes (DP, AD, GQ, PL). Note: this is not checked- Returns:
-
filters
public GenotypeBuilder filters(List<String> 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
public GenotypeBuilder filters(String... filters)
varargs version of #filters- Parameters:
filters
-- Returns:
-
filter
public GenotypeBuilder filter(String 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
public GenotypeBuilder unfiltered()
This genotype is unfiltered- Returns:
-
maxAttributes
public GenotypeBuilder maxAttributes(int i)
Tell's this builder that we have at most these number of attributes- Returns:
-
-