Python API
Generated from public symbols and docstrings in py-cfdnalab/src/cfdnalab.
Jump To
Midpoint Profiles
Load midpoint profile Zarr stores and extract count arrays or data frames by group, fragment length bin, and midpoint position.
| Symbol | Type | Summary |
|---|---|---|
read_midpoints | function | Open a cfDNAlab midpoint profile Zarr store. |
MidpointProfiles | class | Helper for loading and slicing midpoint profile Zarr output. |
read_midpoints
read_midpoints(path: pathlib.Path | str) -> MidpointProfiles
Open a cfDNAlab midpoint profile Zarr store.
Parameters
path: Path to a.midpoint_profiles.zarrdirectory.
Returns
MidpointProfiles: Loaded midpoint profile helper.
MidpointProfiles
Helper for loading and slicing midpoint profile Zarr output.
Midpoint profiles store counts as (group, length_bin, position). The class
exposes metadata as pandas data frames and count slices as NumPy arrays.
Public Methods
| Method | Summary |
|---|---|
group_idx | Find the midpoint group index for a group name. |
length_bin_idx | Find the length-bin index whose interval contains a fragment length. |
group_metadata | Return midpoint group labels and eligible interval counts. |
counts_array | Return midpoint counts as a dense NumPy array. |
length_bins | Get the fragment length bins available in this midpoint-profile output. |
positions | Get the midpoint position bins available in this output. |
data_frame | Create a pandas DataFrame of midpoint profile counts. |
MidpointProfiles.group_idx
MidpointProfiles.group_idx
MidpointProfiles.group_idx(group_name: str) -> int
Find the midpoint group index for a group name.
Parameters
group_name: Group name to resolve.
Returns
int: Group index.
MidpointProfiles.length_bin_idx
MidpointProfiles.length_bin_idx
MidpointProfiles.length_bin_idx(length: int) -> int
Find the length-bin index whose interval contains a fragment length.
Parameters
length: Fragment length in bp.
Returns
int: Length-bin index.
MidpointProfiles.group_metadata
MidpointProfiles.group_metadata
MidpointProfiles.group_metadata() -> pd.DataFrame
Return midpoint group labels and eligible interval counts.
Returns
pandas.DataFrame: Columns aregroup_idx,group_name, andeligible_intervals.
MidpointProfiles.counts_array
MidpointProfiles.counts_array
MidpointProfiles.counts_array(*, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, with_lengths: int | Sequence[int] | None = None, with_length_range: Sequence[int] | None = None, length_bin_idxs: int | Sequence[int] | None = None) -> np.ndarray
Return midpoint counts as a dense NumPy array.
The result keeps the midpoint count dimensions in the same order as
the file: group, length bin, then position. Scalar selectors keep their
axis as length one, so the shape is always
(selected groups, selected length bins, positions).
Parameters
groups:Nonefor all groups, one group name, or a sequence of group names. Use eithergroupsorgroup_idxs, not both.group_idxs:Nonefor all groups, one group index, or a sequence of group indices. Use eithergroupsorgroup_idxs, not both.with_lengths: Fragment length or lengths in bp. Counts are returned for the length bins containing these lengths. Multiple lengths must select distinct length bins.with_length_range: Two bp bounds defining a half-open range[start, end). Counts are returned for whole length bins that overlap this range.length_bin_idxs:Nonefor all length bins, one length-bin index, or a sequence of length-bin indices. Use only one ofwith_lengths,with_length_range, orlength_bin_idxs.
Returns
numpy.ndarray: Count array with shape(group, length_bin, position).
MidpointProfiles.length_bins
MidpointProfiles.length_bins
MidpointProfiles.length_bins() -> pd.DataFrame
Get the fragment length bins available in this midpoint-profile output.
Length bins are half-open intervals. A bin with length_start_bp=30
and length_end_bp=50 contains fragment lengths 30 <= length < 50.
Returns
pandas.DataFrame: Columns arelength_bin,length_start_bp, andlength_end_bp.
MidpointProfiles.positions
MidpointProfiles.positions
MidpointProfiles.positions() -> pd.DataFrame
Get the midpoint position bins available in this output.
Returns
pandas.DataFrame: Columns areposition,position_bin_start_bp, andposition_bin_end_bp.
MidpointProfiles.data_frame
MidpointProfiles.data_frame
MidpointProfiles.data_frame(*, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, with_lengths: int | Sequence[int] | None = None, with_length_range: Sequence[int] | None = None, length_bin_idxs: int | Sequence[int] | None = None) -> pd.DataFrame
Create a pandas DataFrame of midpoint profile counts.
Use this for tabular analysis of the midpoint count array. The result expands the selected group and length-bin axes across all midpoint position bins, with group, length-bin, and position metadata on each row.
Parameters
groups:Nonefor all groups, one group name, or a sequence of group names. Use eithergroupsorgroup_idxs, not both.group_idxs:Nonefor all groups, one group index, or a sequence of group indices. Use eithergroupsorgroup_idxs, not both.with_lengths: Fragment length or lengths in bp. The returned rows use the length bins containing these lengths. Multiple lengths must select distinct length bins.with_length_range: Two bp bounds defining a half-open range[start, end). Returned rows use whole length bins that overlap this range.length_bin_idxs:Nonefor all length bins, one length-bin index, or a sequence of length-bin indices. Use only one ofwith_lengths,with_length_range, orlength_bin_idxs.
Returns
pandas.DataFrame: One row per selected group, length bin, and midpoint position bin.
End-Motif Counts
Load dense or sparse end-motif count Zarr stores and extract motif count tables, dense arrays, or sparse matrices.
| Symbol | Type | Summary |
|---|---|---|
read_end_motifs | function | Open a cfDNAlab end-motif count Zarr store. |
EndMotifCounts | class | Common API for global, windowed, and grouped end-motif outputs. |
GlobalEndMotifCounts | class | End-motif counts for global output. |
WindowedEndMotifCounts | class | End-motif counts for fixed-size or BED-window output. |
GroupedEndMotifCounts | class | End-motif counts for grouped BED output. |
read_end_motifs
read_end_motifs(path: pathlib.Path | str) -> GlobalEndMotifCounts | WindowedEndMotifCounts | GroupedEndMotifCounts
Open a cfDNAlab end-motif count Zarr store.
Parameters
path: Path to an.end_motifs.zarrdirectory.
Returns
EndMotifCounts: Mode-specific end-motif count helper.
EndMotifCounts
Common API for global, windowed, and grouped end-motif outputs.
Public Methods
| Method | Summary |
|---|---|
storage_mode | Return how end-motif counts are stored on disk. |
row_mode | Return what each end-motif count row represents. |
motifs_metadata | Return motif-axis labels and motif indices available in this output. |
motif_idx | Find the motif-axis index for a motif label. |
has_motif | Return whether a motif label exists in this output. |
corrected_motifs_metadata | Return the motif axis used by reference-corrected matrices. |
dense_counts_zarr_array | Return the lazy Zarr counts array for dense output. |
EndMotifCounts.storage_mode
EndMotifCounts.storage_mode
EndMotifCounts.storage_mode() -> str
Return how end-motif counts are stored on disk.
Returns
str: Either"dense"or"sparse_coo".
EndMotifCounts.row_mode
EndMotifCounts.row_mode
EndMotifCounts.row_mode() -> str
Return what each end-motif count row represents.
Returns
str: One of"global","size","bed", or"grouped_bed".
EndMotifCounts.motifs_metadata
EndMotifCounts.motifs_metadata
EndMotifCounts.motifs_metadata() -> pd.DataFrame
Return motif-axis labels and motif indices available in this output.
For grouped motifs-file output, the motif labels are the group names
used during counting.
Returns
pandas.DataFrame: Columns aremotif_indexandmotif.
EndMotifCounts.motif_idx
EndMotifCounts.motif_idx
EndMotifCounts.motif_idx(motif: str) -> int
Find the motif-axis index for a motif label.
Parameters
motif: Motif label to resolve.
Returns
int: Motif index.
EndMotifCounts.has_motif
EndMotifCounts.has_motif
EndMotifCounts.has_motif(motif: str) -> bool
Return whether a motif label exists in this output.
Sparse output only stores observed motifs, so an unobserved motif will
return False even if it is part of the complete motif set.
Parameters
motif: Motif label to check.
Returns
bool: Whether the motif can be resolved in this output.
EndMotifCounts.corrected_motifs_metadata
EndMotifCounts.corrected_motifs_metadata
EndMotifCounts.corrected_motifs_metadata(ref_kmers: RefKmerFrequencies, *, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, use_global_bias: bool = False, two_sided_correction: str | None = None) -> pd.DataFrame
Return the motif axis used by reference-corrected matrices.
Use this method to interpret the columns returned by
corrected_counts_array() and sparse_corrected_counts_matrix(). Rows
are in matrix-column order. matrix_column is the zero-based
column in the returned matrix. motif_index is zero-based and refers to
the full correction-mode axis described by motif, not necessarily the
motif axis stored in the end-motif file.
For "joint", "split", and one-sided correction, this is the
selected stored motif axis. For "outside" and "inside", repeated
side labels are deduplicated in their first stored-motif occurrence
order. Label selection returns labels in the requested order. Motif
index selection is not available for "outside" or "inside" because
those modes create a new axis.
Parameters
ref_kmers: Loaded reference k-mer output used for correction.motifs: Motif label or labels on the correction-mode axis. Use eithermotifsormotif_idxs, not both.motif_idxs: Stored motif index or indices. This is only available for"joint","split", and one-sided correction.use_global_bias: Whether a global reference k-mer output may be applied to a non-global end-motif output.two_sided_correction: Required for two-sided motif labels. Use"joint","split","outside", or"inside". Leave asNonefor one-sided motifs or motif groups.
Returns
pandas.DataFrame: Matrix-column metadata withmatrix_column,motif_index, andmotifcolumns.
EndMotifCounts.dense_counts_zarr_array
EndMotifCounts.dense_counts_zarr_array
EndMotifCounts.dense_counts_zarr_array() -> zarr.Array
Return the lazy Zarr counts array for dense output.
This returns the on-disk Zarr array handle without loading the full
dense matrix into memory. Sparse output has no dense counts array.
Returns
zarr.Array: Dense count array with shape(output row, motif).
GlobalEndMotifCounts
End-motif counts for global output.
Public Methods
| Method | Summary |
|---|---|
data_frame | Create a pandas DataFrame for global end-motif counts. |
dense_counts_array | Return global end-motif counts as a dense NumPy array. |
sparse_counts_matrix | Return global end-motif counts as a SciPy sparse matrix. |
corrected_counts_array | Return global reference-corrected end-motif counts as a dense array. |
sparse_corrected_counts_matrix | Return global reference-corrected end-motif counts as a sparse matrix. |
GlobalEndMotifCounts.data_frame
GlobalEndMotifCounts.data_frame
GlobalEndMotifCounts.data_frame(*, ref_kmers: RefKmerFrequencies | None = None, densify: bool = False, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, use_global_bias: bool = False, unsupported_motifs: str = 'error', two_sided_correction: str | None = None) -> pd.DataFrame
Create a pandas DataFrame for global end-motif counts.
Sparse outputs return stored non-zero motif counts unless
densify=True. Densifying adds explicit zero-count rows for selected
observed motifs. Dense outputs always include zero counts. Pass
ref_kmers to add reference-corrected counts.
Reference correction
Reference correction divides each observed end-motif count by a reference-based correction factor for the matched row. This factor is computed from the motif frequencies in the reference k-mer output and normalized so a uniform reference composition leaves counts unchanged. Motifs that are common in the reference row are scaled down. Motifs that are rare in the reference row are scaled up. Only motifs with a positive reference frequency contribute to the row's correction support.
End-motif labels run inward from either fragment end, so reference
correction requires reference k-mer output generated with
--orientation both.
This is an approximate correction for broad or local
reference-composition bias. It assumes that left and right fragment
ends contribute equally within each row. Correction in short windows
can be unreliable, so use windows of at least a few kilobases.
Two-sided correction modes
When motif labels contain both outside and inside bases, such as
"AC_GT", two_sided_correction chooses both the motif labels in the
result and the correction factor used for each returned count.
-
"joint"keeps full labels such as"AC_GT"and corrects each count using the exact reference k-mer"ACGT". -
"split"keeps full labels such as"AC_GT", but calculates the correction factor from the two sides separately. For"AC_GT", separate correction factors are calculated for outside label"AC"and inside label"GT". Those two correction factors are multiplied and applied to the observed"AC_GT"count. Use this when you want full two-sided motif labels in the result, but the exact full reference k-mers are too sparse or you want the reference correction to treat outside and inside sequence composition separately. -
"outside"returns outside labels such as"AC_". For each outside label, all full motif counts with that outside label are summed first. For example,"AC_AA"and"AC_GT"both contribute to the"AC_"count. That summed count is corrected using the outside label"AC". -
"inside"returns inside labels such as"_GT". For each inside label, all full motif counts with that inside label are summed first. For example,"AA_GT"and"AC_GT"both contribute to the"_GT"count. That summed count is corrected using the inside label"GT".
For "split", "outside", and "inside", side-specific reference
frequencies are calculated from the loaded full-length reference
k-mers. For example, the outside frequency for "AC" is the sum of
frequencies for loaded k-mers with prefix "AC", such as "ACTG" and
"ACAA". The inside frequency for "TG" is the corresponding sum over
loaded k-mers with suffix "TG". Separate shorter reference k-mer runs
are not required.
A motifs file used for the reference output restricts these sums to the k-mers in that file. Without a motifs file, all k-mers in the reference output can contribute, including k-mers absent from the sample end-motif output.
corrected_frequency is normalized from corrected_count over the full
correction-mode motif axis for each output row. Motif selection filters
those frequencies afterward and does not renormalize them. A selected
subset can therefore sum to less than 1. If the corrected total is
zero, finite frequencies are zero. With unsupported_motifs="keep_na",
one undefined positive corrected count makes all frequencies in that
output row NaN.
Parameters
ref_kmers: Optional loaded reference k-mer output used for correction.densify: IfTrue, sparse outputs add explicit zero-count rows for selected observed motifs. Dense outputs ignore this option.motifs: Motif label or labels. Use eithermotifsormotif_idxs, not both.motif_idxs: Motif index or indices. Use eithermotifsormotif_idxs, not both.use_global_bias: Whether a global reference k-mer output may be applied to every row.unsupported_motifs: What to do when an observed sample motif has no positive correction factor under the selected mode. Use"error","drop", or"keep_na".two_sided_correction: Required for two-sided motif labels such as"AC_GT"whenref_kmersis passed. Use"joint","split","outside", or"inside". Leave asNonefor one-sided motifs or motif groups.
Returns
pandas.DataFrame: Global row metadata, motif metadata, andcount. Ifref_kmersis passed, also includescorrected_countandcorrected_frequency.
GlobalEndMotifCounts.dense_counts_array
GlobalEndMotifCounts.dense_counts_array
GlobalEndMotifCounts.dense_counts_array(*, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, allow_densify: bool = False) -> np.ndarray
Return global end-motif counts as a dense NumPy array.
Sparse stores are only densified when allow_densify=True. Scalar
motif selectors keep their axis as length one, so the shape is always
(1, selected motifs).
Parameters
motifs: Motif label or labels. Use eithermotifsormotif_idxs, not both.motif_idxs: Motif index or indices. Use eithermotifsormotif_idxs, not both.allow_densify: IfTrue, allow sparse stores to be converted to dense counts.
Returns
numpy.ndarray: Dense count array with shape(global row, motif).
GlobalEndMotifCounts.sparse_counts_matrix
GlobalEndMotifCounts.sparse_counts_matrix
GlobalEndMotifCounts.sparse_counts_matrix(*, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None) -> sparse.coo_matrix
Return global end-motif counts as a SciPy sparse matrix.
Scalar motif selectors keep their axis as length one, so the shape is
always (1, selected motifs).
Parameters
motifs: Motif label or labels. Use eithermotifsormotif_idxs, not both.motif_idxs: Motif index or indices. Use eithermotifsormotif_idxs, not both.
Returns
scipy.sparse.coo_matrix: Sparse count matrix with shape(global row, motif).
GlobalEndMotifCounts.corrected_counts_array
GlobalEndMotifCounts.corrected_counts_array
GlobalEndMotifCounts.corrected_counts_array(ref_kmers: RefKmerFrequencies, *, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, allow_densify: bool = False, use_global_bias: bool = False, unsupported_motifs: str = 'error', two_sided_correction: str | None = None) -> np.ndarray
Return global reference-corrected end-motif counts as a dense array.
The result has one column per motif on the selected correction-mode
axis. "joint", "split", and one-sided correction retain the selected
stored motif axis. "outside" and "inside" replace it with a
deduplicated side axis, so the number of columns can differ from
dense_counts_array(). Use corrected_motifs_metadata() to inspect the
exact column labels and order.
Sparse end-motif stores are not densified unless
allow_densify=True. Use sparse_corrected_counts_matrix() to keep a
sparse result.
unsupported_motifs="drop" is not allowed because arrays have a fixed
row and motif shape. Use
data_frame(ref_kmers=..., unsupported_motifs="drop") when
unsupported motifs should be omitted.
Reference correction
Reference correction divides each observed end-motif count by a reference-based correction factor for the matched row. This factor is computed from the motif frequencies in the reference k-mer output and normalized so a uniform reference composition leaves counts unchanged. Motifs that are common in the reference row are scaled down. Motifs that are rare in the reference row are scaled up. Only motifs with a positive reference frequency contribute to the row's correction support.
End-motif labels run inward from either fragment end, so reference
correction requires reference k-mer output generated with
--orientation both.
This is an approximate correction for broad or local
reference-composition bias. It assumes that left and right fragment
ends contribute equally within each row. Correction in short windows
can be unreliable, so use windows of at least a few kilobases.
Two-sided correction modes
When motif labels contain both outside and inside bases, such as
"AC_GT", two_sided_correction chooses both the motif labels in the
result and the correction factor used for each returned count.
-
"joint"keeps full labels such as"AC_GT"and corrects each count using the exact reference k-mer"ACGT". -
"split"keeps full labels such as"AC_GT", but calculates the correction factor from the two sides separately. For"AC_GT", separate correction factors are calculated for outside label"AC"and inside label"GT". Those two correction factors are multiplied and applied to the observed"AC_GT"count. Use this when you want full two-sided motif labels in the result, but the exact full reference k-mers are too sparse or you want the reference correction to treat outside and inside sequence composition separately. -
"outside"returns outside labels such as"AC_". For each outside label, all full motif counts with that outside label are summed first. For example,"AC_AA"and"AC_GT"both contribute to the"AC_"count. That summed count is corrected using the outside label"AC". -
"inside"returns inside labels such as"_GT". For each inside label, all full motif counts with that inside label are summed first. For example,"AA_GT"and"AC_GT"both contribute to the"_GT"count. That summed count is corrected using the inside label"GT".
For "split", "outside", and "inside", side-specific reference
frequencies are calculated from the loaded full-length reference
k-mers. For example, the outside frequency for "AC" is the sum of
frequencies for loaded k-mers with prefix "AC", such as "ACTG" and
"ACAA". The inside frequency for "TG" is the corresponding sum over
loaded k-mers with suffix "TG". Separate shorter reference k-mer runs
are not required.
A motifs file used for the reference output restricts these sums to the k-mers in that file. Without a motifs file, all k-mers in the reference output can contribute, including k-mers absent from the sample end-motif output.
An observed sample motif with a positive count is unsupported when it
has no positive correction factor under the selected mode.
unsupported_motifs="keep_na" keeps
that matrix cell as NaN. The "drop" policy is unavailable for
matrices because it would change a fixed result axis.
GlobalEndMotifCounts.sparse_corrected_counts_matrix
GlobalEndMotifCounts.sparse_corrected_counts_matrix
GlobalEndMotifCounts.sparse_corrected_counts_matrix(ref_kmers: RefKmerFrequencies, *, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, use_global_bias: bool = False, unsupported_motifs: str = 'error', two_sided_correction: str | None = None) -> sparse.coo_matrix
Return global reference-corrected end-motif counts as a sparse matrix.
The result has one column per motif on the selected correction-mode
axis. "outside" and "inside" can therefore have fewer columns than
sparse_counts_matrix(). Use corrected_motifs_metadata() to inspect
the exact column labels and order. Corrected zeroes are not stored.
Corrected NaN values from
unsupported_motifs="keep_na" are stored so they remain visible.
unsupported_motifs="drop" is not allowed because sparse matrices
still have a fixed row and motif shape. Use
data_frame(ref_kmers=..., unsupported_motifs="drop") when
unsupported motifs should be omitted.
Reference correction
Reference correction divides each observed end-motif count by a reference-based correction factor for the matched row. This factor is computed from the motif frequencies in the reference k-mer output and normalized so a uniform reference composition leaves counts unchanged. Motifs that are common in the reference row are scaled down. Motifs that are rare in the reference row are scaled up. Only motifs with a positive reference frequency contribute to the row's correction support.
End-motif labels run inward from either fragment end, so reference
correction requires reference k-mer output generated with
--orientation both.
This is an approximate correction for broad or local
reference-composition bias. It assumes that left and right fragment
ends contribute equally within each row. Correction in short windows
can be unreliable, so use windows of at least a few kilobases.
Two-sided correction modes
When motif labels contain both outside and inside bases, such as
"AC_GT", two_sided_correction chooses both the motif labels in the
result and the correction factor used for each returned count.
-
"joint"keeps full labels such as"AC_GT"and corrects each count using the exact reference k-mer"ACGT". -
"split"keeps full labels such as"AC_GT", but calculates the correction factor from the two sides separately. For"AC_GT", separate correction factors are calculated for outside label"AC"and inside label"GT". Those two correction factors are multiplied and applied to the observed"AC_GT"count. Use this when you want full two-sided motif labels in the result, but the exact full reference k-mers are too sparse or you want the reference correction to treat outside and inside sequence composition separately. -
"outside"returns outside labels such as"AC_". For each outside label, all full motif counts with that outside label are summed first. For example,"AC_AA"and"AC_GT"both contribute to the"AC_"count. That summed count is corrected using the outside label"AC". -
"inside"returns inside labels such as"_GT". For each inside label, all full motif counts with that inside label are summed first. For example,"AA_GT"and"AC_GT"both contribute to the"_GT"count. That summed count is corrected using the inside label"GT".
For "split", "outside", and "inside", side-specific reference
frequencies are calculated from the loaded full-length reference
k-mers. For example, the outside frequency for "AC" is the sum of
frequencies for loaded k-mers with prefix "AC", such as "ACTG" and
"ACAA". The inside frequency for "TG" is the corresponding sum over
loaded k-mers with suffix "TG". Separate shorter reference k-mer runs
are not required.
A motifs file used for the reference output restricts these sums to the k-mers in that file. Without a motifs file, all k-mers in the reference output can contribute, including k-mers absent from the sample end-motif output.
An observed sample motif with a positive count is unsupported when it
has no positive correction factor under the selected mode.
unsupported_motifs="keep_na" keeps
that matrix cell as NaN. The "drop" policy is unavailable for
matrices because it would change a fixed result axis.
WindowedEndMotifCounts
End-motif counts for fixed-size or BED-window output.
Public Methods
| Method | Summary |
|---|---|
data_frame | Create a pandas DataFrame of end-motif counts for genomic windows. |
window_metadata | Return genomic window metadata for this end-motif output. |
dense_counts_array | Return windowed end-motif counts as a dense NumPy array. |
sparse_counts_matrix | Return windowed end-motif counts as a SciPy sparse matrix. |
corrected_counts_array | Return windowed reference-corrected end-motif counts as a dense array. |
sparse_corrected_counts_matrix | Return windowed reference-corrected end-motif counts as a sparse matrix. |
WindowedEndMotifCounts.data_frame
WindowedEndMotifCounts.data_frame
WindowedEndMotifCounts.data_frame(*, ref_kmers: RefKmerFrequencies | None = None, window_idxs: int | Sequence[int] | None = None, densify: bool = False, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, max_blacklisted_fraction: float = 1.0, use_global_bias: bool = False, unsupported_motifs: str = 'error', two_sided_correction: str | None = None) -> pd.DataFrame
Create a pandas DataFrame of end-motif counts for genomic windows.
Use window_idxs to keep only selected windows and motifs or
motif_idxs to keep only selected motifs. Sparse outputs return stored
non-zero rows unless densify=True. Densifying adds explicit
zero-count rows for selected observed motifs. Dense outputs always
include zero counts. Pass ref_kmers to add reference-corrected counts.
Reference correction
Reference correction divides each observed end-motif count by a reference-based correction factor for the matched row. This factor is computed from the motif frequencies in the reference k-mer output and normalized so a uniform reference composition leaves counts unchanged. Motifs that are common in the reference row are scaled down. Motifs that are rare in the reference row are scaled up. Only motifs with a positive reference frequency contribute to the row's correction support.
End-motif labels run inward from either fragment end, so reference
correction requires reference k-mer output generated with
--orientation both.
This is an approximate correction for broad or local
reference-composition bias. It assumes that left and right fragment
ends contribute equally within each row. Correction in short windows
can be unreliable, so use windows of at least a few kilobases.
Two-sided correction modes
When motif labels contain both outside and inside bases, such as
"AC_GT", two_sided_correction chooses both the motif labels in the
result and the correction factor used for each returned count.
-
"joint"keeps full labels such as"AC_GT"and corrects each count using the exact reference k-mer"ACGT". -
"split"keeps full labels such as"AC_GT", but calculates the correction factor from the two sides separately. For"AC_GT", separate correction factors are calculated for outside label"AC"and inside label"GT". Those two correction factors are multiplied and applied to the observed"AC_GT"count. Use this when you want full two-sided motif labels in the result, but the exact full reference k-mers are too sparse or you want the reference correction to treat outside and inside sequence composition separately. -
"outside"returns outside labels such as"AC_". For each outside label, all full motif counts with that outside label are summed first. For example,"AC_AA"and"AC_GT"both contribute to the"AC_"count. That summed count is corrected using the outside label"AC". -
"inside"returns inside labels such as"_GT". For each inside label, all full motif counts with that inside label are summed first. For example,"AA_GT"and"AC_GT"both contribute to the"_GT"count. That summed count is corrected using the inside label"GT".
For "split", "outside", and "inside", side-specific reference
frequencies are calculated from the loaded full-length reference
k-mers. For example, the outside frequency for "AC" is the sum of
frequencies for loaded k-mers with prefix "AC", such as "ACTG" and
"ACAA". The inside frequency for "TG" is the corresponding sum over
loaded k-mers with suffix "TG". Separate shorter reference k-mer runs
are not required.
A motifs file used for the reference output restricts these sums to the k-mers in that file. Without a motifs file, all k-mers in the reference output can contribute, including k-mers absent from the sample end-motif output.
corrected_frequency is normalized from corrected_count over the full
correction-mode motif axis for each output row. Motif selection filters
those frequencies afterward and does not renormalize them. A selected
subset can therefore sum to less than 1. If the corrected total is
zero, finite frequencies are zero. With unsupported_motifs="keep_na",
one undefined positive corrected count makes all frequencies in that
output row NaN.
Parameters
ref_kmers: Optional loaded reference k-mer output used for correction.window_idxs:Nonefor all windows, one window index, or a sequence of window indices.densify: IfTrue, sparse outputs add explicit zero-count rows for selected observed motifs. Dense outputs ignore this option.motifs: Motif label or labels. Use eithermotifsormotif_idxs, not both.motif_idxs: Motif index or indices. Use eithermotifsormotif_idxs, not both.max_blacklisted_fraction: Maximum rowblacklisted_fractionin 0..1 to retain before counts are returned. The default1.0keeps all selected windows.use_global_bias: Whether a global reference k-mer output may be applied to every row.unsupported_motifs: What to do when an observed sample motif has no positive correction factor under the selected mode. Use"error","drop", or"keep_na".two_sided_correction: Required for two-sided motif labels such as"AC_GT"whenref_kmersis passed. Use"joint","split","outside", or"inside". Leave asNonefor one-sided motifs or motif groups.
Returns
pandas.DataFrame: Window metadata, motif metadata, andcount. Ifref_kmersis passed, also includescorrected_countandcorrected_frequency.
WindowedEndMotifCounts.window_metadata
WindowedEndMotifCounts.window_metadata
WindowedEndMotifCounts.window_metadata() -> pd.DataFrame
Return genomic window metadata for this end-motif output.
Public genomic window metadata uses window_idx, chrom, start,
and end columns.
Returns
pandas.DataFrame: Columns arewindow_idx,chrom,start,end, andblacklisted_fraction.
WindowedEndMotifCounts.dense_counts_array
WindowedEndMotifCounts.dense_counts_array
WindowedEndMotifCounts.dense_counts_array(*, window_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, allow_densify: bool = False) -> np.ndarray
Return windowed end-motif counts as a dense NumPy array.
Sparse stores are only densified when allow_densify=True. Scalar
selectors keep their axes as length one, so the shape is always
(selected windows, selected motifs).
Parameters
window_idxs:Nonefor all windows, one window index, or a sequence of window indices.motifs: Motif label or labels. Use eithermotifsormotif_idxs, not both.motif_idxs: Motif index or indices. Use eithermotifsormotif_idxs, not both.allow_densify: IfTrue, allow sparse stores to be converted to dense counts.
Returns
numpy.ndarray: Dense count array with shape(window, motif).
WindowedEndMotifCounts.sparse_counts_matrix
WindowedEndMotifCounts.sparse_counts_matrix
WindowedEndMotifCounts.sparse_counts_matrix(*, window_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None) -> sparse.coo_matrix
Return windowed end-motif counts as a SciPy sparse matrix.
Scalar selectors keep their axes as length one, so the shape is always
(selected windows, selected motifs).
Parameters
window_idxs:Nonefor all windows, one window index, or a sequence of window indices.motifs: Motif label or labels. Use eithermotifsormotif_idxs, not both.motif_idxs: Motif index or indices. Use eithermotifsormotif_idxs, not both.
Returns
scipy.sparse.coo_matrix: Sparse count matrix with shape(window, motif).
WindowedEndMotifCounts.corrected_counts_array
WindowedEndMotifCounts.corrected_counts_array
WindowedEndMotifCounts.corrected_counts_array(ref_kmers: RefKmerFrequencies, *, window_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, allow_densify: bool = False, max_blacklisted_fraction: float = 1.0, use_global_bias: bool = False, unsupported_motifs: str = 'error', two_sided_correction: str | None = None) -> np.ndarray
Return windowed reference-corrected end-motif counts as a dense array.
The result has one row per selected window and one column per motif on
the selected correction-mode axis. "outside" and "inside" replace
the stored joint axis with a deduplicated side axis. Use
corrected_motifs_metadata() to inspect the exact column labels and
order. Sparse end-motif stores are not densified unless
allow_densify=True. Use
sparse_corrected_counts_matrix() to keep a sparse result.
unsupported_motifs="drop" is not allowed because arrays have a fixed
row and motif shape. Use
data_frame(ref_kmers=..., unsupported_motifs="drop") when
unsupported motifs should be omitted.
Reference correction
Reference correction divides each observed end-motif count by a reference-based correction factor for the matched row. This factor is computed from the motif frequencies in the reference k-mer output and normalized so a uniform reference composition leaves counts unchanged. Motifs that are common in the reference row are scaled down. Motifs that are rare in the reference row are scaled up. Only motifs with a positive reference frequency contribute to the row's correction support.
End-motif labels run inward from either fragment end, so reference
correction requires reference k-mer output generated with
--orientation both.
This is an approximate correction for broad or local
reference-composition bias. It assumes that left and right fragment
ends contribute equally within each row. Correction in short windows
can be unreliable, so use windows of at least a few kilobases.
Two-sided correction modes
When motif labels contain both outside and inside bases, such as
"AC_GT", two_sided_correction chooses both the motif labels in the
result and the correction factor used for each returned count.
-
"joint"keeps full labels such as"AC_GT"and corrects each count using the exact reference k-mer"ACGT". -
"split"keeps full labels such as"AC_GT", but calculates the correction factor from the two sides separately. For"AC_GT", separate correction factors are calculated for outside label"AC"and inside label"GT". Those two correction factors are multiplied and applied to the observed"AC_GT"count. Use this when you want full two-sided motif labels in the result, but the exact full reference k-mers are too sparse or you want the reference correction to treat outside and inside sequence composition separately. -
"outside"returns outside labels such as"AC_". For each outside label, all full motif counts with that outside label are summed first. For example,"AC_AA"and"AC_GT"both contribute to the"AC_"count. That summed count is corrected using the outside label"AC". -
"inside"returns inside labels such as"_GT". For each inside label, all full motif counts with that inside label are summed first. For example,"AA_GT"and"AC_GT"both contribute to the"_GT"count. That summed count is corrected using the inside label"GT".
For "split", "outside", and "inside", side-specific reference
frequencies are calculated from the loaded full-length reference
k-mers. For example, the outside frequency for "AC" is the sum of
frequencies for loaded k-mers with prefix "AC", such as "ACTG" and
"ACAA". The inside frequency for "TG" is the corresponding sum over
loaded k-mers with suffix "TG". Separate shorter reference k-mer runs
are not required.
A motifs file used for the reference output restricts these sums to the k-mers in that file. Without a motifs file, all k-mers in the reference output can contribute, including k-mers absent from the sample end-motif output.
An observed sample motif with a positive count is unsupported when it
has no positive correction factor under the selected mode.
unsupported_motifs="keep_na" keeps
that matrix cell as NaN. The "drop" policy is unavailable for
matrices because it would change a fixed result axis.
WindowedEndMotifCounts.sparse_corrected_counts_matrix
WindowedEndMotifCounts.sparse_corrected_counts_matrix
WindowedEndMotifCounts.sparse_corrected_counts_matrix(ref_kmers: RefKmerFrequencies, *, window_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, max_blacklisted_fraction: float = 1.0, use_global_bias: bool = False, unsupported_motifs: str = 'error', two_sided_correction: str | None = None) -> sparse.coo_matrix
Return windowed reference-corrected end-motif counts as a sparse matrix.
The result has one row per selected window and one column per motif on
the selected correction-mode axis. "outside" and "inside" can have
fewer columns than sparse_counts_matrix(). Use
corrected_motifs_metadata() to inspect the exact column labels and
order. Corrected zeroes are not stored. Corrected NaN values from
unsupported_motifs="keep_na" are stored so they remain visible.
unsupported_motifs="drop" is not allowed because sparse matrices
still have a fixed row and motif shape. Use
data_frame(ref_kmers=..., unsupported_motifs="drop") when
unsupported motifs should be omitted.
Reference correction
Reference correction divides each observed end-motif count by a reference-based correction factor for the matched row. This factor is computed from the motif frequencies in the reference k-mer output and normalized so a uniform reference composition leaves counts unchanged. Motifs that are common in the reference row are scaled down. Motifs that are rare in the reference row are scaled up. Only motifs with a positive reference frequency contribute to the row's correction support.
End-motif labels run inward from either fragment end, so reference
correction requires reference k-mer output generated with
--orientation both.
This is an approximate correction for broad or local
reference-composition bias. It assumes that left and right fragment
ends contribute equally within each row. Correction in short windows
can be unreliable, so use windows of at least a few kilobases.
Two-sided correction modes
When motif labels contain both outside and inside bases, such as
"AC_GT", two_sided_correction chooses both the motif labels in the
result and the correction factor used for each returned count.
-
"joint"keeps full labels such as"AC_GT"and corrects each count using the exact reference k-mer"ACGT". -
"split"keeps full labels such as"AC_GT", but calculates the correction factor from the two sides separately. For"AC_GT", separate correction factors are calculated for outside label"AC"and inside label"GT". Those two correction factors are multiplied and applied to the observed"AC_GT"count. Use this when you want full two-sided motif labels in the result, but the exact full reference k-mers are too sparse or you want the reference correction to treat outside and inside sequence composition separately. -
"outside"returns outside labels such as"AC_". For each outside label, all full motif counts with that outside label are summed first. For example,"AC_AA"and"AC_GT"both contribute to the"AC_"count. That summed count is corrected using the outside label"AC". -
"inside"returns inside labels such as"_GT". For each inside label, all full motif counts with that inside label are summed first. For example,"AA_GT"and"AC_GT"both contribute to the"_GT"count. That summed count is corrected using the inside label"GT".
For "split", "outside", and "inside", side-specific reference
frequencies are calculated from the loaded full-length reference
k-mers. For example, the outside frequency for "AC" is the sum of
frequencies for loaded k-mers with prefix "AC", such as "ACTG" and
"ACAA". The inside frequency for "TG" is the corresponding sum over
loaded k-mers with suffix "TG". Separate shorter reference k-mer runs
are not required.
A motifs file used for the reference output restricts these sums to the k-mers in that file. Without a motifs file, all k-mers in the reference output can contribute, including k-mers absent from the sample end-motif output.
An observed sample motif with a positive count is unsupported when it
has no positive correction factor under the selected mode.
unsupported_motifs="keep_na" keeps
that matrix cell as NaN. The "drop" policy is unavailable for
matrices because it would change a fixed result axis.
GroupedEndMotifCounts
End-motif counts for grouped BED output.
Public Methods
| Method | Summary |
|---|---|
data_frame | Create a pandas DataFrame of end-motif counts for grouped BED rows. |
group_metadata | Return grouped BED metadata for this end-motif output. |
group_idx | Find the end-motif row index for a group name. |
dense_counts_array | Return grouped end-motif counts as a dense NumPy array. |
sparse_counts_matrix | Return grouped end-motif counts as a SciPy sparse matrix. |
corrected_counts_array | Return grouped reference-corrected end-motif counts as a dense array. |
sparse_corrected_counts_matrix | Return grouped reference-corrected end-motif counts as a sparse matrix. |
GroupedEndMotifCounts.data_frame
GroupedEndMotifCounts.data_frame
GroupedEndMotifCounts.data_frame(*, ref_kmers: RefKmerFrequencies | None = None, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, densify: bool = False, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, max_blacklisted_fraction: float = 1.0, use_global_bias: bool = False, unsupported_motifs: str = 'error', two_sided_correction: str | None = None) -> pd.DataFrame
Create a pandas DataFrame of end-motif counts for grouped BED rows.
Use groups or group_idxs to keep only selected groups and motifs
or motif_idxs to keep only selected motifs. Sparse outputs return
stored non-zero rows unless densify=True. Densifying adds explicit
zero-count rows for selected observed motifs. Dense outputs always
include zero counts. Pass ref_kmers to add reference-corrected counts.
Reference correction
Reference correction divides each observed end-motif count by a reference-based correction factor for the matched row. This factor is computed from the motif frequencies in the reference k-mer output and normalized so a uniform reference composition leaves counts unchanged. Motifs that are common in the reference row are scaled down. Motifs that are rare in the reference row are scaled up. Only motifs with a positive reference frequency contribute to the row's correction support.
End-motif labels run inward from either fragment end, so reference
correction requires reference k-mer output generated with
--orientation both.
This is an approximate correction for broad or local
reference-composition bias. It assumes that left and right fragment
ends contribute equally within each row. Correction in short windows
can be unreliable, so use windows of at least a few kilobases.
Two-sided correction modes
When motif labels contain both outside and inside bases, such as
"AC_GT", two_sided_correction chooses both the motif labels in the
result and the correction factor used for each returned count.
-
"joint"keeps full labels such as"AC_GT"and corrects each count using the exact reference k-mer"ACGT". -
"split"keeps full labels such as"AC_GT", but calculates the correction factor from the two sides separately. For"AC_GT", separate correction factors are calculated for outside label"AC"and inside label"GT". Those two correction factors are multiplied and applied to the observed"AC_GT"count. Use this when you want full two-sided motif labels in the result, but the exact full reference k-mers are too sparse or you want the reference correction to treat outside and inside sequence composition separately. -
"outside"returns outside labels such as"AC_". For each outside label, all full motif counts with that outside label are summed first. For example,"AC_AA"and"AC_GT"both contribute to the"AC_"count. That summed count is corrected using the outside label"AC". -
"inside"returns inside labels such as"_GT". For each inside label, all full motif counts with that inside label are summed first. For example,"AA_GT"and"AC_GT"both contribute to the"_GT"count. That summed count is corrected using the inside label"GT".
For "split", "outside", and "inside", side-specific reference
frequencies are calculated from the loaded full-length reference
k-mers. For example, the outside frequency for "AC" is the sum of
frequencies for loaded k-mers with prefix "AC", such as "ACTG" and
"ACAA". The inside frequency for "TG" is the corresponding sum over
loaded k-mers with suffix "TG". Separate shorter reference k-mer runs
are not required.
A motifs file used for the reference output restricts these sums to the k-mers in that file. Without a motifs file, all k-mers in the reference output can contribute, including k-mers absent from the sample end-motif output.
corrected_frequency is normalized from corrected_count over the full
correction-mode motif axis for each output row. Motif selection filters
those frequencies afterward and does not renormalize them. A selected
subset can therefore sum to less than 1. If the corrected total is
zero, finite frequencies are zero. With unsupported_motifs="keep_na",
one undefined positive corrected count makes all frequencies in that
output row NaN.
Parameters
ref_kmers: Optional loaded reference k-mer output used for correction.groups:Nonefor all groups, one group name, or a sequence of group names. Use eithergroupsorgroup_idxs, not both.group_idxs:Nonefor all groups, one group index, or a sequence of group indices. Use eithergroupsorgroup_idxs, not both.densify: IfTrue, sparse outputs add explicit zero-count rows for selected observed motifs. Dense outputs ignore this option.motifs: Motif label or labels. Use eithermotifsormotif_idxs, not both.motif_idxs: Motif index or indices. Use eithermotifsormotif_idxs, not both.max_blacklisted_fraction: Maximum rowblacklisted_fractionin 0..1 to retain before counts are returned. The default1.0keeps all selected groups.use_global_bias: Whether a global reference k-mer output may be applied to every row.unsupported_motifs: What to do when an observed sample motif has no positive correction factor under the selected mode. Use"error","drop", or"keep_na".two_sided_correction: Required for two-sided motif labels such as"AC_GT"whenref_kmersis passed. Use"joint","split","outside", or"inside". Leave asNonefor one-sided motifs or motif groups.
Returns
pandas.DataFrame: Group metadata, motif metadata, andcount. Ifref_kmersis passed, also includescorrected_countandcorrected_frequency.
GroupedEndMotifCounts.group_metadata
GroupedEndMotifCounts.group_metadata
GroupedEndMotifCounts.group_metadata() -> pd.DataFrame
Return grouped BED metadata for this end-motif output.
Returns
pandas.DataFrame: Columns aregroup_idx,group_name,eligible_windows, andblacklisted_fraction.
GroupedEndMotifCounts.group_idx
GroupedEndMotifCounts.group_idx
GroupedEndMotifCounts.group_idx(group_name: str) -> int
Find the end-motif row index for a group name.
Parameters
group_name: Group name to resolve.
Returns
int: Group index.
GroupedEndMotifCounts.dense_counts_array
GroupedEndMotifCounts.dense_counts_array
GroupedEndMotifCounts.dense_counts_array(*, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, allow_densify: bool = False) -> np.ndarray
Return grouped end-motif counts as a dense NumPy array.
Sparse stores are only densified when allow_densify=True. Scalar
selectors keep their axes as length one, so the shape is always
(selected groups, selected motifs).
Parameters
groups:Nonefor all groups, one group name, or a sequence of group names. Use eithergroupsorgroup_idxs, not both.group_idxs:Nonefor all groups, one group index, or a sequence of group indices. Use eithergroupsorgroup_idxs, not both.motifs: Motif label or labels. Use eithermotifsormotif_idxs, not both.motif_idxs: Motif index or indices. Use eithermotifsormotif_idxs, not both.allow_densify: IfTrue, allow sparse stores to be converted to dense counts.
Returns
numpy.ndarray: Dense count array with shape(group, motif).
GroupedEndMotifCounts.sparse_counts_matrix
GroupedEndMotifCounts.sparse_counts_matrix
GroupedEndMotifCounts.sparse_counts_matrix(*, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None) -> sparse.coo_matrix
Return grouped end-motif counts as a SciPy sparse matrix.
Scalar selectors keep their axes as length one, so the shape is always
(selected groups, selected motifs).
Parameters
groups:Nonefor all groups, one group name, or a sequence of group names. Use eithergroupsorgroup_idxs, not both.group_idxs:Nonefor all groups, one group index, or a sequence of group indices. Use eithergroupsorgroup_idxs, not both.motifs: Motif label or labels. Use eithermotifsormotif_idxs, not both.motif_idxs: Motif index or indices. Use eithermotifsormotif_idxs, not both.
Returns
scipy.sparse.coo_matrix: Sparse count matrix with shape(group, motif).
GroupedEndMotifCounts.corrected_counts_array
GroupedEndMotifCounts.corrected_counts_array
GroupedEndMotifCounts.corrected_counts_array(ref_kmers: RefKmerFrequencies, *, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, allow_densify: bool = False, max_blacklisted_fraction: float = 1.0, use_global_bias: bool = False, unsupported_motifs: str = 'error', two_sided_correction: str | None = None) -> np.ndarray
Return grouped reference-corrected end-motif counts as a dense array.
The result has one row per selected group and one column per motif on
the selected correction-mode axis. "outside" and "inside" replace
the stored joint axis with a deduplicated side axis. Use
corrected_motifs_metadata() to inspect the exact column labels and
order. Sparse end-motif stores are not densified unless
allow_densify=True. Use
sparse_corrected_counts_matrix() to keep a sparse result.
unsupported_motifs="drop" is not allowed because arrays have a fixed
row and motif shape. Use
data_frame(ref_kmers=..., unsupported_motifs="drop") when
unsupported motifs should be omitted.
Reference correction
Reference correction divides each observed end-motif count by a reference-based correction factor for the matched row. This factor is computed from the motif frequencies in the reference k-mer output and normalized so a uniform reference composition leaves counts unchanged. Motifs that are common in the reference row are scaled down. Motifs that are rare in the reference row are scaled up. Only motifs with a positive reference frequency contribute to the row's correction support.
End-motif labels run inward from either fragment end, so reference
correction requires reference k-mer output generated with
--orientation both.
This is an approximate correction for broad or local
reference-composition bias. It assumes that left and right fragment
ends contribute equally within each row. Correction in short windows
can be unreliable, so use windows of at least a few kilobases.
Two-sided correction modes
When motif labels contain both outside and inside bases, such as
"AC_GT", two_sided_correction chooses both the motif labels in the
result and the correction factor used for each returned count.
-
"joint"keeps full labels such as"AC_GT"and corrects each count using the exact reference k-mer"ACGT". -
"split"keeps full labels such as"AC_GT", but calculates the correction factor from the two sides separately. For"AC_GT", separate correction factors are calculated for outside label"AC"and inside label"GT". Those two correction factors are multiplied and applied to the observed"AC_GT"count. Use this when you want full two-sided motif labels in the result, but the exact full reference k-mers are too sparse or you want the reference correction to treat outside and inside sequence composition separately. -
"outside"returns outside labels such as"AC_". For each outside label, all full motif counts with that outside label are summed first. For example,"AC_AA"and"AC_GT"both contribute to the"AC_"count. That summed count is corrected using the outside label"AC". -
"inside"returns inside labels such as"_GT". For each inside label, all full motif counts with that inside label are summed first. For example,"AA_GT"and"AC_GT"both contribute to the"_GT"count. That summed count is corrected using the inside label"GT".
For "split", "outside", and "inside", side-specific reference
frequencies are calculated from the loaded full-length reference
k-mers. For example, the outside frequency for "AC" is the sum of
frequencies for loaded k-mers with prefix "AC", such as "ACTG" and
"ACAA". The inside frequency for "TG" is the corresponding sum over
loaded k-mers with suffix "TG". Separate shorter reference k-mer runs
are not required.
A motifs file used for the reference output restricts these sums to the k-mers in that file. Without a motifs file, all k-mers in the reference output can contribute, including k-mers absent from the sample end-motif output.
An observed sample motif with a positive count is unsupported when it
has no positive correction factor under the selected mode.
unsupported_motifs="keep_na" keeps
that matrix cell as NaN. The "drop" policy is unavailable for
matrices because it would change a fixed result axis.
GroupedEndMotifCounts.sparse_corrected_counts_matrix
GroupedEndMotifCounts.sparse_corrected_counts_matrix
GroupedEndMotifCounts.sparse_corrected_counts_matrix(ref_kmers: RefKmerFrequencies, *, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, max_blacklisted_fraction: float = 1.0, use_global_bias: bool = False, unsupported_motifs: str = 'error', two_sided_correction: str | None = None) -> sparse.coo_matrix
Return grouped reference-corrected end-motif counts as a sparse matrix.
The result has one row per selected group and one column per motif on
the selected correction-mode axis. "outside" and "inside" can have
fewer columns than sparse_counts_matrix(). Use
corrected_motifs_metadata() to inspect the exact column labels and
order. Corrected zeroes are not stored. Corrected NaN values from
unsupported_motifs="keep_na" are stored so they remain visible.
unsupported_motifs="drop" is not allowed because sparse matrices
still have a fixed row and motif shape. Use
data_frame(ref_kmers=..., unsupported_motifs="drop") when
unsupported motifs should be omitted.
Reference correction
Reference correction divides each observed end-motif count by a reference-based correction factor for the matched row. This factor is computed from the motif frequencies in the reference k-mer output and normalized so a uniform reference composition leaves counts unchanged. Motifs that are common in the reference row are scaled down. Motifs that are rare in the reference row are scaled up. Only motifs with a positive reference frequency contribute to the row's correction support.
End-motif labels run inward from either fragment end, so reference
correction requires reference k-mer output generated with
--orientation both.
This is an approximate correction for broad or local
reference-composition bias. It assumes that left and right fragment
ends contribute equally within each row. Correction in short windows
can be unreliable, so use windows of at least a few kilobases.
Two-sided correction modes
When motif labels contain both outside and inside bases, such as
"AC_GT", two_sided_correction chooses both the motif labels in the
result and the correction factor used for each returned count.
-
"joint"keeps full labels such as"AC_GT"and corrects each count using the exact reference k-mer"ACGT". -
"split"keeps full labels such as"AC_GT", but calculates the correction factor from the two sides separately. For"AC_GT", separate correction factors are calculated for outside label"AC"and inside label"GT". Those two correction factors are multiplied and applied to the observed"AC_GT"count. Use this when you want full two-sided motif labels in the result, but the exact full reference k-mers are too sparse or you want the reference correction to treat outside and inside sequence composition separately. -
"outside"returns outside labels such as"AC_". For each outside label, all full motif counts with that outside label are summed first. For example,"AC_AA"and"AC_GT"both contribute to the"AC_"count. That summed count is corrected using the outside label"AC". -
"inside"returns inside labels such as"_GT". For each inside label, all full motif counts with that inside label are summed first. For example,"AA_GT"and"AC_GT"both contribute to the"_GT"count. That summed count is corrected using the inside label"GT".
For "split", "outside", and "inside", side-specific reference
frequencies are calculated from the loaded full-length reference
k-mers. For example, the outside frequency for "AC" is the sum of
frequencies for loaded k-mers with prefix "AC", such as "ACTG" and
"ACAA". The inside frequency for "TG" is the corresponding sum over
loaded k-mers with suffix "TG". Separate shorter reference k-mer runs
are not required.
A motifs file used for the reference output restricts these sums to the k-mers in that file. Without a motifs file, all k-mers in the reference output can contribute, including k-mers absent from the sample end-motif output.
An observed sample motif with a positive count is unsupported when it
has no positive correction factor under the selected mode.
unsupported_motifs="keep_na" keeps
that matrix cell as NaN. The "drop" policy is unavailable for
matrices because it would change a fixed result axis.
Reference K-mer Frequencies
Load reference k-mer frequency Zarr stores and extract frequency tables, dense arrays, sparse matrices, and reconstructed counts.
| Symbol | Type | Summary |
|---|---|---|
read_ref_kmers | function | Open a cfDNAlab reference k-mer frequency output directory. |
RefKmerFrequencies | class | Common API for global, windowed, and grouped reference k-mer outputs. |
GlobalRefKmerFrequencies | class | Reference k-mer frequencies for global output. |
WindowedRefKmerFrequencies | class | Reference k-mer frequencies for fixed-size or BED-window output. |
GroupedRefKmerFrequencies | class | Reference k-mer frequencies for grouped BED output. |
read_ref_kmers
read_ref_kmers(path: pathlib.Path | str) -> GlobalRefKmerFrequencies | WindowedRefKmerFrequencies | GroupedRefKmerFrequencies
Open a cfDNAlab reference k-mer frequency output directory.
RefKmerFrequencies
Common API for global, windowed, and grouped reference k-mer outputs.
A reference k-mer output describes the expected background k-mer composition for one or more rows. A row can be the whole reference, a genomic window, a BED interval, or a grouped BED entry.
The file stores frequencies. Count helpers reconstruct comparable counts as
frequency * row_scaling_factor[row], where the scaling factor is the
number of reference k-mer positions represented by that row.
Public Python selectors use zero-based indices. For example, motif_idxs=0
selects the first motif in motifs_metadata().
Public Methods
| Method | Summary |
|---|---|
storage_mode | Return whether the output is saved as dense values or sparse values. |
row_mode | Return what each reference k-mer frequency row represents. |
motif_axis_kind | Return whether columns represent concrete k-mers or motif groups. |
kmer_size | Return the k-mer size used by the reference k-mer command. |
canonical | Return whether reverse-complement k-mers were collapsed. |
orientation | Return which sequence orientations contributed to each motif frequency. |
all_motifs | Return whether the command kept every requested motif target. |
assign_by | Return the window assignment rule used by the command. |
reference_contig_footprint | Return which reference contigs contributed to the output. |
motifs_metadata | Return the k-mer labels and motif indices available in this output. |
motif_idx | Find the zero-based motif-axis index for a motif label. |
has_motif | Return whether a motif label exists in this output. |
row_scaling_factors | Return row metadata and factors used to reconstruct k-mer counts. |
dense_frequencies_zarr_array | Return the on-disk frequency array for advanced dense-output workflows. |
RefKmerFrequencies.storage_mode
RefKmerFrequencies.storage_mode
RefKmerFrequencies.storage_mode() -> str
Return whether the output is saved as dense values or sparse values.
Dense output has a value for every row and motif. Sparse output stores only non-zero values and is usually better for large outputs.
RefKmerFrequencies.row_mode
RefKmerFrequencies.row_mode
RefKmerFrequencies.row_mode() -> str
Return what each reference k-mer frequency row represents.
global has one row for the whole reference. size and bed rows are
genomic windows. grouped_bed rows are BED groups.
RefKmerFrequencies.motif_axis_kind
RefKmerFrequencies.motif_axis_kind
RefKmerFrequencies.motif_axis_kind() -> str
Return whether columns represent concrete k-mers or motif groups.
RefKmerFrequencies.kmer_size
RefKmerFrequencies.kmer_size
RefKmerFrequencies.kmer_size() -> int
Return the k-mer size used by the reference k-mer command.
RefKmerFrequencies.canonical
RefKmerFrequencies.canonical
RefKmerFrequencies.canonical() -> bool
Return whether reverse-complement k-mers were collapsed.
RefKmerFrequencies.orientation
RefKmerFrequencies.orientation
RefKmerFrequencies.orientation() -> str
Return which sequence orientations contributed to each motif frequency.
"both" averages the reference-forward sequence and its reverse
complement. "reference_forward" uses only the sequence read
left-to-right from the stored reference.
RefKmerFrequencies.all_motifs
RefKmerFrequencies.all_motifs
RefKmerFrequencies.all_motifs() -> bool
Return whether the command kept every requested motif target.
For full k-mer output, this means every A/C/G/T k-mer for the requested k. For motifs-file output, this means every target from the motifs file.
RefKmerFrequencies.assign_by
RefKmerFrequencies.assign_by
RefKmerFrequencies.assign_by() -> str
Return the window assignment rule used by the command.
RefKmerFrequencies.reference_contig_footprint
RefKmerFrequencies.reference_contig_footprint
RefKmerFrequencies.reference_contig_footprint() -> Any
Return which reference contigs contributed to the output.
The result is decoded metadata from the output file. It is useful for checking that the reference used for loading matches the expected genome or contig subset.
RefKmerFrequencies.motifs_metadata
RefKmerFrequencies.motifs_metadata
RefKmerFrequencies.motifs_metadata() -> pd.DataFrame
Return the k-mer labels and motif indices available in this output.
For grouped motifs-file output, the motif labels are the motif-group
names used during counting. The returned motif_index values are
zero-based and can be passed to motif_idxs.
If all_motifs() is false, the motif axis is the combined set of
motifs or motifs-file targets observed anywhere in the output.
Densifying sparse output fills zeroes only across this listed axis. It
does not add every possible k-mer.
RefKmerFrequencies.motif_idx
RefKmerFrequencies.motif_idx
RefKmerFrequencies.motif_idx(motif: str) -> int
Find the zero-based motif-axis index for a motif label.
RefKmerFrequencies.has_motif
RefKmerFrequencies.has_motif
RefKmerFrequencies.has_motif(motif: str) -> bool
Return whether a motif label exists in this output.
Observed-only output can omit motifs that were not observed anywhere in
the output, so this can return False even for a valid A/C/G/T k-mer.
RefKmerFrequencies.row_scaling_factors
RefKmerFrequencies.row_scaling_factors
RefKmerFrequencies.row_scaling_factors() -> pd.DataFrame
Return row metadata and factors used to reconstruct k-mer counts.
Frequencies are fractions. Multiplying a row's frequency by its
row_scaling_factor gives the reconstructed count for that row.
RefKmerFrequencies.dense_frequencies_zarr_array
RefKmerFrequencies.dense_frequencies_zarr_array
RefKmerFrequencies.dense_frequencies_zarr_array() -> zarr.Array
Return the on-disk frequency array for advanced dense-output workflows.
Most users should use dense_frequencies_array(), which returns a
NumPy array, or data_frame(), which returns a pandas data frame. This
method returns the underlying Zarr array so advanced users can slice it
without first reading the whole array into memory.
This is only available for dense output. Sparse output does not have an
on-disk dense frequency array. Use sparse_frequencies_matrix() for
sparse output, or call a dense helper with allow_densify=True when the
full selected result is small enough to hold in memory.
GlobalRefKmerFrequencies
Reference k-mer frequencies for global output.
Public Methods
| Method | Summary |
|---|---|
data_frame | Create a pandas data frame for global reference k-mer frequencies. |
dense_frequencies_array | Return global reference k-mer frequencies as a dense NumPy array. |
dense_counts_array | Return reconstructed global reference k-mer counts as a dense array. |
sparse_frequencies_matrix | Return global reference k-mer frequencies as a SciPy sparse matrix. |
sparse_counts_matrix | Return reconstructed global reference k-mer counts as a SciPy sparse matrix. |
GlobalRefKmerFrequencies.data_frame
GlobalRefKmerFrequencies.data_frame
GlobalRefKmerFrequencies.data_frame(*, densify: bool = False, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None) -> pd.DataFrame
Create a pandas data frame for global reference k-mer frequencies.
The data frame contains one row per selected motif with frequency and
reconstructed count. Sparse output returns only non-zero stored values
unless densify=True, which adds zero-frequency rows for the selected
motifs in motifs_metadata(). For observed-only output, those selected
labels are the combined set observed anywhere in the output. Densifying
does not add every possible k-mer unless all_motifs() is true.
GlobalRefKmerFrequencies.dense_frequencies_array
GlobalRefKmerFrequencies.dense_frequencies_array
GlobalRefKmerFrequencies.dense_frequencies_array(*, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, allow_densify: bool = False) -> np.ndarray
Return global reference k-mer frequencies as a dense NumPy array.
Sparse output requires allow_densify=True because the method creates
an in-memory array with one value for every selected motif in
motifs_metadata(), including zeroes that were not stored on disk.
GlobalRefKmerFrequencies.dense_counts_array
GlobalRefKmerFrequencies.dense_counts_array
GlobalRefKmerFrequencies.dense_counts_array(*, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, allow_densify: bool = False) -> np.ndarray
Return reconstructed global reference k-mer counts as a dense array.
Counts are reconstructed from frequencies with the global row scaling
factor. Sparse output requires allow_densify=True because the method
creates an in-memory array with explicit zeroes for selected motifs in
motifs_metadata().
GlobalRefKmerFrequencies.sparse_frequencies_matrix
GlobalRefKmerFrequencies.sparse_frequencies_matrix
GlobalRefKmerFrequencies.sparse_frequencies_matrix(*, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None) -> sparse.coo_matrix
Return global reference k-mer frequencies as a SciPy sparse matrix.
GlobalRefKmerFrequencies.sparse_counts_matrix
GlobalRefKmerFrequencies.sparse_counts_matrix
GlobalRefKmerFrequencies.sparse_counts_matrix(*, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None) -> sparse.coo_matrix
Return reconstructed global reference k-mer counts as a SciPy sparse matrix.
WindowedRefKmerFrequencies
Reference k-mer frequencies for fixed-size or BED-window output.
Public Methods
| Method | Summary |
|---|---|
data_frame | Create a pandas data frame for windowed reference k-mer frequencies. |
window_metadata | Return genomic window metadata for this reference k-mer output. |
dense_frequencies_array | Return windowed reference k-mer frequencies as a dense NumPy array. |
dense_counts_array | Return reconstructed windowed reference k-mer counts as a dense array. |
sparse_frequencies_matrix | Return windowed reference k-mer frequencies as a SciPy sparse matrix. |
sparse_counts_matrix | Return reconstructed windowed reference k-mer counts as a SciPy sparse matrix. |
WindowedRefKmerFrequencies.data_frame
WindowedRefKmerFrequencies.data_frame
WindowedRefKmerFrequencies.data_frame(*, window_idxs: int | Sequence[int] | None = None, densify: bool = False, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, max_blacklisted_fraction: float = 1.0) -> pd.DataFrame
Create a pandas data frame for windowed reference k-mer frequencies.
window_idxs and motif_idxs are zero-based indices. The data frame
includes window metadata, motif metadata, frequency, and reconstructed
count.
Sparse output returns only non-zero stored values unless densify=True,
which adds zero-frequency rows for the selected windows and the
selected motifs in motifs_metadata(). For observed-only output, those
selected labels are the combined set observed anywhere in the output.
Densifying does not add every possible k-mer unless all_motifs() is
true.
WindowedRefKmerFrequencies.window_metadata
WindowedRefKmerFrequencies.window_metadata
WindowedRefKmerFrequencies.window_metadata() -> pd.DataFrame
Return genomic window metadata for this reference k-mer output.
window_idx is the zero-based row index accepted by window selectors.
start and end are half-open genomic coordinates.
WindowedRefKmerFrequencies.dense_frequencies_array
WindowedRefKmerFrequencies.dense_frequencies_array
WindowedRefKmerFrequencies.dense_frequencies_array(*, window_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, allow_densify: bool = False) -> np.ndarray
Return windowed reference k-mer frequencies as a dense NumPy array.
Sparse output requires allow_densify=True because the method creates
an in-memory array with one value for every selected window and every
selected motif in motifs_metadata(), including zeroes that were not
stored on disk.
WindowedRefKmerFrequencies.dense_counts_array
WindowedRefKmerFrequencies.dense_counts_array
WindowedRefKmerFrequencies.dense_counts_array(*, window_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, allow_densify: bool = False) -> np.ndarray
Return reconstructed windowed reference k-mer counts as a dense array.
Counts are reconstructed row-wise from frequencies and
row_scaling_factor. Sparse output requires allow_densify=True
because the method creates an in-memory array with explicit zeroes for
selected motifs in motifs_metadata().
WindowedRefKmerFrequencies.sparse_frequencies_matrix
WindowedRefKmerFrequencies.sparse_frequencies_matrix
WindowedRefKmerFrequencies.sparse_frequencies_matrix(*, window_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None) -> sparse.coo_matrix
Return windowed reference k-mer frequencies as a SciPy sparse matrix.
WindowedRefKmerFrequencies.sparse_counts_matrix
WindowedRefKmerFrequencies.sparse_counts_matrix
WindowedRefKmerFrequencies.sparse_counts_matrix(*, window_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None) -> sparse.coo_matrix
Return reconstructed windowed reference k-mer counts as a SciPy sparse matrix.
GroupedRefKmerFrequencies
Reference k-mer frequencies for grouped BED output.
Public Methods
| Method | Summary |
|---|---|
data_frame | Create a pandas data frame for grouped reference k-mer frequencies. |
group_metadata | Return grouped BED metadata for this reference k-mer output. |
group_idx | Find the zero-based reference k-mer row index for a group name. |
dense_frequencies_array | Return grouped reference k-mer frequencies as a dense NumPy array. |
dense_counts_array | Return reconstructed grouped reference k-mer counts as a dense array. |
sparse_frequencies_matrix | Return grouped reference k-mer frequencies as a SciPy sparse matrix. |
sparse_counts_matrix | Return reconstructed grouped reference k-mer counts as a SciPy sparse matrix. |
GroupedRefKmerFrequencies.data_frame
GroupedRefKmerFrequencies.data_frame
GroupedRefKmerFrequencies.data_frame(*, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, densify: bool = False, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, max_blacklisted_fraction: float = 1.0) -> pd.DataFrame
Create a pandas data frame for grouped reference k-mer frequencies.
group_idxs and motif_idxs are zero-based indices. groups selects
rows by group name. The data frame includes group metadata, motif
metadata, frequency, and reconstructed count.
Sparse output returns only non-zero stored values unless densify=True,
which adds zero-frequency rows for the selected groups and the selected
motifs in motifs_metadata(). For observed-only output, those selected
labels are the combined set observed anywhere in the output. Densifying
does not add every possible k-mer unless all_motifs() is true.
GroupedRefKmerFrequencies.group_metadata
GroupedRefKmerFrequencies.group_metadata
GroupedRefKmerFrequencies.group_metadata() -> pd.DataFrame
Return grouped BED metadata for this reference k-mer output.
group_idx is the zero-based row index accepted by group selectors.
GroupedRefKmerFrequencies.group_idx
GroupedRefKmerFrequencies.group_idx
GroupedRefKmerFrequencies.group_idx(group_name: str) -> int
Find the zero-based reference k-mer row index for a group name.
GroupedRefKmerFrequencies.dense_frequencies_array
GroupedRefKmerFrequencies.dense_frequencies_array
GroupedRefKmerFrequencies.dense_frequencies_array(*, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, allow_densify: bool = False) -> np.ndarray
Return grouped reference k-mer frequencies as a dense NumPy array.
Sparse output requires allow_densify=True because the method creates
an in-memory array with one value for every selected group and every
selected motif in motifs_metadata(), including zeroes that were not
stored on disk.
GroupedRefKmerFrequencies.dense_counts_array
GroupedRefKmerFrequencies.dense_counts_array
GroupedRefKmerFrequencies.dense_counts_array(*, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None, allow_densify: bool = False) -> np.ndarray
Return reconstructed grouped reference k-mer counts as a dense array.
Counts are reconstructed row-wise from frequencies and
row_scaling_factor. Sparse output requires allow_densify=True
because the method creates an in-memory array with explicit zeroes for
selected motifs in motifs_metadata().
GroupedRefKmerFrequencies.sparse_frequencies_matrix
GroupedRefKmerFrequencies.sparse_frequencies_matrix
GroupedRefKmerFrequencies.sparse_frequencies_matrix(*, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None) -> sparse.coo_matrix
Return grouped reference k-mer frequencies as a SciPy sparse matrix.
GroupedRefKmerFrequencies.sparse_counts_matrix
GroupedRefKmerFrequencies.sparse_counts_matrix
GroupedRefKmerFrequencies.sparse_counts_matrix(*, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, motifs: str | Sequence[str] | None = None, motif_idxs: int | Sequence[int] | None = None) -> sparse.coo_matrix
Return reconstructed grouped reference k-mer counts as a SciPy sparse matrix.
Length Counts
Load fragment length-count TSV outputs and return counts, fractions, or densities as arrays, matrices, vectors, or data frames.
| Symbol | Type | Summary |
|---|---|---|
read_lengths | function | Read a cfDNAlab length-count TSV and return the matching loader class. |
LengthCounts | class | Common API for global, windowed, and grouped length-count outputs. |
GlobalLengthCounts | class | Length counts for global output. |
WindowedLengthCounts | class | Length counts for fixed-size or BED-window output. |
GroupedLengthCounts | class | Length counts for grouped BED output. |
read_lengths
read_lengths(path: pathlib.Path | str) -> GlobalLengthCounts | WindowedLengthCounts | GroupedLengthCounts
Read a cfDNAlab length-count TSV and return the matching loader class.
Parameters
path: Path to a.length_counts.tsvor.length_counts.tsv.zstfile.
Returns
LengthCounts:GlobalLengthCounts,WindowedLengthCounts, orGroupedLengthCounts, depending on the TSV metadata columns.
LengthCounts
Common API for global, windowed, and grouped length-count outputs.
Public Methods
| Method | Summary |
|---|---|
length_bins | Return fragment length bin definitions used by the count columns. |
length_bin_idx | Find the length-bin index whose interval contains a fragment length. |
counts_array | Return raw length counts as a dense NumPy array. |
LengthCounts.length_bins
LengthCounts.length_bins
LengthCounts.length_bins() -> pd.DataFrame
Return fragment length bin definitions used by the count columns.
Length bins are half-open intervals. A bin with length_start_bp=30
and length_end_bp=50 contains fragment lengths 30 <= length < 50.
Returns
pandas.DataFrame: Columns arelength_bin,length_start_bp,length_end_bp,length_midpoint_bp, andlength_width_bp.
LengthCounts.length_bin_idx
LengthCounts.length_bin_idx
LengthCounts.length_bin_idx(length: int) -> int
Find the length-bin index whose interval contains a fragment length.
Parameters
length: Fragment length in bp.
Returns
int: Length-bin index.
Raises
KeyError: If no length bin containslength.
LengthCounts.counts_array
LengthCounts.counts_array
LengthCounts.counts_array(*, with_lengths: int | Sequence[int] | None = None, with_length_range: Sequence[int] | None = None, length_bin_idxs: int | Sequence[int] | None = None) -> np.ndarray
Return raw length counts as a dense NumPy array.
Use with_lengths, with_length_range, or length_bin_idxs to select
length bins. Range selection uses whole bins overlapping the half-open
[start, end) bp range.
Parameters
with_lengths: Fragment length or lengths in bp. Counts are returned for the length bins containing these lengths. Multiple lengths must select distinct length bins.with_length_range: Two bp bounds defining a half-open range[start, end).length_bin_idxs:Nonefor all length bins, one length-bin index, or a sequence of length-bin indices. Use only one ofwith_lengths,with_length_range, orlength_bin_idxs.
Returns
numpy.ndarray: Count array with shape(output row, length_bin). Output rows are windows for windowed output, groups for grouped output, and the single global summary row for global output.
GlobalLengthCounts
Length counts for global output.
Public Methods
| Method | Summary |
|---|---|
data_frame | Create a pandas DataFrame for the global fragment length distribution. |
GlobalLengthCounts.data_frame
GlobalLengthCounts.data_frame
GlobalLengthCounts.data_frame(*, with_lengths: int | Sequence[int] | None = None, with_length_range: Sequence[int] | None = None, length_bin_idxs: int | Sequence[int] | None = None, value: str = 'count', denominator: str = 'all_bins', keep_wide: bool = False) -> pd.DataFrame
Create a pandas DataFrame for the global fragment length distribution.
Long output has one row per length bin with bin metadata. Wide output has one row with one value column per length bin.
Parameters
with_lengths: Fragment length or lengths in bp. Returned values use the length bins containing these lengths. Multiple lengths must select distinct length bins.with_length_range: Two bp bounds defining a half-open range[start, end). Returned values use whole length bins that overlap this range.length_bin_idxs:Nonefor all length bins, one length-bin index, or a sequence of length-bin indices. Use only one ofwith_lengths,with_length_range, orlength_bin_idxs.value: One of"count","fraction", or"density". Fractions are within the global row. Densities are fractions divided by the length-bin width.denominator: For"fraction"and"density","all_bins"divides by the row total over all length bins, while"selected_bins"divides by the total over the returned length bins. Ignored for"count".keep_wide: IfFalse, return one row per length bin. IfTrue, return one row with one value column per length bin.
Returns
pandas.DataFrame: Global length-count values with length-bin metadata for long output or value-prefixed columns for wide output.
WindowedLengthCounts
Length counts for fixed-size or BED-window output.
Public Methods
| Method | Summary |
|---|---|
window_metadata | Return genomic window metadata for this length-count output. |
counts_array | Return raw length counts as a dense NumPy array. |
data_frame | Create a pandas DataFrame of fragment length distributions for windows. |
WindowedLengthCounts.window_metadata
WindowedLengthCounts.window_metadata
WindowedLengthCounts.window_metadata() -> pd.DataFrame
Return genomic window metadata for this length-count output.
Returns
pandas.DataFrame: Columns arewindow_idx,chrom,start,end, and optionallyblacklisted_fraction.
WindowedLengthCounts.counts_array
WindowedLengthCounts.counts_array
WindowedLengthCounts.counts_array(*, window_idxs: int | Sequence[int] | None = None, with_lengths: int | Sequence[int] | None = None, with_length_range: Sequence[int] | None = None, length_bin_idxs: int | Sequence[int] | None = None) -> np.ndarray
Return raw length counts as a dense NumPy array.
Scalar selectors keep their axis as length one, so the shape is always
(selected windows, length_bin).
Parameters
window_idxs:Nonefor all windows, one window index, or a sequence of window indices.with_lengths: Fragment length or lengths in bp. Counts are returned for the length bins containing these lengths. Multiple lengths must select distinct length bins.with_length_range: Two bp bounds defining a half-open range[start, end).length_bin_idxs:Nonefor all length bins, one length-bin index, or a sequence of length-bin indices. Use only one ofwith_lengths,with_length_range, orlength_bin_idxs.
Returns
numpy.ndarray: Count array with shape(window, length_bin).
WindowedLengthCounts.data_frame
WindowedLengthCounts.data_frame
WindowedLengthCounts.data_frame(*, window_idxs: int | Sequence[int] | None = None, with_lengths: int | Sequence[int] | None = None, with_length_range: Sequence[int] | None = None, length_bin_idxs: int | Sequence[int] | None = None, value: str = 'count', denominator: str = 'all_bins', keep_wide: bool = False, max_blacklisted_fraction: float = 1.0) -> pd.DataFrame
Create a pandas DataFrame of fragment length distributions for windows.
Use window_idxs to keep only selected genomic windows. Long output has
one row per selected window and length bin. Wide output has one row per
selected window with one value column per length bin.
Parameters
window_idxs:Nonefor all windows, a window index, or a sequence of window indices.with_lengths: Fragment length or lengths in bp. Returned values use the length bins containing these lengths. Multiple lengths must select distinct length bins.with_length_range: Two bp bounds defining a half-open range[start, end). Returned values use whole length bins that overlap this range.length_bin_idxs:Nonefor all length bins, one length-bin index, or a sequence of length-bin indices. Use only one ofwith_lengths,with_length_range, orlength_bin_idxs.value: One of"count","fraction", or"density". Fractions are within each selected window. Densities are fractions divided by the length-bin width.denominator: For"fraction"and"density","all_bins"divides by each row's total over all length bins, while"selected_bins"divides by the total over the returned length bins. Ignored for"count".keep_wide: IfFalse, return one row per selected window and length bin. IfTrue, return one row per selected window with one value column per length bin.max_blacklisted_fraction: Maximumblacklisted_fractionin 0..1 to keep. The default1.0keeps all selected windows.
Returns
pandas.DataFrame: Window metadata and length-count values.
GroupedLengthCounts
Length counts for grouped BED output.
Public Methods
| Method | Summary |
|---|---|
group_metadata | Return grouped BED metadata for this length-count output. |
group_idx | Find the count-row index for a group name. |
counts_array | Return raw length counts as a dense NumPy array. |
data_frame | Create a pandas DataFrame of fragment length distributions for groups. |
GroupedLengthCounts.group_metadata
GroupedLengthCounts.group_metadata
GroupedLengthCounts.group_metadata() -> pd.DataFrame
Return grouped BED metadata for this length-count output.
Returns
pandas.DataFrame: Columns aregroup_idx,group_name,eligible_windows, and optionallyblacklisted_fraction.
GroupedLengthCounts.group_idx
GroupedLengthCounts.group_idx
GroupedLengthCounts.group_idx(group_name: str) -> int
Find the count-row index for a group name.
Parameters
group_name: Group name to resolve.
Returns
int: Group index.
GroupedLengthCounts.counts_array
GroupedLengthCounts.counts_array
GroupedLengthCounts.counts_array(*, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, with_lengths: int | Sequence[int] | None = None, with_length_range: Sequence[int] | None = None, length_bin_idxs: int | Sequence[int] | None = None) -> np.ndarray
Return raw length counts as a dense NumPy array.
Scalar selectors keep their axis as length one, so the shape is always
(selected groups, length_bin).
Parameters
groups:Nonefor all groups, one group name, or a sequence of group names. Use eithergroupsorgroup_idxs, not both.group_idxs:Nonefor all groups, one group index, or a sequence of group indices. Use eithergroupsorgroup_idxs, not both.with_lengths: Fragment length or lengths in bp. Counts are returned for the length bins containing these lengths. Multiple lengths must select distinct length bins.with_length_range: Two bp bounds defining a half-open range[start, end).length_bin_idxs:Nonefor all length bins, one length-bin index, or a sequence of length-bin indices. Use only one ofwith_lengths,with_length_range, orlength_bin_idxs.
Returns
numpy.ndarray: Count array with shape(group, length_bin).
GroupedLengthCounts.data_frame
GroupedLengthCounts.data_frame
GroupedLengthCounts.data_frame(*, groups: str | Sequence[str] | None = None, group_idxs: int | Sequence[int] | None = None, with_lengths: int | Sequence[int] | None = None, with_length_range: Sequence[int] | None = None, length_bin_idxs: int | Sequence[int] | None = None, value: str = 'count', denominator: str = 'all_bins', keep_wide: bool = False, max_blacklisted_fraction: float = 1.0) -> pd.DataFrame
Create a pandas DataFrame of fragment length distributions for groups.
Use groups or group_idxs to keep only selected grouped BED rows.
Long output has one row per selected group and length bin. Wide output
has one row per selected group with one value column per length bin.
Parameters
groups:Nonefor all groups, one group name, or a sequence of group names. Use eithergroupsorgroup_idxs, not both.group_idxs:Nonefor all groups, one group index, or a sequence of group indices. Use eithergroupsorgroup_idxs, not both.with_lengths: Fragment length or lengths in bp. Returned values use the length bins containing these lengths. Multiple lengths must select distinct length bins.with_length_range: Two bp bounds defining a half-open range[start, end). Returned values use whole length bins that overlap this range.length_bin_idxs:Nonefor all length bins, one length-bin index, or a sequence of length-bin indices. Use only one ofwith_lengths,with_length_range, orlength_bin_idxs.value: One of"count","fraction", or"density". Fractions are within each selected group. Densities are fractions divided by the length-bin width.denominator: For"fraction"and"density","all_bins"divides by each row's total over all length bins, while"selected_bins"divides by the total over the returned length bins. Ignored for"count".keep_wide: IfFalse, return one row per selected group and length bin. IfTrue, return one row per selected group with one value column per length bin.max_blacklisted_fraction: Maximumblacklisted_fractionin 0..1 to keep. The default1.0keeps all selected groups.
Returns
pandas.DataFrame: Group metadata and length-count values.