# Filter the 3-column BLAST output according to following rules
# 1. Remove self matches, multiple matches
# 2. Re-order gene pairs lexicographically
import os
import sys
try:
infile = sys.argv[1]
outfile = sys.argv[2]
except:
print "Usage: python filter_blast.py infile outfile"
fp = file(infile)
pairs = {}
j = 0
for row in fp:
j+=1
a,b,e = row.split()
e = float(e)
if a==b: continue
if a>b: a,b=b,a
pair_name = "%s&%s"%(a,b)
if pair_name not in pairs or (pair_name in pairs and e<pairs[pair_name]):
pairs[pair_name] = e
print j,"records read"
print len(pairs),"records after filtering"
fw = file(outfile,"w")
for k,e in sorted(pairs.items()):
a,b = k.split("&")
fw.write("%s\t%s\t%g\n"%(a,b,e))
Filter the 3-column BLAST output according to following rules
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- Given a binary treestruct TreeLinkNode {TreeLinkNode *lef...
- 刮风了,天空更干净了。下班出来,被前面的云霞震撼了。 今天早上乖乖五点半吃了奶,又睡着了,一直到七点半醒,创造了新...