|
| 1 | +(data-lineage-page)= |
| 2 | + |
| 3 | +# Data lineage |
| 4 | + |
| 5 | +This guide shows how to get started with native provenance tracking, also known as *data lineage*, introduced in {ref}`Nextflow 25.04 <migrating-25-04-page>`. |
| 6 | + |
| 7 | +:::{warning} |
| 8 | +Data lineage is an experimental feature. It may change in future releases. |
| 9 | +::: |
| 10 | + |
| 11 | +## Overview |
| 12 | + |
| 13 | +The *provenance* or *lineage* of a data entity, such as a file or record, is the history of computations and intermediate data that produced the entity. Data lineage is useful for verifying the integrity and reproducibility of pipeline results. |
| 14 | + |
| 15 | +Nextflow's built-in data lineage, when enabled, tracks all of your workflow runs, task runs, and outputs in a single place as *lineage records*. You can then query these records from the command line, or use them in a Nextflow script. Every lineage record has a unique hash called a *lineage ID* (LID) by which it is accessed. |
| 16 | + |
| 17 | +## Enable data lineage |
| 18 | + |
| 19 | +To get started, enable data lineage in your Nextflow configuraiton: |
| 20 | + |
| 21 | +```groovy |
| 22 | +lineage.enabled = true |
| 23 | +``` |
| 24 | + |
| 25 | +Optionally, set the location of the lineage store: |
| 26 | + |
| 27 | +```groovy |
| 28 | +lineage.store.location = '.lineage' |
| 29 | +``` |
| 30 | + |
| 31 | +It defaults to `.lineage` in the current directory. |
| 32 | + |
| 33 | +:::{tip} |
| 34 | +Place these settings in `~/.nextflow/config` to apply them globally. |
| 35 | +::: |
| 36 | + |
| 37 | +See the {ref}`config-lineage` config scope for details. |
| 38 | + |
| 39 | +## Generate lineage metadata |
| 40 | + |
| 41 | +Run a Nextflow pipeline to generate some lineage metadata. For example: |
| 42 | + |
| 43 | +```bash |
| 44 | +nextflow run rnaseq-nf -profile conda |
| 45 | +``` |
| 46 | + |
| 47 | +This pipeline will execute several tasks and publish several output files, all of which will be recorded in the lineage store. |
| 48 | + |
| 49 | +## Explore lineage |
| 50 | + |
| 51 | +Now that you have generated some lineage metadata, you can explore it from the command line using the {ref}`cli-lineage` command. |
| 52 | + |
| 53 | +First, use the `list` subcommand to list the workflow runs in the lineage store: |
| 54 | + |
| 55 | +```console |
| 56 | +$ nextflow lineage list |
| 57 | +TIMESTAMP RUN NAME SESSION ID LINEAGE ID |
| 58 | +2025-05-09 13:28:30 CDT peaceful_blackwell 065bdc6b-89b4-42ee-92c1-2a5af37f2c50 lid://16b31030474f2e96c55f4940bca3ab64 |
| 59 | +``` |
| 60 | + |
| 61 | +The *lineage ID* (LID) is the unique identifier for the workflow run and the entrypoint for exploring the lineage. |
| 62 | + |
| 63 | +Use the `view` subcommand to view the lineage record for the workflow run: |
| 64 | + |
| 65 | +```console |
| 66 | +$ nextflow lineage view lid://16b31030474f2e96c55f4940bca3ab64 |
| 67 | +{ |
| 68 | + "type": "WorkflowRun", |
| 69 | + "workflow": { |
| 70 | + "scriptFiles": [ |
| 71 | + ... |
| 72 | + ], |
| 73 | + "repository": "https://github.com/nextflow-io/rnaseq-nf", |
| 74 | + "commitId": "86165b8c81d43a1f57363964431395152e353e56" |
| 75 | + }, |
| 76 | + "sessionId": "065bdc6b-89b4-42ee-92c1-2a5af37f2c50", |
| 77 | + "name": "peaceful_blackwell", |
| 78 | + "params": [ |
| 79 | + ... |
| 80 | + ], |
| 81 | + "config": { |
| 82 | + ... |
| 83 | + } |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +Every workflow run is represented in the lineage store as a `WorkflowRun` record, which includes information such as the pipeline repository, revision, run name, parameters, and resolved config. |
| 88 | + |
| 89 | +:::{note} |
| 90 | +The data model for every lineage record is defined in the Nextflow [source code](https://github.com/nextflow-io/nextflow/tree/master/modules/nf-lineage/src/main/nextflow/lineage/model). |
| 91 | +::: |
| 92 | + |
| 93 | +The output files of a workflow run can be accessed as `lid://<workflow-run-hash>/<path>`, where `<path>` is the file path relative to the workflow output directory. |
| 94 | + |
| 95 | +:::{note} |
| 96 | +Files must be published to the workflow output directory as defined by the `outputDir` config option (or `-output-dir` command line option) in order to be recorded as workflow outputs in the lineage store. |
| 97 | +::: |
| 98 | + |
| 99 | +List the output directory to see the available files: |
| 100 | + |
| 101 | +```console |
| 102 | +$ find results |
| 103 | +results |
| 104 | +results/fastqc_ggal_gut_logs |
| 105 | +results/fastqc_ggal_gut_logs/ggal_gut_1_fastqc.html |
| 106 | +results/fastqc_ggal_gut_logs/ggal_gut_1_fastqc.zip |
| 107 | +results/fastqc_ggal_gut_logs/ggal_gut_2_fastqc.html |
| 108 | +results/fastqc_ggal_gut_logs/ggal_gut_2_fastqc.zip |
| 109 | +results/multiqc_report.html |
| 110 | +``` |
| 111 | + |
| 112 | +Now, use the workflow LID and relative path to view the lineage record for an output file: |
| 113 | + |
| 114 | +```console |
| 115 | +$ nextflow lineage view lid://16b31030474f2e96c55f4940bca3ab64/multiqc_report.html |
| 116 | +{ |
| 117 | + "type": "FileOutput", |
| 118 | + "path": "/results/multiqc_report.html", |
| 119 | + "checksum": { |
| 120 | + "value": "03fd5ed150c7862e1fad5efd4f574a47", |
| 121 | + "algorithm": "nextflow", |
| 122 | + "mode": "standard" |
| 123 | + }, |
| 124 | + "source": "lid://862df53160e07cd823c0c3960545e747/multiqc_report.html", |
| 125 | + "workflowRun": "lid://16b31030474f2e96c55f4940bca3ab64", |
| 126 | + "taskRun": null, |
| 127 | + "size": 5079806, |
| 128 | + "createdAt": "2025-05-09T13:27:34.576590545-05:00", |
| 129 | + "modifiedAt": "2025-05-09T13:27:34.586590551-05:00", |
| 130 | + "labels": null |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +Every output file is represented in the lineage store as a `FileOutput` record, which includes basic file information such as the real path, checksum, file size and created/modified timestamps. It also includes lineage information, such as the workflow run and task run that produced it. |
| 135 | + |
| 136 | +Since this record is a workflow output, it is not linked directly to a task run, but rather to the original task output. |
| 137 | + |
| 138 | +Any LID in a lineage record can itself be viewed, allowing you to traverse the lineage metadata interactively. Use the value of `source` to view the original task output: |
| 139 | + |
| 140 | +```console |
| 141 | +$ nextflow lineage view lid://862df53160e07cd823c0c3960545e747/multiqc_report.html |
| 142 | +{ |
| 143 | + "type": "FileOutput", |
| 144 | + "path": "/work/86/2df53160e07cd823c0c3960545e747/multiqc_report.html", |
| 145 | + "checksum": { |
| 146 | + "value": "b14f5171a48ce5c22ea27d7b8e57b6c4", |
| 147 | + "algorithm": "nextflow", |
| 148 | + "mode": "standard" |
| 149 | + }, |
| 150 | + "source": "lid://862df53160e07cd823c0c3960545e747", |
| 151 | + "workflowRun": "lid://16b31030474f2e96c55f4940bca3ab64", |
| 152 | + "taskRun": "lid://862df53160e07cd823c0c3960545e747", |
| 153 | + "size": 5079806, |
| 154 | + "createdAt": "2025-05-09T13:27:34.236590379-05:00", |
| 155 | + "modifiedAt": "2025-05-09T13:27:34.246590383-05:00", |
| 156 | + "labels": null |
| 157 | +} |
| 158 | +``` |
| 159 | + |
| 160 | +This record is the task output for the same file -- it has a value for `taskRun` which is the same as its `source`. |
| 161 | + |
| 162 | +View the lineage record for the task that produced this file: |
| 163 | + |
| 164 | +```console |
| 165 | +$ nextflow lineage view lid://862df53160e07cd823c0c3960545e747 |
| 166 | +{ |
| 167 | + "type": "TaskRun", |
| 168 | + "sessionId": "065bdc6b-89b4-42ee-92c1-2a5af37f2c50", |
| 169 | + "name": "MULTIQC", |
| 170 | + "codeChecksum": { |
| 171 | + "value": "edf2e9f84cd3a18ee9259012b660f2dd", |
| 172 | + "algorithm": "nextflow", |
| 173 | + "mode": "standard" |
| 174 | + }, |
| 175 | + "script": "\n cp multiqc/* .\n echo \"custom_logo: $PWD/nextflow_logo.png\" \u003e\u003e multiqc_config.yaml\n multiqc -n multiqc_report.html .\n ", |
| 176 | + "input": [ |
| 177 | + { |
| 178 | + "type": "path", |
| 179 | + "name": "*", |
| 180 | + "value": [ |
| 181 | + "lid://eff8846883b46c5a76f11e7e4480a6c8/ggal_gut", |
| 182 | + "lid://2d8bd92c69f732605bc99941e60d5319/fastqc_ggal_gut_logs" |
| 183 | + ] |
| 184 | + }, |
| 185 | + { |
| 186 | + "type": "path", |
| 187 | + "name": "config", |
| 188 | + "value": [ |
| 189 | + { |
| 190 | + "path": "https://github.com/nextflow-io/rnaseq-nf/tree/86165b8c81d43a1f57363964431395152e353e56/multiqc", |
| 191 | + "checksum": { |
| 192 | + "value": "2aac500cdfb292e961e678433e7dc3d8", |
| 193 | + "algorithm": "nextflow", |
| 194 | + "mode": "standard" |
| 195 | + } |
| 196 | + } |
| 197 | + ] |
| 198 | + } |
| 199 | + ], |
| 200 | + "container": null, |
| 201 | + "conda": "file:///conda/env-4a436c230263dfdbbf4dddd0623505d1", |
| 202 | + "spack": null, |
| 203 | + "architecture": null, |
| 204 | + "globalVars": {}, |
| 205 | + "binEntries": [], |
| 206 | + "workflowRun": "lid://16b31030474f2e96c55f4940bca3ab64" |
| 207 | +} |
| 208 | +``` |
| 209 | + |
| 210 | +Every task run is represented in the lineage store as a `TaskRun`, which includes information such as the name, script, inputs, and software dependencies. From here, you can continue traversing through the file inputs to view upstream tasks. |
| 211 | + |
| 212 | +Finally, use the `render` subcommand to render the entire lineage of the MULTIQC report as an HTML report: |
| 213 | + |
| 214 | +```console |
| 215 | +$ nextflow lineage render lid://16b31030474f2e96c55f4940bca3ab64/multiqc_report.html |
| 216 | +Rendered lineage graph for lid://16b31030474f2e96c55f4940bca3ab64/multiqc_report.html to lineage.html |
| 217 | +``` |
| 218 | + |
| 219 | +Open the HTML report in a web browser to view the lineage graph. |
| 220 | + |
| 221 | +## Query lineage records |
| 222 | + |
| 223 | +To find a lineage record, you normally have to know the LID of the record, or you have to know the LID of a downstream record (such as a workflow run) from which you can traverse to the desired record. However, you can also query the entire lineage store by fields, allowing you to quickly find relevant records and aggregate records from different runs. |
| 224 | + |
| 225 | +Use the `find` subcommand to find all tasks executed by a workflow run: |
| 226 | + |
| 227 | +```console |
| 228 | +$ nextflow lineage find type=TaskRun workflowRun=lid://16b31030474f2e96c55f4940bca3ab64 |
| 229 | +[ |
| 230 | + "lid://2d8bd92c69f732605bc99941e60d5319", |
| 231 | + "lid://eff8846883b46c5a76f11e7e4480a6c8", |
| 232 | + "lid://862df53160e07cd823c0c3960545e747", |
| 233 | + "lid://6d3bff36bf2c3c14c2d383384621e8ca" |
| 234 | +] |
| 235 | +``` |
| 236 | + |
| 237 | +You can use any field defined the [lineage data model](https://github.com/nextflow-io/nextflow/tree/master/modules/nf-lineage/src/main/nextflow/lineage/model). |
| 238 | + |
| 239 | +:::{tip} |
| 240 | +Since the `find` and `view` subcommands always output JSON, you can use JSON processing tools such as [jq](https://jqlang.org/) to further query and transform results. |
| 241 | +::: |
| 242 | + |
| 243 | +## Compare two task runs |
| 244 | + |
| 245 | +Since task run LIDs are based on the standard {ref}`task hash <cache-resume-task-hash>`, it is easy to compare two task runs in the lineage metadata. This is especially useful when a task is unexpectedly re-executed during a resumed run. As long as lineage is enabled for the initial and resumed runs, the two tasks can be compared without any additional runs. |
| 246 | + |
| 247 | +This section builds on the previous `rnaseq-nf` example to demonstrate how to compare two task runs in the event of a cache invalidation. |
| 248 | + |
| 249 | +First, modify the pipeline in a way that invalidates the cache, such as modifying the script of the `MULTIQC` process. |
| 250 | + |
| 251 | +Resume the pipeline, which should re-execute the `MULTIQC` task: |
| 252 | + |
| 253 | +```console |
| 254 | +$ nextflow run rnaseq-nf -profile conda -resume |
| 255 | + |
| 256 | + ... |
| 257 | + |
| 258 | +[6d/3bff36] process > RNASEQ:INDEX (ggal_1_48850000_49020000) [100%] 1 of 1, cached: 1 ✔ |
| 259 | +[2d/8bd92c] process > RNASEQ:FASTQC (FASTQC on ggal_gut) [100%] 1 of 1, cached: 1 ✔ |
| 260 | +[ef/f88468] process > RNASEQ:QUANT (ggal_gut) [100%] 1 of 1, cached: 1 ✔ |
| 261 | +[94/33dda7] process > MULTIQC [100%] 1 of 1 ✔ |
| 262 | +``` |
| 263 | + |
| 264 | +Retrieve the hash of the MULTIQC run from the log file or work directory -- in this case it is `9433dda73f2193491f9a26e3e23cd8a1`. |
| 265 | + |
| 266 | +Finally, compare the task hash of the initial run (taken from the original example) to that of the resumed run: |
| 267 | + |
| 268 | +```console |
| 269 | +$ nextflow lineage diff lid://862df53160e07cd823c0c3960545e747 lid://9433dda73f2193491f9a26e3e23cd8a1 |
| 270 | +diff --git 862df53160e07cd823c0c3960545e747 9433dda73f2193491f9a26e3e23cd8a1 |
| 271 | +--- 862df53160e07cd823c0c3960545e747 |
| 272 | ++++ 9433dda73f2193491f9a26e3e23cd8a1 |
| 273 | +@@ -3,11 +3,11 @@ |
| 274 | + "sessionId": "065bdc6b-89b4-42ee-92c1-2a5af37f2c50", |
| 275 | + "name": "MULTIQC", |
| 276 | + "codeChecksum": { |
| 277 | +- "value": "edf2e9f84cd3a18ee9259012b660f2dd", |
| 278 | ++ "value": "9615a8da3a3f9e935cfc8e4042cdf5e0", |
| 279 | + "algorithm": "nextflow", |
| 280 | + "mode": "standard" |
| 281 | + }, |
| 282 | +- "script": "\n cp multiqc/* .\n echo \"custom_logo: $PWD/nextflow_logo.png\" \u003e\u003e multiqc_config.yaml\n multiqc -n multiqc_report.html .\n ", |
| 283 | ++ "script": "\n cp multiqc/* . # hello!\n echo \"custom_logo: $PWD/nextflow_logo.png\" \u003e\u003e multiqc_config.yaml\n multiqc -n multiqc_report.html .\n ", |
| 284 | + "input": [ |
| 285 | + { |
| 286 | + "type": "path", |
| 287 | +@@ -38,5 +38,5 @@ |
| 288 | + "architecture": null, |
| 289 | + "globalVars": {}, |
| 290 | + "binEntries": [], |
| 291 | +- "workflowRun": "lid://16b31030474f2e96c55f4940bca3ab64" |
| 292 | ++ "workflowRun": "lid://65044872aad36f97e42336b9ba0dee57" |
| 293 | + } |
| 294 | +``` |
| 295 | + |
| 296 | +Note the difference between the task scripts, highlighting the change that caused the task to be re-executed. |
| 297 | + |
| 298 | +## Use lineage with workflow outputs |
| 299 | + |
| 300 | +Workflow outputs declared in the `output` block are also recorded in the lineage store. The output of a workflow run can be accessed as `lid://<workflow-run-hash>#output`. |
| 301 | + |
| 302 | +Run the `rnaseq-nf` pipeline using the `preview-25-04` branch, which uses the `output` block to publish outputs: |
| 303 | + |
| 304 | +```console |
| 305 | +$ nextflow -r preview-25-04 -profile conda |
| 306 | +``` |
| 307 | + |
| 308 | +View the workflow output in the lineage metadata: |
| 309 | + |
| 310 | +```console |
| 311 | +$ nextflow lineage view lid://9410d13abeec617640b5fe9735ba12fc#output |
| 312 | +[ |
| 313 | + { |
| 314 | + "type": "Collection", |
| 315 | + "name": "samples", |
| 316 | + "value": "lid://9410d13abeec617640b5fe9735ba12fc/samples.json" |
| 317 | + }, |
| 318 | + { |
| 319 | + "type": "Path", |
| 320 | + "name": "summary", |
| 321 | + "value": "lid://9410d13abeec617640b5fe9735ba12fc/multiqc_report.html" |
| 322 | + } |
| 323 | +] |
| 324 | +``` |
| 325 | + |
| 326 | +This view can be used to traverse output files directly instead of inferring LIDs from the workflow output directory. |
| 327 | + |
| 328 | +See {ref}`workflow-output-def` for more information about the `output` block. |
| 329 | + |
| 330 | +## Use lineage in a Nextflow script |
| 331 | + |
| 332 | +Since lineage IDs are valid URIs, output files in the lineage store can be accessed by their LID in a Nextflow script, like any other path. The LID path returns the *real* path as defined by the `path` field in the `FileOutput` record. |
| 333 | + |
| 334 | +The following script uses the `samples.json` from the previous example as an input samplesheet: |
| 335 | + |
| 336 | +```nextflow |
| 337 | +channel.fromPath('lid://9410d13abeec617640b5fe9735ba12fc/samples.json') |
| 338 | + .splitJson() |
| 339 | + .view() |
| 340 | +``` |
| 341 | + |
| 342 | +```console |
| 343 | +[id:gut, quant:/results/gut/quant, fastqc:/results/gut/fastqc] |
| 344 | +``` |
| 345 | + |
| 346 | +The `fromLineage` channel factory can also be used to query lineage records in a similar manner as the `find` subcommand. See {ref}`channel-from-lineage` for details. |
0 commit comments