These are chat archives for nextflow-io/nextflow

7th
Jul 2016
Evan Floden
@evanfloden
Jul 07 2016 09:55
What is the best way to split a channel containing a directory into a channel that emits the files within the directory? Moreover, I have a set made up of a value and a directory path and I want a new channel that emits each file in the directory path along with the value. I had a try with .fromPath but could not manage to make it work with the value as well.
# from some output
set val (datasetID), file(“paramastrap_directory") into paramastrapPhylipsDir

# a new channel (paramastrapPhylipsFiles) that emits
set val (datasetID), file(“paramastrap_indv_file") into paramastrapPhylipsFiles
Paolo Di Tommaso
@pditommaso
Jul 07 2016 10:14
so you have a channel that emits tuple like
< id1, dir1 >
< id2, dir2 > 
:
and you want
< id1, dir1/file_a >
< id1, dir1/file_b >
:
< id2, dir2/file_x >
< id2, dir2/file_y > 
:
or
< id1, [dir1/file_a, dir1/file_b, ...] >
:
< id2, [dir2/file_x, dir2/file_y, ..]  >
:
?
Evan Floden
@evanfloden
Jul 07 2016 10:26
Exactly. The first one!
Paolo Di Tommaso
@pditommaso
Jul 07 2016 10:41
ok
idAndDirChannel.flatMap {  id, dir -> dir.listFiles().collect { [id, it] } }
easy!
:)
to recap, given the dir get the list of files
then use collect (that is the same of map for list) to transform each file to a pair <id, file>
then flatMap to the rest
Evan Floden
@evanfloden
Jul 07 2016 11:07
That's nice!
Also thanks for the biscuits!
Paolo Di Tommaso
@pditommaso
Jul 07 2016 11:08
;)