TrackData#

class alphagenome.data.track_data.TrackData(values, metadata, resolution=1, interval=None, uns=None)[source]#

Container for storing track values and metadata.

TrackData stores multiple genomic tracks at the same resolution, stacked into an N-dimensional array whose last axis is num_tracks (for example, shape (positional_bins, num_tracks)). It also contains metadata information as a pandas DataFrame with num_tracks rows.

Metadata DataFrame has two main required columns:

  • name: The name of the track.

  • strand: The strand of the track (‘+’, ‘-’, or ‘.’).

Other columns are optional.

Valid shapes of TrackData.values are:

  • [num_tracks]

  • [positional_bins, num_tracks]

  • [positional_bins, positional_bins, num_tracks]

  • …

TrackData can store both model predictions and raw data. It can optionally hold information about the genome.Interval from which the data were derived and .uns for storing additional unstructured data.

In addition to being a container, TrackData provides functionality for common aggregation and slicing operations.

values#

A numpy array of floats or integers representing the track values. Positional axes have the same length. Example valid shapes are: [num_tracks], [positional_bins, num_tracks], and [positional_bins, positional_bins, num_tracks].

metadata#

A pandas DataFrame containing metadata for each track. The DataFrame must have at least two columns: ‘name’ and ‘strand’.

resolution#

The resolution of the track data in base pairs.

interval#

An optional Interval object representing the genomic region.

uns#

An optional dictionary to store additional unstructured data.

positional_axes#

Tuple of positional dimension sizes in values.

num_tracks#

Total number of tracks along the last axis of values.

width#

Genomic width covered by the track bins (positional_bins * resolution).

names#

Array of track names from metadata['name'].

strands#

Array of track strands from metadata['strand'].

ontology_terms#

Optional list of OntologyTerm objects parsed from metadata['ontology_curie'].

Raises:

ValueError – If the number of tracks in values does not match the number of rows in metadata, or if metadata contains duplicate (name, strand) pairs, or if the positional axes have different lengths, or if the interval width does not match the expected width.

Methods

bin_index(relative_position)

Returns the bin index for a relative position.

change_resolution(resolution[, aggregation_type])

Changes the resolution of the track data.

copy()

Returns a deep copy of the TrackData object.

downsample(resolution[, aggregation_type])

Downsamples the track data to a lower resolution.

filter_to_negative_strand()

Filters tracks to the negative DNA strand.

filter_to_nonnegative_strand()

Filters tracks to the non-negative DNA strands (positive and unstranded).

filter_to_nonpositive_strand()

Filters tracks to the non-positive DNA strands (negative and unstranded).

filter_to_observed()

Filters tracks to observed tracks.

filter_to_positive_strand()

Filters tracks to the positive DNA strand.

filter_to_stranded()

Filters tracks to stranded tracks (excluding unstranded).

filter_to_unstranded()

Filters tracks to unstranded tracks.

filter_tracks(mask)

Filters tracks by a boolean mask.

groupby(column)

Splits tracks into groups based on a metadata column.

pad(start_pad, end_pad)

Pads the track data along positional axes.

resize(width)

Resizes the track data by cropping or padding with a fixed center.

reverse_complement()

Reverse complements the track data and interval if present.

select_tracks_by_index(idx)

Selects tracks by numerical index.

select_tracks_by_name(names)

Selects tracks by name.

slice_by_interval(interval[, match_resolution])

Slices the track data using a genome.Interval.

slice_by_positions(start, end)

Slices the track data along the positional axes.

upsample(resolution[, aggregation_type])

Upsamples the track data to a higher resolution.

with_metadata_column(name, value)

Returns a new TrackData with an added/updated metadata column.

with_name_suffix(suffix)

Returns a new TrackData object with suffixed track names.