#coding:utf-8
__author__ = 'similarface'
from collections importdefaultdict
PMRAdata=defaultdict(list)for line in open('/Users/similarface/Documents/PMRA_Marker_List_Detailed2.txt','r'):if not line.startswith("affy_snp_id"):
lines=line.strip().split('\t')
PMRAdata[lines[1]].append(lines[2])
wegeneRawData=defaultdict(list)for line in open('/Users/similarface/Documents/wegeneRawData.txt','r'):if not line.startswith("#"):
lines=line.strip().split('\t')try:
wegeneRawData[lines[1]].append(lines[2])exceptException,e:pass
print(wegeneRawData.keys())
v23andmeData=defaultdict(list)for line in open('/Users/similarface/Documents/genome_wang_mian_Full_20151021231213.txt','r'):if not line.startswith("#"):
lines=line.strip().split('\t')
v23andmeData[lines[1]].append(lines[2])
PMRAdrawdata={}for k,v inPMRAdata.items():
PMRAdrawdata[k]=len(v)
wegeneRawdrawdata={}for k,v inwegeneRawData.items():
wegeneRawdrawdata[k]=len(v)
v23andmePMRAdrawdata={}for k,v inv23andmeData.items():
v23andmePMRAdrawdata[k]=len(v)importnumpy as np,arrayfrom matplotlib importpyplot as plt
plt.figure(figsize=(9,6))
X= [str(i) for i in np.arange(22)+1]+['X','Y','MT']#X=np.arange(22)+1
#X是1,2,3,4,5,6,7,8,柱的个数#numpy.random.uniform(low=0.0, high=1.0, size=None), normal#uniform均匀分布的随机数,normal是正态分布的随机数,0.5-1均匀分布的数,一共有n个
Y=[]for i inX:
Y.append(PMRAdrawdata[i])
Y1=[]for i inX:
Y1.append(wegeneRawdrawdata[i])
Y2=[]for i inX:
Y2.append(v23andmePMRAdrawdata[i])
Y=np.array(Y)
Y1=np.array(Y1)
Y2=np.array(Y2)
plt.bar(np.arange(len(X)),Y,width=0.3,facecolor = 'green',edgecolor = 'white')
plt.bar(np.arange(len(X))+0.3,Y1,width = 0.3,facecolor = 'blue',edgecolor = 'white')
plt.bar(np.arange(len(X))+0.6,Y2,width = 0.3,facecolor = 'red',edgecolor = 'white')
plt.xticks(np.arange(len(X)),X)
plt.legend(('PMRA','wegene','23andme'))
plt.xlabel("chr")
plt.ylabel("Number of Markers")
plt.title(u"PMRA wegene 23andme 各染色体分布")
plt.show()