Class StorageTable
-
Constructor Summary
ConstructorsConstructorDescriptionStorageTable
(Storage storage) Constructs an instance of theStorageTable
class with the specified storage. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addContigFilter
(String contigIdentifier, int[] positions) Updates the contig filter with the specified contig identifier and positions.boolean
addFeatureFilter
(String featureIdentifierOrName) Adds a feature filter using the provided identifier or name.boolean
addSampleFilter
(String sampleIdentifier) Adds a sample filter using the provided identifier.void
Clears all filters used for building the table.void
Populates thetable
with data ofFeature
s from the storage.void
Populates thetable
with data ofFeature
s from the storage.void
Populates thetable
with data ofVariant
s from the storage.void
populateWithAlleleProfile
(boolean enumerate) Populates thetable
with allele profile data from the storage.void
populateWithProteoformProfile
(boolean enumerate) Populates thetable
with proteoform profile data from the storage.void
populateWithVariantsProfile
(boolean simple) Populates thetable
with variant profile data from the storage.void
print
(boolean all) Prints the contents of thetable
to the standard output.void
setFilters
(Set<String> query) Sets filters for building the table based on the provided query strings.void
write()
Writes the currenttable
to a TSV file in the current user directory atSystem.getProperty("user.dir")
.void
Writes the currenttable
to a tabular file with the specified separator.
-
Constructor Details
-
StorageTable
Constructs an instance of theStorageTable
class with the specified storage.- Parameters:
storage
- TheStorage
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
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
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, andfalse
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
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, andfalse
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
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 thetable
with data ofVariant
s 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:
- chrom: Chromosome/contig identifier.
- position: Variant position.
- reference: Reference allele/base content.
- alternative: Alternative allele/base content.
- type: Variant type, see
Variant.Type
. - feature_id: Affected feature name or
null
. - impact: Impact of the variant or
null
. - effect: Effect of the variant or
null
. Constants.AttributesKeys.VARIANT_FREQUENCY
: Variant frequency wrt. samples.Constants.AttributesKeys.MEAN_COVERAGE
: Mean coverage wrt. samples.Constants.AttributesKeys.MEAN_ENTROPY
: Mean entropy wrt. samples.
-
populateFromFeatures
public void populateFromFeatures()Populates thetable
with data ofFeature
s 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:
- chrom: Chromosome/contig identifier.
- start: Start position of the feature.
- end: End position of the feature.
- strand: Strand information (+/-).
- id: Feature identifier.
- name: Feature name.
- type: Feature type.
Constants.AttributesKeys.NUMBER_OF_ALLELES
: Number of non-reference alleles associated with the feature.Constants.AttributesKeys.DIVERSITY_ALLELE
: Diversity of alleles associated with the feature.Constants.AttributesKeys.FREQUENCY_REFERENCE
: Fraction of samples with the reference allele wrt. the feature.Constants.AttributesKeys.NUMBER_OF_PROTEOFORMS
: Number of non-reference proteoforms associated with the feature (0 for non-coding features).Constants.AttributesKeys.DIVERSITY_PROTEOFORM
: Diversity of proteoforms associated with the feature (0.0 for non-coding features).Constants.AttributesKeys.FREQUENCY_DISRUPTED
: Fraction of samples with disrupted proteoforms associated with the feature (0.0 for non-coding features).
-
populateFromSamples
public void populateFromSamples()Populates thetable
with data ofFeature
s 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 thetable
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 thetable
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 thetable
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
Writes the currenttable
to a tabular file with the specified separator.If the table is not populated (i.e., it is
null
or empty), anIllegalStateException
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 currenttable
to a TSV file in the current user directory atSystem.getProperty("user.dir")
.If the table is not populated (i.e., it is
null
or empty), anIllegalStateException
is thrown. -
print
public void print(boolean all) Prints the contents of thetable
to the standard output.This method checks if the
table
is populated and not empty before printing. If the table is not populated, anIllegalStateException
is thrown. Depending on the value of theall
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.
-