SequenceFeature.get_split_kws

static SequenceFeature.get_split_kws(split_types=None, n_split_min=1, n_split_max=15, steps_pattern=None, n_min=2, n_max=4, len_max=15, steps_periodicpattern=None, strategy=None)[source]

Create dictionary with kwargs for three split types:

  • Segment: continuous sub-sequence.

  • Pattern: non-periodic discontinuous sub-sequence

  • PeriodicPattern: periodic discontinuous sub-sequence.

A strategy preset names the Comparative Physicochemical Profiling (CPP) strategy directly instead of spelling it out through split_types, n_split_min, and n_split_max.

Added in version 0.1.0.

Changed in version 1.2.0: Added the strategy presets for compositional and positional CPP features.

Parameters:
  • split_types ({'Segment', 'Pattern', 'PeriodicPattern'} or list-like of str, default=None) – Split types for which to create parameter dictionaries. A string selects one type; a non-empty list, tuple, one-dimensional NumPy array, or pandas Series selects the supplied types. If None, all three split types are selected. Must remain None when strategy is not None.

  • n_split_min (int, default=1) – Minimum number of segments for the Segment entry. Must be >= 1 and no greater than n_split_max when Segment is selected. Must remain 1 when strategy is not None.

  • n_split_max (int, default=15) – Maximum number of segments for the Segment entry. Must be >= 1 and no less than n_split_min when Segment is selected. Must remain 15 when strategy is not None.

  • steps_pattern (list-like of int, default=None) – Step sizes for the Pattern entry. A supplied list, tuple, one-dimensional NumPy array, or pandas Series must contain at least one non-negative integer and is sorted before use. If None, [3, 4] is used when Pattern is selected. For a selected Pattern, all steps must be positive and len_max must exceed the smallest step.

  • n_min (int, default=2) – Minimum number of steps for the Pattern entry. Must be >= 1 and no greater than n_max when Pattern is selected.

  • n_max (int, default=4) – Maximum number of steps for the Pattern entry. Must be >= 1 and no less than n_min when Pattern is selected.

  • len_max (int, default=15) – Maximum residue position reached by a Pattern entry as its start position varies. Must be >= 1 and exceed the smallest steps_pattern value when Pattern is selected.

  • steps_periodicpattern (list-like of int, default=None) – Alternating step sizes for the PeriodicPattern entry. A supplied list, tuple, one-dimensional NumPy array, or pandas Series must contain exactly two non-negative integers and is sorted before use. If None, [3, 4] is used when PeriodicPattern is selected. For a selected PeriodicPattern, both steps must be positive.

  • strategy ({'compositional', 'positional'} or None, default=None) –

    Preset for the CPP strategy, which sets split_types, n_split_min, and n_split_max:

    • 'compositional': a single whole-part Segment (position-agnostic average), identical to get_split_kws(split_types="Segment", n_split_min=1, n_split_max=1).

    • 'positional': sub-segments plus both discontinuous split types, identical to get_split_kws(split_types=["Segment", "Pattern", "PeriodicPattern"], n_split_min=2, n_split_max=15). steps_pattern, n_min, n_max, len_max, and steps_periodicpattern still apply.

    Together, both presets cover the default split set. If None, the split set is defined by split_types, n_split_min, and n_split_max. Otherwise, those three parameters must remain at their defaults.

Returns:

split_kws – Nested dictionary for the selected split types. The Segment entry contains n_split_min and n_split_max; the Pattern entry contains steps, n_min, n_max, and len_max; and the PeriodicPattern entry contains steps. Calling without arguments returns all three entries. strategy='compositional' returns only {'Segment': {'n_split_min': 1, 'n_split_max': 1}}.

Return type:

dict

Raises:

ValueError – If strategy is not 'compositional', 'positional', or None; if strategy is given while split_types, n_split_min, or n_split_max is not at its default; if split_types is empty, neither a string nor an accepted one-dimensional list-like object, or contains an unknown split type; if n_split_min, n_split_max, n_min, n_max, or len_max is not an integer >= 1; if a supplied step collection is not an accepted one-dimensional list-like object of non-negative integers, has fewer than one steps_pattern value, or does not have exactly two steps_periodicpattern values; if a selected Pattern or PeriodicPattern has a zero step; or if the bounds of a selected split type are inconsistent (n_split_min > n_split_max, n_min > n_max, or len_max <= min(steps_pattern)).

Notes

The split bounds returned here are validated for internal consistency (e.g., n_split_min <= n_split_max, n_min <= n_max, len_max > min(steps_pattern)); inconsistent values raise a ValueError.

Beyond that, the feasible maxima are effectively capped by the CPP part lengths used to build df_parts (tmd_len, jmd_n_len, jmd_c_len; defaults 20/10/10): a Segment cannot be split into more pieces than its part has residues, and a Pattern/PeriodicPattern cannot span beyond the part length. Choosing n_split_max, n_max, or len_max larger than a part can accommodate does not raise here — those splits simply yield empty feature buckets downstream. The one config that is always degenerate regardless of part length, an empty Pattern bucket where even the shortest repeat exceeds len_max (n_min * min(steps_pattern) > len_max), emits a UserWarning naming the offending parameters so it can be fixed by raising len_max or lowering steps_pattern/n_min.

The strategy presets are convenience only: the returned dictionary is equal to the one from the equivalent explicit call and is consumed downstream in the same way.

Examples

Get default arguments for all splits types (Segment, Pattern, PeriodicPattern):

import aaanalysis as aa
aa.options["verbose"] = False
sf = aa.SequenceFeature()
split_kws = sf.get_split_kws()
split_kws
{'Segment': {'n_split_min': 1, 'n_split_max': 15},
 'Pattern': {'steps': [3, 4], 'n_min': 2, 'n_max': 4, 'len_max': 15},
 'PeriodicPattern': {'steps': [3, 4]}}

You can also retrieve arguments for specific split types:

split_kws = sf.get_split_kws(split_types=["Segment", "Pattern"])
split_kws
{'Segment': {'n_split_min': 1, 'n_split_max': 15},
 'Pattern': {'steps': [3, 4], 'n_min': 2, 'n_max': 4, 'len_max': 15}}

The arguments for each split type can be adjusted. For Segments, their minimum and maximum length can be changed by the n_split_min (default=1) and n_split_max (default=15) parameters:

split_kws = sf.get_split_kws(split_types="Segment", n_split_min=5, n_split_max=10)
split_kws
{'Segment': {'n_split_min': 5, 'n_split_max': 10}}

For PeriodicPattern, the step size of each odd and even step can be specified as follows using the steps_periodicpattern (default=[3, 4]):

split_kws = sf.get_split_kws(split_types="PeriodicPattern", steps_periodicpattern=[5, 10])
split_kws
{'PeriodicPattern': {'steps': [5, 10]}}

And for Patterns, the step size, the minimum and maximum number of steps, and the maximum residue size of the pattern can be adjusted using the steps_pattern (default=[3, 4]), n_min (default=2), n_max (default=4), and len_max (default=15) parameters:

split_kws = sf.get_split_kws(split_types="Pattern", steps_pattern=[5, 10], n_min=3, n_max=5, len_max=30)
split_kws
{'Pattern': {'steps': [5, 10], 'n_min': 3, 'n_max': 5, 'len_max': 30}}

Instead of spelling out the split arguments, you can select a CPP strategy with the strategy preset. The compositional strategy returns a single whole-part Segment, the same as split_types="Segment", n_split_min=1, n_split_max=1:

split_kws = sf.get_split_kws(strategy="compositional")
split_kws
{'Segment': {'n_split_min': 1, 'n_split_max': 1}}

The positional strategy returns sub-segments (n_split_min=2, n_split_max=15) together with Pattern and PeriodicPattern, whose arguments can still be adjusted. Changing split_types, n_split_min, or n_split_max from its default alongside strategy raises a ValueError:

split_kws = sf.get_split_kws(strategy="positional", steps_pattern=[3, 4], n_min=2, n_max=4, len_max=15)
split_kws
{'Segment': {'n_split_min': 2, 'n_split_max': 15},
 'Pattern': {'steps': [3, 4], 'n_min': 2, 'n_max': 4, 'len_max': 15},
 'PeriodicPattern': {'steps': [3, 4]}}