Class Variant
This class represents a nucleotide variant, including its reference base content, type (e.g., SNV, insertion, deletion), and occurrences
in samples and alleles. It provides methods to determine the type of the variant, check its canonical or padded canonical status. It
extends the Attributes
class to inherit functionality for managing attributes associated with the variant.
In contrast to other entities in the model, this class does not implement an identifier, but the combination of position
,
reference
, and alternative
is used as such. Variants are stored in the Contig.variants
property of the model.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Represents a simplified variant stub with position and alternative allele information.static enum
Enum representing the type of variant. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Indicates whether this variant is active.final String
The alternative base content of this variant.final int
The 1-based position of this variant on a contig.final String
The reference base content of this variant.final Variant.Type
The type of this variant (e.g., SNV, insertion, deletion). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAlleleRelation
(String featureIdentifier, String alleleIdentifier) Associates an allele and its parent feature with this variant.void
addSampleRelation
(String sampleIdentifier, Set<VariantCall> variantCalls) Associates a sample with this variant by adding the sample identifier and its associated variant calls.Converts this variant to a masked stub representation.asStub()
Converts this variant to a simplified stub representation.boolean
Compares this variant to another object for equality.getFeatureRelation
(String featureIdentifier) Retrieves a set of allele identifiers associated with a specific feature for this variant.Retrieves a set of tuples representing the feature and allele occurrences associated with this variant.Retrieves a set of sample identifiers that have occurrences of this variant.getSampleRelation
(String sampleIdentifier) Retrieves the variant call string associated with a specific sample.int
hashCode()
Computes the hash code for this variant.boolean
Checks if all variant calls for this variant are filtered.boolean
isFiltered
(String sampleIdentifier) Checks if the variant is filtered with respect to a specific sample.boolean
isFiltered
(Collection<String> sampleIdentifiers) Checks if the variant is filtered with respect to all specified samples.boolean
Checks if the variant is associated with a specific allele.boolean
ofAlleles
(Collection<String> alleleIdentifiers) Checks if the variant is associated with any of the specified alleles.boolean
Checks if the variant is associated with a specific feature.boolean
ofFeatures
(Collection<String> featureIdentifiers) Checks if the variant is associated with any of the specified features.boolean
Checks if the variant is associated with a specific sample.boolean
ofSamples
(Collection<String> sampleIdentifiers) Checks if the variant is associated with any of the specified samples.toString()
Converts the variant to its string representation.Methods inherited from class model.Attributes
attributesAsString, attributesAsString, clearAttributes, extendAttribute, extendAttributes, getAttribute, getAttributeOrDefault, getAttributes, getAttributeSet, hasAnyAttribute, hasAttribute, removeAttribute, setAttribute, setAttributeIfAbsent, setAttributes, setAttributesIfAbsent
-
Field Details
-
position
public final int positionThe 1-based position of this variant on a contig. -
reference
The reference base content of this variant. -
alternative
The alternative base content of this variant. -
type
The type of this variant (e.g., SNV, insertion, deletion). -
active
protected transient boolean activeIndicates whether this variant is active.This boolean flag is used to mark variants that are newly identified and not present in an existing storage or modified. It is set to
true
for newly created or touched entries, but will not be serialized. During deserialization, it is assumed that all variants are idle and should be set tofalse
(seeStorage.typeAdapter()
).
-
-
Constructor Details
-
Variant
Constructs a newVariant
instance, based on the provided position, reference, and alternative content.The constructor determines the type of variant based on the reference and alternative content as well as if the reference and alternative content match any padded canonical content type. If they do not, an
IllegalArgumentException
is thrown.- Parameters:
position
- The 1-based position of the variant on a contig.reference
- The reference base content of the variant.alternative
- The alternative base content of the variant.- Throws:
IllegalArgumentException
- If the reference and alternative content do not match any padded canonical content type.
-
-
Method Details
-
ofSample
Checks if the variant is associated with a specific sample.- Parameters:
sampleIdentifier
- The unique identifier of the sample to check.- Returns:
true
if the variant is associated with the given sample identifier,false
otherwise.
-
ofSamples
Checks if the variant is associated with any of the specified samples.- Parameters:
sampleIdentifiers
- A collection of sample identifiers to check.- Returns:
true
if the variant is associated with at least one of the given sample identifiers,false
otherwise.
-
ofFeature
Checks if the variant is associated with a specific feature.This method determines whether the given feature identifier exists in the
features
map. Thefeatures
map contains associations between feature identifiers and their related alleles.- Parameters:
featureIdentifier
- The unique identifier of the feature to check.- Returns:
true
if the feature identifier exists in thefeatures
map;false
otherwise.
-
ofFeatures
Checks if the variant is associated with any of the specified features.- Parameters:
featureIdentifiers
- A collection of feature identifiers to check.- Returns:
true
if the variant is associated with at least one of the given feature identifiers,false
otherwise.
-
ofAllele
Checks if the variant is associated with a specific allele.- Parameters:
alleleIdentifier
- The unique identifier of the allele to check.- Returns:
true
if the variant is associated with the given allele identifier,false
otherwise.
-
ofAlleles
Checks if the variant is associated with any of the specified alleles.- Parameters:
alleleIdentifiers
- A collection of allele identifiers to check.- Returns:
true
if the variant is associated with at least one of the given allele identifiers,false
otherwise.
-
isFiltered
Checks if the variant is filtered with respect to a specific sample.Retrieves the variant call string associated with the given sample identifier from the `samples` map. It then checks if the variant call is filtered using the
VariantCall.isFiltered(String)
method. If the sample identifier does not exist in the map, the method returnsfalse
, indicating that the variant is considered not filtered.- Parameters:
sampleIdentifier
- The identifier of the sample to check.- Returns:
true
if the variant is filtered for the specified sample;false
otherwise.
-
isFiltered
Checks if the variant is filtered with respect to all specified samples.See
isFiltered(String)
.- Parameters:
sampleIdentifiers
- A collection of sample identifiers to check.- Returns:
true
if the variant is filtered for all specified samples;false
otherwise.
-
isFiltered
public boolean isFiltered()Checks if all variant calls for this variant are filtered.This method iterates through all variant calls in the `samples` map and checks if each call is filtered using the
VariantCall.isFiltered(String)
method. If all calls are filtered, it returnstrue
; otherwise, it returnsfalse
.- Returns:
true
if all variant calls for this variant are filtered;false
otherwise.
-
getRelatedSamples
Retrieves a set of sample identifiers that have occurrences of this variant.This method returns an unmodifiable set of sample identifiers associated with this variant. The collection ensures that external modifications are not allowed, preserving the integrity of the data.
- Returns:
- A set of sample identifiers that have occurrences of this variant.
-
getSampleRelation
Retrieves the variant call string associated with a specific sample.This method fetches the variant call string for the given sample identifier from the `samples` map. If the sample identifier does not exist in the map, it returns
null
.- Parameters:
sampleIdentifier
- The unique identifier of the sample whose relation is to be retrieved.- Returns:
- The variant call string associated with the given sample identifier, or
null
if the sample is not found.
-
getFeatureRelation
Retrieves a set of allele identifiers associated with a specific feature for this variant.This method fetches the set of allele identifiers for the given feature identifier from the `features` map. If the feature identifier does not exist in the map, it returns an empty set.
- Parameters:
featureIdentifier
- The unique identifier of the feature whose allele relations are to be retrieved.- Returns:
- A set of allele identifiers associated with the given feature identifier, or an empty set if the feature is not found.
-
getRelatedAlleles
Retrieves a set of tuples representing the feature and allele occurrences associated with this variant. -
addSampleRelation
Associates a sample with this variant by adding the sample identifier and its associated variant calls.This method updates the `samples` map by associating the given sample identifier with a string representation of the provided variant calls. The variant calls are converted to strings using their `toString` method and concatenated with a pipe ('|') delimiter.
This will also mark the variant as active by setting the
active
property totrue
, indicating that the variant has been modified. This will overwrite any existing association for the given sample identifier.- Parameters:
sampleIdentifier
- The unique identifier of the sample to associate with this variant.variantCalls
- A set ofVariantCall
objects representing the variant calls to associate with the sample. Each variant call is converted to its string representation.
-
addAlleleRelation
Associates an allele and its parent feature with this variant.- Parameters:
featureIdentifier
- The identifier of the feature to associate with this variant.alleleIdentifier
- The identifier of the allele to associate with the feature.
-
asStub
Converts this variant to a simplified stub representation.This method creates a
Variant.Stub
object that encapsulates the position and alternative allele of this variant. The stub serves as a simplified representation of the variant.- Returns:
- A
Variant.Stub
object containing the position and alternative allele of this variant.
-
asMaskedStub
Converts this variant to a masked stub representation.This method creates a
Variant.Stub
object that encapsulates the position of this variant and a masked alternative allele represented byConstants.ANY_NUCLEOTIDE
.- Returns:
- A
Variant.Stub
object containing the position of this variant and a masked alternative allele.
-
toString
Converts the variant to its string representation.This method generates a string representation of the variant based on its type:
- For
Variant.Type.SNV
, the format is: "prefix + position + reference + '>' + alternative". - For
Variant.Type.INSERTION
, the format is: "prefix + position + '_' + (position + 1) + 'ins' + alternative". - For
Variant.Type.DELETION
, the format is: "prefix + position + '_' + (position + reference.length() - 1) + 'del'".
- For
-
hashCode
public int hashCode()Computes the hash code for this variant.This method calculates the hash code of the variant based on its string representation.
-
equals
Compares this variant to another object for equality.This method checks if the provided object is the same instance as this object. If not, it verifies that the object is of the same class and compares their string representations for equality.
-