<jupyter_start><jupyter_text>making plotsss<jupyter_code>def plot_microsat_allele_dist(df, gray = 0):
    df2 = df[df["Size1"]> 50]
    df2 = df2[df2["Size2"]> 50]

    if gray == 1: 
        (sns.jointplot("Allele1", "Allele2", data=df2, color="k").plot_joint(sns.kdeplot, zorder=0, n_levels=6))
        plt.title("                                                                                "+'allele \n                                                                                     Distribution')
        return  
    sns.jointplot("Allele1", "Allele2", data=df2, kind="kde", space=0, color="gray")
    plt.title("allele\n    distribution")
    

plot_microsat_allele_dist(plex1df)
plot_microsat_allele_dist(plex2df)
plot_microsat_allele_dist(plex3df)
plex1df[plex1df['Allele1']!= 0].plot.scatter('Allele1', 'Allele2', s = 200)
plt.title('Plex1')
plex2df[plex2df['Allele1']!= 0].plot.scatter('Allele1', 'Allele2', s =200)
plt.title('Plex2')
plex3df[plex2df['Allele1']!= 0].plot.scatter('Allele1', 'Allele2', s =200)
plt.title('Plex3')<jupyter_output><empty_output><jupyter_text>calculating heterozigosity and FIS for the sacramento population<jupyter_code>def Expected_Heterozigosity(loci, pop):
    unique_elements, counts_elements = np.unique(list(pop[loci].values), return_counts=True)
    counts_elements = np.array(counts_elements/sum(counts_elements))
    return 1 - sum(counts_elements*counts_elements)

def Heterozigosity(loci, pop):
    result = 0
    for i in pop[loci].values:
        if i[0] != i[1]: result += 1
    return result/pop.shape[0]


def fuse_equivalents(al1, al2):
    return tuple(np.sort([al1,al2]))

plt.rcParams["figure.figsize"] = (25,10)

plex1df["bothalleles"] = plex1df.apply(lambda x: fuse_equivalents(x['Allele1'], x['Allele2']), axis =1)
examplepl1 = plex1df.copy().sort_values(by='bothalleles')
examplepl1 = examplepl1[examplepl1['bothalleles']!= (0,0)]


plex2df["bothalleles"] = plex2df.apply(lambda x: fuse_equivalents(x['Allele1'], x['Allele2']), axis =1)
examplepl2 = plex2df.copy().sort_values(by='bothalleles')
examplepl2 = examplepl2[examplepl2['bothalleles']!= (0,0)]

plex3df["bothalleles"] = plex3df.apply(lambda x: fuse_equivalents(x['Allele1'], x['Allele2']), axis =1)
examplepl3 = plex3df.copy().sort_values(by='bothalleles')
examplepl3 = examplepl3[examplepl3['bothalleles']!= (0,0)]

Hplex1 = Heterozigosity('bothalleles',examplepl1)
Hexplex1 = Expected_Heterozigosity('bothalleles', examplepl1)
Hplex2 = Heterozigosity('bothalleles',examplepl2)
Hexplex2 = Expected_Heterozigosity('bothalleles', examplepl2)
Hplex3 = Heterozigosity('bothalleles',examplepl3)
Hexplex3 = Expected_Heterozigosity('bothalleles', examplepl3)
print("the observed heterozigosity for plex 1,2,3 are respectively: "+str((Hplex1,Hplex2, Hplex3)))
print("the expected heterozigosity for plex 1,2,3 are respectively: "+str((Hexplex1, Hexplex2, Hplex3)))
FISplex1, FISplex2, FISplex3 = ((Hexplex1 -Hplex1)/Hexplex1,(Hexplex2 -Hplex2)/Hexplex2 ,(Hexplex3 -Hplex3)/Hexplex3)

sns.countplot(x='bothalleles', data= examplepl1)
plt.title("Plex1 allele distribution FIS = " + ('%.2f' % FISplex1))
plt.show()

sns.countplot(x='bothalleles', data= examplepl2)
plt.title("Plex2 allele distribution FIS = "+ ('%.2f' % FISplex2))
plt.show()
sns.countplot(x='bothalleles', data= examplepl3)
plt.title("Plex3 allele distribution FIS = "+ ('%.2f' % FISplex3))
plt.show()<jupyter_output>the observed heterozigosity for plex 1,2,3 are respectively: (0.7, 0.8387096774193549, 0.8709677419354839)
the expected heterozigosity for plex 1,2,3 are respectively: (0.74777777777777776, 0.78511966701352764, 0.8709677419354839)<jupyter_text>calculating PCAs for the msats  join both plexes<jupyter_code>plex2df['Sample Name2'] = plex2df['Sample Name'].apply(lambda x: x)
plex2df['Size1plex2'] = plex2df['Size1'].apply(lambda x: x)
plex2df['Size2plex2'] = plex2df['Size2'].apply(lambda x: x)
plex3df['Sample Name3'] = plex3df['Sample Name'].apply(lambda x: x)
plex3df['Size1plex3'] = plex3df['Size1'].apply(lambda x: x)
plex3df['Size2plex3'] = plex3df['Size2'].apply(lambda x: x)
newDF = pd.concat([plex1df[['Sample Name', 'Size1', 'Size2']] ,plex2df[['Size1plex2', 'Size2plex2']],
                   plex3df[['Size1plex3', 'Size2plex3', 'Sample Name3']], plex2df['Sample Name2']], axis =1)
newDF.head()
from sklearn.decomposition import PCA as sklearnPCA
sklearn_pca = sklearnPCA(n_components=2)

plex1df_wo_blank =  plex1df[plex1df['Allele1']!=0].copy()
plex2df_wo_blank =  plex1df[plex2df['Allele1']!=0].copy()
bothplexdf = newDF[newDF['Size1']!= 0].copy()


Xplex1 = plex1df_wo_blank.iloc[:,8:10].values
Xplex2 = plex2df_wo_blank.iloc[:,8:10].values
Xboth = bothplexdf.iloc[:,1:7].values

PCvalues = sklearn_pca.fit_transform(Xplex1)
PCvalues2 = sklearn_pca.fit_transform(Xplex2)
PCvaluesboth = sklearn_pca.fit_transform(Xboth)

plex1df_wo_blank["PC1"] = pd.Series(PCvalues[:,0], index = plex1df_wo_blank.index)
plex1df_wo_blank["PC2"] = pd.Series(PCvalues[:,1], index = plex1df_wo_blank.index)

plex2df_wo_blank["PC1"] = pd.Series(PCvalues2[:,0], index = plex2df_wo_blank.index)
plex2df_wo_blank["PC2"] = pd.Series(PCvalues2[:,1], index = plex2df_wo_blank.index)

bothplexdf["PC1"] = pd.Series(PCvaluesboth[:,0], index = bothplexdf.index)
bothplexdf["PC2"] = pd.Series(PCvaluesboth[:,1], index = bothplexdf.index)
plex1df_wo_blank.plot.scatter('PC1', 'PC2', s = 200, alpha = .9)
plt.title('Plex1 PCA')
plex2df_wo_blank.plot.scatter('PC1', 'PC2', s = 200, alpha = .9)
plt.title('Plex2 PCA')
bothplexdf.plot.scatter('PC1', 'PC2', s = 200, alpha = .9)
plt.title('Plex1/2/3 PCA')
from sklearn.manifold import TSNE
TSNEvalues1 = TSNE(n_components=2,  perplexity=8.0).fit_transform(Xplex1)
TSNEvalues2 = TSNE(n_components=2,  perplexity=8.0).fit_transform(Xplex2)
TSNEvaluesboth = TSNE(n_components=2,  perplexity=8.0).fit_transform(Xboth)


plex1df_wo_blank["tSNE1"] = pd.Series(TSNEvalues1[:,0], index = plex1df_wo_blank.index)
plex1df_wo_blank["tSNE2"] = pd.Series(TSNEvalues1[:,1], index = plex1df_wo_blank.index)

plex2df_wo_blank["tSNE1"] = pd.Series(TSNEvalues2[:,0], index = plex2df_wo_blank.index)
plex2df_wo_blank["tSNE2"] = pd.Series(TSNEvalues2[:,1], index = plex2df_wo_blank.index)

bothplexdf["tSNE1"] = pd.Series(TSNEvaluesboth[:,0], index = bothplexdf.index)
bothplexdf["tSNE2"] = pd.Series(TSNEvaluesboth[:,1], index = bothplexdf.index)
plex1df_wo_blank.plot.scatter('tSNE1', 'tSNE2', s = 200, alpha = .9)
plt.title('Plex1 tSNE')
plex2df_wo_blank.plot.scatter('tSNE1', 'tSNE2', s = 200, alpha = .9)
plt.title('Plex2 tSNE')
bothplexdf.plot.scatter('tSNE1', 'tSNE2', s = 200, alpha = .9)
plt.title('Plex1/2/3 tSNE')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16514174291285436, 'fraction_numerical': 0.06404679766011699, 'mean_word_length': 6.018947368421053, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '339457', 'license': 'MIT', 'n_tokens_mistral': 2826, 'n_tokens_neox': 2658, 'n_words': 412, 'path': 'microsat analysis sacramento perch.ipynb', 'repo_name': 'sanchestm/Sacramento-Perch-Microsatelite-Anaysis', 'size': '6667'}