PLINK pca

 

#coding:utf-8
__author__ = 'similarface'
import os
import pandas as pd
import matplotlib.pyplot as plt

path='plink.eigenvec'

def plinkPca(filepath,header=""):
    data=pd.read_table(path,header=None,sep=' ')
    filterdata=data.loc[:,0:5]
    label=filterdata[0].tolist()
    label_uniq = list(set(label))
    label_uniq.sort(key=label.index)
    filterdata.columns=['pop','human','pca0','pca1','pca2','pca3']
    colors=['gold', 'red', 'blue', 'green', 'black', 'yellow', 'orangered', 'sienna', 'tomato', 'silver', 'fuchsia', 'orange', 'coral', 'orchid', 'magenta', 'chartreuse', 'navy', 'violet', 'beige', 'khaki', 'tan', 'indigo', 'cyan', 'azure', 'teal']
    colors=colors[0:len(label_uniq)]
    markers = ['o', 'x', 's', 'p', '^', '>', '+', 'D', '*', '<', '2','_']*10
    markers=markers[0:len(label_uniq)]
    #调整画布大小
    fig = plt.figure(figsize=(8,8),dpi=100)
    plt.clf()
    for i,targer_name,color,marker in zip(range(len(label_uniq)),label_uniq,colors,markers):
        plt.scatter(filterdata[filterdata['pop']==targer_name]['pca0'],filterdata[filterdata['pop']==targer_name]['pca1'], s=20, edgecolor='k',c=color,marker=marker)
    plt.legend(labels = label_uniq, bbox_to_anchor=(1.0,0.95))
    plt.title(header)
    plt.show()

    
plinkPca(path,header="EUR PCA")

 

 

posted @ 2018-06-12 10:20  similarface  阅读(512)  评论(0编辑  收藏  举报