gpt4 book ai didi

regex - pcregrep 一个 wiggle 文件来提取染色体。多行正则表达式搜索

转载 作者:行者123 更新时间:2023-12-04 04:51:36 25 4
gpt4 key购买 nike

我编写了一个简单的正则表达式,与 pcregrep 一起使用以返回摆动文件中的给定染色体(见下文)。

 pcregrep -M '^fixedStep chrom=2.*\n[0-9\n]*' input.txt

输入.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 号染色体的有效方法。

最佳答案

你会使用 awk 吗?那么这应该有效:

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

关于regex - pcregrep 一个 wiggle 文件来提取染色体。多行正则表达式搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17354962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com