简体   繁体   中英

How to filter list of tuples?

Hey guys I am kinda new to Nextflow I would like to parse a channel that is a list of tuples that look like that:

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

I would like to filter it to contain only tuples with Type1 to get:

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

What would be the best approach? I tried.filter() however obviously it returns a full list as soon as it detects Type1 without removing Type2.

You can use the map operator and the Groovy findAll() method with a closure to find the tuples where "Type1" is the first element. For example:

workflow {

    ...

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM