diff --git a/src/main/java/htsjdk/variant/variantcontext/VariantContextBuilder.java b/src/main/java/htsjdk/variant/variantcontext/VariantContextBuilder.java index 33844dba9a..921f0630cb 100644 --- a/src/main/java/htsjdk/variant/variantcontext/VariantContextBuilder.java +++ b/src/main/java/htsjdk/variant/variantcontext/VariantContextBuilder.java @@ -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 getFilters() { + return filters; + } + + /** + * Getter for attributes (DANGEROUS!!! DOES NOT MAKE A COPY!!!) + * @return the current map of attributes + */ + public Map 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 @@ -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 alleles) { @@ -160,7 +216,7 @@ public VariantContextBuilder alleles(final Collection alleles) { } public VariantContextBuilder alleles(final List alleleStrings) { - final List alleles = new ArrayList(alleleStrings.size()); + final List alleles = new ArrayList<>(alleleStrings.size()); for ( int i = 0; i < alleleStrings.size(); i++ ) { alleles.add(Allele.create(alleleStrings.get(i), i == 0)); @@ -174,7 +230,7 @@ public VariantContextBuilder alleles(final String ... alleleStrings) { } public List getAlleles() { - return new ArrayList(alleles); + return new ArrayList<>(alleles); } /** @@ -190,7 +246,7 @@ public List 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 attributes) { this.attributes = new HashMap<>(); @@ -199,6 +255,32 @@ public VariantContextBuilder attributes(final Map attributes) { return this; } + + /** + * Tells this builder to put this map of attributes into the resulting VariantContext. 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 attributes) { + if (this.attributes == null) { + this.attributes = new HashMap<>(); + } + if (attributes != null) { + this.attributes.putAll(attributes); + } + this.attributesCanBeModified = true; + return this; + } + + /** * Puts the key -> value mapping into this builder's attributes * @@ -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(); @@ -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 keys) { makeAttributesModifiable(); @@ -255,7 +337,9 @@ private void makeAttributesModifiable() { * This builder's filters are set to this value * * filters can be null -> 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 filters) { this.filters = filters; @@ -265,8 +349,8 @@ public VariantContextBuilder filters(final Set 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(Arrays.asList(filters))); @@ -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); @@ -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; @@ -303,7 +387,8 @@ public VariantContextBuilder unfiltered() { * * Note that genotypes can be null -> 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; @@ -322,7 +407,7 @@ public VariantContextBuilder genotypesNoValidation(final GenotypesContext genoty * * Note that genotypes can be null, meaning there are no genotypes * - * @param genotypes + * @param genotypes Collection of genotypes to set as genotypes for this builder */ public VariantContextBuilder genotypes(final Collection genotypes) { return genotypes(GenotypesContext.copy(genotypes)); @@ -330,7 +415,7 @@ public VariantContextBuilder genotypes(final Collection genotypes) { /** * Tells this builder that the resulting VariantContext should use a GenotypeContext 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))); @@ -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; @@ -356,7 +441,7 @@ 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); @@ -364,8 +449,8 @@ public VariantContextBuilder noID() { /** * 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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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;