Package model

Class Sample


public class Sample extends Attributes
Represents a single biological sample.

This class provides a structure to store and manage variant calls associated with a biological sample. Furthermore, it allows the association with an allele per feature. It extends the Attributes class to inherit functionality for managing attributes associated with the sample.

Samples are stored in the Storage.samples property of the model.

  • Field Details

    • _id

      public final String _id
      Unique identifier of this sample.

      This field serves as the unique identifier for the sample and is used to reference it in the model. This should be at best a database identifier, such as a NCBI accession number, or strain identifier.

  • Constructor Details

    • Sample

      public Sample(String identifier, int capacityFeatures)
      Constructs a new Sample instance with the specified id and initial capacity for the alleles map.

      This constructor initializes a Sample object with the given identifier and allocates a HashMap instance for the alleles field with the specified initial capacity. The _id field is set to the provided identifier, and the superclass constructor is invoked to initialize inherited properties.

      Instances of this class are not related to variants from within this constructor. Instead, variants are linked via the Variant.samples and Allele classes.

      Parameters:
      identifier - The unique identifier of the sample, used as its unique key.
      capacityFeatures - The initial capacity for the alleles map, which stores feature-allele associations.
  • Method Details

    • addRelation

      public void addRelation(String featureIdentifier, String alleleIdentifier)
      Associates a specific allele of a feature with this sample.

      This method updates the alleles map by setting the sequence type (allele) for the specified feature. The feature and allele are identified by their id.

      Parameters:
      featureIdentifier - The id of the feature (Feature._id) to associate with the allele.
      alleleIdentifier - The unique identifier of the allele (SequenceType._id) to set for the feature.
    • getRelatedAllele

      public String getRelatedAllele(String featureIdentifier)
      Retrieves the allele associated with a specific feature in this sample.

      This method looks up the alleles map to find the allele associated with the given feature identifier. If no association exists, it returns the default reference allele defined in Constants.REFERENCE.

      Parameters:
      featureIdentifier - The unique identifier of the feature (Feature.name) to retrieve the associated allele for.
      Returns:
      The unique identifier of the allele (SequenceType._id) associated with the feature, or the default reference allele if no association exists.
    • getRelatedAlleles

      public Set<htsjdk.samtools.util.Tuple<String,String>> getRelatedAlleles()
      Retrieves all feature-allele associations in this sample.

      This method converts the alleles map, which stores feature names as keys and their associated allele identifiers as values, into a collection of Tuple objects. Each tuple contains a feature name and its corresponding allele identifier.

      Returns:
      A Set of Tuple objects, where each tuple represents a feature-allele association.
    • getRelatedAllelesCount

      public int getRelatedAllelesCount()
      Retrieves the number of alternate alleles in this sample.

      This method returns the size of the alleles map, which represents the number of unique alleles associated with features in this sample. This corresponds to the number of non-reference alleles present in the sample.

      Returns:
      The number of alleles in this sample.
    • toString

      public String toString()
      Converts the sample to its string representation.

      This method returns the unique identifier of the sample as its string representation.

      Overrides:
      toString in class Object
      Returns:
      A String representing the unique identifier of the sample.
    • hashCode

      public int hashCode()
      Computes the hash code for this sample.

      This method calculates the hash code of the sample based on its unique identifier.

      Overrides:
      hashCode in class Object
      Returns:
      The hash code of the sample.
    • equals

      public boolean equals(Object obj)
      Compares this sample to another object for equality.

      This method checks if the provided object is the same instance as this sample. If not, it verifies that the object is of the same class and compares their unique identifiers for equality.

      Overrides:
      equals in class Object
      Parameters:
      obj - The object to compare with this Sample instance.
      Returns:
      true if the objects are the same instance or if their unique identifiers are equal; false otherwise.