Metadata-Version: 2.4
Name: dcat-ap-plus-chromatography
Version: 0.1.0
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Chemistry
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Software Development :: Libraries
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: Chromatography datasets in DCAT-AP-PLUS and Chem-DCAT-AP, completed by computation rather than by a reasoner and answered with verdicts.
Keywords: chromatography,DCAT-AP,Chem-DCAT-AP,NFDI4Cat,RDF,provenance,retention
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: Bug Tracker, https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-chromatography/issues
Project-URL: Changelog, https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-chromatography/src/branch/main/CHANGELOG.md
Project-URL: documentation, https://dcat-ap-plus-chromatography.readthedocs.io
Project-URL: repository, https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-chromatography

# dcat-ap-plus-chromatography

Chromatography datasets in DCAT-AP-PLUS and Chem-DCAT-AP, completed by computation rather than by a reasoner and
answered with verdicts.

Status: pre-release. The interface is not stable.

Specification: [docs/specification](https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-chromatography/src/branch/main/docs/specification/README.md). Notebooks: [docs/notebooks](https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-chromatography/src/branch/main/docs/notebooks/README.md).

## Description

The package extends Chem-DCAT-AP with a LinkML schema for liquid and gas chromatography. For the records of a
catalogue, it computes what the schema alone does not determine.

| 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. |
| 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`, `dcat_ap_plus_chromatography_interface`, `dcat_ap_plus_chromatography_impl`, `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. Each computed node keeps its unit, its propagated uncertainty and an activity naming the step, its premises and its hypotheses. A stated value is checked, never overwritten. |
| Elution | `transport`, `ladder`, `carrier` | Isocratic transport (retention law, plate height, resolution, peak capacity), gradient elution as a contact ladder 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, a parquet table with JSON-LD metadata, carries a run, its analysis and its peaks as typed models of the extension. The models are generated from the schema with its imports merged. |
| Transfer and separation trees | `contacts`, `branching`, `ranks` | Contact descriptions of columns and eluents, a response model that predicts elution orders for new descriptions, the record of which descriptions transfer, and separation trees that send the compounds one dimension leaves together to another. |

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

## Framework

```mermaid
flowchart TD
  vendor[vendor files] --> converter[external converter, such as raw2dcat]
  converter --> descriptions[RDF descriptions in PROV-O and QUDT]

  schema[schema: LinkML, imports Chem-DCAT-AP] --> artefacts[artefacts: OWL, SHACL, JSON-LD context]
  schema --> census[census: distinctions the RDF cannot carry]

  descriptions --> provenance[provenance: stated or supplied]
  descriptions --> operations[operations: records, signatures, attributes]
  descriptions --> computing[computing steps: nodes computed from stated nodes]
  elution[elution: transport, contact ladder, carrier gas] --> computing
  transfer[contact descriptions, separation trees] -. what may be published .-> computing
  provenance --> comparison[comparability, corroboration, linkage]
  provenance --> refinement[refinement and scores: cells, pair statuses, requirement levels]
  operations --> refinement
  refinement --> admission[admission: slots named by their partition]
  comparison --> status[status: margin against none of these, threshold]
  status --> propagation[propagation: rules, depth to evidence]
  propagation --> status

  identifiers[identifiers: stage key from file digests] --> emission[emission: stage writer]
  computing --> emission
  status --> emission
  refinement --> emission
  admission --> emission
  emission --> dataset[(stage dataset: named graphs, TriG and JSON-LD)]
  dataset --> published[default graph: published values only]
  artefacts --> validation{SHACL validation}
  published --> validation
  published --> questions[questions: one verdict per step]
```

## Installation

From PyPI, for Python 3.13. The wheels for Linux, macOS and Windows carry the Rust core.

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

Notebook 20 runs with nothing but these packages; the others need a clone of the repository. Installing from the
source distribution, or from the repository, compiles the Rust core and needs a Rust toolchain.

## 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 (notebook 19):

```python
from scidats import SciDatS

from dcat_ap_plus_chromatography import profile

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)
```

The formulas are available on their own:

```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)
```

The notebooks in [docs/notebooks](https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-chromatography/src/branch/main/docs/notebooks/README.md) show every part on synthetic records and on public retention data.

## Data

Notebooks 14–17 and 19 read extracts of RepoRT (Kretschmer et al., *Nature Methods* 21, 153–155, 2024) in
[docs/notebooks/data/report](https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-chromatography/src/branch/main/docs/notebooks/data/report/README.md). The extracts are licensed CC BY-SA 4.0, as RepoRT is; the
rest of the repository is under the MIT licence.

## 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. Each language keeps its own build tool, and they 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 the artefact runtime runs: `elute`, `elution-composition`, `retention-factor`, `carrier`, `contact-numbers` | 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; `rust.py` asks the extension module | uv |
| `docs/notebooks/` | Python | demonstrations; notebook 18 shows the Rust core agreeing with the Python reference | uv |
| `tests/fixtures/core/` | JSON | values of the Python reference, written by `scripts/generate_core_fixtures.py`, that the Rust and TypeScript tests must reproduce | |

## Development

Requires [uv](https://docs.astral.sh/uv/), the Rust toolchain pinned in `rust-toolchain.toml` (installed by rustup on
first use), [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 -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/). The project follows the
[copier-python](https://gitlab.com/opensourcelab/software-dev/copier-python) template; `copier update` brings in
changes of the template. See [CONTRIBUTING.md](https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-chromatography/src/branch/main/CONTRIBUTING.md).

## Support

Questions and reports go to the [issue tracker](https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-chromatography/issues).

## Authors and acknowledgment

Kundai Farai Sachikonye, University of Greifswald. Developed within NFDI4Cat, the National Research Data Infrastructure
for Catalysis-Related Sciences. See [CONTRIBUTORS.md](https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-chromatography/src/branch/main/CONTRIBUTORS.md).

## Licence

MIT. See [LICENSE](https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-chromatography/src/branch/main/LICENSE). The RepoRT extracts in `docs/notebooks/data/report` are CC BY-SA 4.0.

