Skip to content

Commit

Permalink
add getters to VariantContextBuilder (#1247)
Browse files Browse the repository at this point in the history
* added getters for some of the VariantContextBuilder fields
  • Loading branch information
Yossi Farjoun authored and lbergelson committed Dec 21, 2018
1 parent a4b7da8 commit 0bf5ff6
Showing 1 changed file with 116 additions and 31 deletions.
147 changes: 116 additions & 31 deletions src/main/java/htsjdk/variant/variantcontext/VariantContextBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,62 @@ public VariantContextBuilder(final String source, final String contig, final lon
toValidate.add(VariantContext.Validation.ALLELES);
}

/**
* Getter for contig
* @return the current contig
*/
public String getContig() {
return contig;
}

/**
* Getter for start position
* @return the current start position
*/
public long getStart() {
return start;
}

/**
* Getter for stop position
* @return the current stop position
*/
public long getStop() {
return stop;
}

/**
* Getter for id of variant
* @return the current variant id
*/
public String getID() {
return ID;
}

/**
* Getter for genotypes (DANGEROUS!!! DOES NOT MAKE A COPY!!!)
* @return the current GenotypeContext
*/
public GenotypesContext getGenotypes() {
return genotypes;
}

/**
* Getter for filters (DANGEROUS!!! DOES NOT MAKE A COPY!!!)
* @return the current set of filters
*/
public Set<String> getFilters() {
return filters;
}

/**
* Getter for attributes (DANGEROUS!!! DOES NOT MAKE A COPY!!!)
* @return the current map of attributes
*/
public Map<String, Object> getAttributes() {
return attributes;
}

/**
* 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
Expand Down Expand Up @@ -150,7 +206,7 @@ public VariantContextBuilder copy() {
/**
* Tells this builder to use this collection of alleles for the resulting VariantContext
*
* @param alleles
* @param alleles a Collection of alleles to set as the alleles of this builder
* @return this builder
*/
public VariantContextBuilder alleles(final Collection<Allele> alleles) {
Expand All @@ -160,7 +216,7 @@ public VariantContextBuilder alleles(final Collection<Allele> alleles) {
}

public VariantContextBuilder alleles(final List<String> alleleStrings) {
final List<Allele> alleles = new ArrayList<Allele>(alleleStrings.size());
final List<Allele> alleles = new ArrayList<>(alleleStrings.size());

for ( int i = 0; i < alleleStrings.size(); i++ ) {
alleles.add(Allele.create(alleleStrings.get(i), i == 0));
Expand All @@ -174,7 +230,7 @@ public VariantContextBuilder alleles(final String ... alleleStrings) {
}

public List<Allele> getAlleles() {
return new ArrayList<Allele>(alleles);
return new ArrayList<>(alleles);
}

/**
Expand All @@ -190,7 +246,7 @@ public List<Allele> getAlleles() {
* Value for each attribute must be of a type that implements {@link Serializable} or else
* serialization will fail.
*
* @param attributes a Map of attributes to replace any existing attributes with
* @param attributes a Map of attributes to replace existing attributes with
*/
public VariantContextBuilder attributes(final Map<String, ?> attributes) {
this.attributes = new HashMap<>();
Expand All @@ -199,6 +255,32 @@ public VariantContextBuilder attributes(final Map<String, ?> attributes) {
return this;
}


/**
* Tells this builder to put this map of attributes into the resulting <code>VariantContext</code>. 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 implements {@link Serializable} or else
* serialization will fail.
*
* @param attributes a Map of attributes to complement any existing attributes with, overwriting any that
* share the same key.
*/
public VariantContextBuilder putAttributes(final Map<String, ?> attributes) {
if (this.attributes == null) {
this.attributes = new HashMap<>();
}
if (attributes != null) {
this.attributes.putAll(attributes);
}
this.attributesCanBeModified = true;
return this;
}


/**
* Puts the key -&gt; value mapping into this builder's attributes
*
Expand All @@ -215,7 +297,7 @@ public VariantContextBuilder attribute(final String key, final Object value) {
* Removes key if present in the attributes
*
* @param key key to remove
* @return
* @return this builder
*/
public VariantContextBuilder rmAttribute(final String key) {
makeAttributesModifiable();
Expand All @@ -227,7 +309,7 @@ public VariantContextBuilder rmAttribute(final String key) {
* Removes list of keys if present in the attributes
*
* @param keys list of keys to remove
* @return
* @return this builder
*/
public VariantContextBuilder rmAttributes(final List<String> keys) {
makeAttributesModifiable();
Expand Down Expand Up @@ -255,7 +337,9 @@ private void makeAttributesModifiable() {
* This builder's filters are set to this value
*
* filters can be <code>null</code> -&gt; meaning there are no filters
* @param filters
*
* @param filters Set of strings to set as the filters for this builder
* @return this builder
*/
public VariantContextBuilder filters(final Set<String> filters) {
this.filters = filters;
Expand All @@ -265,8 +349,8 @@ public VariantContextBuilder filters(final Set<String> filters) {
/**
* {@link #filters}
*
* @param filters
* @return
* @param filters Set of strings to set as the filters for this builder
* @return this builder
*/
public VariantContextBuilder filters(final String ... filters) {
filters(new LinkedHashSet<String>(Arrays.asList(filters)));
Expand All @@ -282,7 +366,7 @@ public VariantContextBuilder filter(final String filter) {
/**
* Tells this builder that the resulting VariantContext should have PASS filters
*
* @return
* @return this builder
*/
public VariantContextBuilder passFilters() {
return filters(VariantContext.PASSES_FILTERS);
Expand All @@ -291,7 +375,7 @@ public VariantContextBuilder passFilters() {
/**
* Tells this builder that the resulting VariantContext be unfiltered
*
* @return
* @return this builder
*/
public VariantContextBuilder unfiltered() {
this.filters = null;
Expand All @@ -303,7 +387,8 @@ public VariantContextBuilder unfiltered() {
*
* Note that genotypes can be <code>null</code> -&gt; meaning there are no genotypes
*
* @param genotypes
* @param genotypes GenotypeContext to use in this builder
* @return this builder
*/
public VariantContextBuilder genotypes(final GenotypesContext genotypes) {
this.genotypes = genotypes;
Expand All @@ -322,15 +407,15 @@ public VariantContextBuilder genotypesNoValidation(final GenotypesContext genoty
*
* Note that genotypes can be <code>null</code>, meaning there are no genotypes
*
* @param genotypes
* @param genotypes Collection of genotypes to set as genotypes for this builder
*/
public VariantContextBuilder genotypes(final Collection<Genotype> genotypes) {
return genotypes(GenotypesContext.copy(genotypes));
}

/**
* Tells this builder that the resulting <code>VariantContext</code> should use a <code>GenotypeContext</code> containing genotypes
* @param genotypes
* @param genotypes genotypes to set as genotypes for this builder
*/
public VariantContextBuilder genotypes(final Genotype ... genotypes) {
return genotypes(GenotypesContext.copy(Arrays.asList(genotypes)));
Expand All @@ -346,8 +431,8 @@ public VariantContextBuilder noGenotypes() {

/**
* Tells us that the resulting VariantContext should have ID
* @param ID
* @return
* @param ID id of variant
* @return this builder
*/
public VariantContextBuilder id(final String ID) {
this.ID = ID;
Expand All @@ -356,16 +441,16 @@ public VariantContextBuilder id(final String ID) {

/**
* Tells us that the resulting VariantContext should not have an ID
* @return
* @return this builder
*/
public VariantContextBuilder noID() {
return id(VCFConstants.EMPTY_ID_FIELD);
}

/**
* Tells us that the resulting VariantContext should have log10PError
* @param log10PError
* @return
* @param log10PError value of QUAL field for this builder
* @return this builder
*/
public VariantContextBuilder log10PError(final double log10PError) {
this.log10PError = log10PError;
Expand All @@ -374,8 +459,8 @@ public VariantContextBuilder log10PError(final double log10PError) {

/**
* Tells us that the resulting VariantContext should have source field set to source
* @param source
* @return
* @param source string describing the source of the variant
* @return this builder
*/
public VariantContextBuilder source(final String source) {
this.source = source;
Expand All @@ -384,10 +469,10 @@ public VariantContextBuilder source(final String source) {

/**
* Tells us that the resulting VariantContext should have the specified location
* @param contig
* @param start
* @param stop
* @return
* @param contig the contig the variant is on (must be in the dictionary)
* @param start the start position of the variant
* @param stop the end position of the variant
* @return this builder
*/
public VariantContextBuilder loc(final String contig, final long start, final long stop) {
this.contig = contig;
Expand All @@ -399,8 +484,8 @@ public VariantContextBuilder loc(final String contig, final long start, final lo

/**
* Tells us that the resulting VariantContext should have the specified contig chr
* @param contig
* @return
* @param contig the contig of the variant
* @return this builder
*/
public VariantContextBuilder chr(final String contig) {
this.contig = contig;
Expand All @@ -409,8 +494,8 @@ public VariantContextBuilder chr(final String contig) {

/**
* Tells us that the resulting VariantContext should have the specified contig start
* @param start
* @return
* @param start the start position of the variant
* @return this builder
*/
public VariantContextBuilder start(final long start) {
this.start = start;
Expand All @@ -420,8 +505,8 @@ public VariantContextBuilder start(final long start) {

/**
* Tells us that the resulting VariantContext should have the specified contig stop
* @param stop
* @return
* @param stop the stop position of the variant
* @return this builder
*/
public VariantContextBuilder stop(final long stop) {
this.stop = stop;
Expand Down

0 comments on commit 0bf5ff6

Please sign in to comment.