使用pcregrep提取染色体的摆动文件。 多行正则表达式搜索。

3
我用简单的正则表达式编写了一个用于 pcregrep 的代码,可以在 wiggle 文件中返回指定的染色体(见下文)。
 pcregrep -M '^fixedStep chrom=2.*\n[0-9\n]*' input.txt

Input.wig

fixedStep chrom=1 start=14154 step=1
1
1
1
1
1
fixedStep chrom=2 start=14154 step=1
1
1
3
10
120
14
5
9
fixedStep chrom=2 start=20145 step=1
1
1
11
1
1
fixedStep chrom=2 start=30535 step=1
3
24
11
fixedStep chrom=3 start=14154 step=1
1
1
1
1
1

输出结果为:
fixedStep chrom=2 start=14154 step=1
1
1
3
10
120
14
5
9
fixedStep chrom=2 start=30124 step=1
fixedStep chrom=2 start=50345 step=1
4
23
90
fixedStep chrom=3 start=14154 step=1

但我想要的是:
fixedStep chrom=2 start=14154 step=1
1
1
3
10
120
14
5
9
fixedStep chrom=2 start=20145 step=1
1
1
11
1
1
fixedStep chrom=2 start=30535 step=1
3
24
11

更具体地说,我想找到文件中与之匹配的每个条目。
fixedStep chrom=2 start=ANY step=1
1
2
3
4

并删除它,同时保留所有其他染色体。

编辑:

我部分解决了搜索问题;我可以使用

pcregrep -M '^fixed.*chrom=2.*(\n[0-9]+)*' input.txt

为了获得正确的输出,但我仍然没有找到一种有效的方法从input.txt中删除染色体2。

1个回答

4

你会使用 awk 吗?如果是的话,那么这应该能用:

awk '/chrom=2/{p=1}/chrom=[^2]/{p=0}p' input

那相反的呢?我如何删除每个chromo=2条目并保留其他所有内容? - Artem
1
只需反转 p 的值。awk '/chrom=2/{p=0}/chrom=[^2]/{p=1}p' input - jaypal singh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接