Virtual Tracks¶
Functions for creating and managing virtual tracks, which define computed views over existing tracks with custom iterators and filters.
pymisha.gvtrack_create ¶
Create a virtual track.
A virtual track evaluates an aggregation function over a source track,
intervals set, or genomic sequence within each iterator interval. Virtual
tracks can be referenced by name anywhere a track expression is accepted
(e.g., in gextract, gsummary, gdist). The virtual track
persists in memory for the duration of the current session.
| PARAMETER | DESCRIPTION |
|---|---|
vtrack_name
|
Name for the virtual track. If a virtual track with this name already exists, it is silently overwritten.
TYPE:
|
src
|
Source for the virtual track. Can be:
TYPE:
|
func
|
Aggregation function to apply. Supported functions include:
TYPE:
|
params
|
Function-specific parameter. For example, a percentile in [0, 1]
for
TYPE:
|
sshift
|
Shift added to the start coordinate of each iterator interval before the virtual track function is evaluated.
TYPE:
|
eshift
|
Shift added to the end coordinate of each iterator interval before the virtual track function is evaluated.
TYPE:
|
**kwargs
|
Additional keyword arguments, depending on
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the filter source is invalid or refers to a non-intervals-type track. |
See Also
gvtrack_info : Retrieve the configuration of a virtual track. gvtrack_iterator : Override iterator shifts for a virtual track. gvtrack_iterator_2d : Set 2D iterator shifts for a virtual track. gvtrack_filter : Attach or clear a genomic mask filter. gvtrack_rm : Remove a single virtual track. gvtrack_ls : List all virtual tracks.
Examples:
Create a virtual track with a max aggregation:
>>> pm.gvtrack_create("vt_max", "dense_track", func="max")
>>> pm.gextract("vt_max", pm.gintervals(["1"], [0], [10000]), iterator=1000)
Create a quantile virtual track with a median (0.5) parameter:
Create a distance virtual track from an intervals source:
Create a PWM virtual track scanning both strands:
>>> import numpy as np
>>> pssm = np.array([[0.7, 0.1, 0.1, 0.1],
... [0.1, 0.7, 0.1, 0.1],
... [0.1, 0.1, 0.7, 0.1],
... [0.1, 0.1, 0.1, 0.7]])
>>> pm.gvtrack_create("motif", None, func="pwm",
... pssm=pssm, bidirect=True, prior=0.01)
Create a k-mer counting virtual track:
pymisha.gvtrack_ls ¶
List all currently defined virtual tracks.
Returns the names of all virtual tracks that have been created in the
current session via gvtrack_create. Unlike the R counterpart, this
function does not support pattern filtering; use standard Python list
comprehensions to filter the result if needed.
| RETURNS | DESCRIPTION |
|---|---|
list of str
|
Names of all virtual tracks in the current session. Returns an empty list if no virtual tracks have been created. |
See Also
gvtrack_create : Create a new virtual track. gvtrack_info : Retrieve configuration of a virtual track. gvtrack_rm : Remove a single virtual track. gvtrack_clear : Remove all virtual tracks.
Examples:
>>> import pymisha as pm
>>> _ = pm.gdb_init_examples()
>>> pm.gvtrack_clear()
>>> pm.gvtrack_ls()
[]
>>> pm.gvtrack_create("vt1", "dense_track", func="avg")
>>> pm.gvtrack_create("vt2", "dense_track", func="max")
>>> pm.gvtrack_ls()
['vt1', 'vt2']
Filter with a list comprehension:
pymisha.gvtrack_info ¶
Return the definition of a virtual track.
Retrieves the full internal configuration dictionary for a previously created virtual track. This is useful for inspecting or programmatically modifying virtual track settings.
| PARAMETER | DESCRIPTION |
|---|---|
vtrack_name
|
Name of an existing virtual track.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
A copy of the virtual track configuration dictionary. Keys always
include |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If no virtual track with the given name exists. |
See Also
gvtrack_create : Create a new virtual track. gvtrack_ls : List all virtual tracks. gvtrack_filter : Attach or clear a genomic mask filter.
Examples:
pymisha.gvtrack_iterator ¶
Define modification rules for the 1D iterator of a virtual track.
By default a virtual track is evaluated over the same iterator intervals
as the calling function (e.g., gextract, gsummary). This function
allows independent control of the genomic window the virtual track sees
by applying custom start/end shifts. It can also project a 2D iterator
down to one of its 1D dimensions.
| PARAMETER | DESCRIPTION |
|---|---|
vtrack_name
|
Name of an existing virtual track.
TYPE:
|
dim
|
Dimension projection for 2D iterators:
TYPE:
|
sshift
|
Value added to the start coordinate of each iterator interval. Negative values expand the window upstream.
TYPE:
|
eshift
|
Value added to the end coordinate of each iterator interval. Positive values expand the window downstream.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If no virtual track with the given name exists. |
See Also
gvtrack_create : Create a new virtual track. gvtrack_iterator_2d : Set 2D iterator shifts for a virtual track. gvtrack_filter : Attach a genomic mask filter.
Examples:
Shift the evaluation window 200 bp downstream:
>>> pm.gvtrack_create("vt1", "dense_track", func="avg")
>>> pm.gvtrack_iterator("vt1", sshift=200, eshift=200)
>>> pm.gextract("dense_track", "vt1",
... pm.gintervals(["1"], [0], [500]))
Expand the window symmetrically by 500 bp in each direction:
>>> pm.gvtrack_create("vt2", "dense_track", func="sum")
>>> pm.gvtrack_iterator("vt2", sshift=-500, eshift=500)
Project dimension 1 of a 2D iterator for a 1D virtual track:
pymisha.gvtrack_iterator_2d ¶
Define modification rules for the 2D iterator of a virtual track.
Sets independent start/end shifts for both dimensions of a 2D iterator interval. The shifts are added to the coordinates of each 2D iterator interval before the virtual track function is evaluated.
| PARAMETER | DESCRIPTION |
|---|---|
vtrack_name
|
Name of an existing virtual track.
TYPE:
|
sshift1
|
Value added to the
TYPE:
|
eshift1
|
Value added to the
TYPE:
|
sshift2
|
Value added to the
TYPE:
|
eshift2
|
Value added to the
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If no virtual track with the given name exists. |
See Also
gvtrack_create : Create a new virtual track. gvtrack_iterator : Set 1D iterator shifts or project a 2D dimension.
Examples:
pymisha.gvtrack_filter ¶
Attach or clear a genomic mask filter on a virtual track.
When a filter is attached, the virtual track function is evaluated only over the unmasked regions -- that is, regions NOT covered by the filter intervals. Masked positions are excluded from aggregation, and an iterator interval that is entirely masked returns NaN. The filter persists on the virtual track until explicitly cleared.
Filters are applied after iterator modifiers (sshift/eshift/
dim). The order of operations is: (1) apply iterator shifts,
(2) subtract mask from the shifted intervals, (3) evaluate the virtual
track function over the remaining unmasked segments.
| PARAMETER | DESCRIPTION |
|---|---|
vtrack_name
|
Name of an existing virtual track.
TYPE:
|
mask
|
The genomic mask to apply. Accepted forms:
TYPE:
|
filter
|
Backward-compatible alias for
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If no virtual track with the given name exists. |
ValueError
|
If a string filter source is not a recognized intervals set or intervals-type track, or if a DataFrame is missing required columns. |
See Also
gvtrack_create : Create a virtual track (filter can also be set at
creation time via the filter keyword argument).
gvtrack_info : Inspect a virtual track's configuration including its
filter.
gvtrack_iterator : Set iterator shifts (applied before the filter).
Examples:
Attach a filter to exclude specific regions:
>>> pm.gvtrack_create("vt1", "dense_track", func="avg")
>>> mask = pm.gintervals(["1", "1"], [100, 500], [200, 600])
>>> pm.gvtrack_filter("vt1", filter=mask)
>>> pm.gvtrack_info("vt1")["filter"] is not None
True
Clear the filter:
Use multiple filter sources (automatically unified):
pymisha.gvtrack_rm ¶
Remove a virtual track.
Deletes a single virtual track from the current session. If the named virtual track does not exist, the call is silently ignored (no error is raised).
| PARAMETER | DESCRIPTION |
|---|---|
vtrack_name
|
Name of the virtual track to remove.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
See Also
gvtrack_create : Create a new virtual track. gvtrack_clear : Remove all virtual tracks at once. gvtrack_ls : List all virtual tracks.
Examples:
>>> import pymisha as pm
>>> _ = pm.gdb_init_examples()
>>> pm.gvtrack_clear()
>>> pm.gvtrack_create("vt1", "dense_track", func="max")
>>> pm.gvtrack_create("vt2", "dense_track", func="min")
>>> pm.gvtrack_ls()
['vt1', 'vt2']
>>> pm.gvtrack_rm("vt1")
>>> pm.gvtrack_ls()
['vt2']
Removing a non-existent track is a no-op:
pymisha.gvtrack_clear ¶
Remove all virtual tracks.
Clears the entire virtual track registry for the current session.
After this call, gvtrack_ls() returns an empty list. This is
useful for resetting state between analyses or in test fixtures.
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
See Also
gvtrack_rm : Remove a single virtual track by name. gvtrack_ls : List all virtual tracks. gvtrack_create : Create a new virtual track.
Examples: