LiGt
LiGt

Reputation: 11

Nextflow : process multiple samples

I'm new to nextflow and I'm having problems. I have a workflow with several processes and I would like to run it for different samples. Here is the repository architecture: sample :

- sample1 :

  1. fastq1
  2. fastq2
  3. ...

- sample2 :

  1. fastq1
  2. fastq2
  3. ...

- sample3 :

  1. fastq1
  2. fastq2
  3. ...

- etc...

I use Nextflow 21.10.6 DSL2.

I tried to build a channel with Channel.fromPath(path/to/sample/*.fastq.gz) but I don't get what I want. Can anyone help me? Thanks

Upvotes: 1

Views: 311

Answers (1)

Steve
Steve

Reputation: 54502

If you're parent directory names are your sample names, and you would like a channel of tuples where the first element is the sample name, you could try the following:

params.reads = '/path/to/*/*.fastq.gz'


workflow {

    Channel
        .fromPath( params.reads )
        .map { tuple(it.parent.name, it ) }
        .set { samples }

    samples.view()
}

Results:

$ mkdir -p /path/to/sample{1..3}
$ touch /path/to/sample{1..3}/{A,B,C}.fastq.gz

$ nextflow run main.nf 
N E X T F L O W  ~  version 22.10.7
Launching `main.nf` [sick_curie] DSL2 - revision: 286312b44c
[sample1, /path/to/sample1/C.fastq.gz]
[sample1, /path/to/sample1/B.fastq.gz]
[sample1, /path/to/sample1/A.fastq.gz]
[sample3, /path/to/sample3/C.fastq.gz]
[sample3, /path/to/sample3/B.fastq.gz]
[sample3, /path/to/sample3/A.fastq.gz]
[sample2, /path/to/sample2/C.fastq.gz]
[sample2, /path/to/sample2/B.fastq.gz]
[sample2, /path/to/sample2/A.fastq.gz]

Upvotes: 1

Related Questions