Skip to content

Instantly share code, notes, and snippets.

@SamStudio8
Created July 28, 2021 17:00
Show Gist options
  • Select an option

  • Save SamStudio8/4320e63ad22743b9da967e452054909c to your computer and use it in GitHub Desktop.

Select an option

Save SamStudio8/4320e63ad22743b9da967e452054909c to your computer and use it in GitHub Desktop.

Revisions

  1. SamStudio8 created this gist Jul 28, 2021.
    49 changes: 49 additions & 0 deletions collect.nf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    #!/usr/bin/env nextflow

    params.testdir = "/cephfs/covid/software/sam/nf-test/"

    params.fofn_single = [params.testdir, 'samples.csv'].join('/')
    single_manifest_ch = Channel
    .fromPath(params.fofn_single) // open say, a CSV
    .splitCsv(header:true) // split text stream into CSV records
    .map { row-> file(row.path) } // coerce the record and return a file for each line
    .collect() // emit all items as one

    process echo_fofn_single {

    input:
    file '*.txt' from single_manifest_ch

    output:
    publishDir path: "${params.testdir}", pattern: "out", mode: "copy", overwrite: true
    file "out"

    script:
    """
    cat *.txt > out
    """
    }


    params.fofn_group = [params.testdir, 'grouped_samples.tsv'].join('/')
    group_manifest_ch = Channel
    .fromPath(params.fofn_group)
    .splitCsv(header:true, sep:'\t')
    .map { row-> tuple(row.group, file(row.path)) } // coerce the record into a (group, file) tuple
    .groupTuple() // return tuples of (group, [file1, ...fileN])

    process echo_fofn_group {

    input:
    tuple(group, file(files)) from group_manifest_ch

    output:
    publishDir path: "${params.testdir}", pattern: "g*out", mode: "copy", overwrite: true
    file "g${group}.out"

    script:
    """
    cat ${files} > g${group}.out
    """
    }

    1 change: 1 addition & 0 deletions file1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    hello
    1 change: 1 addition & 0 deletions file2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    world
    1 change: 1 addition & 0 deletions file3.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    hoot
    1 change: 1 addition & 0 deletions file4.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    meow
    1 change: 1 addition & 0 deletions file5.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    bang
    2 changes: 2 additions & 0 deletions g1.out
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    hello
    world
    2 changes: 2 additions & 0 deletions g2.out
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    hoot
    meow
    1 change: 1 addition & 0 deletions g3.out
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    bang
    6 changes: 6 additions & 0 deletions grouped_samples.tsv
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    group path
    1 /cephfs/covid/software/sam/nf-test/file1.txt
    1 /cephfs/covid/software/sam/nf-test/file2.txt
    2 /cephfs/covid/software/sam/nf-test/file3.txt
    2 /cephfs/covid/software/sam/nf-test/file4.txt
    3 /cephfs/covid/software/sam/nf-test/file5.txt
    2 changes: 2 additions & 0 deletions out
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    hello
    world
    3 changes: 3 additions & 0 deletions samples.csv
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    path
    /cephfs/covid/software/sam/nf-test/file1.txt
    /cephfs/covid/software/sam/nf-test/file2.txt