Skip to content

Instantly share code, notes, and snippets.

@heliy
Created April 3, 2014 07:48
Show Gist options
  • Save heliy/9950035 to your computer and use it in GitHub Desktop.
Save heliy/9950035 to your computer and use it in GitHub Desktop.
GeneBank文件绘图 超*初级
import matplotlib.pyplot as plt
import numpy as np
import sys
def get_features(gb):
context=open(gb,"r").read().split("FEATURES")[1].split("ORIGIN")[0].splitlines()
dc={}
for line in context:
if line[5]==' ':
continue
[item,ran]=line.split()
ran=[int(i) for i in ran.split("..")]
if item in dc.keys():
dc[item].append(ran)
else:
dc[item]=[ran]
return dc
level_color={1:'b',
2:'r',
3:'m',
4:'y',
5:'g',
6:'k'}
def gb_plot(gb):
features=get_features(gb)
total=features['source'][0]
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot(range(total[0],total[1]),[0]*(total[1]-total[0]),
linewidth=10,color='c')
ax.text(0,10,"source:"+str(total[0])+".."+str(total[1]),
color='k')
level=1
for key in features.keys():
if key=="source":
continue
sets=features[key]
co=level_color[level]
for se in sets:
ax.axvline(x=se[0],color=co)
ax.axvline(x=se[1],color=co)
ax.plot(range(se[0]+1,se[1]-1),[level*50]*(se[1]-se[0]-2),linewidth=8,color=co)
ax.text(0,level*50+10,key+":"+str(sets),color='k')
level=level+1
plt.axis([total[0],total[1],-30,300])
plt.savefig(gb.replace(".gb",".png"))
if __name__=='__main__':
gb_plot(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment