Skip to content

Commit 74e47f9

Browse files
authored
Merge pull request #6 from gofflab/claude/add-genome-reference-tool-t3h7n
Fix migration not registering species after pip upgrade
2 parents e66a5f9 + 3c8dd19 commit 74e47f9

4 files changed

Lines changed: 75 additions & 9 deletions

File tree

VERSIONINFO.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.3.2 - 04.08.2026
2+
+ Fixed migration bug where species config entries were not restored after `pip install -U`
3+
+ Index directories found in the old package location are now auto-registered as species
14
## v0.3.1 - 04.08.2026
25
+ Moved config and indices to persistent user data directory (`~/.hcrprobedesign/`)
36
+ Reference genomes and configuration now survive `pip install -U` upgrades

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[metadata]
22
# replace with your username:
33
name = hcrprobedesign
4-
version = 0.3.1
4+
version = 0.3.2
55
author = Loyal A. Goff
66
author_email = loyalgoff@jhmi.edu
77
description = Probe Design tool for Hybridization Chain Reaction

src/HCRProbeDesign/_datadir.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def _migrate_old_data():
110110
new_species = new_config.setdefault("species", {})
111111

112112
migrated_any = False
113+
migrated_index_dirs = []
113114

114115
# Migrate index directories
115116
if os.path.isdir(old_indices_dir):
@@ -127,16 +128,17 @@ def _migrate_old_data():
127128
f" Skipping index '{entry}' (already exists in {new_indices_dir})",
128129
file=sys.stderr,
129130
)
130-
continue
131+
else:
132+
print(
133+
f" Moving index '{entry}' -> {new_entry_path}",
134+
file=sys.stderr,
135+
)
136+
shutil.copytree(old_entry_path, new_entry_path)
137+
migrated_any = True
131138

132-
print(
133-
f" Moving index '{entry}' -> {new_entry_path}",
134-
file=sys.stderr,
135-
)
136-
shutil.copytree(old_entry_path, new_entry_path)
137-
migrated_any = True
139+
migrated_index_dirs.append(entry)
138140

139-
# Migrate species config entries
141+
# Migrate species config entries from old config
140142
for name, entry in old_species.items():
141143
if name in new_species:
142144
continue
@@ -157,6 +159,26 @@ def _migrate_old_data():
157159
file=sys.stderr,
158160
)
159161

162+
# Auto-register species for migrated index dirs that have no config entry.
163+
# This handles the case where pip replaced the old HCRconfig.yaml with a
164+
# fresh copy (species: {}) during upgrade, so the config entries were lost
165+
# even though the index files survived.
166+
for dirname in migrated_index_dirs:
167+
# Check if any existing species entry already points to this index dir
168+
index_prefix = os.path.join(new_indices_dir, dirname, dirname)
169+
already_registered = any(
170+
sp.get("bowtie2_index", "") == index_prefix
171+
or os.path.basename(sp.get("bowtie2_index", "")).startswith(dirname)
172+
for sp in new_species.values()
173+
)
174+
if dirname not in new_species and not already_registered:
175+
new_species[dirname] = {"bowtie2_index": index_prefix}
176+
migrated_any = True
177+
print(
178+
f" Auto-registered species '{dirname}' -> {index_prefix}",
179+
file=sys.stderr,
180+
)
181+
160182
# Preserve default_params from old config if not present in new
161183
if "default_params" not in new_config and "default_params" in old_config:
162184
new_config["default_params"] = old_config["default_params"]

tests/test_datadir.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,47 @@ def test_migrate_old_data(tmp_path, monkeypatch):
111111
assert len(bt2_files) == 6
112112

113113

114+
def test_migrate_auto_registers_species_when_config_empty(tmp_path, monkeypatch):
115+
"""Index files survive pip upgrade but old config was replaced with species: {}.
116+
Migration should auto-register species based on index directory names."""
117+
data_dir = tmp_path / "data"
118+
monkeypatch.setenv("HCRPROBEDESIGN_DATA_DIR", str(data_dir))
119+
120+
# Set up old package dir with index files but EMPTY species config
121+
# (simulates pip replacing HCRconfig.yaml with the clean default)
122+
old_pkg = tmp_path / "old_pkg"
123+
old_indices = old_pkg / "indices" / "mm10"
124+
old_indices.mkdir(parents=True)
125+
for suffix in ["1.bt2", "2.bt2", "3.bt2", "4.bt2", "rev.1.bt2", "rev.2.bt2"]:
126+
(old_indices / f"mm10.{suffix}").write_text("fake")
127+
128+
old_config_path = old_pkg / "HCRconfig.yaml"
129+
old_config = {
130+
"species": {},
131+
"default_params": {"tileSize": 52},
132+
}
133+
with open(old_config_path, "w") as fh:
134+
yaml.safe_dump(old_config, fh)
135+
136+
monkeypatch.setattr(_datadir, "_PACKAGE_DIRECTORY", str(old_pkg))
137+
monkeypatch.setattr(_datadir, "_SEED_CONFIG", str(old_config_path))
138+
139+
_datadir.ensure_data_dir()
140+
141+
# Index files should be migrated
142+
new_index_dir = data_dir / "indices" / "mm10"
143+
assert new_index_dir.exists()
144+
bt2_files = glob.glob(str(new_index_dir / "*.bt2*"))
145+
assert len(bt2_files) == 6
146+
147+
# Species should be auto-registered from the directory name
148+
new_config = yaml.safe_load((data_dir / "HCRconfig.yaml").read_text())
149+
assert "mm10" in new_config["species"]
150+
assert new_config["species"]["mm10"]["bowtie2_index"] == os.path.join(
151+
str(data_dir), "indices", "mm10", "mm10"
152+
)
153+
154+
114155
def test_has_old_data_empty(tmp_path, monkeypatch):
115156
monkeypatch.setattr(_datadir, "_PACKAGE_DIRECTORY", str(tmp_path))
116157
# Write an empty config

0 commit comments

Comments
 (0)