Skip to content

Commit 6acc3d4

Browse files
feat(deposition): stop checking for GCAs on NCBI, improve test logging (#6878)
Genbank is no longer syncing assembly GCA accessions from ENA - we know since a over a year when we were told at the ENA days by ENA, see pathoplexus/ena-submission#80. However, we still check for the visibility of all GCAs that we submitted and are not live on Genbank every 12hours. This is custom code and fills up the logs doing sth that will never return any new results. Lets stop checking for this. This PR also contains a PR that improves logging for deposition tests to be more selective and informative: - #6881 That PR was accidentally merged into this branch rather than main. 🚀 Preview: Add `preview` label to enable --------- Co-authored-by: Cornelius Roemer <cornelius.roemer@gmail.com>
1 parent 9b7ad97 commit 6acc3d4

4 files changed

Lines changed: 30 additions & 70 deletions

File tree

ena-submission/pyproject.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ build-backend = "hatchling.build"
2323
packages = ["src/ena_deposition"]
2424

2525
[tool.pytest.ini_options]
26-
# Live logging - show INFO+ during execution
27-
log_cli = true
28-
log_cli_level = "INFO" # Show INFO logs during execution
29-
log_cli_format = "%(asctime)s [%(levelname)8s] %(name)s: %(message)s (%(filename)s:%(lineno)d)"
30-
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
26+
# Logs are only printed for failing tests (under "Captured log call"),
27+
# instead of live-streaming (and interleaving) logs for every test.
28+
log_level = "INFO"
29+
log_format = "%(asctime)s [%(levelname)8s] [%(test_name)s] %(name)s: %(message)s (%(filename)s:%(lineno)d)"
30+
log_date_format = "%Y-%m-%d %H:%M:%S"
3131

32-
# File logging - captures everything for detailed analysis
32+
# File logging - captures everything for detailed analysis, regardless of pass/fail
3333
log_file = "tests.log"
3434
log_file_level = "DEBUG"
35-
log_file_format = "%(asctime)s [%(levelname)8s] %(name)s: %(message)s (%(filename)s:%(lineno)d)"
35+
log_file_format = "%(asctime)s [%(levelname)8s] [%(test_name)s] %(name)s: %(message)s (%(filename)s:%(lineno)d)"
3636
log_file_date_format = "%Y-%m-%d %H:%M:%S"
3737

3838
addopts = [

ena-submission/src/ena_deposition/check_external_visibility.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -73,64 +73,10 @@ def check_visibility(self, config: Config, accession: str) -> datetime | None:
7373
return None
7474

7575

76-
GcaCacheKey = tuple[str] | tuple[str, str] | tuple[str, str, str]
77-
78-
gca_cache: dict[GcaCacheKey, bool] = {}
79-
80-
81-
def _check_and_cache_ncbi_gca(config: Config, path_segments: GcaCacheKey) -> bool:
82-
"""
83-
Helper function to check NCBI for a GCA accession part and cache the result.
84-
Returns True if found and caches True, False if not found and caches False.
85-
"""
86-
cache_key = path_segments
87-
88-
if cache_key in gca_cache:
89-
return gca_cache[cache_key]
90-
91-
url_path = "/".join(path_segments)
92-
response = requests.get(
93-
f"https://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/{url_path}/",
94-
allow_redirects=False,
95-
timeout=config.ncbi_public_search_timeout_seconds,
96-
)
97-
98-
if response.status_code == HTTPStatus.OK:
99-
gca_cache[cache_key] = True
100-
return True
101-
gca_cache[cache_key] = False
102-
return False
103-
104-
105-
def check_gca_cached(config: "Config", accession: str) -> datetime | None:
106-
"""
107-
Checks if a GCA accession exists on NCBI by querying NCBI's API, with caching.
108-
It attempts to validate parts of the accession from longest to shortest.
109-
"""
110-
_prefix, numbers = accession.split("_")
111-
first_three = numbers[:3]
112-
second_three = numbers[3:6]
113-
third_three = numbers[6:9]
114-
115-
if not _check_and_cache_ncbi_gca(config, (first_three,)):
116-
return None
117-
118-
if not _check_and_cache_ncbi_gca(config, (first_three, second_three)):
119-
return None
120-
121-
if not _check_and_cache_ncbi_gca(config, (first_three, second_three, third_three)):
122-
return None
123-
124-
return datetime.now(pytz.UTC)
125-
126-
12776
class NCBIVisibilityChecker(VisibilityChecker):
12877
"""Checker for NCBI visibility"""
12978

13079
def check_visibility(self, config: Config, accession: str) -> datetime | None:
131-
if accession.startswith("GCA"):
132-
return check_gca_cached(config, accession)
133-
13480
if accession.startswith("PRJ"):
13581
path = "bioproject"
13682
elif accession.startswith("SAM"):
@@ -193,12 +139,6 @@ def check_visibility(self, config: Config, accession: str) -> datetime | None:
193139
accession_field_name_prefix="gca_accession",
194140
checker_class=ENAVisibilityChecker,
195141
),
196-
(EntityType.ASSEMBLY, "ncbi_gca_first_publicly_visible"): ColumnCheckConfig(
197-
entry_class=AssemblyTableEntry,
198-
visibility_column="ncbi_gca_first_publicly_visible",
199-
accession_field_name_prefix="gca_accession",
200-
checker_class=NCBIVisibilityChecker,
201-
),
202142
}
203143

204144

@@ -348,8 +288,6 @@ def check_and_update_visibility(config: Config, stop_event: threading.Event):
348288
check_and_update_visibility_all_columns(config, db_engine)
349289
logger.debug("check_and_update_visibility finished, sleeping for a while")
350290

351-
gca_cache.clear()
352-
353291
elapsed_time = time.time() - start_time
354292
if elapsed_time < 60 * config.min_between_publicness_checks:
355293
wait_time = 60 * config.min_between_publicness_checks - elapsed_time

ena-submission/test/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import logging
2+
3+
import pytest
4+
5+
_test_context = {"name": "no-test"}
6+
7+
_original_log_record_factory = logging.getLogRecordFactory()
8+
9+
10+
def _log_record_factory_with_test_name(*args: object, **kwargs: object) -> logging.LogRecord:
11+
record = _original_log_record_factory(*args, **kwargs)
12+
record.test_name = _test_context["name"]
13+
return record
14+
15+
16+
logging.setLogRecordFactory(_log_record_factory_with_test_name)
17+
18+
19+
@pytest.fixture(autouse=True)
20+
def _tag_logs_with_test_name(request: pytest.FixtureRequest):
21+
_test_context["name"] = request.node.name
22+
yield
23+
_test_context["name"] = "no-test"

ena-submission/test/test_ena_submission_integration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ class TestFirstPublicUpdate(TestSubmission):
653653
(EntityType.ASSEMBLY, "ena_nucleotide_first_publicly_visible"): NUCLEOTIDE_CONFIG,
654654
(EntityType.ASSEMBLY, "ncbi_nucleotide_first_publicly_visible"): NUCLEOTIDE_CONFIG,
655655
(EntityType.ASSEMBLY, "ena_gca_first_publicly_visible"): GCA_CONFIG,
656-
(EntityType.ASSEMBLY, "ncbi_gca_first_publicly_visible"): GCA_CONFIG,
657656
}
658657

659658
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)