FASTALoader silently discards sequences when a FASTA record is empty
Author: siddhant-shahhhCreated Sep 13, 2026Updated Sep 13, 2026
Bug
FASTALoader (legacy=False) silently returns fewer sequences than the input file contains when any record has no sequence body. No error and no warning is raised the sequences are just missing from the resulting dataset.
Two cases:
- An empty record in the middle of the file discards every sequence read before it.
- A file ending with a header and no sequence returns an empty dataset.
Both are plausible in practice: FASTA files produced by filtering steps often contain empty records, and a truncated download can end on a header line.
To Reproduce
Steps to reproduce the behavior:
- Install DeepChem from source on master (455d07f3e) with
pip install -e . - Run the following:
import tempfile, os, deepchem as dc
cases = [
("empty record mid-file", ">seq0\nAAAA\n>seq1\n>seq2\nCCCC\n", 2),
("file ends on a header", ">seq0\nAAAA\n>seq1\n", 1),
]
for name, content, expected in cases:
with tempfile.TemporaryDirectory() as d:
path = os.path.join(d, "t.fasta")
open(path, "w").write(content)
got = dc.data.FASTALoader(legacy=False).create_dataset(path).X.shape[0]
print(f"{name}: expected {expected}, got {got}")Output:
empty record mid-file: expected 2, got 1
file ends on a header: expected 1, got 0Expected behavior
Empty records should be skipped, leaving the sequences around them intact. An empty record should not cause previously read sequences to be dropped, and it should not cause the loader to return an empty dataset.
Environment
- OS: macOS 26.6.2 (arm64)
- Python version: 3.12.13
- DeepChem version: 2.8.1.dev (editable install from master @ 455d07f3e)
- RDKit version (optional): 2026.3.6
- TensorFlow version (optional): not installed
- PyTorch version (optional): 2.14.0
- Any other relevant information: the non-legacy path is affected; legacy=True uses BioPython via encode_bio_sequence and is not involved.
Additional context
I have a fix and tests ready and will open a PR shortly.
Source: deepchem/deepchem