Nextflow Channel create with condition

…衆ロ難τιáo~ 提交于 2021-01-29 17:10:22

问题


[Kasumi_H3K36, Kasumi_IgG, /mnt/Data/cut_and_tag/work/d0/3db2bde9eb1bdb0578073fb128bc4c/Kasumi_H3K36.no0.bedgraph]
[Kasumi_JMJD1C, Kasumi_IgG, /mnt/Data/cut_and_tag/work/b1/dffe2120acda5b05860e1a3bb0c1bf/Kasumi_JMJD1C.no0.bedgraph]
[Kasumi_NCOR1, Kasumi_IgG, /mnt/Data/cut_and_tag/work/9f/7c3680a1ff0ae0a5a27f42e1a27225/Kasumi_NCOR1.no0.bedgraph]
[Kasumi_IgG, Kasumi_IgG, /mnt/Data/cut_and_tag/work/21/1038cd4ecbc5b3f88da23ad1ee3147/Kasumi_IgG.no0.bedgraph]
[Kasumi_H4K5, Kasumi_IgG, /mnt/Data/cut_and_tag/work/3d/7b5239ab9dc83b00f992fea8926630/Kasumi_H4K5.no0.bedgraph]

This is one of my channel view. I am trying to make a new control channel when the first and second ID are same, and the rest as sample channel.


回答1:


Here's one way using the branch operator. I made some assumptions about what the fields should be named, but hopefully the pattern is close to what you're looking for:

nextflow.enable.dsl=2

Channel
    .of(
        ['Kasumi_H3K36', 'Kasumi_IgG', file('/mnt/Data/cut_and_tag/work/d0/3db2bde9eb1bdb0578073fb128bc4c/Kasumi_H3K36.no0.bedgraph')],
        ['Kasumi_JMJD1C', 'Kasumi_IgG', file('/mnt/Data/cut_and_tag/work/b1/dffe2120acda5b05860e1a3bb0c1bf/Kasumi_JMJD1C.no0.bedgraph')],
        ['Kasumi_NCOR1', 'Kasumi_IgG', file('/mnt/Data/cut_and_tag/work/9f/7c3680a1ff0ae0a5a27f42e1a27225/Kasumi_NCOR1.no0.bedgraph')],
        ['Kasumi_IgG', 'Kasumi_IgG', file('/mnt/Data/cut_and_tag/work/21/1038cd4ecbc5b3f88da23ad1ee3147/Kasumi_IgG.no0.bedgraph')],
        ['Kasumi_H4K5', 'Kasumi_IgG', file('/mnt/Data/cut_and_tag/work/3d/7b5239ab9dc83b00f992fea8926630/Kasumi_H4K5.no0.bedgraph')],
    ) \
    .branch { sample1, sample2, bedgraph ->
        controls: sample1 == sample2
            return tuple( sample1, sample2, bedgraph )
        others: true
            return tuple( sample1, sample2, bedgraph )
    } \
    .set { inputs } 

inputs.controls.view { "controls: $it" } 
inputs.others.view { "others: $it" }

Results:

others: [Kasumi_H3K36, Kasumi_IgG, /mnt/Data/cut_and_tag/work/d0/3db2bde9eb1bdb0578073fb128bc4c/Kasumi_H3K36.no0.bedgraph]
controls: [Kasumi_IgG, Kasumi_IgG, /mnt/Data/cut_and_tag/work/21/1038cd4ecbc5b3f88da23ad1ee3147/Kasumi_IgG.no0.bedgraph]
others: [Kasumi_JMJD1C, Kasumi_IgG, /mnt/Data/cut_and_tag/work/b1/dffe2120acda5b05860e1a3bb0c1bf/Kasumi_JMJD1C.no0.bedgraph]
others: [Kasumi_NCOR1, Kasumi_IgG, /mnt/Data/cut_and_tag/work/9f/7c3680a1ff0ae0a5a27f42e1a27225/Kasumi_NCOR1.no0.bedgraph]
others: [Kasumi_H4K5, Kasumi_IgG, /mnt/Data/cut_and_tag/work/3d/7b5239ab9dc83b00f992fea8926630/Kasumi_H4K5.no0.bedgraph]

Update from comments:

Channel
    .of(
        ['Kasumi_H3K36', 'Kasumi_IgG', file('/path/to/Kasumi_H3K36.no0.bedgraph')],
        ['Kasumi_JMJD1C', 'Kasumi_IgG', file('/path/to/Kasumi_JMJD1C.no0.bedgraph')],
        ['Kasumi_NCOR1', 'Kasumi_IgG', file('/path/to/Kasumi_NCOR1.no0.bedgraph')],
        ['Kasumi_IgG', 'Kasumi_IgG', file('/path/to/Kasumi_IgG.no0.bedgraph')],
        ['Kasumi_H4K5', 'Kasumi_IgG', file('/path/to/Kasumi_H4K5.no0.bedgraph')],
        ['NB4_H3K36', 'NB4_IgG', file('/path/to/NB4_H3K36.no0.bedgraph')],
        ['NB4_JMJD1C', 'NB4_IgG', file('/path/to/NB4_JMJD1C.no0.bedgraph')],
        ['NB4_NCOR1', 'NB4_IgG', file('/path/to/NB4_NCOR1.no0.bedgraph')],
        ['NB4_IgG', 'NB4_IgG', file('/path/to/NB4_IgG.no0.bedgraph')],
        ['NB4_H4K5', 'NB4_IgG', file('/path/to/NB4_H4K5.no0.bedgraph')],
    ) \
    .branch { test_sample, control_sample, bedgraph ->
        control_samples: test_sample == control_sample
            return tuple( control_sample, tuple( test_sample, bedgraph ) )
        test_samples: true
            return tuple( control_sample, tuple( test_sample, bedgraph ) )
    } \
    .set { inputs }

inputs.test_samples
    .combine( inputs.control_samples, by: 0 ) \
    .map { group, test_tuple, control_tuple ->
        tuple( *test_tuple, *control_tuple )
    } \
    .view()

Results:

[Kasumi_H3K36, /path/to/Kasumi_H3K36.no0.bedgraph, Kasumi_IgG, /path/to/Kasumi_IgG.no0.bedgraph]
[Kasumi_JMJD1C, /path/to/Kasumi_JMJD1C.no0.bedgraph, Kasumi_IgG, /path/to/Kasumi_IgG.no0.bedgraph]
[Kasumi_NCOR1, /path/to/Kasumi_NCOR1.no0.bedgraph, Kasumi_IgG, /path/to/Kasumi_IgG.no0.bedgraph]
[Kasumi_H4K5, /path/to/Kasumi_H4K5.no0.bedgraph, Kasumi_IgG, /path/to/Kasumi_IgG.no0.bedgraph]
[NB4_H3K36, /path/to/NB4_H3K36.no0.bedgraph, NB4_IgG, /path/to/NB4_IgG.no0.bedgraph]
[NB4_JMJD1C, /path/to/NB4_JMJD1C.no0.bedgraph, NB4_IgG, /path/to/NB4_IgG.no0.bedgraph]
[NB4_NCOR1, /path/to/NB4_NCOR1.no0.bedgraph, NB4_IgG, /path/to/NB4_IgG.no0.bedgraph]
[NB4_H4K5, /path/to/NB4_H4K5.no0.bedgraph, NB4_IgG, /path/to/NB4_IgG.no0.bedgraph]


来源:https://stackoverflow.com/questions/65385125/nextflow-channel-create-with-condition

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!