Download libs/utils/io_fasta.py from QPromaQ/Docking_project: direct link, hf CLI and curl.
- Browser
- Download file 828 Bytes
-
https://huggingface.co/datasets/QPromaQ/Docking_project/resolve/main/libs/utils/io_fasta.py
- Command line
-
hf download hf://datasets/QPromaQ/Docking_project/libs/utils/io_fasta.py
-
curl -L -o io_fasta.py https://huggingface.co/datasets/QPromaQ/Docking_project/resolve/main/libs/utils/io_fasta.py
828 Bytes
| from __future__ import annotations | |
| from pathlib import Path | |
| from typing import Dict | |
| def read_fasta(path: str | Path) -> Dict[str, str]: | |
| """Read FASTA entries into mapping of record id to sequence.""" | |
| source = Path(path) | |
| records: Dict[str, str] = {} | |
| current_id = None | |
| current_seq: list[str] = [] | |
| for line in source.read_text(encoding="utf-8").splitlines(): | |
| line = line.strip() | |
| if not line: | |
| continue | |
| if line.startswith(">"): # FASTA header | |
| if current_id is not None: | |
| records[current_id] = "".join(current_seq) | |
| current_id = line[1:].split()[0] | |
| current_seq = [] | |
| else: | |
| current_seq.append(line) | |
| if current_id is not None: | |
| records[current_id] = "".join(current_seq) | |
| return records | |