{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import warnings\n",
"warnings.simplefilter(action='ignore', category=FutureWarning)\n",
"\n",
"import multigrate as mtg\n",
"import scanpy as sc"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# MOFA"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AnnData object with n_obs × n_vars = 30293 × 13\n",
" obs: 'batch_indices', 'n_genes', 'percent_mito', 'leiden_subclusters', 'cell_type', 'tissue', 'batch', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"latent = sc.read('../data/integrated/mofa/gayoso-mofa.h5ad')\n",
"latent"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"latent.obsm['latent'] = latent.X"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Clustering...\n",
"ASW label/batch...\n",
"Graph connectivity...\n",
"ASW label...\n",
"NMI cluster/label...\n",
"ARI cluster/label...\n",
"Isolated label silhouette...\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>score</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>ASW_label/batch</th>\n",
" <td>0.876851</td>\n",
" </tr>\n",
" <tr>\n",
" <th>graph_conn</th>\n",
" <td>0.892205</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ASW_label</th>\n",
" <td>0.558320</td>\n",
" </tr>\n",
" <tr>\n",
" <th>NMI_cluster/label</th>\n",
" <td>0.704188</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ARI_cluster/label</th>\n",
" <td>0.626555</td>\n",
" </tr>\n",
" <tr>\n",
" <th>isolated_label_silhouette</th>\n",
" <td>0.632080</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" score\n",
"ASW_label/batch 0.876851\n",
"graph_conn 0.892205\n",
"ASW_label 0.558320\n",
"NMI_cluster/label 0.704188\n",
"ARI_cluster/label 0.626555\n",
"isolated_label_silhouette 0.632080"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"metrics = mtg.metrics.metrics(None, latent,\n",
" batch_key='batch_indices',\n",
" label_key='cell_type',\n",
" isolated_label_f1=False,\n",
" pcr_batch=False,\n",
" embed='latent', \n",
" save='gayoso-mofa.csv', \n",
" method='mofa')\n",
"metrics"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Seurat"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AnnData object with n_obs × n_vars = 30293 × 20\n",
" obs: 'cell_type', 'batch', 'nCount_RNA', 'nFeature_RNA', 'nCount_SCT', 'nFeature_SCT', 'integrated.weight'\n",
" obsp: 'connectivities'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"latent = sc.read('../data/integrated/seurat/gayoso-seurat.h5ad')\n",
"latent"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"latent.obsm['latent'] = latent.X"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Clustering...\n",
"ASW label/batch...\n",
"Graph connectivity...\n",
"ASW label...\n",
"NMI cluster/label...\n",
"ARI cluster/label...\n",
"Isolated label silhouette...\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>score</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>ASW_label/batch</th>\n",
" <td>0.914544</td>\n",
" </tr>\n",
" <tr>\n",
" <th>graph_conn</th>\n",
" <td>0.936758</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ASW_label</th>\n",
" <td>0.617050</td>\n",
" </tr>\n",
" <tr>\n",
" <th>NMI_cluster/label</th>\n",
" <td>0.709452</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ARI_cluster/label</th>\n",
" <td>0.628502</td>\n",
" </tr>\n",
" <tr>\n",
" <th>isolated_label_silhouette</th>\n",
" <td>0.617743</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" score\n",
"ASW_label/batch 0.914544\n",
"graph_conn 0.936758\n",
"ASW_label 0.617050\n",
"NMI_cluster/label 0.709452\n",
"ARI_cluster/label 0.628502\n",
"isolated_label_silhouette 0.617743"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"metrics = mtg.metrics.metrics(None, latent,\n",
" batch_key='batch',\n",
" label_key='cell_type',\n",
" isolated_label_f1=False,\n",
" pcr_batch=False,\n",
" embed='latent', \n",
" save='gayoso-seurat.csv', \n",
" method='seurat')\n",
"metrics"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# totalVI"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AnnData object with n_obs × n_vars = 30293 × 20\n",
" obs: 'batch_indices', 'n_genes', 'percent_mito', 'leiden_subclusters', 'cell_types', 'tissue', 'batch', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', '_scvi_batch', '_scvi_labels', '_scvi_local_l_mean', '_scvi_local_l_var'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"latent = sc.read('../data/integrated/totalvi/gayoso-totalvi.h5ad')\n",
"latent"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"latent.obsm['latent'] = latent.X"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Clustering...\n",
"ASW label/batch...\n",
"Graph connectivity...\n",
"ASW label...\n",
"NMI cluster/label...\n",
"ARI cluster/label...\n",
"Isolated label silhouette...\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>score</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>ASW_label/batch</th>\n",
" <td>0.955026</td>\n",
" </tr>\n",
" <tr>\n",
" <th>graph_conn</th>\n",
" <td>0.942385</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ASW_label</th>\n",
" <td>0.547595</td>\n",
" </tr>\n",
" <tr>\n",
" <th>NMI_cluster/label</th>\n",
" <td>0.750054</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ARI_cluster/label</th>\n",
" <td>0.694281</td>\n",
" </tr>\n",
" <tr>\n",
" <th>isolated_label_silhouette</th>\n",
" <td>0.576691</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" score\n",
"ASW_label/batch 0.955026\n",
"graph_conn 0.942385\n",
"ASW_label 0.547595\n",
"NMI_cluster/label 0.750054\n",
"ARI_cluster/label 0.694281\n",
"isolated_label_silhouette 0.576691"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"metrics = mtg.metrics.metrics(None, latent,\n",
" batch_key='batch_indices',\n",
" label_key='cell_types',\n",
" isolated_label_f1=False,\n",
" pcr_batch=False,\n",
" embed='latent', \n",
" save='gayoso-totalvi.csv', \n",
" method='totalVI')\n",
"metrics"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}