Metadata-Version: 2.4
Name: dcat-ap-plus-chromatography
Version: 0.1.1
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Rust
Classifier: Topic :: Scientific/Engineering :: Chemistry
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Dist: chem-dcat-ap>=0.1.0rc3
Requires-Dist: dcat-ap-plus>=0.1.0rc4
Requires-Dist: linkml-runtime>=1.11
Requires-Dist: numpy>=2.1
Requires-Dist: rdflib>=7.0
Requires-Dist: linkml>=1.11 ; extra == 'generators'
Requires-Dist: scidats>=0.0.20 ; extra == 'scidats'
Provides-Extra: generators
Provides-Extra: scidats
License-File: LICENSE
Summary: LinkML extension of Chem-DCAT-AP for liquid and gas chromatography, with a Rust-backed computing layer that derives retention quantities with units, uncertainty and PROV-O provenance.
Keywords: chromatography,liquid chromatography,gas chromatography,HPLC,retention time,DCAT-AP-PLUS,Chem-DCAT-AP,LinkML,SHACL,PROV-O,QUDT,SciDatS,RDF,FAIR,research data management,NFDI4Cat,catalysis
Author-email: Kundai Farai Sachikonye <kundai.sachikonye@uni-greifswald.de>
Maintainer: Kundai Farai Sachikonye
License: MIT
Requires-Python: ==3.13.*
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: NFDI4Cat, https://nfdi4cat.org

# dcat-ap-plus-chromatography

[![PyPI](https://img.shields.io/pypi/v/dcat-ap-plus-chromatography)](https://pypi.org/project/dcat-ap-plus-chromatography/)
[![Python](https://img.shields.io/pypi/pyversions/dcat-ap-plus-chromatography)](https://pypi.org/project/dcat-ap-plus-chromatography/)
[![Licence](https://img.shields.io/pypi/l/dcat-ap-plus-chromatography)](https://pypi.org/project/dcat-ap-plus-chromatography/)

A LinkML extension of Chem-DCAT-AP for liquid and gas chromatography, with a computing layer that derives retention
quantities from stated metadata, each with its unit, its uncertainty and its provenance.

Status: alpha. The schema and the interfaces may still change between minor versions.

## Overview

The Data Catalog Vocabulary application profile extended by NFDI4Chem and NFDI4Cat (DCAT-AP-PLUS) and its chemistry
extension, Chem-DCAT-AP, describe a dataset and the chemistry behind it in the Resource Description Framework (RDF). This package adds what a chromatographic dataset needs: the run, the column and its facets, the
mobile phase and its program, the peaks, and the quantities measured or computed on them.

It then completes a catalogue by computation. Values the records do not state, but which follow from what they state
(column volume, dwell time, retention factor, plate number, elution composition), are derived by published formulas.
Each derived value carries its unit from Quantities, Units, Dimensions and Types (QUDT), its propagated standard
uncertainty, and an activity of the PROV Ontology (PROV-O) that names the formula, its premises and its assumptions. A stated value is checked against the derived one and never overwritten.
No reasoner is involved: every question receives a verdict, and a question that cannot be answered names what blocked
it and what would unblock it.

The heavy computing (gradient elution, the fit of contact numbers, the carrier gas) runs in a Rust core compiled into
every wheel.

## Standards

| Standard | Role |
|---|---|
| [DCAT-AP-PLUS](https://pypi.org/project/dcat-ap-plus/) 0.1.0rc4, [Chem-DCAT-AP](https://pypi.org/project/chem-dcat-ap/) 0.1.0rc3 | imported profiles that the schema extends |
| [LinkML](https://linkml.io) | schema language; OWL, SHACL shapes, a JSON-LD context and pydantic models are generated from the schema |
| [PROV-O](https://www.w3.org/TR/prov-o/) | the activities behind runs, analyses and computed values |
| [QUDT](https://qudt.org) | units and quantity kinds |
| [SHACL](https://www.w3.org/TR/shacl/) | validation of catalogues and of SciDatS metadata |
| [SciDatS](https://gitlab.com/opensourcelab/scientificdata/scidats) | parquet tables with DCAT-AP-PLUS metadata; the extension registers as a profile |
| TriG, JSON-LD | the RDF datasets the package writes |

## Parts

| Part | Modules | What it does |
|---|---|---|
| Schema | `schema` | 47 classes, 48 slots and two enumerations: runs, columns as facets, mobile phases, peaks, measured and computed quantities with a standard uncertainty, peak tables, simulations, corroborations, computing steps and the sample role. Every class and slot has an IRI of its own. |
| Census and artefacts | `census`, `artefacts` | Reports which distinctions of the schema the emitted RDF cannot carry. Generates OWL, SHACL shapes and a JSON-LD context from the emitted IRIs, and repairs three defects of the generated shapes. |
| Provenance and verdicts | `provenance`, `verdicts` | Tags every value as stated by its source or supplied by a named convention. Gives every step of a question one verdict and names what blocked it. |
| Comparison | `comparability`, `corroboration`, `linkage`, `retention` | Compares runs on stated facets under declared tolerances, and corroborates retention times at a declared floor. Links records by elimination on witnessed differences before any ranking. |
| Refinement | `refinement`, `scores`, `admission` | Computes the nests, cells and pair statuses of a stage, and requirement levels from what each field does. Admits a new slot under six conditions and names it by the partition of the records it induces. |
| Publication | `status`, `propagation` | Publishes a value only when it leads its best alternative, the candidate "none of these" included, by a threshold that bounds the probability of a wrong publication. Rules propagate published values. |
| Reading and storage | `operations`, `identifiers`, `emission` | Reads records from their PROV-O and QUDT descriptions without a program. Keys a stage by the SHA-256 of its files and writes everything computed about it as one RDF dataset, in TriG and JSON-LD. The default graph of that dataset holds the published values only. |
| Computing steps | `computing`, `main` | Computes nodes from stated nodes by published formulas: column volume, dwell time, retention factor, plate number, elution composition, and for gas chromatography the hold-up time of an open tube, the compressibility factor and the mean velocity. |
| Elution | `transport`, `ladder`, `carrier` | Isocratic transport (retention law, plate height, resolution, peak capacity), gradient elution solved exactly for piecewise-linear programs, and the carrier gas as an ideal gas in viscous flow. |
| SciDatS files | `profile`, `datamodel` | Registers the extension as a SciDatS profile, so that a SciDatS file carries a run, its analysis and its peaks as typed models of the extension. |
| Transfer and separation trees | `contacts`, `branching`, `ranks` | Contact descriptions of columns and eluents, a response model that predicts elution orders for new descriptions, and separation trees that send the compounds one dimension leaves together to another. |
| Rust core | `rust` | `elute`, `elution-composition`, `retention-factor`, `carrier` and `contact-numbers`, one answer or one refusal per record. |

The package does not read vendor files. An external converter, such as raw2dcat, writes the RDF descriptions that the
package reads.

## Installation

Python 3.13. Wheels for Linux, macOS and Windows carry the compiled Rust core.

```console
pip install dcat-ap-plus-chromatography               # the package
pip install "dcat-ap-plus-chromatography[scidats]"    # and SciDatS files
pip install "dcat-ap-plus-chromatography[generators]" # and OWL, SHACL and context generation from the schema
```

Installing from the source distribution compiles the Rust core and needs a [Rust toolchain](https://rustup.rs).

## Usage

Complete a catalogue by computing steps and write the stated and derived graphs as one dataset:

```python
from pathlib import Path

from dcat_ap_plus_chromatography.main import complete_file

completion = complete_file(Path("catalogue.ttl"), Path("completed.trig"))
for node in completion.derived:
    print(node.subject, node.slot, node.quantity)
for blocked in completion.declined:
    print(blocked.subject, blocked.step, blocked.reason)
```

Write a peak table as a SciDatS file, with a `PeakTableDataset` of the extension as its metadata:

```python
from scidats import SciDatS

from dcat_ap_plus_chromatography import profile

profile.register()
sd = SciDatS(dataframe=peaks)  # one row per peak
profile.attach(sd, dataset)  # validated by the extension's models
sd.write_parquet("peaks.scidats.parquet")
conforms, report = profile.validate(SciDatS(input_filename="peaks.scidats.parquet").graph)
```

Ask the Rust core directly; a record it cannot answer is refused with the reason:

```python
from dcat_ap_plus_chromatography import rust

rust.ask("retention-factor", retention_time=4.2, hold_up_time=0.735)  # {'retention_factor': 4.714...}
rust.ask("retention-factor", retention_time=4.2)  # Refusal(label='absent', blocker='`hold_up_time` has no value', needs=None)
```

The formulas are also available in Python:

```python
from dcat_ap_plus_chromatography import ladder

program = ladder.Program((0.0, 2.0, 17.0, 20.0), (0.05, 0.05, 0.999, 0.999))
ladder.elute(program, ladder.ContactNumbers(log_factor=3.0, sensitivity=12.0), holdup_time=0.735, dwell=1.0)
```

## Results on public data

RepoRT datasets 0187–0196 hold one column and one program at five flow rates, in two ionisation modes. Contact numbers
fitted on four flow rates predict the retention times of the fifth with a median absolute error of 0.013 min, over 690
analyte–mode pairs. The run, written as a SciDatS file, conforms to the extension's shapes, and computing steps
complete it from the column dimensions RepoRT states. Notebook 20 reproduces this from the PyPI packages alone.

## Documentation

The source repository holds the specification (23 parts, each with its rules, decisions and checks), 21 notebooks
that show every part on synthetic records and on public retention data, and the changelog.

## Data

Notebooks 14–17 and 19 read extracts of RepoRT (Kretschmer et al., *Nature Methods* 21, 153–155, 2024) in
`docs/notebooks/data/report`, licensed Creative Commons Attribution-ShareAlike 4.0
(CC BY-SA 4.0) as RepoRT is. Notebook 20
downloads the files it reads from RepoRT at a fixed commit.

## Layout

The heavy computing runs in Rust. Python is the prototype, the reference the Rust code is tested against, and the
language of the notebooks. TypeScript carries the web interface. The three share one version.

| Path | Language | What | Tool |
|---|---|---|---|
| `crates/chromatography-core/` | Rust | elution, the contact ladder and its fit, the carrier gas, transport; the tool protocol as JSON in and out; no I/O | cargo |
| `crates/chromatography-tool/` | Rust | the `chromatography tool <name>` command | cargo |
| `crates/chromatography-wasm/` | Rust | the core for browsers, through the same protocol | wasm-pack |
| `crates/chromatography-py/` | Rust | the extension module `dcat_ap_plus_chromatography._core`, built by maturin into every wheel | maturin |
| `packages/chromatography/` | TypeScript | `@dcat-ap-plus/chromatography`: typed calls of the tools and an SVG figure of a program and its elutions | npm |
| `src/dcat_ap_plus_chromatography/`, `tests/` | Python 3.13 | the prototype and reference; schema, stage, emission | uv |
| `docs/notebooks/` | Python | demonstrations | uv |
| `tests/fixtures/core/` | JSON | values of the Python reference that the Rust and TypeScript tests must reproduce | |

## Development

Requires [uv](https://docs.astral.sh/uv/), the Rust toolchain pinned in `rust-toolchain.toml`,
[wasm-pack](https://rustwasm.github.io/wasm-pack/) and Node 20 or later.

```console
# Python
uv sync   # compiles the extension module from crates/chromatography-py with maturin
uv run pre-commit install --install-hooks
uv run ruff check .
uv run ruff format --check .
uv run zuban check
uv run pytest
uv run --group notebooks python docs/notebooks/build.py
uv run --group docs sphinx-build -W -b html docs docs/_build

# Rust
cargo fmt --all --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace

# WebAssembly and TypeScript (the build runs wasm-pack first)
npm ci
npm run build
npm run typecheck
npm test
```

After a change to a Python reference function, regenerate the fixtures with
`uv run python scripts/generate_core_fixtures.py`; a test fails while they are out of date. Commit messages follow
[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/); see
`CONTRIBUTING.md`.

## Citation

Sachikonye, K. F. (2026). *dcat-ap-plus-chromatography* (version 0.1.1) [Software]. https://pypi.org/project/dcat-ap-plus-chromatography/

## Acknowledgement

Kundai Farai Sachikonye, University of Greifswald. Developed within
[NFDI4Cat](https://nfdi4cat.org), the National Research Data Infrastructure for Catalysis-Related Sciences, funded by
the German Research Foundation (DFG), project number 441926934.

## Licence

MIT. The RepoRT extracts in `docs/notebooks/data/report` are CC BY-SA 4.0.

