我想基于strand(column8)和tss(column 5)检索每个ref基因(第7列)的uniq count(第4列)行。 如果一个ref基因具有相同的计数,并且它在负链上,那么保持该行的最高tss同样如此 如果一个ref基因具有相同的计数,并且它在正链上,则保持该行具有最低的tss
我正在研究格式的数据:
CHR TSS-25bp TSS+25bp count tss Ensemble transcript refgene strand
chr15 79554474 79554524 2 79554499 ENSMUST00000089311 Sun2 -
chr15 79554475 79554525 2 79554500 ENSMUST00000100439 Sun2 -
chr15 79554477 79554527 2 79554502 ENSMUST00000046259 Sun2 -
chr15 79569054 79569104 1 79569079 ENSMUST00000159660 Sun2 -
chr15 79570243 79570293 4 79570268 ENSMUST00000160355 Sun2 -
chr17 44914075 44914125 2 44914100 ENSMUST00000050630 Supt3h +
chr17 44914248 44914298 3 44914273 ENSMUST00000130623 Supt3h +
chr17 44914319 44914369 3 44914344 ENSMUST00000127798 Supt3h +
chr11 87551028 87551078 2 87551053 ENSMUST00000152700 Supt4h1 +
chr11 87551029 87551079 2 87551054 ENSMUST00000141169 Supt4h1 +
chr7 29099891 29099941 2 29099916 ENSMUST00000003527 Supt5h -
chr11
78020504 78020554 3 78020529 ENSMUST00000108314 Supt6h -
我希望在输出中有这个:
CHR TSS-25bp TSS+25bp count tss Ensemble transcript refgene strand
chr15 79554477 79554527 2 79554502 ENSMUST00000046259 Sun2 -
chr15 79569054 79569104 1 79569079 ENSMUST00000159660 Sun2 -
chr15 79570243 79570293 4 79570268 ENSMUST00000160355 Sun2 -
chr17 44914075 44914125 2 44914100 ENSMUST00000050630 Supt3h +
chr17 44914248 44914298 3 44914273 ENSMUST00000130623 Supt3h +
chr11 87551028 87551078 2 87551053 ENSMUST00000152700 Supt4h1 +
chr7 29099891 29099941 2 29099916 ENSMUST00000003527 Supt5h -
chr11 78020504 78020554 3 78020529 ENSMUST00000108314 Supt6h -
到目前为止,我有这个,
#!/bin/bash
example=Workbook4.txt
for gene in `cut -f7 example | uniq`
do
sign=`grep $gene example | cut -f8 | uniq`
for count in `grep $gene example | cut -f4 | sort | uniq`
do
if [ "$sign" == "-" ]
then
grep $gene example | grep $count example | sort -k5 | head -1 ----
else
grep $gene example | grep $count example | sort -k5 | tail -1 ----
done
break
done
我不确定那个粗体的那个。如果你能帮我解决这个问题会很好。
答案 0 :(得分:2)
这似乎可以提供您想要的输出:
awk '
NR==1 {print; next}
{key = $4 SUBSEP $7 SUBSEP $8}
!(key in line) || ($8 == "-" && $5 > tss[key]) || ($8 == "+" && $5 < tss[key]) {
line[key] = $0
tss[key] = $5
}
END {for (key in line) print line[key]}
' file
CHR TSS-25bp TSS+25bp count tss Ensemble transcript refgene strand
chr11 78020504 78020554 3 78020529 ENSMUST00000108314 Supt6h -
chr15 79569054 79569104 1 79569079 ENSMUST00000159660 Sun2 -
chr15 79554477 79554527 2 79554502 ENSMUST00000046259 Sun2 -
chr17 44914248 44914298 3 44914273 ENSMUST00000130623 Supt3h +
chr17 44914075 44914125 2 44914100 ENSMUST00000050630 Supt3h +
chr15 79570243 79570293 4 79570268 ENSMUST00000160355 Sun2 -
chr11 87551028 87551078 2 87551053 ENSMUST00000152700 Supt4h1 +
chr7 29099891 29099941 2 29099916 ENSMUST00000003527 Supt5h -