尴尬选择具有科学符号的值

发布于 2025-02-13 14:17:35 字数 710 浏览 0 评论 0原文

尊敬的生物信息学家,

我对价值观的尴尬和科学符号有问题。

我想根据$ 5的最低价值选择尴尬来选择行,以便

Chrpa1_10100    2434    PF00063 des 3.9E-21 IPR001609   
Chrpa1_10100    2434    PF03547 des 4.5E-7  IPR004776   
Chrpa1_10100    2434    PF07857 des 3.3E-7  IPR012435   
Chrpa1_10100    2434    PF13516 des 0.085   IPR001611   

在这种情况下只保留一个ID $ 1 ::,我想要:

Chrpa1_10100 2434 PF00063 des 3.9E-21 IPR001609

如果我这样做:

cat file |sort -k1,1|uniq| awk -F'\t' '$5 > max[$1] { max[$1]=$5; row[$1]=$0 } END { for (i in row) print row[i] }'

但是我想要这个:

Chrpa1_10100 2434    PF13516 des 0.085   IPR001611

谢谢您,请提前欢呼,

Dear bioinformaticians,

I have a problem with awk and scientific notation of values.

I want to use awk to select rows based on the min value of $5 to keep only one ID of $1 ::

Chrpa1_10100    2434    PF00063 des 3.9E-21 IPR001609   
Chrpa1_10100    2434    PF03547 des 4.5E-7  IPR004776   
Chrpa1_10100    2434    PF07857 des 3.3E-7  IPR012435   
Chrpa1_10100    2434    PF13516 des 0.085   IPR001611   

in this particular case, I want :

Chrpa1_10100 2434 PF00063 des 3.9E-21 IPR001609

If I do :

cat file |sort -k1,1|uniq| awk -F'\t' '$5 > max[$1] { max[$1]=$5; row[$1]=$0 } END { for (i in row) print row[i] }'

but I want this one :

Chrpa1_10100 2434    PF13516 des 0.085   IPR001611

Thank you in advance,

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萧瑟寒风 2025-02-20 14:17:36

我的命令行给我这一点:CHRPA1_10100 2434 PF13516 DES 0.085
IPR001611,但我想要此CHRPA1_10100 2434 PF00063 DES 3.9E-21
IPR001609

以下数字

3.9E-21 4.5E-7 3.3E-7 0.085

3.9e-21最小,0.085是最大的,此代码

awk -F'\t' '$5 > max[$1] { max[$1]=$5; row[$1]=$0 } END { for (i in row) print row[i] }'

选择最大数字,因此它确实找到了使用0.085的行。 。如果您想要3.9E-21您需要实现查找最小价值,但请记住,尽管未知平均值零对于查找正数的最大数字是可以的,但这不是缩影,因此,我建议按照改善

awk -F'\t' '!($1 in min)||($5 < min[$1]){ min[$1]=$5; row[$1]=$0 } END { for (i in row) print row[i] }'

说明:更改max to min&gt; to &lt;和更改条件,因此如果没有密钥$ 1在最小数组中或的值$ 5小于min下的值 $ $ 1

,当file.txt内容

Chrpa1_10100 2434 PF00063 des 3.9E-21 IPR001609
Chrpa1_10100 2434 PF03547 des 4.5E-7 IPR004776
Chrpa1_10100 2434 PF07857 des 3.3E-7 IPR012435
Chrpa1_10100 2434 PF13516 des 0.085 IPR001611

然后

awk '!($1 in min)||($5 < min[$1]){ min[$1]=$5; row[$1]=$0 } END { for (i in row) print row[i] }' file.txt

提供输出

Chrpa1_10100 2434 PF00063 des 3.9E-21 IPR001609

(在GAWK 4.2.1中测试)

my command line is giving to me this : Chrpa1_10100 2434 PF13516 des 0.085
IPR001611 but I want this Chrpa1_10100 2434 PF00063 des 3.9E-21
IPR001609

Out of following numbers

3.9E-21 4.5E-7 3.3E-7 0.085

3.9E-21 is smallest, 0.085 is biggest, this code

awk -F'\t' '$5 > max[$1] { max[$1]=$5; row[$1]=$0 } END { for (i in row) print row[i] }'

selects biggest number, hence it did find line with 0.085. If you want 3.9E-21 you need to implement finding minimal value but remembering that while unknown mean zero is fine for finding max of positive numbers, it is not for minumum, therefore I suggest following ameloration

awk -F'\t' '!($1 in min)||($5 < min[$1]){ min[$1]=$5; row[$1]=$0 } END { for (i in row) print row[i] }'

Explanation: changed max to min and > to < and altered condition so is true if there is not key $1 in min array or value of $5 is smaller than value in min under key $1.

When file.txt content is

Chrpa1_10100 2434 PF00063 des 3.9E-21 IPR001609
Chrpa1_10100 2434 PF03547 des 4.5E-7 IPR004776
Chrpa1_10100 2434 PF07857 des 3.3E-7 IPR012435
Chrpa1_10100 2434 PF13516 des 0.085 IPR001611

then

awk '!($1 in min)||($5 < min[$1]){ min[$1]=$5; row[$1]=$0 } END { for (i in row) print row[i] }' file.txt

gives output

Chrpa1_10100 2434 PF00063 des 3.9E-21 IPR001609

(tested in gawk 4.2.1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文