最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

filter - How to subset a nextflow channel using another channel containing only one unknown value - Stack Overflow

programmeradmin6浏览0评论

I have a channel which emit as follows:

[[A, B, C, D], 1]

[[A, B, C, D], 2]

[[A, B, C], 3]

[[A, B, V], 4]

[[A], 5]

[[A1, B1, D], 7]

[[A1, B1, D], 8]

I have another parameter defined by the user. The parameter could be a single number or List of numbers. For example, 4 or [4,7,8]. Based on the user parameter value, I want to subset the channel matching the values of the above channel and pass it to a downstream process. For example, the subsetted channel must only retain [[A, B, V], 4] from the channel, if user input is 4. Similarly, if user input is [7, 8], I would like to retain only [[A1, B1, D], 7] [[A1, B1, D], 8] in the above channel. I tried using combine, filter and branch operator but couldn't get the desired results.

first_chbine(par_ch)
    .branch{ a, b, c, d  ->
        controls: b == d
            return [a, b]
        others: true
            return [a, b]
            }
    .view { }

However, the following works:

first_chbine(par_ch)
    .filter{ it[1] == '4' }

But when it is passed as params or channel, I couldn't able to get the desired result.

I have a channel which emit as follows:

[[A, B, C, D], 1]

[[A, B, C, D], 2]

[[A, B, C], 3]

[[A, B, V], 4]

[[A], 5]

[[A1, B1, D], 7]

[[A1, B1, D], 8]

I have another parameter defined by the user. The parameter could be a single number or List of numbers. For example, 4 or [4,7,8]. Based on the user parameter value, I want to subset the channel matching the values of the above channel and pass it to a downstream process. For example, the subsetted channel must only retain [[A, B, V], 4] from the channel, if user input is 4. Similarly, if user input is [7, 8], I would like to retain only [[A1, B1, D], 7] [[A1, B1, D], 8] in the above channel. I tried using combine, filter and branch operator but couldn't get the desired results.

first_chbine(par_ch)
    .branch{ a, b, c, d  ->
        controls: b == d
            return [a, b]
        others: true
            return [a, b]
            }
    .view { }

However, the following works:

first_chbine(par_ch)
    .filter{ it[1] == '4' }

But when it is passed as params or channel, I couldn't able to get the desired result.

Share Improve this question edited 6 hours ago Ahkam asked 7 hours ago AhkamAhkam 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I think you can just use the join operator for this, for example:

params.input = '4,7,8'


workflow {

    def input_string = params.input.toString()

    par_ch = Channel.fromList(
        input_string.tokenize(',')*.toInteger()
    )

    first_ch = Channel.of(
        [['A', 'B', 'C', 'D'], 1],
        [['A', 'B', 'C', 'D'], 2],
        [['A', 'B', 'C'], 3],
        [['A', 'B', 'V'], 4],
        [['A'], 5],
        [['A1', 'B1', 'D'], 7],
        [['A1', 'B1', 'D'], 8],
    )

    first_ch
        .map { keys, val -> tuple( val, keys ) }
        .join( par_ch )
        .map { val, keys -> tuple( keys, val ) }
        .view()
}

Results:

$ nextflow run main.nf --input 7,8

 N E X T F L O W   ~  version 24.10.4

Launching `main.nf` [gloomy_pike] DSL2 - revision: 8fa7a5ddbc

[[A1, B1, D], 7]
[[A1, B1, D], 8]

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论