79314149

Date: 2024-12-28 16:33:32
Score: 0.5
Natty:
Report link

Building upon the anwser by @Steve on using the bin/ folder for automatic staging of python scripts:

Something that some might find useful is that you can also add symbolic links into your bin/ folder. You can then access all python files inside that symlinked folder using relative imports.

For example, if you have a folder nextflow-pipeline containing your nextflow setup and a separate folder containing your python source code src,

$ tree .
.
├── nextflow-pipeline
│   ├── bin
│   │   └── script1.py
│   └── main.nf
└── src
    └── py_src_1.py

you could symlink the src folder inside bin

$ cd nextflow-pipeline/bin
$ ln -s ../../src/ .
$ tree .
.
├── nextflow-pipeline
│   ├── bin
│   │   ├── script1.py
│   │   └── src -> ../../src/
│   └── main.nf
└── src
    └── py_src_1.py

such that a python script like script1.py

#!/usr/bin/env python3

from src.py_src_1 import outside_test_fn

outside_test_fn()

can be called inside a nextflow workflow

process TestPythonImport {

    script:
    """
    script1.py
    """

}

workflow {

    TestPythonImport()

}

without errors.

This is useful for example if you don't want to move your full python source code inside the nextflow project folder.

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Steve
  • Low reputation (1):
Posted by: Emiel