Python脚本实现批量高亮blocks
脚本说明:对blocks文件进行批量颜色标注。
一、输入文件说明
从blocks文件中整理出需要高亮的目标基因按如下格式保存为highlight.gene.id
Ma07_t18590.1 Ma07_t18650.1 Ma07_t18570.1 Ma07_t18560.1 Ma07_t18640.1 Ma07_t18610.1 Ma07_t18580.1 Ma07_t18680.1 Ma07_t18630.1 Ma07_t18540.1 Ma07_t18620.1 Ma07_t20710.1 Ma07_t20740.1 Ma07_t20750.1 Ma07_t20660.1 Ma07_t20700.1 Ma07_t20680.1 Ma07_t20650.1 Ma07_t20720.1 Ma07_t20730.1
另外还需要*.blocks
文件作为输入
二、输出文件说明
输出文件为highlight.gene.blocks
,可输入JCVI重新绘图
三、脚本文件如下
#打开需要高亮的gene.id文件,准备id列表用于查询
f1 = open(r'/home/liuxin/Figure4A/Expanded_region/test2/highlight.gene.id','r')
f1line = f1.readline()
id = f1line.split(' ')
for i in id:
print (i)
#批量高亮blocks文件中与目标gene.id一致的行
with open(r'/home/liuxin/Figure4A/Expanded_region/test2/expanded_v2.expanded_v4.i1.blocks','r') as raw_file:
while True:
line = raw_file.readline()
if not line:
break
else:
if line.startswith('#'):
continue
cur_line = line.split('\t')
blocksline_id = cur_line[0].split('=')[-1]
if blocksline_id in id:
#以r*开头的行将标记为红色
new_line = 'r*'+cur_line[0]+'\t'+cur_line[1]
print(new_line)
with open('/home/liuxin/Figure4A/Expanded_region/test2/highlight.gene.blocks','a') as save_file:
save_file.write(new_line)
else:
print(line)
with open('/home/liuxin/Figure4A/Expanded_region/test2/highlight.gene.blocks','a') as save_file:
save_file.write(line)