API Reference¶
Auto-generated reference for the public API, rendered by mkdocstrings.
For task-oriented examples see the Usage guide.
Package¶
A unified dataset framework for mass spectrometry.
DatasetNotFoundError
¶
Bases: Exception
Raised when the server returns 404 for a dataset.
DownloadError
¶
Bases: Exception
Raised on network or server failures during download.
ExtractionError
¶
Bases: DownloadError
Raised when a server-side extraction task fails.
Dataset
dataclass
¶
Result object returned by load_dataset.
Supports len(), indexing, and iteration over downloaded file paths.
RepoSource
¶
Bases: str, Enum
Supported repository sources for dataset imports.
download_dataset
¶
download_dataset(dataset_id: str, *, force_download: bool = False, show_progress: bool = True, max_workers: int = 4, filenames: list[str] | None = None, store_as: StoreFormat = 'mszx', output_dir: Path | None = None) -> Dataset
Download a dataset and return a Dataset pointing to local files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_id
|
str
|
Server-side dataset identifier (UUID). |
required |
force_download
|
bool
|
Re-download parts even if they already exist on disk. |
False
|
show_progress
|
bool
|
Show a |
True
|
max_workers
|
int
|
Maximum number of parallel downloads. |
4
|
filenames
|
list[str] | None
|
Optional list of filenames to include. When provided, the server returns a manifest containing only matching parts. |
None
|
store_as
|
StoreFormat
|
On-disk format for downloaded parts. Defaults to |
'mszx'
|
output_dir
|
Path | None
|
Optional destination directory. When set, files are written
directly here (no |
None
|
Source code in src/msdatasets/download.py
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 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 | |
download_repo_dataset
¶
download_repo_dataset(source: RepoSource | str, accession: str, *, filenames: list[str] | None = None, force_download: bool = False, show_progress: bool = True, max_workers: int = 4, store_as: StoreFormat = 'mszx', output_dir: Path | None = None) -> Dataset
Trigger a repository import and download the resulting dataset.
Posts to /repositories/{source}/projects/{accession}/dataset to create
a dataset from a PRIDE or MassIVE project. The endpoint is
idempotent—calling it for an already-imported project returns the
existing dataset and job statuses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
RepoSource | str
|
Repository source ( |
required |
accession
|
str
|
Project accession (e.g. |
required |
filenames
|
list[str] | None
|
Optional list of specific filenames to import. When None, all files in the project are imported. |
None
|
force_download
|
bool
|
Re-download parts even if they already exist on disk. |
False
|
show_progress
|
bool
|
Show a |
True
|
max_workers
|
int
|
Maximum number of parallel downloads. |
4
|
store_as
|
StoreFormat
|
On-disk format for downloaded parts. See |
'mszx'
|
output_dir
|
Path | None
|
Optional destination directory. See |
None
|
Source code in src/msdatasets/download.py
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 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 | |
load_dataset
¶
load_dataset(dataset_id: str, *, force_download: bool = False, show_progress: bool = True, max_workers: int = 4, load_annotations: list[AnnotationFormat] | None = None) -> MSCompressDataset
Download a dataset and return an MSCompressDataset.
Convenience wrapper around download_dataset that loads the
downloaded files into an mscompress.datasets.torch.MSCompressDataset
ready for iteration. Requires PyTorch to be installed.
If dataset_id matches the pattern {source}/<accession> (e.g.
pride/PXD075509 or massive/MSV000078787), the repository import
flow is used instead. A specific filename subset may be specified in
square brackets: pride/PXD000001[file1.raw,file2.mzML].
If dataset_id matches hf/<owner>/<repo> (e.g.
hf/myorg/proteomics-bench), files are pulled directly from the
HuggingFace dataset repo. Requires the hf extra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_id
|
str
|
Server-side dataset identifier, or a repository specifier like
|
required |
force_download
|
bool
|
Re-download parts even if they already exist on disk. |
False
|
show_progress
|
bool
|
Show a |
True
|
max_workers
|
int
|
Maximum number of parallel downloads. |
4
|
load_annotations
|
list[AnnotationFormat] | None
|
Annotation formats to load alongside spectra (forwarded to
|
None
|
Source code in src/msdatasets/download.py
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 | |
load_repo_dataset
¶
load_repo_dataset(source: RepoSource | str, accession: str, *, filenames: list[str] | None = None, force_download: bool = False, show_progress: bool = True, max_workers: int = 4, load_annotations: list[AnnotationFormat] | None = None) -> MSCompressDataset
Trigger a repository import and return an MSCompressDataset once ready.
Convenience wrapper around download_repo_dataset that loads the
downloaded files into an mscompress.datasets.torch.MSCompressDataset.
Requires PyTorch to be installed.
load_annotations is forwarded to MSCompressDataset. When set, the
dataset's __getitem__ returns (mz, intensity, annotations_dict)
instead of just (mz, intensity).
Source code in src/msdatasets/download.py
download_hf_dataset
¶
download_hf_dataset(repo_id: str, *, filenames: list[str] | None = None, revision: str | None = None, token: str | None = None, force_download: bool = False, show_progress: bool = True, output_dir: Path | None = None) -> Dataset
Download a HuggingFace dataset repo of MS files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_id
|
str
|
HuggingFace dataset repo ID in |
required |
filenames
|
list[str] | None
|
Optional list of specific filenames to fetch. When provided, the names
are passed through as |
None
|
revision
|
str | None
|
Optional branch, tag, or commit. Defaults to the repo's default branch. |
None
|
token
|
str | None
|
Optional HF auth token. Falls back to |
None
|
force_download
|
bool
|
Re-download files even if HF's cache already has them. |
False
|
show_progress
|
bool
|
When False, sets |
True
|
output_dir
|
Path | None
|
Optional destination directory. When set, files land here directly
(no |
None
|
Notes
--store-as conversion (mszx → msz / mzml) is not supported in this
version. MSCompressDataset reads .mszx natively, so the PyTorch
path works end-to-end without conversion.
Source code in src/msdatasets/hf.py
load_hf_dataset
¶
load_hf_dataset(repo_id: str, *, filenames: list[str] | None = None, revision: str | None = None, token: str | None = None, force_download: bool = False, show_progress: bool = True, output_dir: Path | None = None, load_annotations: list[AnnotationFormat] | None = None) -> MSCompressDataset
Download an HF dataset repo and return an MSCompressDataset.
Convenience wrapper around download_hf_dataset. Requires PyTorch.
load_annotations is forwarded to MSCompressDataset. When set, the
dataset's __getitem__ returns (mz, intensity, annotations_dict)
instead of just (mz, intensity).
Source code in src/msdatasets/hf.py
Configuration¶
msdatasets.config
¶
Configuration: paths, URLs, and environment variables.
get_api_url
¶
Return the base API URL.
Resolution: MS_API_URL env var, or the default production URL.
get_cache_dir
¶
Return the root cache directory for downloaded datasets.
Resolution order:
1. MS_DATASETS_CACHE env var
2. MS_HOME env var + /datasets
3. ~/.ms/datasets