def pca(data, group_dic, n=None, args=None):
    pca = PCA(n_components=2)
    group = []
    length = OrderedDict()
    temp = 0
    for (name, g) in group_dic.items():
        length[name] = [temp, (temp + len(g))]
        temp += len(g)
        group += g
    data = data[group]
    newData = pca.fit_transform(data.T)
    colors = {}
    colors1 = ['blue', 'red', 'green', 'turquoise', 'grey']
    i = 0
    for (name, number) in length.items():
        colors[name] = colors1[i]
        i += 1
    if (args.ac and args.bc):
        colors[group1] = args.ac
        colors[group2] = args.bc
    for (name, number) in length.items():
        plt.scatter(newData[number[0]:number[1], 0], newData[number[0]:number[1], 1], label=name, color=colors[name])
    plt.title('PCA analysis', size=20)
    pc1 = (100 * pca.explained_variance_ratio_[0])
    pc2 = (100 * pca.explained_variance_ratio_[1])
    plt.xlabel(('PC1(%.1f)' % pc1), size=15)
    plt.ylabel(('PC1(%.1f)' % pc2), size=15)
    plt.legend()
    plt.savefig(('PCA_%s.png' % n))
    plt.close()
def pca(data, group_dic, n=None, args=None):
    pca = PCA(n_components=2)
    group = []
    length = OrderedDict()
    temp = 0
    for (name, g) in group_dic.items():
        length[name] = [temp, (temp + len(g))]
        temp += len(g)
        group += g
    data = data[group]
    newData = pca.fit_transform(data.T)
    colors = {}
    colors1 = ['blue', 'red', 'green', 'turquoise', 'grey']
    i = 0
    for (name, number) in length.items():
        colors[name] = colors1[i]
        i += 1
    if (args.ac and args.bc):
        colors[group1] = args.ac
        colors[group2] = args.bc
    for (name, number) in length.items():
        plt.scatter(newData[number[0]:number[1], 0], newData[number[0]:number[1], 1], label=name, color=colors[name])
    plt.title('PCA analysis', size=20)
    pc1 = (100 * pca.explained_variance_ratio_[0])
    pc2 = (100 * pca.explained_variance_ratio_[1])
    plt.xlabel(('PC1(%.1f)' % pc1), size=15)
    plt.ylabel(('PC1(%.1f)' % pc2), size=15)
    plt.legend()
    plt.savefig(('PCA_%s.png' % n))
    plt.close()