Feature Selector Consensus Parse Helper

GitHub Link to Code.

Consensus nomenclature pattern parsing utilities.

class mdxplain.feature_selection.helper.feature_selector_consensus_parse_helper.FeatureSelectorConsensusParseHelper

Helper class for parsing consensus nomenclature patterns.

Provides static methods to parse consensus patterns like “7x50”, “7x*”, “7x-8x”, and “*40-*50” to identify matching residue indices based on trajectory metadata.

static parse_consensus_category(param_tokens: List[str], features_list: List[list]) Tuple[List[int], Set[int]]

Parse ‘consensus’ category and return matching feature indices plus matched residue indices.

Uses unified interface like other parsers. Converts features_list to metadata format and delegates to parse_consensus_pattern.

Parameters

param_tokensList[str]

List of parameter tokens (should be single pattern like [“7x50-8x50”])

features_listList[list]

List of features from metadata (each feature is a list of partners)

Returns

Tuple[List[int], Set[int]]

Tuple of (feature_indices, matched_residue_indices)

Examples

>>> # Single consensus position
>>> indices, residue_indices = FeatureSelectorConsensusParseHelper.parse_consensus_category(
...     ["7x50"], features_list
... )
>>> # Consensus range
>>> indices, residue_indices = FeatureSelectorConsensusParseHelper.parse_consensus_category(
...     ["7x50-8x50"], features_list
... )
static parse_consensus_pattern(metadata: dict, pattern: str) Tuple[List[int], Set[int]]

Parse consensus nomenclature pattern and return matching feature indices plus residue indices.

Parameters

metadatadict

Trajectory metadata with residue information

patternstr

Consensus pattern to parse:

  • Single: “7x50” → Find first entry containing substring

  • Wildcard: “7x*” → Find all containing “7x”

  • Range: “7x-8x” → From first “7x” to last “8x” (consensus != None)

  • Range All: “all 7x-8x” → Same but include None entries

  • Multi-Pattern: “*40-*50” → All blocks like 1x40-1x50, 2x40-2x50, etc.

Returns

Tuple[List[int], Set[int]]

Tuple of (feature_indices, matched_residue_indices)

Examples

>>> # Single position
>>> indices, residue_indices = FeatureSelectorConsensusParseHelper.parse_consensus_pattern(metadata, "7x50")
>>> # ([145], {5})  # Feature 145, residue.index 5
>>> # Wildcard
>>> indices, residue_indices = FeatureSelectorConsensusParseHelper.parse_consensus_pattern(metadata, "7x*")
>>> # ([145, 146, ...], {5, 6, ...})  # All features and residues with "7x" in consensus
>>> # Range
>>> indices, residue_indices = FeatureSelectorConsensusParseHelper.parse_consensus_pattern(metadata, "7x-8x")
>>> # ([145, 146, ..., 180], {5, 6, ..., 20})  # From first "7x" to last "8x"