Skip to content

Commit

Permalink
[automated] Fix code linting
Browse files Browse the repository at this point in the history
  • Loading branch information
nf-core-bot committed Mar 19, 2024
1 parent 4ba4cae commit 458b651
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/content/docs/contributing/nf_core_basic_training.md
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,7 @@ workflow DEMOTEST {
SALMON_INDEX()
```
Now we are still missing an input for our module. In order to build an index, we require the reference fasta. Luckily, the template pipeline has this already all configured, and we can access it by just using `params.fasta` and `view` it to insppect the channel content. (We will see later how to add more input files.)
Now we are still missing an input for our module. In order to build an index, we require the reference fasta. Luckily, the template pipeline has this already all configured, and we can access it by just using `params.fasta` and `view` it to insppect the channel content. (We will see later how to add more input files.)
```bash
fasta = Channel.fromPath(params.fasta)
Expand Down Expand Up @@ -1087,7 +1086,7 @@ In the directory `exercise_6` you will find the custom script `print_hello.py`,
To generate a module for a custom script you need to follow the same steps when adding a remote module.
Then, you can supply the command for your script in the `script` block but your script needs to be present
and *executable* in the `bin`
and _executable_ in the `bin`
folder of the pipeline.
In the nf-core pipelines,
this folder is in the main directory and you can see in [`rnaseq`](https://github.com/nf-core/rnaseq).
Expand All @@ -1097,7 +1096,7 @@ This is an Rscript present in the [`bin`](https://github.com/nf-core/rnaseq/tree
We can find the module that runs this script in
[`modules/local/tximport`](https://github.com/nf-core/rnaseq/blob/master/modules/local/tximport/main.nf).
As we can see the script is being called in the `script` block, note that `tximport.r` is
being executed as if it was called from the command line and therefore needs to be *executable*.
being executed as if it was called from the command line and therefore needs to be _executable_.
<blockquote style="border-left: 4px solid #F0AD4E; background-color: #FFF3CD; padding: 10px;">
Expand All @@ -1113,11 +1112,12 @@ being executed as if it was called from the command line and therefore needs to
</blockquote>
_Tip: Try to follow best practices when writing a script for
reproducibility and maintenance purposes: add the
shebang (e.g. `#!/usr/bin/env python`), and a header
with description and type of license._
reproducibility and maintenance purposes: add the
shebang (e.g. `#!/usr/bin/env python`), and a header
with description and type of license._
### 1. Write your script
Let's create a simple custom script that converts a MAF file to a BED file called `maf2bed.py` and place it in the bin directory of our nf-core-testpipeline::
```
Expand Down Expand Up @@ -1157,6 +1157,7 @@ if __name__ == "__main__":
```
### 2. Make sure your script is in the right folder
Now, let's move it to the correct directory:
```
Expand All @@ -1165,13 +1166,13 @@ chmod +x /path/where/pipeline/is/bin/maf2bed.py
```
### 3. Create your custom module
Then, let's write our module. We will call the process
"CONVERT_MAF2BED" and add any tags or/and labels that
are appropriate (this is optional) and directives (via
conda and/or container) for
the definition of dependencies.
<details>
<summary><span style="color: forestgreen; font-weight: bold;">More info on labels</span></summary>
A `label` will
Expand All @@ -1186,6 +1187,7 @@ withLabel:process_single {
time = { check_max( 1.h * task.attempt, 'time' ) }
}
```
</details>
<details>
Expand All @@ -1195,8 +1197,7 @@ A `tag` is simple a user provided identifier associated to
the task. In our process example, the input is a tuple
comprising a hash of metadata for the maf file called
`meta` and the path to the `maf` file. It may look
similar to: `[[id:'123', data_type:'maf'],
/path/to/file/example.maf]`. Hence, when nextflow makes
similar to: `[[id:'123', data_type:'maf'], /path/to/file/example.maf]`. Hence, when nextflow makes
the call and `$meta.id` is `123` name of the job
will be "CONVERT_MAF2BED(123)". If `meta` does not have
`id` in its hash, then this will be literally `null`.
Expand All @@ -1218,6 +1219,7 @@ process foo {
'''
}
```
Multiple packages can be specified separating them with a blank space e.g. `bwa=0.7.15 samtools=1.15.1`. The name of the channel from where a specific package needs to be downloaded can be specified using the usual Conda notation i.e. prefixing the package with the channel name as shown here `bioconda::bwa=0.7.15`
```
Expand All @@ -1230,6 +1232,7 @@ process foo {
'''
}
```
Similarly, we can apply the `container` directive to execute the process script in a [Docker](http://docker.io/) or [Singularity](https://docs.sylabs.io/guides/3.5/user-guide/introduction.html) container. When running Docker, it requires the Docker daemon to be running in machine where the pipeline is executed, i.e. the local machine when using the local executor or the cluster nodes when the pipeline is deployed through a grid executor.
```
Expand Down Expand Up @@ -1259,6 +1262,7 @@ process foo {
'''
}
```
</details>
Since `maf2bed.py` is in the `bin` directory we can directory call it in the script block of our new module `CONVERT_MAF2BED`. You only have to be careful with how you call variables (some explanations on when to use `${variable}` vs. `$variable`):
Expand Down Expand Up @@ -1296,9 +1300,8 @@ maf2bed.py --mafin $maf --bedout ${prefix}.bed
More on nextflow's process components in the [docs](https://www.nextflow.io/docs/latest/process.html).
### Include your module in the workflow
In general, we will call out nextflow module `main.nf` and save it in the `modules` folder under another folder called `conver_maf2bed`. If you believe your custom script could be useful for others and it is potentially reusable or calling a tool that is not yet present in nf-core modules you can start the process of making it official adding a `meta.yml` [explained above](#adding-modules-to-a-pipeline). In the `meta.yml` The overall tree for the pipeline skeleton will look as follows:
```
Expand All @@ -1317,7 +1320,7 @@ pipeline/
...
```
To use our custom module located in `./modules/local/convert_maf2bed` within our workflow, we use a module inclusions command as follows (this has to be done before we invoke our workflow):
To use our custom module located in `./modules/local/convert_maf2bed` within our workflow, we use a module inclusions command as follows (this has to be done before we invoke our workflow):
```
include { CONVERT_MAF2BED } from './modules/local/convert_maf2bed/main'
Expand All @@ -1328,6 +1331,7 @@ workflow {
```
### Other notes
#### What happens in I want to use containers but there is no image created with the packages I need?
No worries, this can be done fairly easy thanks to [BioContainers](https://biocontainers-edu.readthedocs.io/en/latest/what_is_biocontainers.html), see instructions [here](https://github.com/BioContainers/multi-package-containers). If you see the combination that you need in the repo, you can also use [this website](https://midnighter.github.io/mulled) to find out the "mulled" name of this container.
Expand All @@ -1336,10 +1340,9 @@ No worries, this can be done fairly easy thanks to [BioContainers](https://bioco
You are in luck, we have more documentation [here](https://nf-co.re/docs/contributing/modules#software-requirements)
#### I want to know more about modules!
See more info about modules in the nextflow docs [here](https://nf-co.re/docs/contributing/modules#software-requirements.)
See more info about modules in the nextflow docs [here](https://nf-co.re/docs/contributing/modules#software-requirements.)
## Lint all modules
Expand Down

0 comments on commit 458b651

Please sign in to comment.