【问题标题】:How to filter list of tuples?如何过滤元组列表?
【发布时间】:2023-01-27 00:09:11
【问题描述】:

大家好,我是 Nextflow 的新手,我想解析一个通道,它是一个看起来像这样的元组列表:

[ID, [[Type1, file, file], [[Type2, file, file],(...)]

我想将其过滤为仅包含 Type1 的元组以获取:

[ID, [[Type1, file, file]]

最好的方法是什么?我尝试了 .filter() 但是很明显,它在不删除 Type2 的情况下检测到 Type1 后立即返回完整列表。

【问题讨论】:

    标签: nextflow


    【解决方案1】:

    您可以使用 map 运算符和带有闭包的 Groovy findAll() 方法来查找“Type1”是第一个元素的元组。例如:

    workflow {
    
        ...
    
        your_channel.map { id, the_list ->
            tuple( id, the_list.findAll { it.first() == "Type1" } )
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2013-05-03
      • 1970-01-01
      • 1970-01-01
      • 2012-10-18
      • 2011-05-27
      • 1970-01-01
      • 1970-01-01
      • 2020-12-23
      相关资源
      最近更新 更多