5.5 EXERCISE 1

  • Let’s create a couple of files (e.g. paired-end reads) and let’s try to read them as a tuple.

First create a couple of empty files:

touch aaa_1.txt aaa_2.txt

See here fromFilePairs.

Answer

#!/usr/bin/env nextflow

nextflow.enable.dsl=2

/*
* Let's create the channel `my_files`
* using the method fromFilePairs 
*/

Channel
    .fromFilePairs( "aaa_{1,2}.txt" )
    .set {my_files}

my_files.view()
  • For the second part of this exercise, We can start again from .fromPath and read the previous 3 .txt files (“aa.txt”, “bb.txt”, “cc.txt”) into the input channel.


Try to reshape the input channel using different operators by generating: - A single emission. - A channel with each possible file combination - A tuple with a custom id, i.e. something like [“id”, [“aa.txt”, “bb.txt”, “cc.txt”]]

See here the list of Operators available.

Answer

#!/usr/bin/env nextflow
nextflow.enable.dsl=2

Channel
    .fromPath("{aa,bb,cc}.txt")
    .set {my_files}

my_files
    .collect()
    .view()
// You can also write it as: my_files.collect().view()

my_files
    .combine(my_files)
    .view()

my_files
    .collect()
    .map{
    ["id", it]
    }
    .view()