fetch¶
fetch
¶
Export project metadata + files from the database to a local folder.
These helpers are the "consumer" side of noxdb: given a project_id, materialize either the metadata table (CSV / Excel) or the file payloads (downloaded via SFTP when the database is reached through an SSH jump host, or copied directly from the filesystem when running on LiSC).
Layout produced by :func:export_project:
<output_dir>/
├── metadata.csv # tidy wide-form table
├── metadata.xlsx # same, Excel
├── README.txt # project summary
└── files/
└── <sample_name>/<file_type>.<ext> # layout='by_sample'
# or
└── <file_type>/<sample_name>.<ext> # layout='by_type'
A file registered as a member of a tar (archive_member set) is
extracted on its own: read at archive_offset when known, otherwise
looked up by name in the tar, and checked against checksum_md5.
All functions take an optional cursor and open their own
:func:noxdb.transaction block when one isn't provided, so they
work as one-shot calls from a notebook or composed inside a larger
read transaction.
export_metadata_table
¶
export_metadata_table(cur=None, *, project_id: int, output_dir: Path | str, formats: tuple[str, ...] = ('csv',)) -> dict[str, Path]
Write the project tidy table to disk in the requested formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cur
|
Optional cursor from |
None
|
|
project_id
|
int
|
Project to export. |
required |
output_dir
|
Path | str
|
Destination directory. Created if missing. |
required |
formats
|
tuple[str, ...]
|
Iterable of |
('csv',)
|
Returns:
| Type | Description |
|---|---|
dict[str, Path]
|
|
dict[str, Path]
|
written. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ImportError
|
If |
Source code in src/noxdb/fetch.py
download_files_for_project
¶
download_files_for_project(cur=None, *, project_id: int, output_dir: Path | str, file_types: list[str] | None = None, layout: str = 'by_sample', config_path: str | Path | None = DEFAULT_CONFIG_PATH, ssh_section: str = DEFAULT_SSH_SECTION, **ssh_overrides: Any) -> dict[str, Any]
Copy every file registered for a project into a local folder.
SSH credentials are resolved from config_path / ssh_section
the same way
init_pool does. When
ssh_host is unset the function falls back to local file copy
via shutil.copyfile (useful when running on LiSC itself).
Already-present destinations are skipped, so the call is resumable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cur
|
Optional cursor from |
None
|
|
project_id
|
int
|
Project to download. |
required |
output_dir
|
Path | str
|
Destination directory. Created if missing. |
required |
file_types
|
list[str] | None
|
Only download files whose |
None
|
layout
|
str
|
|
'by_sample'
|
config_path
|
str | Path | None
|
Path to the MariaDB-style config file. |
DEFAULT_CONFIG_PATH
|
ssh_section
|
str
|
Section name within |
DEFAULT_SSH_SECTION
|
**ssh_overrides
|
Any
|
Per-call SSH kwargs that win over the config
file and |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
``{"downloaded": [...], "skipped": [...], "failed": [...], |
dict[str, Any]
|
"output_dir": str} |
dict[str, Any]
|
|
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Unknown |
ImportError
|
If SFTP is needed and |
Source code in src/noxdb/fetch.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 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 | |
export_project
¶
export_project(cur=None, *, project_id: int, output_dir: Path | str, file_types: list[str] | None = None, layout: str = 'by_sample', metadata_formats: tuple[str, ...] = ('csv',), include_files: bool = True, config_path: str | Path | None = DEFAULT_CONFIG_PATH, ssh_section: str = DEFAULT_SSH_SECTION, **ssh_overrides: Any) -> dict[str, Any]
One-shot export: metadata table + files + README.
Combines
export_metadata_table
and
download_files_for_project
and writes a small README.txt describing the project. Useful
for handing a self-contained snapshot to a collaborator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cur
|
Optional cursor from |
None
|
|
project_id
|
int
|
Project to export. |
required |
output_dir
|
Path | str
|
Destination directory. Created if missing. |
required |
file_types
|
list[str] | None
|
Forwarded to
|
None
|
layout
|
str
|
Forwarded to
|
'by_sample'
|
metadata_formats
|
tuple[str, ...]
|
Forwarded to
|
('csv',)
|
include_files
|
bool
|
When |
True
|
config_path
|
str | Path | None
|
DEFAULT_CONFIG_PATH
|
|
ssh_section
|
str
|
DEFAULT_SSH_SECTION
|
|
**ssh_overrides
|
Any
|
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
``{"project", "summary", "metadata", "files", "readme", |
dict[str, Any]
|
"output_dir"}`` — the project row, the |
dict[str, Any]
|
|
dict[str, Any]
|
dict, paths of the metadata files, the file-download report, |
dict[str, Any]
|
and the README path. |
Source code in src/noxdb/fetch.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |