<jupyter_start><jupyter_text>t-SNE<jupyter_code>def tsne(df, vcf, meta_data):
    tsne_pipeline = make_pipeline(StandardScaler(), TSNE(n_components=2))
    
    X_embedded = tsne_pipeline.fit_transform(df.T)
    tsne_df = pd.DataFrame(data = X_embedded, index=vcf['samples'])
    
    pop_df = meta_data.set_index('PGDP_ID')
    
    tsne_df.index = tsne_df.index.str.replace('Sci_', '', regex=True)
    
    final_tsne = pd.merge(tsne_df, pop_df['C_origin'], left_index=True, right_index=True)
    
    return final_tsne
def plot_tsne(tsne_df, pop, chrom):
    fig, ax = plt.subplots(figsize = (6,5))
    
    groups = tsne_df.groupby('C_origin')
    for name, group in groups:
        ax.scatter(group[0], group[1], label=name)
    
    ax.set_xlabel('Component 1', fontsize = 10)
    ax.set_ylabel('Component 2', fontsize = 10)
#     ax.text(s = 'Chromosome {}'.format(chrom), size=20, rotation=0, ha = 'center', x=0.5,y=1.06,transform=ax.transAxes)
#     plt.title('{}'.format(pop), fontsize = 20, rotation='vertical',x=-0.22,y=0.35)
    ax.legend(bbox_to_anchor=(1.01, 0.75))
#     ax.get_legend().remove()
    
    
    fig.savefig('../figures/tsne_{}_{}.pdf'.format(pop, chrom), bbox_inches='tight')<jupyter_output><empty_output><jupyter_text>Females<jupyter_code>females_chr7_df = vcf2df(chr7_females)
pruned_females_7 = ld_prune(females_chr7_df, size=200, step=20, threshold=.1, n_iter=1)
females_chr7 = tsne(pruned_females_7, chr7_females, meta_data_females)
plot_tsne(females_chr7, 'Females', '7')
females_chrX_df = vcf2df(chrX_females)
pruned_females_X = ld_prune(females_chrX_df, size=200, step=20, threshold=.1, n_iter=1)
females_chrX = tsne(pruned_females_X, chrX_females, meta_data_females)
plot_tsne(females_chrX, 'Females', 'X')<jupyter_output><empty_output><jupyter_text>Males<jupyter_code>males_chr7_df = vcf2df(chr7_males)
pruned_males_7 = ld_prune(males_chr7_df, size=200, step=20, threshold=.1, n_iter=1)
males_chr7 = tsne(pruned_males_7, chr7_males, meta_data_males)
plot_tsne(males_chr7, 'Males', '7')
males_chrX_df = vcf2df(chrX_males)
pruned_males_X = ld_prune(males_chrX_df, size=200, step=20, threshold=.1, n_iter=1)
males_chrX = tsne(pruned_males_X, chrX_males, meta_data_males)
plot_tsne(males_chrX, 'Males', 'X')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14907651715039577, 'fraction_numerical': 0.036499560246262094, 'mean_word_length': 6.109375, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '368311', 'license': 'MIT', 'n_tokens_mistral': 1045, 'n_tokens_neox': 1012, 'n_words': 127, 'path': 'notebooks/t-SNE.ipynb', 'repo_name': 'janneengestoft/birc-project', 'size': '2274'}