Skip to content

TALOS-N

TalosN

TalosN

TalosN(shifts, sequence=None, entry_id=None, entity_id=None, entry=None, data_dir=None)

Predict backbone torsion angles, S2 order parameters, and secondary structure from assigned chemical shifts using the NIH TALOS-N binary.

Build from a shift table:

tn = TalosN.from_bmrb(15000, data_dir="~/talosn_data")
tn.run(auto_install=True)
tn.order_parameters        # predS2 table
tn.torsion_angles          # pred.tab
tn.secondary_structure     # predSS.tab
Source code in makeshift/talosn/engine.py
def __init__(self, shifts, sequence=None, entry_id=None, entity_id=None,
             entry=None, data_dir=None):
    self.shifts = shifts
    self.sequence = sequence
    self.entry_id = entry_id
    self.entity_id = entity_id
    self.entry = entry
    self.data_dir = data_dir
    self.results = None

from_bmrb classmethod

from_bmrb(bmrb_id, entity_id=None, sequence=None, data_dir=None, **fetch_kw)

Fetch a BMRB entry and build from its assigned chemical shifts.

Source code in makeshift/talosn/engine.py
@classmethod
def from_bmrb(cls, bmrb_id, entity_id=None, sequence=None, data_dir=None, **fetch_kw):
    """Fetch a BMRB entry and build from its assigned chemical shifts."""
    from ..entry import NMRStarEntry
    entry = NMRStarEntry.from_bmrb(bmrb_id, **fetch_kw)
    return cls.from_entry(entry, entity_id=entity_id, sequence=sequence,
                          data_dir=data_dir)

from_entry classmethod

from_entry(entry, entity_id=None, sequence=None, data_dir=None)

Build from an already-parsed :class:NMRStarEntry.

Source code in makeshift/talosn/engine.py
@classmethod
def from_entry(cls, entry, entity_id=None, sequence=None, data_dir=None):
    """Build from an already-parsed :class:`NMRStarEntry`."""
    from ..chemshift import ChemicalShifts

    if sequence is None:
        seqs = entry.sequences()
        if entity_id is not None:
            sequence = entry.sequences(entity_id=entity_id)
        else:
            poly = seqs[
                seqs["Polymer_type"].str.contains("polypeptide", case=False, na=False)
            ]
            if poly.empty:
                raise ValueError(
                    f"No polypeptide sequence found in entry {getattr(entry, 'entry_id', None)}"
                )
            sequence = poly.iloc[0]["Polymer_seq_one_letter_code"]
            entity_id = poly.iloc[0]["ID"]
        if not isinstance(sequence, str) or not sequence or pd.isna(sequence):
            raise ValueError("could not resolve a sequence; pass sequence=... explicitly")

    shifts = utils.filter_backbone(ChemicalShifts.from_entry(entry).data)
    if shifts.empty:
        raise ValueError(
            f"No backbone chemical shifts in entry {getattr(entry, 'entry_id', None)}"
        )
    return cls(shifts, sequence,
               entry_id=getattr(entry, "entry_id", None),
               entity_id=entity_id, entry=entry, data_dir=data_dir)

predict_s2

predict_s2(**run_kw)

Run if needed and return the predS2 table, raising if absent.

Source code in makeshift/talosn/engine.py
def predict_s2(self, **run_kw):
    """Run if needed and return the predS2 table, raising if absent."""
    if self.results is None:
        self.run(**run_kw)
    s2_df = self.results.get("s2")
    if s2_df is None or len(s2_df) == 0:
        raise RuntimeError(
            "TALOS-N did not produce predS2.tab. Ensure backbone carbon "
            "shifts (CA/CB/C) are present and that TALOS-N data are "
            "installed via install_talosn_data()."
        )
    return s2_df

Data installation

install_talosn_data

install_talosn_data(data_dir=None, force=False, install_binaries=True, url=TALOSN_DOWNLOAD_URL)
Source code in makeshift/talosn/engine.py
def install_talosn_data(data_dir=None, force=False, install_binaries=True,
                        url=TALOSN_DOWNLOAD_URL):

    data_dir = _resolve_data_dir(data_dir)
    tab_dir = data_dir / "tab"
    bin_dir = data_dir / "bin"

    try:
        binary_installed = _get_talosn_binary(data_dir)
    except RuntimeError:
        binary_installed = None

    if is_talosn_data_installed(data_dir) and binary_installed and not force and not install_binaries:
        _fix_tab_symlinks(data_dir)
        return data_dir

    tab_dir.mkdir(parents=True, exist_ok=True)
    bin_dir.mkdir(parents=True, exist_ok=True)

    archive_path = None
    try:
        with tempfile.NamedTemporaryFile(suffix=".tZ", delete=False) as tmp:
            archive_path = Path(tmp.name)

        print(TALOSN_TERMS_NOTICE)
        print(f"\nDownloading TALOS-N data from {url} ...")
        urllib.request.urlretrieve(url, archive_path)

        with tarfile.open(archive_path, "r:*") as tar:
            for member in tar.getmembers():
                if member.name.startswith("tab/") and member.isfile():
                    dest = tab_dir / Path(member.name).name
                    if force or not dest.exists():
                        tar.extract(member, path=data_dir)
                elif install_binaries and member.name.startswith("bin/") and member.isfile():
                    dest = bin_dir / Path(member.name).name
                    if force or not dest.exists():
                        tar.extract(member, path=data_dir)
                    if dest.is_file():
                        dest.chmod(dest.stat().st_mode | 0o111)

        _fix_tab_symlinks(data_dir)

        if not is_talosn_data_installed(data_dir):
            raise RuntimeError(
                "TALOS-N data installation finished but talos.tab was not found. "
                f"Try downloading manually from {TALOSN_INFO_URL}"
            )

        print(f"TALOS-N data installed in {data_dir}")
        return data_dir

    finally:
        if archive_path is not None and archive_path.exists():
            archive_path.unlink()

is_talosn_data_installed

is_talosn_data_installed(data_dir=None)
Source code in makeshift/talosn/engine.py
def is_talosn_data_installed(data_dir=None):
    talos_tab = _resolve_data_dir(data_dir) / "tab" / "talos.tab"
    if not talos_tab.is_file():
        return False
    return talos_tab.stat().st_size >= _MIN_TALOS_TAB_BYTES

ensure_talosn_data

ensure_talosn_data(data_dir=None, auto_install=False)
Source code in makeshift/talosn/engine.py
def ensure_talosn_data(data_dir=None, auto_install=False):
    data_dir = _resolve_data_dir(data_dir)
    _fix_tab_symlinks(data_dir)
    if is_talosn_data_installed(data_dir):
        return
    if auto_install:
        install_talosn_data(data_dir)
        return
    raise RuntimeError(
        f"TALOS-N database/weight files are not installed in {data_dir}. "
        "Run makeshift.talosn.install_talosn_data() to download them from NIH, "
        f"or see {TALOSN_INFO_URL}"
    )