cdm_data_loaders.ncbi_ftp.assembly ¶
NCBI FTP assembly-specific domain logic.
Provides path helpers, file filters, MD5 checksum parsing, and single-assembly
download logic for NCBI GenBank/RefSeq assemblies. Orchestration (batching,
threading, CLI) lives in :mod:cdm_data_loaders.pipelines.ncbi_ftp_download.
parse_md5_checksums_file ¶
Parse an NCBI md5checksums.txt file into a filename-to-hash mapping.
Each line has the format <md5> ./<filename> (two-space separator).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
raw text of the md5checksums.txt file |
required |
Returns:
| Type | Description |
|---|---|
dict[PurePosixPath, str]
|
dict mapping filename to MD5 hex digest |
Source code in src/cdm_data_loaders/ncbi_ftp/assembly.py
filter_assembly_checksums ¶
Filter a parsed md5checksums.txt mapping to files matching FILE_FILTERS.
Source code in src/cdm_data_loaders/ncbi_ftp/assembly.py
build_accession_path ¶
Build the relative output path for an assembly directory.
Produces raw_data/{GCF|GCA}/{000}/{001}/{215}/{assembly_dir}/.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assembly_dir
|
PurePosixPath
|
full assembly directory name (e.g. |
required |
Returns:
| Type | Description |
|---|---|
PurePosixPath
|
relative path |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the assembly directory name cannot be parsed |
Source code in src/cdm_data_loaders/ncbi_ftp/assembly.py
parse_assembly_path ¶
Extract database, assembly_dir, and accession from an FTP assembly path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assembly_path
|
PurePosixPath
|
FTP directory path (e.g. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, PurePosixPath, str]
|
tuple of |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the path cannot be parsed |
Source code in src/cdm_data_loaders/ncbi_ftp/assembly.py
download_assembly_to_local ¶
download_assembly_to_local(
assembly_path: PurePosixPath,
output_dir: Path,
ftp_host: str = FTP_HOST,
ftp: FTP | None = None,
) -> dict[str, Any]
Download one assembly from NCBI FTP to a local directory.
Creates a directory structure under output_dir matching the S3 layout,
downloads filtered files, verifies MD5 checksums, and writes .md5
sidecar files for downstream metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assembly_path
|
PurePosixPath
|
FTP directory path for the assembly |
required |
output_dir
|
Path
|
base output directory |
required |
ftp_host
|
str
|
FTP hostname |
FTP_HOST
|
ftp
|
FTP | None
|
optional existing FTP connection (caller manages lifecycle) |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
json parsable dict with download statistics |