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'
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]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Unknown |
ImportError
|
If SFTP is needed and |
Source code in src/noxdb/fetch.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 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 | |
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
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 395 396 397 398 399 400 401 402 403 404 405 406 407 | |