Nextflow 快速搭建生信分析流程(五)- Filtering operators

本节我们介绍Nextflow中的Operator类型,Operator用户连接不同的Channel或者按照用户指定的规则进行数据的变换操作。

Operators分为以下7种类型:

Filtering operators

Transforming operators

Splitting operators

Combining operators

Forking operators

Maths operators

Other operators

Filtering operators-过滤操作符

过滤操作符主要包括:distinct, filter, first, last, randomSample, take, unique, until

1. filter

filter操作符按照指定的过滤规则进行元素过滤,过滤方法可以使用正则表达式;

Channel
.from( 'a', 'b', 'aa', 'bc', 3, 4.5 )
.filter( ~/^a.*/ )
.view()

2. unique

unique操作符用于去除元素中的重复项;

Channel
.from( 1,1,1,5,7,7,7,3,3 )
.unique()
.view()

3. distinct

distinct 操作符用于删除channel中连续重复的项,使得后面的元素与前面的元素是不同的。

Channel
.from( 1,1,2,2,2,3,1,1,2,2,3 )
.distinct()
.subscribe onNext: { println it }, onComplete: { println 'Done' }

4. first

first操作符创建一个含有满足条件的第一个元素的channel,可以使用正则表达式或者闭包;

// emits the first item for which the predicate evaluates to true: 4
Channel
.from( 1,2,3,4,5 )
.first { it > 3 }
.view()

5. randomSample

randomSample操作符用于从一个channel中随机选取一定数目的元素,并保存到一个新的channel中;

Channel
.from( 1..100 )
.randomSample( 10 )
.view()

6. take

take操作符用于提取一个channel中的前n个元素;

Channel
.from( 1,2,3,4,5,6 )
.take( 3 )
.subscribe onNext: { println it }, onComplete: { println 'Done' }

7. last

last操作符用于从channel中提取最后一个满足条件的元素;

Channel
.from( 1,2,3,4,5,6 )
.last()
.view()

8. until

until操作符用于从channel提取元素,直到达到满足条件的位置;

Channel
.from( 3,2,1,5,1,5 )
.until{ it==5 }
.view()

(0)

相关推荐