AAPred.predict
- AAPred.predict(df_seq, level='sequence', threshold=None, list_parts=None, window=3, tmd_len=None, step=1, jmd_n_len=10, jmd_c_len=10)[source]
Predict from raw sequences at a chosen level: whole protein, domain, or residue window.
One predictor for all three granularities, selected with
level:'sequence'— one score per protein (sequence level).'domain'— a boundary-sensitivity scan: the TMD boundaries are shifted by every offset in[-window, +window]and each shifted definition is featurized and scored.'window'— a per-residue profile: a length-tmd_lenwindow is slid along each sequence (spaced bystep) and scored at every valid position.
Each level featurizes with the bound
df_featand averages the fitted-model ensemble. Whenthresholdis given, apredicted_labelcolumn is added (score at or above the threshold ->label_posfromfit(), else the negative class); withthreshold=None(default) only the scores are returned.Note
Requires a
df_featbound at construction and a priorfit().Added in version 1.1.0.
- Parameters:
df_seq (pd.DataFrame, shape (n_proteins, n_seq_info)) – DataFrame containing an
entrycolumn of unique protein identifiers and asequencecolumn;level='domain'additionally needstmd_start/tmd_stop.level (str, default="sequence") – Prediction granularity:
'sequence','domain', or'window'.threshold (int or float, optional) – If given (in
[0, 1]), add apredicted_labelcolumn (score>= threshold->label_pos, else the negative class).None(default) returns scores only.list_parts (list of str, optional) – Sequence parts to build for featurization. Defaults to the standard CPP parts.
window (int, default=3) – (
level='domain'only) Maximum absolute boundary shift, in residues, scanned per side.tmd_len (int, optional) – (
level='window'only, required there) Length in residues of the window anchored at each position.step (int, default=1) – (
level='window'only) Spacing between consecutive anchor positions.jmd_n_len (int, default=10) – (
level='window'only) N-terminal flank required around each window.jmd_c_len (int, default=10) – (
level='window'only) C-terminal flank required around each window.
- Returns:
df_pred – Long-format predictions; columns depend on
level:entry/score/score_std('sequence'),entry/offset/score/is_best('domain'),entry/position/score/score_std('window'). Pluspredicted_labelwhenthresholdis given.- Return type:
pd.DataFrame
See also
AAPred.eval()for cross-validated model evaluation (df_eval).
Examples
AAPred().predict()scores raw sequences at three levels selected bylevel: the whole protein ('sequence'), a domain with a boundary-sensitivity scan ('domain'), and a sliding per-residue window ('window'). We binddf_featto the model so the feature matrix is computed internally from adf_seq(see [Breimann25]):predictscores raw sequences; thelevelpicks the granularity (one method, three cases):level='sequence'— one score per protein — is this whole protein positive?level='domain'— boundary-sensitivity scan — how does the score depend on the exact boundary?level='window'— per-residue profile — which regions score highest?
Add
threshold=to also get apredicted_labelcolumn.import aaanalysis as aa aa.options["verbose"] = False # Disable verbosity # DOM_GSEC example dataset + its feature set (see [Breimann25]_) df_seq = aa.load_dataset(name="DOM_GSEC") labels = df_seq["label"].to_list() df_feat = aa.load_features(name="DOM_GSEC").head(20) # Training feature matrix sf = aa.SequenceFeature() X = sf.feature_matrix(features=df_feat, df_parts=sf.get_df_parts(df_seq=df_seq)) # Bind df_feat so raw sequences are featurized internally by predict() aapred = aa.AAPred(df_feat=df_feat, random_state=42) aapred.fit(X, labels)
<aaanalysis.prediction._aa_pred.AAPred at 0x116f1aba0>
Sequence level (
level='sequence'). Each protein gets one positive-class score and its across-model standard deviation.list_partsselects which sequence parts are built for featurization (defaults to the standard CPP parts):df_pred = aapred.predict(df_seq.head(10), level="sequence", list_parts=["tmd", "jmd_n_tmd_n", "tmd_c_jmd_c"]) aa.display_df(df_pred, n_rows=10, show_shape=True)
DataFrame shape: (10, 3)
entry score score_std 1 P05067 0.960000 0.000000 2 P14925 0.940000 0.000000 3 P70180 0.970000 0.000000 4 Q03157 0.990000 0.000000 5 Q06481 1.000000 0.000000 6 P35613 0.940000 0.000000 7 P35070 0.630000 0.000000 8 P09803 0.990000 0.000000 9 P19022 1.000000 0.000000 10 P16070 0.930000 0.000000 Passing a
threshold(in[0, 1]) adds apredicted_labelcolumn (score at or above the threshold maps to the positive class, else the negative class):df_pred = aapred.predict(df_seq.head(10), level="sequence", threshold=0.5) aa.display_df(df_pred, n_rows=10, show_shape=True)
DataFrame shape: (10, 4)
entry score score_std predicted_label 1 P05067 0.960000 0.000000 1 2 P14925 0.940000 0.000000 1 3 P70180 0.970000 0.000000 1 4 Q03157 0.990000 0.000000 1 5 Q06481 1.000000 0.000000 1 6 P35613 0.940000 0.000000 1 7 P35070 0.630000 0.000000 1 8 P09803 0.990000 0.000000 1 9 P19022 1.000000 0.000000 1 10 P16070 0.930000 0.000000 1 Domain level (
level='domain'). The domain boundaries are shifted by every offset in[-window, +window];is_bestflags the highest-scoring definition (offset0is the annotated boundary):df_domain = aapred.predict(df_seq[df_seq["entry"] == "P05067"], level="domain", window=3) aa.display_df(df_domain, n_rows=10, show_shape=True)
DataFrame shape: (7, 4)
entry offset score is_best 1 P05067 -3 0.270000 False 2 P05067 -2 0.790000 False 3 P05067 -1 0.730000 False 4 P05067 0 0.960000 True 5 P05067 1 0.840000 False 6 P05067 2 0.530000 False 7 P05067 3 0.450000 False Window level (
level='window'). A length-tmd_lenwindow is slid along each sequence (spaced bystep), giving a per-residue profile.jmd_n_len/jmd_c_lenset the flanking region required around each window:row = df_seq[df_seq["entry"] == "P05067"].iloc[0] tmd_len = int(row["tmd_stop"] - row["tmd_start"] + 1) df_window = aapred.predict(df_seq[df_seq["entry"] == "P05067"][["entry", "sequence"]], level="window", tmd_len=tmd_len, step=5, jmd_n_len=10, jmd_c_len=10) aa.display_df(df_window, n_rows=10, show_shape=True)
DataFrame shape: (146, 4)
entry position score score_std 1 P05067 22 0.290000 0.000000 2 P05067 27 0.270000 0.000000 3 P05067 32 0.040000 0.000000 4 P05067 37 0.100000 0.000000 5 P05067 42 0.120000 0.000000 6 P05067 47 0.020000 0.000000 7 P05067 52 0.120000 0.000000 8 P05067 57 0.070000 0.000000 9 P05067 62 0.070000 0.000000 10 P05067 67 0.250000 0.000000