Package op

Class StorageTable

java.lang.Object
op.StorageTable

public class StorageTable extends Object
The StorageTable class provides functionality to create and manage tabular representations of genomic data stored in a Storage instance using the tablesaw library.
  • Constructor Details

    • StorageTable

      public StorageTable(Storage storage)
      Constructs an instance of the StorageTable class with the specified storage.
      Parameters:
      storage - The Storage instance containing genomic data.
  • Method Details

    • clearFilters

      public void clearFilters()
      Clears all filters used for building the table.

      This method removes all entries from the contig, feature, and sample filters. After calling this method, the filters will be empty, and the user must reapply filters if needed before populating the table.

    • addContigFilter

      public boolean addContigFilter(String contigIdentifier, int[] positions)
      Updates the contig filter with the specified contig identifier and positions.

      If the contig identifier does not exist in the storage, no action is taken and false is returned.

      If the contig identifier already exists in the filter, its associated positions are replaced. An empty array of positions indicates that all positions within the contig should be included. If the filter is successfully updated, true is returned.

      The table is not automatically updated after modifying the filter; the user must call one of the populate methods to refresh the table.

      Parameters:
      contigIdentifier - The identifier of the contig to be added or updated in the filter.
      positions - An array of positions (as integers) associated with the contig. If the array is empty, it indicates that all positions within the contig should be included.
      Returns:
      true if the filter was successfully updated; false if the contig identifier does not exist in the storage.
    • addFeatureFilter

      public boolean addFeatureFilter(String featureIdentifierOrName)
      Adds a feature filter using the provided identifier or name.

      This method checks if the given feature identifier or name exists in the storage. If it exists, the feature is added to the featureFilter. If the feature does not exist, no changes are made, and false is returned.

      The table is not automatically updated after modifying the filter; the user must call one of the populate methods to refresh the table.

      Parameters:
      featureIdentifierOrName - The identifier or name of the feature to include in the filter.
      Returns:
      true if the feature was successfully added to the filter; false if the feature does not exist in the storage.
    • addSampleFilter

      public boolean addSampleFilter(String sampleIdentifier)
      Adds a sample filter using the provided identifier.

      This method checks if the given sample identifier exists in the storage. If it exists, the sample is added to the sampleFilter. If the sample does not exist, no changes are made, and false is returned.

      The table is not automatically updated after modifying the filter; the user must call one of the populate methods to refresh the table.

      Parameters:
      sampleIdentifier - The identifier of the sample to include in the filter.
      Returns:
      true if the sample was successfully added to the filter; false if the sample does not exist in the storage.
    • setFilters

      public void setFilters(Set<String> query)
      Sets filters for building the table based on the provided query strings.

      This method clears all existing filters and processes each query string to determine the type of filter to apply. Queries can specify sample filters, feature filters, or contig filters with optional position ranges.

      The method performs the following steps for each query:

      • Trims the query string and skips blank queries.
      • Attempts to add the query as a sample or feature filter.
      • If not a sample or feature, parses the query as a contig filter with optional position ranges.
      • Handles position ranges in the format "start-end" or "start" and generates an array of positions.

      If the query cannot be parsed (e.g., due to invalid formatting), it is ignored.

      Parameters:
      query - A set of query strings specifying the filters to apply.
    • populateFromVariants

      public void populateFromVariants()
      Populates the table with data of Variants from the storage.

      The table is created with predefined columns and filled with variant data filtered by the current contig, position, sample, and feature filters. The table is then sorted in ascending order based on chromosome and position.

      The columns of the table include:

    • populateFromFeatures

      public void populateFromFeatures()
      Populates the table with data of Features from the storage.

      The table is created with predefined columns and filled with feature data filtered by the current contig and feature filters. Additional attributes are dynamically added as columns if they are not part of the standard attributes. The table is then sorted in ascending order based on chromosome and start position.

      The (default) columns of the table include:

    • populateFromSamples

      public void populateFromSamples()
      Populates the table with data of Features from the storage.

      The table is created with predefined columns and filled with sample data filtered by the current sample filter. Additional attributes are dynamically added as columns if they are not part of the standard attributes. The table is then sorted in ascending order based on diversity allele and diversity proteoform.

      The (default) columns of the table include:

    • populateWithAlleleProfile

      public void populateWithAlleleProfile(boolean enumerate)
      Populates the table with allele profile data from the storage.

      Each row in the table represents a sample, with the first column being the sample identifier ("id") and subsequent columns representing features. The values in the feature columns are allele identifiers or numeric indices (0 represents the reference, 1 the first non-reference allele, and so on), depending on the `enumerate` flag.

      The data is filtered by the current contig and feature filters.

      Parameters:
      enumerate - A boolean flag indicating whether to replace allele identifiers with numeric indices.
    • populateWithProteoformProfile

      public void populateWithProteoformProfile(boolean enumerate)
      Populates the table with proteoform profile data from the storage.

      Each row in the table represents a sample, with the first column being the sample identifier ("id") and subsequent columns representing coding features. The values in the feature columns are proteoform identifiers or numeric indices (0 represents synonymous, 1 the first non-synonymous proteoform, and so on), depending on the `enumerate` flag.

      The data is filtered by the current contig and feature filters, and only coding features are included.

      Parameters:
      enumerate - A boolean flag indicating whether to replace proteoform identifiers with numeric indices.
    • populateWithVariantsProfile

      public void populateWithVariantsProfile(boolean simple)
      Populates the table with variant profile data from the storage.

      Each row in the table represents a unique variant position, with columns for chromosome, position, reference allele, and samples. The values in the sample columns are either the alternative allele or a placeholder (e.g., ".") if the sample does not have the variant. The `simple` flag determines whether to use a simplified representation of the variant calls.

      The data is filtered by the current contig, position, and sample filters.

      Parameters:
      simple - A boolean flag indicating whether to use a simplified representation of variant calls.
    • write

      public void write(String file, char separator)
      Writes the current table to a tabular file with the specified separator.

      If the table is not populated (i.e., it is null or empty), an IllegalStateException is thrown.

      Parameters:
      file - The path to the output file.
      separator - The character to use as the separator in the file.
    • write

      public void write()
      Writes the current table to a TSV file in the current user directory at System.getProperty("user.dir").

      If the table is not populated (i.e., it is null or empty), an IllegalStateException is thrown.

    • print

      public void print(boolean all)
      Prints the contents of the table to the standard output.

      This method checks if the table is populated and not empty before printing. If the table is not populated, an IllegalStateException is thrown. Depending on the value of the all parameter, it either prints the entire table or a truncated version.

      Parameters:
      all - A boolean flag indicating whether to print the entire table (true) or a truncated version (false).
      Throws:
      IllegalStateException - If the table is not populated or is empty.