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
strategypreset names the Comparative Physicochemical Profiling (CPP) strategy directly instead of spelling it out throughsplit_types,n_split_min, andn_split_max.Added in version 0.1.0.
Changed in version 1.2.0: Added the
strategypresets 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 remainNonewhenstrategyis notNone.n_split_min (int, default=1) – Minimum number of segments for the
Segmententry. Must be >= 1 and no greater thann_split_maxwhenSegmentis selected. Must remain 1 whenstrategyis notNone.n_split_max (int, default=15) – Maximum number of segments for the
Segmententry. Must be >= 1 and no less thann_split_minwhenSegmentis selected. Must remain 15 whenstrategyis notNone.steps_pattern (list-like of int, default=None) – Step sizes for the
Patternentry. A supplied list, tuple, one-dimensional NumPy array, or pandas Series must contain at least one non-negative integer and is sorted before use. IfNone,[3, 4]is used whenPatternis selected. For a selectedPattern, all steps must be positive andlen_maxmust exceed the smallest step.n_min (int, default=2) – Minimum number of steps for the
Patternentry. Must be >= 1 and no greater thann_maxwhenPatternis selected.n_max (int, default=4) – Maximum number of steps for the
Patternentry. Must be >= 1 and no less thann_minwhenPatternis selected.len_max (int, default=15) – Maximum residue position reached by a
Patternentry as its start position varies. Must be >= 1 and exceed the smalleststeps_patternvalue whenPatternis selected.steps_periodicpattern (list-like of int, default=None) – Alternating step sizes for the
PeriodicPatternentry. A supplied list, tuple, one-dimensional NumPy array, or pandas Series must contain exactly two non-negative integers and is sorted before use. IfNone,[3, 4]is used whenPeriodicPatternis selected. For a selectedPeriodicPattern, both steps must be positive.strategy ({'compositional', 'positional'} or None, default=None) –
Preset for the CPP strategy, which sets
split_types,n_split_min, andn_split_max:'compositional': a single whole-partSegment(position-agnostic average), identical toget_split_kws(split_types="Segment", n_split_min=1, n_split_max=1).'positional': sub-segments plus both discontinuous split types, identical toget_split_kws(split_types=["Segment", "Pattern", "PeriodicPattern"], n_split_min=2, n_split_max=15).steps_pattern,n_min,n_max,len_max, andsteps_periodicpatternstill apply.
Together, both presets cover the default split set. If
None, the split set is defined bysplit_types,n_split_min, andn_split_max. Otherwise, those three parameters must remain at their defaults.
- Returns:
split_kws – Nested dictionary for the selected split types. The
Segmententry containsn_split_minandn_split_max; thePatternentry containssteps,n_min,n_max, andlen_max; and thePeriodicPatternentry containssteps. Calling without arguments returns all three entries.strategy='compositional'returns only{'Segment': {'n_split_min': 1, 'n_split_max': 1}}.- Return type:
- Raises:
ValueError – If
strategyis not'compositional','positional', orNone; ifstrategyis given whilesplit_types,n_split_min, orn_split_maxis not at its default; ifsplit_typesis empty, neither a string nor an accepted one-dimensional list-like object, or contains an unknown split type; ifn_split_min,n_split_max,n_min,n_max, orlen_maxis 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 onesteps_patternvalue, or does not have exactly twosteps_periodicpatternvalues; if a selectedPatternorPeriodicPatternhas a zero step; or if the bounds of a selected split type are inconsistent (n_split_min>n_split_max,n_min>n_max, orlen_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 aValueError.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): aSegmentcannot be split into more pieces than its part has residues, and aPattern/PeriodicPatterncannot span beyond the part length. Choosingn_split_max,n_max, orlen_maxlarger 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 emptyPatternbucket where even the shortest repeat exceedslen_max(n_min * min(steps_pattern) > len_max), emits aUserWarningnaming the offending parameters so it can be fixed by raisinglen_maxor loweringsteps_pattern/n_min.The
strategypresets 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 then_split_min(default=1) andn_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 thesteps_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 thesteps_pattern(default=[3, 4]),n_min(default=2),n_max(default=4), andlen_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
strategypreset. Thecompositionalstrategy returns a single whole-partSegment, the same assplit_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
positionalstrategy returns sub-segments (n_split_min=2,n_split_max=15) together withPatternandPeriodicPattern, whose arguments can still be adjusted. Changingsplit_types,n_split_min, orn_split_maxfrom its default alongsidestrategyraises aValueError: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]}}