我试图找到一个很好的方法来实现这一点,但不幸的是,我没有找到一个。你知道吗
我正在处理以下格式的文件:
=Cluster=
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22491.xml;spectrum=1074 true
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22498.xml;spectrum=2950 true=Cluster=
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22498.xml;spectrum=1876 true
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22498.xml;spectrum=3479 true
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22498.xml;spectrum=3785 true=Cluster=
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22493.xml;spectrum=473 true
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22493.xml;spectrum=473 true
正如您所看到的,每个规范行都是不同的,除了最后一行,其中字符串谱的编号是重复的。
我想做的是获取模式=Cluster=
之间的每个信息块,并检查是否有谱值重复的行。如果有多行重复,则删除除一行之外的所有行。你知道吗
输出文件应如下所示:
=Cluster=
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22491.xml;spectrum=1074 true
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22498.xml;spectrum=2950 true=Cluster=
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22498.xml;spectrum=1876 true
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22498.xml;spectrum=3479 true
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22498.xml;spectrum=3785 true=Cluster=
SPEC PRD000681;PRIDE_Exp_Complete_Ac_22493.xml;spectrum=473 true
我用这个来分割文件使用的模式,但我不知道如何检查是否有重复频谱。你知道吗
#!/usr/bin/perl
undef $/;
$_ = <>;
$n = 0;
for $match (split(/(?==Cluster=)/)) {
open(O, '>temp' . ++$n);
print O $match;
close(O);
}
PD:我使用Perl是因为它对我来说更容易,但我也理解python。你知道吗
类似这样的操作将删除重复的行(整个文件)。你知道吗
如果您想更具体地了解光谱值,例如:
在划分集群时,您可以做一些非常类似的事情,但只需:
这会将默认的“print”位置设置为
$output
(您也需要在循环外声明它)。你知道吗您还应该:
use strict;
use warnings;
<>
读入$_
,这是不必要的。但是如果你不得不这样做的话,最好是$block = do { local $/; <> };
。然后$block =~ m/regex/
open ( my $output, '>', 'filename' ) or die $!;
or die $!
通常就足够了)。你知道吗所以这就像:
如果重复行是连续的,则可以使用以下perl oneliner:
原始文件是扩展名为
.back
的备份您还可以使用这个
python
脚本,我在其中使用了来自itertools
模块的groupby
。你知道吗我假设您的输入文件名为
f_input.txt
,输出文件名为new_file.txt
。你知道吗输出文件
new_file.txt
将与所需的输出类似。你知道吗相关问题 更多 >
编程相关推荐