cdm_data_loaders.ncbi_ftp.metadata ¶
Frictionless data package descriptor creation for NCBI FTP assemblies.
Creates KBase credit metadata descriptors for each promoted assembly,
matching the schema produced by kbase-transfers/scripts/ncbi/download_genomes.py.
Each descriptor is a frictionless Package-compatible JSON document
describing the assembly's data files, stored at::
{key_prefix}metadata/{assembly_dir}_datapackage.json
and archived alongside raw data at::
{key_prefix}archive/{release_tag}/metadata/{assembly_dir}_datapackage.json
The descriptor resources list records the final Lakehouse S3 key, byte
size, file format, and MD5 hash of each promoted data file.
DescriptorResource ¶
Bases: TypedDict
A single resource entry in the frictionless descriptor resources list.
Source code in src/cdm_data_loaders/ncbi_ftp/metadata.py
build_descriptor_key ¶
Return the S3 key for the live descriptor of assembly_dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assembly_dir
|
PurePosixPath
|
full assembly directory name, e.g. |
required |
key_prefix
|
PurePosixPath
|
Lakehouse key prefix (trailing slash optional) |
required |
Returns:
| Type | Description |
|---|---|
PurePosixPath
|
S3 key, e.g. |
Source code in src/cdm_data_loaders/ncbi_ftp/metadata.py
build_archive_descriptor_key ¶
build_archive_descriptor_key(
assembly_dir: PurePosixPath,
release_tag: str,
key_prefix: PurePosixPath,
archive_reason: str = "unknown",
) -> PurePosixPath
Return the S3 key for the archived descriptor of assembly_dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assembly_dir
|
PurePosixPath
|
full assembly directory name |
required |
release_tag
|
str
|
NCBI release tag used in the archive path, e.g. |
required |
key_prefix
|
PurePosixPath
|
Lakehouse key prefix |
required |
archive_reason
|
str
|
reason for archival, encoded as a path segment |
'unknown'
|
Returns:
| Type | Description |
|---|---|
PurePosixPath
|
S3 key under |
Source code in src/cdm_data_loaders/ncbi_ftp/metadata.py
create_descriptor ¶
create_descriptor(
assembly_dir: PurePosixPath,
accession_full: str,
resources: list[DescriptorResource],
*,
timestamp: int | None = None
) -> dict[str, Any]
Build a KBase credit metadata descriptor for an NCBI assembly.
Matches the schema produced by
kbase-transfers/scripts/ncbi/download_genomes.py::create_frictionless_descriptor().
Resource names are lowercased. Resources whose hash value is None
have the hash key removed entirely (frictionless does not accept null
hash values).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assembly_dir
|
PurePosixPath
|
full assembly directory name (includes the accession
suffix, e.g. |
required |
accession_full
|
str
|
accession without suffix, e.g. |
required |
resources
|
list[DescriptorResource]
|
list of :class: |
required |
timestamp
|
int | None
|
Unix timestamp to embed; defaults to |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
descriptor dict ready for serialisation and frictionless validation |
Source code in src/cdm_data_loaders/ncbi_ftp/metadata.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
validate_descriptor ¶
Validate a descriptor with frictionless.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
descriptor
|
dict[str, Any]
|
descriptor dict from :func: |
required |
accession_full
|
str
|
accession (used only in error messages) |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if frictionless reports any metadata errors |
Source code in src/cdm_data_loaders/ncbi_ftp/metadata.py
upload_descriptor ¶
upload_descriptor(
descriptor: dict[str, Any],
assembly_dir: PurePosixPath,
bucket: PurePosixPath,
key_prefix: PurePosixPath,
*,
dry_run: bool = False
) -> PurePosixPath
Serialise and upload a descriptor to the live metadata/ path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
descriptor
|
dict[str, Any]
|
descriptor dict from :func: |
required |
assembly_dir
|
PurePosixPath
|
full assembly directory name |
required |
bucket
|
PurePosixPath
|
S3 bucket name |
required |
key_prefix
|
PurePosixPath
|
Lakehouse key prefix |
required |
dry_run
|
bool
|
if True, log without uploading |
False
|
Returns:
| Type | Description |
|---|---|
PurePosixPath
|
S3 key the descriptor was (or would be) written to |
Source code in src/cdm_data_loaders/ncbi_ftp/metadata.py
archive_descriptor ¶
archive_descriptor(
assembly_dir: PurePosixPath,
bucket: PurePosixPath,
key_prefix: PurePosixPath,
release_tag: str,
*,
archive_reason: str = "unknown",
dry_run: bool = False
) -> bool
Copy the live descriptor to the archive path.
If the live descriptor does not yet exist (e.g. archival is triggered
before the first promote), logs a warning and returns False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assembly_dir
|
PurePosixPath
|
full assembly directory name |
required |
bucket
|
PurePosixPath
|
S3 bucket name |
required |
key_prefix
|
PurePosixPath
|
Lakehouse key prefix |
required |
release_tag
|
str
|
NCBI release tag for the archive path |
required |
archive_reason
|
str
|
metadata value describing why archived (matches raw data metadata) |
'unknown'
|
dry_run
|
bool
|
if True, log without copying |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
|