tfmindi.pp.extract_seqlets#
- tfmindi.pp.extract_seqlets(contrib, oh, method='recursive_q99_abs_smooth', motifs=None, **method_kwargs)#
Extract, scale, and process seqlets from saliency maps.
Seqlets are called from either the projected 1D attribution track
(contrib * oh).sum(1)or, for"finemo_fit_contrib", directly from the rawcontrib/oh/motifs, using the selectedmethod; each seqlet’s contribution matrix is then normalized by its maximum absolute contribution value and sign-corrected.- Parameters:
contrib (
ndarray) – Contribution scores array with shape (n_examples, 4, length)oh (
ndarray) – One-hot encoded sequences array with shape (n_examples, 4, length)method (
Literal['recursive_q99_abs_smooth','recursive_raw','hysteresis','local_contrast','wavelet_otsu','finemo_fit_contrib'] (default:'recursive_q99_abs_smooth')) –Seqlet-calling algorithm to use. One of:
"recursive_q99_abs_smooth"(default): triangular-smooth, per-example q99 normalisation, then the recursive caller onabs(track). Acceptssmooth_window(9),threshold(0.05),min_seqlet_len(4),max_seqlet_len(25),additional_flanks(3),n_bins(1000). If calling seqlets on data with a large dynamic range, consider increasingn_bins."recursive_raw": recursive caller on the raw signed track (reproduces the previous TF-MInDi default behaviour). Same knobs as above."hysteresis": two-threshold local caller. Acceptssmooth_window,seed_z(2.5),grow_z(1.0),min_seqlet_len(4),max_seqlet_len(25),merge_gap(2)."local_contrast": multi-scale sliding-window contrast caller. Acceptswindows(10, 16, 24),smooth_window(9),seed_z(4.0),expand_z(1.25), …"wavelet_otsu": wavelet-denoise + Otsu-threshold caller (needs PyWavelets). Acceptswavelet,threshold_scale(1.7),otsu_weight,min_seqlet_len, …"finemo_fit_contrib": fitsmotifs(after IC scaling) directly against the rawcontrib/oharrays via thefinemopackage (GPU-optimized), instead of thresholding the projected 1D track. Requiresmotifsto be given. Acceptsic_trim_threshold(0.2),ic_background,pseudocount,include_rc,include_neg,compile_optimizer,batch_size.
motifs (
dict[str,ndarray] |None(default:None)) – Mapping of motif_id -> PFM array of shape (4, W) in A, C, G, T order, each column summing to 1. Only used (and required) whenmethod="finemo_fit_contrib".**method_kwargs – Method-specific hyperparameters forwarded to the selected caller, overriding its defaults, e.g.
threshold=0.1for the recursive methods,seed_z=3.0forhysteresis,threshold_scale=2.0forwavelet_otsu. Passing a keyword the chosen caller does not accept raises aTypeError. See the per-method caller classes for the full parameter lists (rec_q99_smooth_abs,recursive_raw,hysteresis,local_contrast,wavelet_otsu,finemo_fit_contrib).
- Return type:
- Returns:
DataFrame with seqlet coordinates and scores [example_idx, start, end, attribution, score]
List of processed seqlet contribution matrices
Examples
>>> seqlets_df, seqlet_matrices = extract_seqlets(contrib, oh) >>> print(seqlets_df.columns.tolist()) ['example_idx', 'start', 'end', 'attribution', 'score'] >>> # switch caller and tune it in one call >>> seqlets_df, seqlet_matrices = extract_seqlets(contrib, oh, method="hysteresis", seed_z=3.0) >>> # fit known motifs directly against the contribution scores via finemo >>> seqlets_df, seqlet_matrices = extract_seqlets(contrib, oh, method="finemo_fit_contrib", motifs=motifs)