Skip to content

Instantly share code, notes, and snippets.

@SamStudio8
Created July 28, 2021 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamStudio8/4320e63ad22743b9da967e452054909c to your computer and use it in GitHub Desktop.
Save SamStudio8/4320e63ad22743b9da967e452054909c to your computer and use it in GitHub Desktop.
collect_nf
#!/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
"""
}
hello
world
hoot
meow
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
hello
world
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
path
/cephfs/covid/software/sam/nf-test/file1.txt
/cephfs/covid/software/sam/nf-test/file2.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment