cdm_data_loaders.ncbi_ftp.manifest ¶
Phase 1: Assembly summary diffing and manifest generation.
Downloads the current NCBI assembly summary from FTP, compares it against a
previous snapshot, and produces transfer_manifest.txt (assemblies to
download), removed_manifest.txt (assemblies to archive), and a JSON diff
summary. All filtering logic (prefix range, limit) lives here so that
downstream phases receive a final, pre-filtered manifest.
AssemblyRecord
dataclass
¶
Parsed row from an NCBI assembly summary file.
Attributes: accession: Assembly accession (e.g., "GCF_000001215.4"). status: "latest", "replaced", or "suppressed". seq_rel_date: Release date. ftp_url: Full FTP URL. assembly_dir: Assembly directory name (final path segment from the FTP URL).
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
DiffResult
dataclass
¶
Result of comparing current and previous assembly summaries.
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
download_assembly_summary ¶
Download the assembly summary file from NCBI FTP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
str
|
|
'refseq'
|
ftp_host
|
str
|
FTP hostname |
FTP_HOST
|
Returns:
| Type | Description |
|---|---|
str
|
raw text content of the summary file |
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
parse_assembly_summary ¶
Parse an NCBI assembly summary into a dict of assembly records.
Accepts a file path, raw text string, or list of lines.
Columns of interest (0-indexed): 0: assembly_accession (e.g. GCF_000001215.4) 10: version_status ("latest", "replaced", "suppressed") 14: seq_rel_date 19: ftp_path (full FTP URL or "na")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path | list[str]
|
file path, raw text, or list of lines |
required |
Returns:
| Type | Description |
|---|---|
dict[str, AssemblyRecord]
|
dict mapping accession to :class: |
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
get_latest_assembly_paths ¶
get_latest_assembly_paths(
assemblies: dict[str, AssemblyRecord],
ftp_host: str = FTP_HOST,
) -> list[tuple[str, PurePosixPath]]
Extract FTP directory paths for all assemblies with latest status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assemblies
|
dict[str, AssemblyRecord]
|
parsed assembly records |
required |
ftp_host
|
str
|
FTP hostname for URL stripping |
FTP_HOST
|
Returns:
| Type | Description |
|---|---|
list[tuple[str, PurePosixPath]]
|
list of |
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
accession_prefix ¶
Extract the 3-digit prefix from an accession (e.g. GCF_000005845.2 → "000").
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
filter_by_prefix_range ¶
filter_by_prefix_range(
assemblies: dict[str, AssemblyRecord],
prefix_from: str | None = None,
prefix_to: str | None = None,
) -> dict[str, AssemblyRecord]
Filter assemblies to those whose 3-digit accession prefix is in range.
Both bounds are inclusive. If neither is set, returns all assemblies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assemblies
|
dict[str, AssemblyRecord]
|
dict of parsed assembly records |
required |
prefix_from
|
str | None
|
lower bound (inclusive), e.g. |
None
|
prefix_to
|
str | None
|
upper bound (inclusive), e.g. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, AssemblyRecord]
|
filtered dict |
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
compute_diff ¶
compute_diff(
current: dict[str, AssemblyRecord],
previous_assemblies: (
dict[str, AssemblyRecord] | None
) = None,
previous_accessions: set[str] | None = None,
) -> DiffResult
Compute the diff between current and previous assembly state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current
|
dict[str, AssemblyRecord]
|
the new NCBI summary (parsed) |
required |
previous_assemblies
|
dict[str, AssemblyRecord] | None
|
full parsed previous summary, or None if using fallback |
None
|
previous_accessions
|
set[str] | None
|
set of known accessions (store-scan fallback) |
None
|
Returns:
| Type | Description |
|---|---|
DiffResult
|
diff result with new/updated/replaced/suppressed lists |
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
scan_store_to_synthetic_summary ¶
scan_store_to_synthetic_summary(
bucket: PurePosixPath,
key_prefix: PurePosixPath,
release_date: str,
database: str = "refseq",
progress_callback: (
Callable[[int, str], None] | None
) = None,
) -> dict[str, AssemblyRecord]
Scan S3 store and build a synthetic assembly summary from existing objects.
This function is useful when bootstrapping a diffs against an existing, pre-populated S3 store that lacks a baseline assembly summary.
For each assembly found in the store:
- Extracts the accession and assembly directory name from S3 paths
- Applies the provided
release_dateas syntheticseq_rel_datefor all assemblies
- Applies the provided
- Creates an
AssemblyRecordwithstatus="latest" - Filters to accessions matching the expected prefix for
database(GCF_for"refseq",GCA_for"genbank")
The function paginates through S3 to handle large stores efficiently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bucket
|
PurePosixPath
|
S3 bucket name |
required |
key_prefix
|
PurePosixPath
|
S3 key prefix (all objects under this prefix are scanned) |
required |
release_date
|
str
|
release date string in |
required |
database
|
str
|
|
'refseq'
|
progress_callback
|
Callable[[int, str], None] | None
|
optional callable invoked after each accession is
processed with |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, AssemblyRecord]
|
dict mapping accession to |
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
verify_transfer_candidates ¶
verify_transfer_candidates(
accessions: list[str],
current_assemblies: dict[str, AssemblyRecord],
bucket: PurePosixPath,
key_prefix: PurePosixPath,
ftp_host: str = FTP_HOST,
progress_callback: (
Callable[[int, int, str], None] | None
) = None,
) -> list[str]
Verify which transfer candidates actually need downloading.
For each accession, downloads md5checksums.txt from NCBI FTP and
compares the checksums of filtered files against the md5 user metadata
on corresponding S3 objects. Only accessions where at least one file
differs or is missing from S3 are returned.
This acts as a final gate before Phase 2: even if the summary diff flags an assembly, we skip it if every file in the store already matches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accessions
|
list[str]
|
list of candidate accessions (new + updated from diff) |
required |
current_assemblies
|
dict[str, AssemblyRecord]
|
parsed current assembly summary |
required |
bucket
|
PurePosixPath
|
S3 bucket name |
required |
key_prefix
|
PurePosixPath
|
S3 key prefix for the Lakehouse dataset root |
required |
ftp_host
|
str
|
NCBI FTP hostname |
FTP_HOST
|
progress_callback
|
Callable[[int, int, str], None] | None
|
optional callable invoked after each accession is
processed with |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
filtered list of accessions that actually need downloading |
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | |
write_transfer_manifest ¶
write_transfer_manifest(
diff: DiffResult,
current_assemblies: dict[str, AssemblyRecord],
output_path: Path,
ftp_host: str = FTP_HOST,
) -> list[PurePosixPath]
Write the transfer manifest (new + updated assemblies).
Each line is an FTP directory path suitable for Phase 2 download.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diff
|
DiffResult
|
computed diff result |
required |
current_assemblies
|
dict[str, AssemblyRecord]
|
parsed current assembly summary |
required |
output_path
|
Path
|
path to write the manifest file |
required |
ftp_host
|
str
|
FTP hostname for URL stripping |
FTP_HOST
|
Returns:
| Type | Description |
|---|---|
list[PurePosixPath]
|
list of FTP paths written |
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
write_removed_manifest ¶
Write the removed manifest (replaced + suppressed accessions).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diff
|
DiffResult
|
computed diff result |
required |
output_path
|
Path
|
path to write the manifest file |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list of accessions written |
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
write_updated_manifest ¶
Write the updated manifest (accessions whose content changed).
This file is consumed by Phase 3 to archive existing S3 objects before they are overwritten by the new versions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diff
|
DiffResult
|
computed diff result |
required |
output_path
|
Path
|
path to write the manifest file |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list of accessions written |
Source code in src/cdm_data_loaders/ncbi_ftp/manifest.py
write_diff_summary ¶
write_diff_summary(
diff: DiffResult,
output_path: Path,
database: str,
prefix_from: str | None = None,
prefix_to: str | None = None,
) -> dict[str, Any]
Write a JSON diff summary file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diff
|
DiffResult
|
computed diff result |
required |
output_path
|
Path
|
path to write the JSON file |
required |
database
|
str
|
database name ( |
required |
prefix_from
|
str | None
|
lower bound of prefix filter (if any) |
None
|
prefix_to
|
str | None
|
upper bound of prefix filter (if any) |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
the summary dict that was written |