James Fellows Yates
01/09/2026, 10:20 AMchannel.of('1,2\nalpha,one', '1,2\nbeta,two', '1,2\ngamma,three')
.collectFile(
name: 'sample.txt',
storeDir: '/home/james/git/jfy133/NextflowSandbox/collectfile_manualheader',
newLine: true,
keepHeader: true,
)
.subscribe { file ->
println "Entries are saved to file: $file"
println "File content is:\n${file.text}"
}
Results in an empty line between the 'kept' header, and the rest of the rows? I'm guessing it's due to the \n, but I don't see how to otherwise specify the header based on the string 🤔
1,2
alpha,one
gamma,three
beta,twoJames Fellows Yates
01/09/2026, 10:20 AMcollectFile beforeNicolas Vannieuwkerke
01/09/2026, 10:23 AMchannel.of('1,2', 'alpha,one', 'beta,two', 'gamma,three') ?James Fellows Yates
01/09/2026, 10:25 AMsort: true to ensure stable output files, and if I do it like you have suggested the header won't be at the topJames Fellows Yates
01/09/2026, 10:25 AMgamma,three
alpha,one
beta,two
1,2James Fellows Yates
01/09/2026, 10:27 AM// This works but weirdly produces an empty line between the header and the rest of the rows
// Specify the header for each element in the map, split with a new line
// In collect file make sure to specify newLine to ensure each element is a new row, and keepHeader to keep the first half of the element and share across all
channel.of('1,2\nalpha,one\n', '1,2\nbeta,two\n', '1,2\ngamma,three\n')
.collectFile(
name: 'sample.txt',
storeDir: '/home/james/git/jfy133/NextflowSandbox/collectfile_manualheader',
keepHeader: true,
)
.subscribe { file ->
println "Entries are saved to file: $file"
println "File content is:\n${file.text}"
}Nicolas Vannieuwkerke
01/09/2026, 10:27 AMJames Fellows Yates
01/09/2026, 10:27 AM1,2
alpha,one
beta,two
gamma,threeJames Fellows Yates
01/09/2026, 10:27 AMJames Fellows Yates
01/09/2026, 10:28 AMJames Fellows Yates
01/09/2026, 10:28 AMJames Fellows Yates
01/09/2026, 10:28 AMch_bin_contig_names = ch_binning_results_gunzipped
.transpose()
.map { meta, binfile -> [meta + [bin_id: binfile.name], binfile] }
.splitFasta(record: [header: true], elem: 1)
.map { meta, contig_header ->
"bin_id\tassembly_id\tbinner\tcontig_id\n${meta['bin_id']}\t${meta['assembler']}-${meta['id']}\t${meta['binner']}\t${contig_header['header']}\n"
}
.collectFile(
name: 'contig_to_bin_map.tsv',
storeDir: params.outdir + '/GenomeBinning/QC',
keepHeader: true,
sort: true,
)Nicolas Vannieuwkerke
01/09/2026, 10:29 AMNicolas Vannieuwkerke
01/09/2026, 10:30 AMArthur
01/09/2026, 12:29 PMnextflow slack tooJames Fellows Yates
01/09/2026, 12:29 PMArthur
01/09/2026, 12:33 PMJames Fellows Yates
01/09/2026, 12:36 PMMaxime Garcia
01/09/2026, 12:42 PMMahesh Binzer-Panchal
01/12/2026, 10:02 AMJames Fellows Yates
01/12/2026, 10:02 AMMahesh Binzer-Panchal
01/12/2026, 12:26 PMchannel.of(
"""\
1,2
alpha,one
""",
"""\
1,2
beta,two
""",
"""\
1,2
gamma,three
"""
)
.collectFile(
name: 'sample.txt',
// storeDir: '/home/james/git/jfy133/NextflowSandbox/collectfile_manualheader',
// newLine: true,
keepHeader: true,
// skip: 1
)
.subscribe { file ->
println "Entries are saved to file: $file"
println "File content is:\n${file.text}"
}
it works as expected.
File content is:
1,2
alpha,one
beta,two
gamma,three
Edit: Never mind. I see you discovered the ending in new line fixes it already.Mahesh Binzer-Panchal
01/12/2026, 12:36 PM.map { meta, binfile -> [meta + [bin_id: binfile.name], binfile] }
.splitFasta(record: [header: true], elem: 1)
Since when did splitFasta go into a tuple to find the file?Mahesh Binzer-Panchal
01/12/2026, 12:40 PMchannel.of('1,2\nalpha,one', '1,2\nbeta,two', '1,2\ngamma,three')
.collectFile(
keepHeader: true,
) { txt ->
["sample.txt", txt + '\n']
}
.subscribe { file ->
println "Entries are saved to file: $file"
println "File content is:\n${file.text}"
}
and just to make sure it works with a file too
channel.fromPath('data/*.txt')
.collectFile(
keepHeader: true,
) { infile ->
["sample.txt", infile.text + '\n']
}
.subscribe { file ->
println "Entries are saved to file: $file"
println "File content is:\n${file.text}"
}James Fellows Yates
01/14/2026, 12:17 PM["sample.txt"] but which is why I don't think ti was working for me...Mahesh Binzer-Panchal
01/14/2026, 12:19 PMJames Fellows Yates
01/14/2026, 12:21 PM