# Append to params from a .csv

**URL:** <https://community.seqera.io/t/append-to-params-from-a-csv/1161>\
**Category:** Ask for help\
**Created:** [September 6, 2024, 3:01pm UTC](https://community.seqera.io/t/append-to-params-from-a-csv/1161 "2024-09-06T15:01:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Welch](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bill_welch/32/995_2.png) [@Bill\_Welch](https://community.seqera.io/u/Bill_Welch)\
**Post date:** [September 6, 2024, 3:01pm UTC](https://community.seqera.io/t/append-to-params-from-a-csv/1161/1 "2024-09-06T15:01:21Z")

</div>

My ask is for a way to read values from a .csv and have them appended to params with the code all in nextflow, not some wrapper script. As a convenience for my users, I’d like to let them set some params in a .csv instead of a nextflow.config or command line options. As a stretch, read the .csv directly from S3.

.csv could be row or column oriented, but I’ll go with row oriented for this example. The names of the columns become the names of the elements of params. The values of the one row become the values of the params elements.

`s3://bucket/input.csv` is:

```auto
n_one,s_two,n_three
1,two,3

```

resulting in `params.n_one`, `params.s_two`, `params.n_three` being visible to the workflow:

```auto
// use these, somehow, to read from s3??
// import nextflow.cloud.aws.utils.*
// import nextflow.cloud.aws.nio.*

workflow {
 // some way to read .csv and append values to params

log.info("${params.n_one}") // value set in .csv

}

```

---

<div class="post-metadata">

**Author:** ![mahesh.binzerpanchal](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mahesh.binzerpanchal/32/253_2.png) [@mahesh.binzerpanchal](https://community.seqera.io/u/mahesh.binzerpanchal)\
**Post date:** [September 6, 2024, 4:59pm UTC](https://community.seqera.io/t/append-to-params-from-a-csv/1161/2 "2024-09-06T16:59:23Z")

</div>

Have you considered the `-params-file` option (I notice you only mention command-line or config)?  
Rather than a csv though, you provide a yml or json, e.g.,

`params.yml`:

```yaml
n_one: 1
s_two: 'two'
n_three: 3

```

and then doing

```bash
nextflow run <script> -params-file params.yml [other options]

```

The parameters are then available as you would expect. They take lower precedence than command-line options, but higher precedence than a config file. See [Configuration — Nextflow v24.08.0-edge documentation](https://www.nextflow.io/docs/latest/config.html).

---

<div class="post-metadata">

**Author:** ![Bill\_Welch](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bill_welch/32/995_2.png) [@Bill\_Welch](https://community.seqera.io/u/Bill_Welch)\
**Post date:** [September 6, 2024, 6:26pm UTC](https://community.seqera.io/t/append-to-params-from-a-csv/1161/3 "2024-09-06T18:26:23Z")

</div>

Thank you for bringing attention to `-params-file`. At the moment, the users have .csv config files for their code that we’re wrapping in nextflow and we’d like to leverage those.

What would be really interesting would be some idea of how to extend the logic that handles `-params-file` to ingest .csv. Subclass? Plugin?

---

<div class="post-metadata">

**Author:** ![mahesh.binzerpanchal](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mahesh.binzerpanchal/32/253_2.png) [@mahesh.binzerpanchal](https://community.seqera.io/u/mahesh.binzerpanchal)\
**Post date:** [September 6, 2024, 7:23pm UTC](https://community.seqera.io/t/append-to-params-from-a-csv/1161/4 "2024-09-06T19:23:18Z")

</div>

You can do it like this, but I think it would be better to use the standard yaml or json format if you can wrangle it. You could also write a plugin too.

```nextflow
params.params_csv = null
params.input = 'input.file'

workflow {
    if ( params.params_csv ) {
        params = params + file( params.params_csv, checkIfExists: true)
            .splitCsv(header: true)
            .head()
        println params
    }
    if ( params.s_two == 'two' ) {
        println "S TWO"
    }
}

```

output:

```console
$ nextflow run main.nf --params_csv params.csv 

 N E X T F L O W ~ version 24.04.4

Launching `main.nf` [fabulous_miescher] DSL2 - revision: 2b28f701b9

[params_csv:params.csv, input:input.file, n_one:1, s_two:two, n_three:3]
S TWO

```

---

<div class="post-metadata">

**Author:** ![Bill\_Welch](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bill_welch/32/995_2.png) [@Bill\_Welch](https://community.seqera.io/u/Bill_Welch)\
**Post date:** [September 8, 2024, 12:17am UTC](https://community.seqera.io/t/append-to-params-from-a-csv/1161/5 "2024-09-08T00:17:05Z")

</div>

Thank you.

---

<div class="post-metadata">

**Author:** ![qup9](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/qup9/32/512_2.png) [@qup9](https://community.seqera.io/u/qup9)\
**Post date:** [September 13, 2024, 4:30pm UTC](https://community.seqera.io/t/append-to-params-from-a-csv/1161/6 "2024-09-13T16:30:09Z")

</div>

I think nf-core has this built into the template. I ended up using a simple csv file with one column, so I did not use the nf-core feature.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/system/32/2402_2.png) [@system](https://community.seqera.io/u/system)\
**Post date:** [September 20, 2024, 4:30pm UTC](https://community.seqera.io/t/append-to-params-from-a-csv/1161/7 "2024-09-20T16:30:42Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
