Docking_project / libs /encoders /sequence_features.py
QPromaQ's picture
Upload folder using huggingface_hub
c289d87 verified
Raw
History Blame Contribute Delete
826 Bytes
from __future__ import annotations
from typing import Dict
AA_ALPHABET = "ACDEFGHIKLMNPQRSTVWY"
def compute_sequence_features(sequence: str) -> Dict[str, float]:
"""Compute simple amino-acid composition and coarse biochemical summaries."""
seq = sequence.strip().upper()
length = max(len(seq), 1)
features: Dict[str, float] = {f"aa_frac_{aa}": seq.count(aa) / length for aa in AA_ALPHABET}
aromatic = set("FWY")
polar = set("STNQ")
charged = set("KRHDE")
features.update(
{
"seq_length": float(len(seq)),
"frac_aromatic": sum(1 for aa in seq if aa in aromatic) / length,
"frac_polar": sum(1 for aa in seq if aa in polar) / length,
"frac_charged": sum(1 for aa in seq if aa in charged) / length,
}
)
return features