SequenceFeatureTransformer
- class SequenceFeatureTransformer(split_kws=None, df_scales=None, n_filter=100, label_test=1, label_ref=0, max_overlap=0.5, max_cor=0.5, simplify=False, n_jobs=1, random_state=None, verbose=False)[source]
SequenceFeatureTransformer: leak-free CPP feature selection as a scikit-learn transformer.
Wraps the
get_df_parts->CPP.run()->feature_matrixchain (seeSequenceFeature.feature_matrix()) behind the scikit-learnfit/transformAPI so CPP feature selection happens on the training fold only:fit()selects from(X, y)and stores them;transform()applies the same features to produce the numeric matrixX. Dropped inside asklearn.pipeline.Pipeline(orsklearn.model_selection.cross_val_score()), the test fold never influences which features are chosen — the honest, leak-free counterpart of selecting on the full labeled set.Xis adf_seqDataFrame (sequence information, one row per protein) or a pre-builtdf_parts;yare the class labels. Selection is binary (onelabel_testvs onelabel_ref), configured by the constructor’s CPP levers.Warning
Experimental. Part of the evolving
aaanalysis.pipeergonomics layer; its API may change between minor releases without the usual deprecation cycle.Added in version 1.1.0.
Notes
Follows the scikit-learn estimator contract: the constructor only stores parameters (so the estimator is cloneable), all validation happens in
fit(), and learned state carries a trailing underscore (features_,df_feat_).
See also
CPPfor the underlying feature selection.SequenceFeature.feature_matrix()for the parts-to-matrix step applied bytransform.
- Parameters:
Methods
fit(X[, y])Select CPP features from
(X, y)(the training fold) and store them.get_feature_names_out([input_features])Output feature names: the CPP feature ids selected in
fit()(one per output column).transform(X)Build the CPP feature matrix
Xfrom the features selected infit().- __init__(split_kws=None, df_scales=None, n_filter=100, label_test=1, label_ref=0, max_overlap=0.5, max_cor=0.5, simplify=False, n_jobs=1, random_state=None, verbose=False)[source]
- Parameters:
split_kws (dict, optional) – CPP split configuration (see
SequenceFeature.get_split_kws()).Noneuses the CPP default (Segment + Pattern + PeriodicPattern).df_scales (pd.DataFrame, shape (n_letters, n_scales), optional) – Amino-acid scales used for CPP feature selection — the bundled AAontology scales or a subset of them.
None(default) uses the full bundled set (load_scales()). The feature matrix is always built from the full bundled scales so aCPP.simplify()scale swap still resolves. A genuinely custom (non-AAontology) scale set is not supported here, because CPP validates scale coverage against the bundled category table.n_filter (int, default=100) – Number of features CPP selects (passed to
CPP.run()).label_test (int, default=1) – Class label of the test/positive group for CPP selection.
label_ref (int, default=0) – Class label of the reference/negative group for CPP selection.
max_overlap (float, default=0.5) – Maximum feature overlap allowed during CPP selection.
max_cor (float, default=0.5) – Maximum feature correlation allowed during CPP selection.
simplify (bool, default=False) – If
True, refine the selected feature set withCPP.simplify()after selection.n_jobs (int, optional) – Number of CPU cores for the CPP run and the feature-matrix build.
Noneuses the optimized number; default1.random_state (int, optional) – Seed for the CPP run, for reproducibility.
verbose (bool, default=False) – If
True, verbose outputs are enabled.
Examples
SequenceFeatureTransformerruns leak-free CPP feature selection behind the scikit-learnfit/transformAPI. First, theDOM_GSECdataset:import aaanalysis as aa aa.options["verbose"] = False # Disable verbosity # DOM_GSEC example dataset (df_seq with an 'entry' + 'sequence' column, one row per protein) df_seq = aa.load_dataset(name="DOM_GSEC", n=20) labels = df_seq["label"].to_list()
Construct the transformer with the CPP selection levers: the split configuration
split_kwsand scalesdf_scales, the number of featuresn_filter, thelabel_test/label_refgroups, themax_overlap/max_corredundancy caps, whether tosimplifythe selected set, andn_jobs/random_state/verbose:sft = aa.SequenceFeatureTransformer( split_kws=aa.SequenceFeature.get_split_kws(split_types=["Segment", "Pattern"]), df_scales=aa.load_scales(name="scales"), n_filter=50, label_test=1, label_ref=0, max_overlap=0.5, max_cor=0.5, simplify=False, n_jobs=1, random_state=42, verbose=False) X = sft.fit_transform(df_seq, labels) aa.display_df(sft.df_feat_, n_rows=10, show_shape=True)
DataFrame shape: (50, 13)
feature category subcategory scale_name scale_description abs_auc abs_mean_dif mean_dif std_test std_ref p_val_mann_whitney p_val_fdr_bh positions 1 TMD-Pattern(C,4,8)-BEGF750101 Conformation α-helix α-helix Conformational ...in-Dirkx, 1975) 0.444000 0.299000 0.299000 0.090000 0.196000 0.000002 0.007628 23,27 2 TMD_C_JMD_C-Pat...4,8)-BEGF750101 Conformation α-helix α-helix Conformational ...in-Dirkx, 1975) 0.444000 0.299000 0.299000 0.090000 0.196000 0.000002 0.007628 24,28 3 TMD_C_JMD_C-Pat...,12)-CRAJ730103 Conformation β-turn β-turn Normalized freq...d et al., 1973) 0.431000 0.251000 -0.251000 0.088000 0.143000 0.000003 0.007628 24,28,32 4 TMD_C_JMD_C-Pat...,12)-MUNV940102 Energy Free energy (folding) Free energy (α-helix) Free energy in ...-Serrano, 1994) 0.422000 0.148000 -0.148000 0.056000 0.097000 0.000005 0.008571 24,28,32 5 TMD_C_JMD_C-Pat...,14)-ZIMJ680104 Energy Isoelectric point Isoelectric point Isoelectric poi...n et al., 1968) 0.402000 0.130000 0.130000 0.080000 0.088000 0.000013 0.008588 27,30,33 6 TMD_C_JMD_C-Pat...,14)-ZIMJ680104 Energy Isoelectric point Isoelectric point Isoelectric poi...n et al., 1968) 0.402000 0.130000 0.130000 0.080000 0.088000 0.000013 0.008588 28,31,34 7 TMD_C_JMD_C-Pat...,14)-CRAJ730103 Conformation β-turn β-turn Normalized freq...d et al., 1973) 0.398000 0.286000 -0.286000 0.115000 0.178000 0.000017 0.008588 27,31 8 TMD_C_JMD_C-Pat...,14)-MUNV940102 Energy Free energy (folding) Free energy (α-helix) Free energy in ...-Serrano, 1994) 0.391000 0.153000 -0.153000 0.067000 0.130000 0.000023 0.008588 27,31 9 TMD-Segment(10,11)-CHAM820102 Polarity Hydrophobicity (interface) Free energy (interface) Free energy of ...-Charton, 1982) 0.389000 0.169000 -0.169000 0.050000 0.130000 0.000026 0.008588 27,28 10 TMD-Pattern(C,4...,11)-FUKS010106 Composition Membrane proteins (MPs) Proteins of mesophiles (INT) Interior compos...ishikawa, 2001) 0.384000 0.219000 0.219000 0.166000 0.122000 0.000033 0.008588 20,23,27