From 82dcc5370b381efd493ed33d949dc102d7427271 Mon Sep 17 00:00:00 2001 From: Lukas Heumos Date: Mon, 22 Apr 2024 08:47:27 -0700 Subject: [PATCH] Simplify (#27) * :art: Use script Signed-off-by: zethson * :sparkles: Simplify language Signed-off-by: zethson * :art: Refactor Signed-off-by: zethson * :art: Wording Signed-off-by: zethson * :art: Simplify Signed-off-by: zethson --------- Signed-off-by: zethson --- docs/mcmicro_02.ipynb | 54 ++---------------------------------- docs/register_mcmicro_run.py | 25 +++++++++++++++++ 2 files changed, 27 insertions(+), 52 deletions(-) create mode 100644 docs/register_mcmicro_run.py diff --git a/docs/mcmicro_02.ipynb b/docs/mcmicro_02.ipynb index b404e1c..a68be40 100644 --- a/docs/mcmicro_02.ipynb +++ b/docs/mcmicro_02.ipynb @@ -97,7 +97,7 @@ "id": "e16d2a67", "metadata": {}, "source": [ - "Now we register our Nextflow run by specifying the pipeline name, its version and its associated reference." + "Now we register our Nextflow run by running our [registration script](https://github.com/laminlabs/nextflow-lamin-usecases/blob/main/docs/register_mcmicro_run.py)." ] }, { @@ -107,57 +107,7 @@ "metadata": {}, "outputs": [], "source": [ - "!python register_nf_run.py -p mcmicro -v 1.0.0 -r https://github.com/labsyspharm/mcmicro" - ] - }, - { - "cell_type": "markdown", - "id": "863bbe66", - "metadata": {}, - "source": [ - ":::{dropdown} How to amend a `register_nf_run.py` to register input & output files in LaminDB?\n", - "\n", - "First we created a Transform for the run:\n", - "\n", - "```python\n", - "parser = argparse.ArgumentParser()\n", - "parser.add_argument(\"-p\", \"--pipeline-name\", required=True)\n", - "parser.add_argument(\"-v\", \"--pipeline-version\", required=True)\n", - "parser.add_argument(\"-r\", \"--pipeline-reference\", required=True)\n", - "args = parser.parse_args()\n", - "\n", - "transform = ln.Transform(\n", - " name=args.pipeline_name,\n", - " version=args.pipeline_version,\n", - " type=\"pipeline\",\n", - " reference=args.pipeline_reference,\n", - ")\n", - "ln.track(transform=transform)\n", - "run = ln.dev.run_context.run\n", - "```\n", - "\n", - "To query input files via LaminDB, we added the following lines:\n", - "\n", - "```python\n", - "mcmicro_input = ln.Artifact.filter(key__startswith=\"exemplar-001\")\n", - "input_paths = [input_fastq.stage() for input_fastq in mcmicro_input]\n", - "```\n", - "\n", - "To register the output file and nextflow ID with LaminDB, we added the following line to the last task:\n", - "\n", - "```python\n", - "output = ln.Artifact(\n", - " \"exemplar-001/registration/exemplar-001.ome.tif\", description=\"mcmicro\"\n", - ")\n", - "output.save()\n", - "\n", - "nextflow_id = getoutput(f\"nextflow log | awk '/{run.id}/{{print $8}}'\")\n", - "run.reference = nextflow_id\n", - "run.reference_type = \"nextflow_id\"\n", - "run.save()\n", - "```\n", - "\n", - ":::\n" + "!python register_mcmicro_run.py" ] }, { diff --git a/docs/register_mcmicro_run.py b/docs/register_mcmicro_run.py new file mode 100644 index 0000000..61f79d6 --- /dev/null +++ b/docs/register_mcmicro_run.py @@ -0,0 +1,25 @@ +from subprocess import getoutput + +import lamindb as ln + +transform = ln.Transform( + name="mcmicro", + version="1.0.0", + type="pipeline", + reference="https://github.com/labsyspharm/mcmicro", +) +ln.track(transform=transform) +run = ln.dev.run_context.run + +mcmicro_input = ln.Artifact.filter(key__startswith="exemplar-001") +input_paths = [input_fastq.stage() for input_fastq in mcmicro_input] + +output = ln.Artifact( + "exemplar-001/registration/exemplar-001.ome.tif", description="mcmicro" +) +output.save() + +nextflow_id = getoutput(f"nextflow log | awk '/{run.id}/{{print $8}}'") +run.reference = nextflow_id +run.reference_type = "nextflow_id" +run.save()