{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.simplefilter(action='ignore', category=FutureWarning)\n",
    "\n",
    "import scanpy as sc\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Prep RNA-seq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 149926 × 27504\n",
       "    obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt'\n",
       "    var: 'names', 'n_cells', 'mt', 'n_cells_by_counts', 'mean_counts', 'log1p_mean_counts', 'pct_dropout_by_counts', 'total_counts', 'log1p_total_counts', 'highly_variable', 'means', 'dispersions', 'dispersions_norm'\n",
       "    uns: 'Batch_colors', 'celltype.l1_colors', 'celltype.l2_colors', 'celltype.l3_colors', 'donor_colors', 'neighbors', 'pca', 'umap'\n",
       "    obsm: 'X_pca', 'X_umap'\n",
       "    varm: 'PCs'\n",
       "    layers: 'count'\n",
       "    obsp: 'connectivities', 'distances'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna1 = sc.read('../data/hao-2020/expressions.h5ad')\n",
    "scrna1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "View of AnnData object with n_obs × n_vars = 49183 × 27504\n",
       "    obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt'\n",
       "    var: 'names', 'n_cells', 'mt', 'n_cells_by_counts', 'mean_counts', 'log1p_mean_counts', 'pct_dropout_by_counts', 'total_counts', 'log1p_total_counts', 'highly_variable', 'means', 'dispersions', 'dispersions_norm'\n",
       "    uns: 'Batch_colors', 'celltype.l1_colors', 'celltype.l2_colors', 'celltype.l3_colors', 'donor_colors', 'neighbors', 'pca', 'umap'\n",
       "    obsm: 'X_pca', 'X_umap'\n",
       "    varm: 'PCs'\n",
       "    layers: 'count'\n",
       "    obsp: 'connectivities', 'distances'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# take only unperturbed\n",
    "scrna1 = scrna1[scrna1.obs.time == 0]\n",
    "scrna1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 10025 × 25604\n",
       "    obs: 'cell_type', 'n_genes', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt'\n",
       "    var: 'gene_ids', 'feature_types', 'genome', 'n_cells', 'mt', 'n_cells_by_counts', 'mean_counts', 'log1p_mean_counts', 'pct_dropout_by_counts', 'total_counts', 'log1p_total_counts'\n",
       "    layers: 'count'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna2 = sc.read('../data/10xpbmc10k-2020/expressions.h5ad')\n",
    "scrna2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 97039 × 24737\n",
       "    obs: 'sample_id', 'n_genes', 'n_genes_by_counts', 'total_counts', 'total_counts_mt', 'pct_counts_mt', 'full_clustering', 'initial_clustering', 'Resample', 'Collection_Day', 'Sex', 'Age_interval', 'Swab_result', 'Status', 'Smoker', 'Status_on_day_collection', 'Status_on_day_collection_summary', 'Days_from_onset', 'Site', 'time_after_LPS', 'Worst_Clinical_Status', 'Outcome', 'patient_id'\n",
       "    var: 'feature_types'\n",
       "    uns: 'full_clustering_colors', 'hvg', 'initial_clustering_colors', 'leiden', 'neighbors', 'pca', 'umap'\n",
       "    obsm: 'X_pca', 'X_pca_harmony', 'X_umap'\n",
       "    layers: 'count'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna3 = sc.read('../data/haniffa-2021/expressions_healthy.h5ad')\n",
    "scrna3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 6334 × 21819\n",
       "    obs: 'n_genes', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt', 'cell_type', 'batch'\n",
       "    var: 'gene_ids', 'feature_types', 'genome', 'mt', 'n_cells-0', 'n_cells_by_counts-0', 'mean_counts-0', 'log1p_mean_counts-0', 'pct_dropout_by_counts-0', 'total_counts-0', 'log1p_total_counts-0', 'highly_variable-0', 'means-0', 'dispersions-0', 'dispersions_norm-0', 'n_cells-1', 'n_cells_by_counts-1', 'mean_counts-1', 'log1p_mean_counts-1', 'pct_dropout_by_counts-1', 'total_counts-1', 'log1p_total_counts-1', 'highly_variable-1', 'means-1', 'dispersions-1', 'dispersions_norm-1'\n",
       "    obsm: 'X_pca'\n",
       "    layers: 'count'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna_query1 = sc.read('../data/sanger-2021/expressions.h5ad')\n",
    "scrna_query1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "scrna_query1.obs['Batch'] = scrna_query1.obs['batch']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 527286 × 24737\n",
       "    obs: 'sample_id', 'n_genes', 'n_genes_by_counts', 'total_counts', 'total_counts_mt', 'pct_counts_mt', 'full_clustering', 'initial_clustering', 'Resample', 'Collection_Day', 'Sex', 'Age_interval', 'Swab_result', 'Status', 'Smoker', 'Status_on_day_collection', 'Status_on_day_collection_summary', 'Days_from_onset', 'Site', 'time_after_LPS', 'Worst_Clinical_Status', 'Outcome', 'patient_id'\n",
       "    var: 'feature_types'\n",
       "    uns: 'full_clustering_colors', 'hvg', 'initial_clustering_colors', 'leiden', 'neighbors', 'pca', 'umap'\n",
       "    obsm: 'X_pca', 'X_pca_harmony', 'X_umap'\n",
       "    layers: 'count'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna_query2 = sc.read('../data/haniffa-2021/expressions_covid.h5ad')\n",
    "scrna_query2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18410"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "common_genes = list(set(scrna1.var_names) & set(scrna2.var_names) & set(scrna3.var_names) & set(scrna_query1.var_names) & set(scrna_query2.var_names))\n",
    "len(common_genes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "scrna1 = scrna1[:, common_genes]\n",
    "scrna2 = scrna2[:, common_genes]\n",
    "scrna3 = scrna3[:, common_genes]\n",
    "scrna_query1 = scrna_query1[:, common_genes]\n",
    "scrna_query2 = scrna_query2[:, common_genes]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 689867 × 18410\n",
       "    obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt', 'cell_type', 'sample_id', 'full_clustering', 'initial_clustering', 'Resample', 'Collection_Day', 'Sex', 'Age_interval', 'Swab_result', 'Status', 'Smoker', 'Status_on_day_collection', 'Status_on_day_collection_summary', 'Days_from_onset', 'Site', 'time_after_LPS', 'Worst_Clinical_Status', 'Outcome', 'patient_id', 'batch'\n",
       "    var: 'names-0', 'n_cells-0', 'mt-0', 'n_cells_by_counts-0', 'mean_counts-0', 'log1p_mean_counts-0', 'pct_dropout_by_counts-0', 'total_counts-0', 'log1p_total_counts-0', 'highly_variable-0', 'means-0', 'dispersions-0', 'dispersions_norm-0', 'n_cells-1', 'mt-1', 'n_cells_by_counts-1', 'mean_counts-1', 'log1p_mean_counts-1', 'pct_dropout_by_counts-1', 'total_counts-1', 'log1p_total_counts-1', 'gene_ids-1', 'feature_types-1', 'genome-1', 'feature_types-2', 'mt-3', 'gene_ids-3', 'feature_types-3', 'genome-3', 'n_cells-0-3', 'n_cells_by_counts-0-3', 'mean_counts-0-3', 'log1p_mean_counts-0-3', 'pct_dropout_by_counts-0-3', 'total_counts-0-3', 'log1p_total_counts-0-3', 'highly_variable-0-3', 'means-0-3', 'dispersions-0-3', 'dispersions_norm-0-3', 'n_cells-1-3', 'n_cells_by_counts-1-3', 'mean_counts-1-3', 'log1p_mean_counts-1-3', 'pct_dropout_by_counts-1-3', 'total_counts-1-3', 'log1p_total_counts-1-3', 'highly_variable-1-3', 'means-1-3', 'dispersions-1-3', 'dispersions_norm-1-3', 'feature_types-4'\n",
       "    layers: 'count'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "adata = scrna1.concatenate(scrna2, scrna3, scrna_query1, scrna_query2)\n",
    "adata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "adata.X = adata.layers['count']\n",
    "sc.pp.normalize_total(adata, target_sum=1e4)\n",
    "sc.pp.log1p(adata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "sc.pp.highly_variable_genes(adata, n_top_genes=4000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "View of AnnData object with n_obs × n_vars = 689867 × 4000\n",
       "    obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt', 'cell_type', 'sample_id', 'full_clustering', 'initial_clustering', 'Resample', 'Collection_Day', 'Sex', 'Age_interval', 'Swab_result', 'Status', 'Smoker', 'Status_on_day_collection', 'Status_on_day_collection_summary', 'Days_from_onset', 'Site', 'time_after_LPS', 'Worst_Clinical_Status', 'Outcome', 'patient_id', 'batch'\n",
       "    var: 'names-0', 'n_cells-0', 'mt-0', 'n_cells_by_counts-0', 'mean_counts-0', 'log1p_mean_counts-0', 'pct_dropout_by_counts-0', 'total_counts-0', 'log1p_total_counts-0', 'highly_variable-0', 'means-0', 'dispersions-0', 'dispersions_norm-0', 'n_cells-1', 'mt-1', 'n_cells_by_counts-1', 'mean_counts-1', 'log1p_mean_counts-1', 'pct_dropout_by_counts-1', 'total_counts-1', 'log1p_total_counts-1', 'gene_ids-1', 'feature_types-1', 'genome-1', 'feature_types-2', 'mt-3', 'gene_ids-3', 'feature_types-3', 'genome-3', 'n_cells-0-3', 'n_cells_by_counts-0-3', 'mean_counts-0-3', 'log1p_mean_counts-0-3', 'pct_dropout_by_counts-0-3', 'total_counts-0-3', 'log1p_total_counts-0-3', 'highly_variable-0-3', 'means-0-3', 'dispersions-0-3', 'dispersions_norm-0-3', 'n_cells-1-3', 'n_cells_by_counts-1-3', 'mean_counts-1-3', 'log1p_mean_counts-1-3', 'pct_dropout_by_counts-1-3', 'total_counts-1-3', 'log1p_total_counts-1-3', 'highly_variable-1-3', 'means-1-3', 'dispersions-1-3', 'dispersions_norm-1-3', 'feature_types-4', 'highly_variable', 'means', 'dispersions', 'dispersions_norm'\n",
       "    uns: 'log1p'\n",
       "    layers: 'count'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "adata = adata[:, adata.var.highly_variable]\n",
    "adata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "scrna1 = adata[adata.obs.batch == '0']\n",
    "scrna2 = adata[adata.obs.batch == '1']\n",
    "scrna3 = adata[adata.obs.batch == '2']\n",
    "scrna_query1 = adata[adata.obs.batch == '3']\n",
    "scrna_query2 = adata[adata.obs.batch == '4']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "del adata"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Prep ADT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 149926 × 228\n",
       "    obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes'\n",
       "    var: 'n_cells'\n",
       "    uns: 'Batch_colors', 'celltype.l1_colors', 'celltype.l2_colors', 'celltype.l3_colors', 'donor_colors', 'neighbors', 'pca', 'umap'\n",
       "    obsm: 'X_pca', 'X_umap'\n",
       "    varm: 'PCs'\n",
       "    layers: 'count'\n",
       "    obsp: 'connectivities', 'distances'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cite = sc.read('../data/hao-2020/protein.h5ad')\n",
    "cite"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "View of AnnData object with n_obs × n_vars = 49183 × 228\n",
       "    obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes'\n",
       "    var: 'n_cells'\n",
       "    uns: 'Batch_colors', 'celltype.l1_colors', 'celltype.l2_colors', 'celltype.l3_colors', 'donor_colors', 'neighbors', 'pca', 'umap'\n",
       "    obsm: 'X_pca', 'X_umap'\n",
       "    varm: 'PCs'\n",
       "    layers: 'count'\n",
       "    obsp: 'connectivities', 'distances'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# take only unperturbed\n",
    "cite = cite[cite.obs.time == 0]\n",
    "cite"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CD4\n",
      "CD4\n",
      "CD3\n",
      "CD56\n",
      "CD56\n",
      "CD11b\n",
      "CD11b\n",
      "CD38\n",
      "CD38\n",
      "CD44\n",
      "CD44\n",
      "CD26\n",
      "CD26\n",
      "CD275\n",
      "CD275\n",
      "CD45\n",
      "CD45\n",
      "CD133\n",
      "CD133\n",
      "CD3\n",
      "CD138\n",
      "CD138\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>CD39</th>\n",
       "      <th>Rat-IgG1-1</th>\n",
       "      <th>CD107a</th>\n",
       "      <th>CD62P</th>\n",
       "      <th>TCR-2</th>\n",
       "      <th>CD30</th>\n",
       "      <th>CD31</th>\n",
       "      <th>CD34</th>\n",
       "      <th>CD35</th>\n",
       "      <th>CD36</th>\n",
       "      <th>...</th>\n",
       "      <th>CD119</th>\n",
       "      <th>CD169</th>\n",
       "      <th>CD28</th>\n",
       "      <th>CD161</th>\n",
       "      <th>CD163</th>\n",
       "      <th>CD138</th>\n",
       "      <th>CD164</th>\n",
       "      <th>CD144</th>\n",
       "      <th>CD202b</th>\n",
       "      <th>CD11c</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>L1_AAACCCATCTCCCTAG</th>\n",
       "      <td>5.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>88.0</td>\n",
       "      <td>48.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>77.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>68.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L1_AAACCCATCTGCGGAC</th>\n",
       "      <td>5.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>39.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>54.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>...</td>\n",
       "      <td>6.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>16.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L1_AAACGAAAGGCCCAAA</th>\n",
       "      <td>34.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>357.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>722.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>...</td>\n",
       "      <td>19.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>70.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L1_AAACGAAAGTTACTCG</th>\n",
       "      <td>6.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>108.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L1_AAACGAACACAGCATT</th>\n",
       "      <td>3.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>33.0</td>\n",
       "      <td>65.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>55.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>51.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>46.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E2L8_TTTGGTTAGGCCTGCT</th>\n",
       "      <td>3.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E2L8_TTTGGTTAGTCAGCGA</th>\n",
       "      <td>36.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>317.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>296.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>646.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>...</td>\n",
       "      <td>18.0</td>\n",
       "      <td>51.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E2L8_TTTGGTTAGTGCCTCG</th>\n",
       "      <td>42.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>1050.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>396.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>3084.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>...</td>\n",
       "      <td>32.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>25.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>109.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E2L8_TTTGGTTTCGTCAACA</th>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>28.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>33.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E2L8_TTTGTTGGTTAGTTCG</th>\n",
       "      <td>24.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>78.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>851.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>...</td>\n",
       "      <td>12.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>49183 rows × 217 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       CD39  Rat-IgG1-1  CD107a   CD62P  TCR-2  CD30   CD31  \\\n",
       "L1_AAACCCATCTCCCTAG     5.0        12.0     9.0    88.0   48.0   3.0   40.0   \n",
       "L1_AAACCCATCTGCGGAC     5.0         3.0    10.0    66.0   15.0   1.0   39.0   \n",
       "L1_AAACGAAAGGCCCAAA    34.0        15.0    37.0   357.0   14.0   4.0  360.0   \n",
       "L1_AAACGAAAGTTACTCG     6.0         5.0    11.0    87.0   15.0   4.0   38.0   \n",
       "L1_AAACGAACACAGCATT     3.0        21.0    33.0    65.0    8.0  10.0   64.0   \n",
       "...                     ...         ...     ...     ...    ...   ...    ...   \n",
       "E2L8_TTTGGTTAGGCCTGCT   3.0         5.0     9.0    67.0    4.0   0.0   13.0   \n",
       "E2L8_TTTGGTTAGTCAGCGA  36.0         9.0    19.0   317.0    5.0   2.0  296.0   \n",
       "E2L8_TTTGGTTAGTGCCTCG  42.0         4.0    76.0  1050.0   10.0   1.0  396.0   \n",
       "E2L8_TTTGGTTTCGTCAACA   1.0         4.0     6.0    80.0   12.0   0.0   28.0   \n",
       "E2L8_TTTGTTGGTTAGTTCG  24.0         5.0    13.0    78.0    4.0   4.0   37.0   \n",
       "\n",
       "                       CD34    CD35  CD36  ...  CD119  CD169   CD28  CD161  \\\n",
       "L1_AAACCCATCTCCCTAG     6.0    77.0   2.0  ...    1.0    3.0   68.0    1.0   \n",
       "L1_AAACCCATCTGCGGAC    11.0    54.0   4.0  ...    6.0    1.0   56.0    0.0   \n",
       "L1_AAACGAAAGGCCCAAA    24.0   722.0  12.0  ...   19.0    5.0   32.0    4.0   \n",
       "L1_AAACGAAAGTTACTCG     8.0    66.0   3.0  ...    3.0    3.0  108.0    7.0   \n",
       "L1_AAACGAACACAGCATT     9.0    55.0   2.0  ...    5.0    4.0   51.0   18.0   \n",
       "...                     ...     ...   ...  ...    ...    ...    ...    ...   \n",
       "E2L8_TTTGGTTAGGCCTGCT   1.0    32.0   1.0  ...    3.0    2.0   37.0    1.0   \n",
       "E2L8_TTTGGTTAGTCAGCGA  11.0   646.0  19.0  ...   18.0   51.0   20.0    5.0   \n",
       "E2L8_TTTGGTTAGTGCCTCG  12.0  3084.0  23.0  ...   32.0   52.0   15.0    5.0   \n",
       "E2L8_TTTGGTTTCGTCAACA   1.0    41.0   0.0  ...    5.0    1.0   33.0    2.0   \n",
       "E2L8_TTTGTTGGTTAGTTCG   5.0   851.0   4.0  ...   12.0    1.0   14.0    1.0   \n",
       "\n",
       "                       CD163  CD138  CD164  CD144  CD202b  CD11c  \n",
       "L1_AAACCCATCTCCCTAG      8.0   16.0    6.0    8.0    15.0   21.0  \n",
       "L1_AAACCCATCTGCGGAC      4.0   13.0    0.0   10.0    10.0   16.0  \n",
       "L1_AAACGAAAGGCCCAAA     14.0   27.0    2.0   19.0    23.0   70.0  \n",
       "L1_AAACGAAAGTTACTCG      3.0   13.0    1.0    9.0    12.0   13.0  \n",
       "L1_AAACGAACACAGCATT      6.0   52.0    4.0    9.0    45.0   46.0  \n",
       "...                      ...    ...    ...    ...     ...    ...  \n",
       "E2L8_TTTGGTTAGGCCTGCT    2.0    8.0    0.0    2.0     7.0    7.0  \n",
       "E2L8_TTTGGTTAGTCAGCGA    7.0   18.0    5.0    7.0     4.0   47.0  \n",
       "E2L8_TTTGGTTAGTGCCTCG   10.0   25.0    9.0    5.0    15.0  109.0  \n",
       "E2L8_TTTGGTTTCGTCAACA    1.0    8.0    4.0    2.0     6.0    8.0  \n",
       "E2L8_TTTGTTGGTTAGTTCG    5.0    9.0   23.0    2.0     2.0   15.0  \n",
       "\n",
       "[49183 rows x 217 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# from https://yoseflab.github.io/scvi-tools-reproducibility/scarches_totalvi_seurat_data/\n",
    "protein_df = pd.DataFrame(index=cite.obs_names)\n",
    "ref_proteins = cite.var_names\n",
    "for p in ref_proteins:\n",
    "    if p.split(\"-\")[-1] == \"1\" or p.split(\"-\")[-1] == \"2\":\n",
    "        root = p.split(\"-\")[0]\n",
    "        if root not in [\"Notch\", \"TCR\"]:\n",
    "            try:\n",
    "                protein_df[root] = (\n",
    "                    cite[:, root + \"-1\"].layers['count']\n",
    "                    + cite[:, root + \"-2\"].layers['count']\n",
    "                )\n",
    "                print(root)\n",
    "            except:\n",
    "                protein_df[p] = cite[:, p].layers['count']\n",
    "        else:\n",
    "            protein_df[p] = cite[:, p].layers['count']\n",
    "    else:\n",
    "        protein_df[p] = cite[:, p].layers['count']\n",
    "protein_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "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>CD39</th>\n",
       "      <th>Rat-IgG1-1</th>\n",
       "      <th>CD107a</th>\n",
       "      <th>CD62P</th>\n",
       "      <th>TCR-2</th>\n",
       "      <th>CD30</th>\n",
       "      <th>CD31</th>\n",
       "      <th>CD34</th>\n",
       "      <th>CD35</th>\n",
       "      <th>CD36</th>\n",
       "      <th>...</th>\n",
       "      <th>CD119</th>\n",
       "      <th>CD169</th>\n",
       "      <th>CD28</th>\n",
       "      <th>CD161</th>\n",
       "      <th>CD163</th>\n",
       "      <th>CD138</th>\n",
       "      <th>CD164</th>\n",
       "      <th>CD144</th>\n",
       "      <th>CD202b</th>\n",
       "      <th>CD11c</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>L1_AAACCCATCTCCCTAG</th>\n",
       "      <td>5.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>88.0</td>\n",
       "      <td>48.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>77.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>68.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L1_AAACCCATCTGCGGAC</th>\n",
       "      <td>5.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>39.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>54.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>...</td>\n",
       "      <td>6.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>16.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L1_AAACGAAAGGCCCAAA</th>\n",
       "      <td>34.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>357.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>722.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>...</td>\n",
       "      <td>19.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>70.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L1_AAACGAAAGTTACTCG</th>\n",
       "      <td>6.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>108.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L1_AAACGAACACAGCATT</th>\n",
       "      <td>3.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>33.0</td>\n",
       "      <td>65.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>55.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>51.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>46.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E2L8_TTTGGTTAGGCCTGCT</th>\n",
       "      <td>3.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E2L8_TTTGGTTAGTCAGCGA</th>\n",
       "      <td>36.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>317.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>296.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>646.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>...</td>\n",
       "      <td>18.0</td>\n",
       "      <td>51.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E2L8_TTTGGTTAGTGCCTCG</th>\n",
       "      <td>42.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>1050.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>396.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>3084.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>...</td>\n",
       "      <td>32.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>25.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>109.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E2L8_TTTGGTTTCGTCAACA</th>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>28.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>33.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E2L8_TTTGTTGGTTAGTTCG</th>\n",
       "      <td>24.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>78.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>851.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>...</td>\n",
       "      <td>12.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>49183 rows × 217 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       CD39  Rat-IgG1-1  CD107a   CD62P  TCR-2  CD30   CD31  \\\n",
       "L1_AAACCCATCTCCCTAG     5.0        12.0     9.0    88.0   48.0   3.0   40.0   \n",
       "L1_AAACCCATCTGCGGAC     5.0         3.0    10.0    66.0   15.0   1.0   39.0   \n",
       "L1_AAACGAAAGGCCCAAA    34.0        15.0    37.0   357.0   14.0   4.0  360.0   \n",
       "L1_AAACGAAAGTTACTCG     6.0         5.0    11.0    87.0   15.0   4.0   38.0   \n",
       "L1_AAACGAACACAGCATT     3.0        21.0    33.0    65.0    8.0  10.0   64.0   \n",
       "...                     ...         ...     ...     ...    ...   ...    ...   \n",
       "E2L8_TTTGGTTAGGCCTGCT   3.0         5.0     9.0    67.0    4.0   0.0   13.0   \n",
       "E2L8_TTTGGTTAGTCAGCGA  36.0         9.0    19.0   317.0    5.0   2.0  296.0   \n",
       "E2L8_TTTGGTTAGTGCCTCG  42.0         4.0    76.0  1050.0   10.0   1.0  396.0   \n",
       "E2L8_TTTGGTTTCGTCAACA   1.0         4.0     6.0    80.0   12.0   0.0   28.0   \n",
       "E2L8_TTTGTTGGTTAGTTCG  24.0         5.0    13.0    78.0    4.0   4.0   37.0   \n",
       "\n",
       "                       CD34    CD35  CD36  ...  CD119  CD169   CD28  CD161  \\\n",
       "L1_AAACCCATCTCCCTAG     6.0    77.0   2.0  ...    1.0    3.0   68.0    1.0   \n",
       "L1_AAACCCATCTGCGGAC    11.0    54.0   4.0  ...    6.0    1.0   56.0    0.0   \n",
       "L1_AAACGAAAGGCCCAAA    24.0   722.0  12.0  ...   19.0    5.0   32.0    4.0   \n",
       "L1_AAACGAAAGTTACTCG     8.0    66.0   3.0  ...    3.0    3.0  108.0    7.0   \n",
       "L1_AAACGAACACAGCATT     9.0    55.0   2.0  ...    5.0    4.0   51.0   18.0   \n",
       "...                     ...     ...   ...  ...    ...    ...    ...    ...   \n",
       "E2L8_TTTGGTTAGGCCTGCT   1.0    32.0   1.0  ...    3.0    2.0   37.0    1.0   \n",
       "E2L8_TTTGGTTAGTCAGCGA  11.0   646.0  19.0  ...   18.0   51.0   20.0    5.0   \n",
       "E2L8_TTTGGTTAGTGCCTCG  12.0  3084.0  23.0  ...   32.0   52.0   15.0    5.0   \n",
       "E2L8_TTTGGTTTCGTCAACA   1.0    41.0   0.0  ...    5.0    1.0   33.0    2.0   \n",
       "E2L8_TTTGTTGGTTAGTTCG   5.0   851.0   4.0  ...   12.0    1.0   14.0    1.0   \n",
       "\n",
       "                       CD163  CD138  CD164  CD144  CD202b  CD11c  \n",
       "L1_AAACCCATCTCCCTAG      8.0   16.0    6.0    8.0    15.0   21.0  \n",
       "L1_AAACCCATCTGCGGAC      4.0   13.0    0.0   10.0    10.0   16.0  \n",
       "L1_AAACGAAAGGCCCAAA     14.0   27.0    2.0   19.0    23.0   70.0  \n",
       "L1_AAACGAAAGTTACTCG      3.0   13.0    1.0    9.0    12.0   13.0  \n",
       "L1_AAACGAACACAGCATT      6.0   52.0    4.0    9.0    45.0   46.0  \n",
       "...                      ...    ...    ...    ...     ...    ...  \n",
       "E2L8_TTTGGTTAGGCCTGCT    2.0    8.0    0.0    2.0     7.0    7.0  \n",
       "E2L8_TTTGGTTAGTCAGCGA    7.0   18.0    5.0    7.0     4.0   47.0  \n",
       "E2L8_TTTGGTTAGTGCCTCG   10.0   25.0    9.0    5.0    15.0  109.0  \n",
       "E2L8_TTTGGTTTCGTCAACA    1.0    8.0    4.0    2.0     6.0    8.0  \n",
       "E2L8_TTTGTTGGTTAGTTCG    5.0    9.0   23.0    2.0     2.0   15.0  \n",
       "\n",
       "[49183 rows x 217 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "protein_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 49183 × 217\n",
       "    obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes'\n",
       "    layers: 'count'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cite1 = sc.AnnData(protein_df)\n",
    "cite1.obs = cite.obs.copy()\n",
    "cite1.layers['count'] = cite1.X.copy()\n",
    "cite1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 97039 × 192\n",
       "    obs: 'sample_id', 'n_genes', 'n_genes_by_counts', 'total_counts', 'total_counts_mt', 'pct_counts_mt', 'full_clustering', 'initial_clustering', 'Resample', 'Collection_Day', 'Sex', 'Age_interval', 'Swab_result', 'Status', 'Smoker', 'Status_on_day_collection', 'Status_on_day_collection_summary', 'Days_from_onset', 'Site', 'time_after_LPS', 'Worst_Clinical_Status', 'Outcome', 'patient_id'\n",
       "    var: 'feature_types'\n",
       "    uns: 'hvg', 'leiden', 'neighbors', 'pca', 'umap'\n",
       "    obsm: 'X_pca', 'X_pca_harmony', 'X_umap'\n",
       "    layers: 'count'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cite3 = sc.read('../data/haniffa-2021/protein_healthy.h5ad')\n",
    "cite3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 527286 × 192\n",
       "    obs: 'sample_id', 'n_genes', 'n_genes_by_counts', 'total_counts', 'total_counts_mt', 'pct_counts_mt', 'full_clustering', 'initial_clustering', 'Resample', 'Collection_Day', 'Sex', 'Age_interval', 'Swab_result', 'Status', 'Smoker', 'Status_on_day_collection', 'Status_on_day_collection_summary', 'Days_from_onset', 'Site', 'time_after_LPS', 'Worst_Clinical_Status', 'Outcome', 'patient_id'\n",
       "    var: 'feature_types'\n",
       "    uns: 'hvg', 'leiden', 'neighbors', 'pca', 'umap'\n",
       "    obsm: 'X_pca', 'X_pca_harmony', 'X_umap'\n",
       "    layers: 'count'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cite_query2 = sc.read('../data/haniffa-2021/protein_covid.h5ad')\n",
    "cite_query2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['CD80', 'CD86', 'CD274', 'PDCD1LG2', 'ICOSLG', 'ITGAM', 'OX40L',\n",
       "       'TNFSF9', 'PVR', 'NECTIN2',\n",
       "       ...\n",
       "       'CD101', 'IL21R', 'C5AR1', 'HLA-F', 'NLRP2', 'Podocalyxin', 'GGT1',\n",
       "       'c-Met', 'LIGHT', 'DR3'],\n",
       "      dtype='object', length=192)"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cite3.var_names = [name[3:] for name in cite3.var_names]\n",
    "cite3.var_names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['CD80', 'CD86', 'CD274', 'PDCD1LG2', 'ICOSLG', 'ITGAM', 'OX40L',\n",
       "       'TNFSF9', 'PVR', 'NECTIN2',\n",
       "       ...\n",
       "       'CD101', 'IL21R', 'C5AR1', 'HLA-F', 'NLRP2', 'Podocalyxin', 'GGT1',\n",
       "       'c-Met', 'LIGHT', 'DR3'],\n",
       "      dtype='object', length=192)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cite_query2.var_names = [name[3:] for name in cite_query2.var_names]\n",
    "cite_query2.var_names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "61"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "common_protein = list(set(cite1.var_names) & set(cite3.var_names) & set(cite_query2.var_names))\n",
    "len(common_protein)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "cite1 = cite1[:, common_protein].copy()\n",
    "cite3 = cite3[:, common_protein].copy()\n",
    "cite_query2 = cite_query2[:, common_protein].copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "def clr_normalize_each_cell(adata, inplace=True):\n",
    "    \"\"\"Normalize count vector for each cell, i.e. for each row of .X\"\"\"\n",
    "\n",
    "    import numpy as np\n",
    "    import scipy\n",
    "\n",
    "    def seurat_clr(x):\n",
    "        s = np.sum(np.log1p(x[x > 0]))\n",
    "        exp = np.exp(s / len(x))\n",
    "        return np.log1p(x / exp)\n",
    "\n",
    "    if not inplace:\n",
    "        adata = adata.copy()\n",
    "\n",
    "    # apply to dense or sparse matrix, along axis. returns dense matrix\n",
    "    adata.X = np.apply_along_axis(\n",
    "        seurat_clr, 1, (adata.X.A if scipy.sparse.issparse(adata.X) else adata.X)\n",
    "    )\n",
    "    return adata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "cite1 = clr_normalize_each_cell(cite1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "cite3.X = cite3.layers['count']\n",
    "cite_query2.X = cite_query2.layers['count']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "cite3 = clr_normalize_each_cell(cite3)\n",
    "cite_query2 = clr_normalize_each_cell(cite_query2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Prep ATAC-seq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 10000 × 40086\n",
       "    obs: 'cell_type'\n",
       "    layers: 'binary'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "atac2 = sc.read('../data/10xpbmc10k-2020/peaks.h5ad')\n",
    "atac2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 6334 × 38313\n",
       "    obs: 'nb_features', 'cell_type', 'batch'\n",
       "    var: 'feature_types', 'genome', 'gene_ids-0', 'n_cells-0', 'commonness-0', 'prop_shared_cells-0', 'variability_score-0', 'gene_ids-1', 'n_cells-1', 'commonness-1', 'prop_shared_cells-1', 'variability_score-1'\n",
       "    layers: 'binary'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "atac_query1 = sc.read('../data/sanger-2021/peaks.h5ad')\n",
    "atac_query1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "atac_query1.obs['Batch'] = atac_query1.obs['batch']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "def merge(A, B, chrom):\n",
    "        new_names_A = []\n",
    "        new_names_B = []\n",
    "        \n",
    "        old_names_A = []\n",
    "        old_names_B = []\n",
    "        \n",
    "        A.sort(key=lambda x: x[0])\n",
    "        B.sort(key=lambda x: x[0])\n",
    "\n",
    "        merged = []\n",
    "        i = j = 0\n",
    "        \n",
    "        while i < len(A) and j < len(B):\n",
    "            \n",
    "            if (A[i][0] >= B[j][0] and A[i][0] <= B[j][1]) or (B[j][0] >= A[i][0] and B[j][0] <= A[i][1]):\n",
    "                left = min(A[i][0], B[j][0])\n",
    "                right = max(A[i][1], B[j][1])\n",
    "                merged.append([left, right])\n",
    "                new_names_A.append(f'{chrom}:{left}-{right}')\n",
    "                new_names_B.append(f'{chrom}:{left}-{right}')\n",
    "                old_names_A.append(f'{chrom}:{A[i][0]}-{A[i][1]}')\n",
    "                old_names_B.append(f'{chrom}:{B[j][0]}-{B[j][1]}')\n",
    "                i+=1 \n",
    "                j+=1\n",
    "            elif B[j][1] < A[i][0]:\n",
    "                new_names_B.append('0') # '0' as a placeholder to be dropped later\n",
    "                old_names_B.append(f'{chrom}:{B[j][0]}-{B[j][1]}')\n",
    "                j+=1\n",
    "            else:\n",
    "                new_names_A.append('0')\n",
    "                old_names_A.append(f'{chrom}:{A[i][0]}-{A[i][1]}')\n",
    "                i+=1\n",
    "        return new_names_A, new_names_B, old_names_A, old_names_B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "def prepare_peaks(adata):\n",
    "    peaks = {}\n",
    "    \n",
    "    for ch in set([name.split(':')[0] for name in adata.var_names]):\n",
    "        peaks[ch] = []\n",
    "        \n",
    "    for name in adata.var_names:\n",
    "        ch = name.split(\":\")[0]\n",
    "        pos = name.split(\":\")[1].split('-')\n",
    "        pos = [int(n) for n in pos]\n",
    "        peaks[ch].append(pos)\n",
    "        \n",
    "    return peaks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "def merge_and_rename_peaks(adata1, adata2, verbose=False):\n",
    "    # create dict with peaks of format {'chr': [[peak1_start, peak1_end], ..., [peakn_start, peakn_end]], ...}\n",
    "    peaks1 = prepare_peaks(adata1)\n",
    "    peaks2 = prepare_peaks(adata2)\n",
    "    \n",
    "    # find chromosomes present in both adatas\n",
    "    common_chrs = peaks1.keys() & peaks2.keys()\n",
    "    \n",
    "    # find new peak intervals\n",
    "    adata1_new_var_names = []\n",
    "    adata2_new_var_names = []\n",
    "\n",
    "    adata1_old_var_names = []\n",
    "    adata2_old_var_names = []\n",
    "\n",
    "    for chrom in common_chrs:\n",
    "        if verbose:\n",
    "            print(f'Processing chromosome {chrom}...')\n",
    "        \n",
    "        new_names1, new_names2, old_names1, old_names2 = merge(peaks1[chrom], peaks2[chrom], chrom)\n",
    "        \n",
    "        adata1_new_var_names.extend(new_names1)\n",
    "        adata2_new_var_names.extend(new_names2)\n",
    "        \n",
    "        adata1_old_var_names.extend(old_names1)\n",
    "        adata2_old_var_names.extend(old_names2)\n",
    "    \n",
    "    # create dataframes with new var names\n",
    "    df1 = pd.DataFrame(list(zip(adata1_old_var_names, adata1_new_var_names)), columns=['old_var_names', 'new_var_names'])\n",
    "    df1 = df1.set_index('old_var_names')\n",
    "    \n",
    "    df2 = pd.DataFrame(list(zip(adata2_old_var_names, adata2_new_var_names)), columns=['old_var_names', 'new_var_names'])\n",
    "    df2 = df2.set_index('old_var_names')\n",
    "    \n",
    "    # fill chromosomes that were not in the common set with '0'\n",
    "    df1 = pd.DataFrame(index=adata1.var_names).join(df1).fillna('0')\n",
    "    df2 = pd.DataFrame(index=adata2.var_names).join(df2).fillna('0')\n",
    "\n",
    "    # join new var names with adata.var\n",
    "    adata1.var = adata1.var.join(df1[['new_var_names']])\n",
    "    adata2.var = adata2.var.join(df2[['new_var_names']])\n",
    "    \n",
    "    # drop peaks with '0'\n",
    "    adata1 = adata1[:, adata1.var['new_var_names'] != '0']\n",
    "    adata2 = adata2[:, adata2.var['new_var_names'] != '0']\n",
    "    \n",
    "    # rename the peaks\n",
    "    adata1.var_names = adata1.var['new_var_names']\n",
    "    adata2.var_names = adata2.var['new_var_names']\n",
    "    \n",
    "    del adata1.var['new_var_names']\n",
    "    del adata2.var['new_var_names']\n",
    "    \n",
    "    return adata1, adata2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "atac2, atac_query1 = merge_and_rename_peaks(atac2, atac_query1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 10000 × 32640\n",
       "    obs: 'cell_type'\n",
       "    layers: 'binary'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "atac2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AnnData object with n_obs × n_vars = 6334 × 32640\n",
       "    obs: 'nb_features', 'cell_type', 'batch', 'Batch'\n",
       "    var: 'feature_types', 'genome', 'gene_ids-0', 'n_cells-0', 'commonness-0', 'prop_shared_cells-0', 'variability_score-0', 'gene_ids-1', 'n_cells-1', 'commonness-1', 'prop_shared_cells-1', 'variability_score-1'\n",
       "    layers: 'binary'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "atac_query1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "atac2.X = atac2.layers['binary']\n",
    "sc.pp.normalize_total(atac2, target_sum=1e4)\n",
    "sc.pp.log1p(atac2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "atac_query1.X = atac_query1.layers['binary']\n",
    "sc.pp.normalize_total(atac_query1, target_sum=1e4)\n",
    "sc.pp.log1p(atac_query1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AAACAGCCAAGGAATC-1       CD4 naive\n",
       "AAACAGCCAATCCCTT-1    CD4 memory T\n",
       "AAACAGCCAATGCGCT-1       CD4 naive\n",
       "AAACAGCCAGTAGGTG-1       CD4 naive\n",
       "AAACAGCCAGTTTACG-1    CD4 memory T\n",
       "                          ...     \n",
       "TTTGTTGGTGACATGC-1       CD8 naive\n",
       "TTTGTTGGTGTTAAAC-1       CD8 naive\n",
       "TTTGTTGGTTAGGATT-1              NK\n",
       "TTTGTTGGTTGGTTAG-1    CD4 memory T\n",
       "TTTGTTGGTTTGCAGA-1    CD8 memory T\n",
       "Name: cell_type, Length: 10000, dtype: category\n",
       "Categories (11, object): ['B', 'CD4 memory T', 'CD4 naive', 'CD8 memory T', ..., 'NK', 'Non-classical monocytes', 'Unconventional T cells', 'pDC']"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "atac2.obs.cell_type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AAACAGCCAAGGAATC-1-1         naive CD4 T cells\n",
       "AAACAGCCAATCCCTT-1-1        memory CD4 T cells\n",
       "AAACAGCCAATGCGCT-1-1         naive CD4 T cells\n",
       "AAACAGCCAGTAGGTG-1-1         naive CD4 T cells\n",
       "AAACAGCCAGTTTACG-1-1        memory CD4 T cells\n",
       "                                 ...          \n",
       "TTTGTTGGTGACATGC-1-1         naive CD8 T cells\n",
       "TTTGTTGGTGTTAAAC-1-1         naive CD8 T cells\n",
       "TTTGTTGGTTAGGATT-1-1    CD56 (bright) NK cells\n",
       "TTTGTTGGTTGGTTAG-1-1        memory CD4 T cells\n",
       "TTTGTTGGTTTGCAGA-1-1      effector CD8 T cells\n",
       "Name: cell_type, Length: 10025, dtype: object"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna2.obs.cell_type"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Clean up"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['B', 'CD4 T', 'CD8 T', 'DC', 'Mono', 'NK', 'other', 'other T'], dtype='object')"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna1.obs['celltype.l1'].astype('category').cat.categories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['ASDC', 'B intermediate', 'B memory', 'B naive', 'CD14 Mono',\n",
       "       'CD16 Mono', 'CD4 CTL', 'CD4 Naive', 'CD4 Proliferating', 'CD4 TCM',\n",
       "       'CD4 TEM', 'CD8 Naive', 'CD8 Proliferating', 'CD8 TCM', 'CD8 TEM',\n",
       "       'Doublet', 'Eryth', 'HSPC', 'ILC', 'MAIT', 'NK', 'NK Proliferating',\n",
       "       'NK_CD56bright', 'Plasmablast', 'Platelet', 'Treg', 'cDC1', 'cDC2',\n",
       "       'dnT', 'gdT', 'pDC'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna1.obs['celltype.l2'].astype('category').cat.categories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['CD56 (bright) NK cells', 'CD56 (dim) NK cells', 'MAIT T cells',\n",
       "       'classical monocytes', 'effector CD8 T cells', 'intermediate monocytes',\n",
       "       'memory B cells', 'memory CD4 T cells', 'myeloid DC', 'naive B cells',\n",
       "       'naive CD4 T cells', 'naive CD8 T cells', 'non-classical monocytes',\n",
       "       'plasmacytoid DC'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna2.obs['cell_type'].astype('category').cat.categories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['ASDC', 'B_exhausted', 'B_immature', 'B_naive', 'B_non-switched_memory',\n",
       "       'B_switched_memory', 'C1_CD16_mono', 'CD14_mono', 'CD16_mono', 'CD4.CM',\n",
       "       'CD4.EM', 'CD4.IL22', 'CD4.Naive', 'CD4.Prolif', 'CD4.Tfh', 'CD4.Th1',\n",
       "       'CD4.Th17', 'CD4.Th2', 'CD8.EM', 'CD8.Naive', 'CD8.Prolif', 'CD8.TE',\n",
       "       'CD83_CD14_mono', 'DC1', 'DC2', 'DC3', 'DC_prolif', 'HSC_CD38neg',\n",
       "       'HSC_CD38pos', 'HSC_erythroid', 'HSC_myeloid', 'HSC_prolif', 'ILC1_3',\n",
       "       'ILC2', 'MAIT', 'Mono_prolif', 'NKT', 'NK_16hi', 'NK_56hi', 'NK_prolif',\n",
       "       'Plasma_cell_IgA', 'Plasma_cell_IgG', 'Plasma_cell_IgM', 'Plasmablast',\n",
       "       'Platelets', 'RBC', 'Treg', 'gdT', 'pDC'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna3.obs['full_clustering'].astype('category').cat.categories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['B_cell', 'CD14', 'CD16', 'CD4', 'CD8', 'DCs', 'HSC', 'Lymph_prolif',\n",
       "       'MAIT', 'Mono_prolif', 'NK_16hi', 'NK_56hi', 'Plasmablast', 'Platelets',\n",
       "       'RBC', 'Treg', 'gdT', 'pDC'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna3.obs['initial_clustering'].astype('category').cat.categories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Bcell Memory', 'Bcell Naive', 'CD14 IL1B Monocyte', 'CD14 Monocyte',\n",
       "       'CD16 Monocyte', 'CD4', 'CD4 Naive', 'CD8 Effector', 'CD8 Naive',\n",
       "       'Cycling', 'GD Tcell', 'ILC', 'MAIT', 'NK', 'Plasmablasts', 'Treg',\n",
       "       'cDC', 'pDC'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna_query1.obs['cell_type'].astype('category').cat.categories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_cell_types1 = {\n",
    "    'ASDC': 'ASDC', \n",
    "    'B intermediate': 'B cell', \n",
    "    'B memory': 'B cell', \n",
    "    'B naive': 'B cell', \n",
    "    'CD14 Mono': 'CD14 Monocyte',\n",
    "    'CD16 Mono': 'CD16 Monocyte', \n",
    "    'CD4 CTL': 'T CD4 memory', \n",
    "    'CD4 Naive': 'T CD4 naive',\n",
    "    'CD4 Proliferating': 'T CD4 memory', \n",
    "    'CD4 TCM': 'T CD4 memory',\n",
    "    'CD4 TEM': 'T CD4 memory', \n",
    "    'CD8 Naive': 'T CD8 naive', \n",
    "    'CD8 Proliferating': 'T CD8 memory', \n",
    "    'CD8 TCM': 'T CD8 memory', \n",
    "    'CD8 TEM': 'T CD8 memory',\n",
    "    'Doublet': 'other', \n",
    "    'Eryth': 'RBC', \n",
    "    'HSPC': 'HSPC', \n",
    "    'ILC': 'ILC', \n",
    "    'MAIT': 'MAIT', \n",
    "    'NK': 'NK', \n",
    "    'NK Proliferating': 'NK',\n",
    "    'NK_CD56bright': 'NK', \n",
    "    'Plasmablast': 'Plasmablast', \n",
    "    'Platelet': 'Platelet', \n",
    "    'Treg': 'Treg', \n",
    "    'cDC1': 'cDC', \n",
    "    'cDC2': 'cDC',\n",
    "    'dnT': 'other T',\n",
    "    'gdT': 'gdT', \n",
    "    'pDC': 'pDC'\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_cell_types2 = {\n",
    "    'CD56 (bright) NK cells': 'NK', \n",
    "    'CD56 (dim) NK cells': 'NK', \n",
    "    'MAIT T cells': 'MAIT',\n",
    "    'classical monocytes': 'CD14 Monocyte', \n",
    "    'effector CD8 T cells': 'T CD8 memory', \n",
    "    'intermediate monocytes': 'CD14 Monocyte',\n",
    "    'memory B cells': 'B cell', \n",
    "    'memory CD4 T cells': 'T CD4 memory', \n",
    "    'myeloid DC': 'cDC', \n",
    "    'naive B cells': 'B cell',\n",
    "    'naive CD4 T cells': 'T CD4 naive', \n",
    "    'naive CD8 T cells': 'T CD8 naive', \n",
    "    'non-classical monocytes': 'CD16 Monocyte',\n",
    "    'plasmacytoid DC': 'pDC'\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_cell_types3 = {\n",
    "    'ASDC': 'ASDC', \n",
    "    'B_exhausted': 'B cell', \n",
    "    'B_immature': 'B cell', \n",
    "    'B_naive': 'B cell', \n",
    "    'B_non-switched_memory': 'B cell',\n",
    "    'B_switched_memory' : 'B cell', \n",
    "    'C1_CD16_mono': 'CD16 Monocyte', \n",
    "    'CD14_mono': 'CD14 Monocyte', \n",
    "    'CD16_mono': 'CD16 Monocyte', \n",
    "    'CD4.CM': 'T CD4 memory',\n",
    "    'CD4.EM': 'T CD4 memory', \n",
    "    'CD4.IL22': 'T CD4 memory', \n",
    "    'CD4.Naive': 'T CD4 naive', \n",
    "    'CD4.Prolif': 'T CD4 memory', \n",
    "    'CD4.Tfh': 'T CD4 memory', \n",
    "    'CD4.Th1': 'T CD4 memory',\n",
    "    'CD4.Th17': 'T CD4 memory', \n",
    "    'CD4.Th2': 'T CD4 memory', \n",
    "    'CD8.EM': 'T CD8 memory', \n",
    "    'CD8.Naive': 'T CD8 naive',\n",
    "    'CD8.Prolif': 'T CD8 memory', \n",
    "    'CD8.TE': 'T CD8 memory',\n",
    "    'CD83_CD14_mono': 'CD14 Monocyte', \n",
    "    'DC1': 'cDC', \n",
    "    'DC2': 'cDC', \n",
    "    'DC3': 'cDC', \n",
    "    'DC_prolif': 'cDC', \n",
    "    'HSC_CD38neg': 'HSPC',\n",
    "    'HSC_CD38pos': 'HSPC', \n",
    "    'HSC_erythroid': 'HSPC', \n",
    "    'HSC_myeloid': 'HSPC', \n",
    "    'HSC_prolif': 'HSPC', \n",
    "    'ILC1_3': 'ILC',\n",
    "    'ILC2': 'ILC', \n",
    "    'MAIT': 'MAIT', \n",
    "    'Mono_prolif': 'other', \n",
    "    'NKT': 'other T', \n",
    "    'NK_16hi': 'NK', \n",
    "    'NK_56hi': 'NK', \n",
    "    'NK_prolif': 'NK',\n",
    "    'Plasma_cell_IgA': 'B cell', \n",
    "    'Plasma_cell_IgG': 'B cell', \n",
    "    'Plasma_cell_IgM': 'B cell', \n",
    "    'Plasmablast': 'Plasmablast',\n",
    "    'Platelets': 'Platelet', \n",
    "    'RBC': 'RBC', \n",
    "    'Treg': 'Treg', \n",
    "    'gdT': 'gdT', \n",
    "    'pDC': 'pDC'\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_cell_types_query1 = {\n",
    "    'Bcell Memory': 'B cell', \n",
    "    'Bcell Naive': 'B cell', \n",
    "    'CD4': 'T CD4 memory', \n",
    "    'CD4 Naive': 'T CD4 naive', \n",
    "    'CD8 Effector': 'T CD8 memory',\n",
    "    'CD8 Naive': 'T CD8 naive', \n",
    "    'CD14 IL1B Monocyte': 'CD14 Monocyte', \n",
    "    'CD14 Monocyte': 'CD14 Monocyte', \n",
    "    'CD16 Monocyte': 'CD16 Monocyte',\n",
    "    'Cycling': 'other', \n",
    "    'GD Tcell': 'gdT', \n",
    "    'ILC': 'ILC', \n",
    "    'MAIT': 'MAIT', \n",
    "    'NK': 'NK', \n",
    "    'Plasmablasts': 'Plasmablast', \n",
    "    'Treg': 'Treg',\n",
    "    'cDC': 'cDC',\n",
    "    'pDC': 'pDC'\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'B_malignant', 'HSC_MK'}"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "set(scrna_query2.obs['full_clustering'].astype('category').cat.categories) - set(scrna3.obs['full_clustering'].astype('category').cat.categories)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_cell_types_query2 = new_cell_types3.copy()\n",
    "new_cell_types_query2['B_malignant'] = 'B cell'\n",
    "new_cell_types_query2['HSC_MK'] = 'HSPC'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "scrna2.obs_names = [name[:-2] for name in scrna2.obs_names]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "scrna2 = scrna2[atac2.obs_names]\n",
    "atac2.obs['cell_type'] = scrna2.obs['cell_type']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_cell_types_scrna1 = [new_cell_types1[name] for name in scrna1.obs['celltype.l2']]\n",
    "new_cell_types_cite1 = [new_cell_types1[name] for name in cite1.obs['celltype.l2']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_cell_types_scrna2 = [new_cell_types2[name] for name in scrna2.obs['cell_type']]\n",
    "new_cell_types_atac2 = [new_cell_types2[name] for name in atac2.obs['cell_type']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_cell_types_scrna3 = [new_cell_types3[name] for name in scrna3.obs['full_clustering']]\n",
    "new_cell_types_cite3 = [new_cell_types3[name] for name in cite3.obs['full_clustering']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_cell_types_scrna_query2 = [new_cell_types_query2[name] for name in scrna_query2.obs['full_clustering']]\n",
    "new_cell_types_cite_query2 = [new_cell_types_query2[name] for name in cite_query2.obs['full_clustering']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_cell_types_scrna_query1 = [new_cell_types_query1[name] for name in scrna_query1.obs['cell_type']]\n",
    "new_cell_types_atac_query1 = [new_cell_types_query1[name] for name in atac_query1.obs['cell_type']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Trying to set attribute `.obs` of view, copying.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Index(['ASDC', 'B cell', 'CD14 Monocyte', 'CD16 Monocyte', 'HSPC', 'ILC',\n",
       "       'MAIT', 'NK', 'Plasmablast', 'Platelet', 'RBC', 'T CD4 memory',\n",
       "       'T CD4 naive', 'T CD8 memory', 'T CD8 naive', 'Treg', 'cDC', 'gdT',\n",
       "       'other', 'other T', 'pDC'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna1.obs['cell_type'] = new_cell_types_scrna1\n",
    "cite1.obs['cell_type'] = new_cell_types_cite1\n",
    "scrna1.obs['cell_type'] = scrna1.obs['cell_type'].astype('category')\n",
    "cite1.obs['cell_type'] = cite1.obs['cell_type'].astype('category')\n",
    "cite1.obs['cell_type'].cat.categories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Trying to set attribute `.obs` of view, copying.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Index(['ASDC', 'B cell', 'CD14 Monocyte', 'CD16 Monocyte', 'HSPC', 'ILC',\n",
       "       'MAIT', 'NK', 'Plasmablast', 'Platelet', 'RBC', 'T CD4 memory',\n",
       "       'T CD4 naive', 'T CD8 memory', 'T CD8 naive', 'Treg', 'cDC', 'gdT',\n",
       "       'other', 'other T', 'pDC'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna3.obs['cell_type'] = new_cell_types_scrna3\n",
    "cite3.obs['cell_type'] = new_cell_types_cite3\n",
    "scrna3.obs['cell_type'] = scrna3.obs['cell_type'].astype('category')\n",
    "cite3.obs['cell_type'] = cite3.obs['cell_type'].astype('category')\n",
    "cite3.obs['cell_type'].cat.categories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Trying to set attribute `.obs` of view, copying.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Index(['B cell', 'CD14 Monocyte', 'CD16 Monocyte', 'MAIT', 'NK',\n",
       "       'T CD4 memory', 'T CD4 naive', 'T CD8 memory', 'T CD8 naive', 'cDC',\n",
       "       'pDC'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna2.obs['old_cell_type'] = scrna2.obs['cell_type'].copy()\n",
    "atac2.obs['old_cell_type'] = atac2.obs['cell_type'].copy()\n",
    "scrna2.obs['cell_type'] = new_cell_types_scrna2\n",
    "atac2.obs['cell_type'] = new_cell_types_atac2\n",
    "scrna2.obs['cell_type'] = scrna2.obs['cell_type'].astype('category')\n",
    "atac2.obs['cell_type'] = atac2.obs['cell_type'].astype('category')\n",
    "atac2.obs['cell_type'].cat.categories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Trying to set attribute `.obs` of view, copying.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Index(['B cell', 'CD14 Monocyte', 'CD16 Monocyte', 'ILC', 'MAIT', 'NK',\n",
       "       'Plasmablast', 'T CD4 memory', 'T CD4 naive', 'T CD8 memory',\n",
       "       'T CD8 naive', 'Treg', 'cDC', 'gdT', 'other', 'pDC'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna_query1.obs['old_cell_type'] = scrna_query1.obs['cell_type'].copy()\n",
    "atac_query1.obs['old_cell_type'] = atac_query1.obs['cell_type'].copy()\n",
    "scrna_query1.obs['cell_type'] = new_cell_types_scrna_query1\n",
    "atac_query1.obs['cell_type'] = new_cell_types_atac_query1\n",
    "scrna_query1.obs['cell_type'] = scrna_query1.obs['cell_type'].astype('category')\n",
    "atac_query1.obs['cell_type'] = atac_query1.obs['cell_type'].astype('category')\n",
    "atac_query1.obs['cell_type'].cat.categories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Trying to set attribute `.obs` of view, copying.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Index(['ASDC', 'B cell', 'CD14 Monocyte', 'CD16 Monocyte', 'HSPC', 'ILC',\n",
       "       'MAIT', 'NK', 'Plasmablast', 'Platelet', 'RBC', 'T CD4 memory',\n",
       "       'T CD4 naive', 'T CD8 memory', 'T CD8 naive', 'Treg', 'cDC', 'gdT',\n",
       "       'other', 'other T', 'pDC'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scrna_query2.obs['cell_type'] = new_cell_types_scrna_query2\n",
    "cite_query2.obs['cell_type'] = new_cell_types_cite_query2\n",
    "scrna_query2.obs['cell_type'] = scrna_query2.obs['cell_type'].astype('category')\n",
    "cite_query2.obs['cell_type'] = cite_query2.obs['cell_type'].astype('category')\n",
    "cite_query2.obs['cell_type'].cat.categories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(View of AnnData object with n_obs × n_vars = 21358 × 4000\n",
       "     obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt', 'cell_type', 'sample_id', 'full_clustering', 'initial_clustering', 'Resample', 'Collection_Day', 'Sex', 'Age_interval', 'Swab_result', 'Status', 'Smoker', 'Status_on_day_collection', 'Status_on_day_collection_summary', 'Days_from_onset', 'Site', 'time_after_LPS', 'Worst_Clinical_Status', 'Outcome', 'patient_id', 'batch'\n",
       "     var: 'names-0', 'n_cells-0', 'mt-0', 'n_cells_by_counts-0', 'mean_counts-0', 'log1p_mean_counts-0', 'pct_dropout_by_counts-0', 'total_counts-0', 'log1p_total_counts-0', 'highly_variable-0', 'means-0', 'dispersions-0', 'dispersions_norm-0', 'n_cells-1', 'mt-1', 'n_cells_by_counts-1', 'mean_counts-1', 'log1p_mean_counts-1', 'pct_dropout_by_counts-1', 'total_counts-1', 'log1p_total_counts-1', 'gene_ids-1', 'feature_types-1', 'genome-1', 'feature_types-2', 'mt-3', 'gene_ids-3', 'feature_types-3', 'genome-3', 'n_cells-0-3', 'n_cells_by_counts-0-3', 'mean_counts-0-3', 'log1p_mean_counts-0-3', 'pct_dropout_by_counts-0-3', 'total_counts-0-3', 'log1p_total_counts-0-3', 'highly_variable-0-3', 'means-0-3', 'dispersions-0-3', 'dispersions_norm-0-3', 'n_cells-1-3', 'n_cells_by_counts-1-3', 'mean_counts-1-3', 'log1p_mean_counts-1-3', 'pct_dropout_by_counts-1-3', 'total_counts-1-3', 'log1p_total_counts-1-3', 'highly_variable-1-3', 'means-1-3', 'dispersions-1-3', 'dispersions_norm-1-3', 'feature_types-4', 'highly_variable', 'means', 'dispersions', 'dispersions_norm'\n",
       "     uns: 'log1p'\n",
       "     layers: 'count',\n",
       " View of AnnData object with n_obs × n_vars = 27825 × 4000\n",
       "     obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt', 'cell_type', 'sample_id', 'full_clustering', 'initial_clustering', 'Resample', 'Collection_Day', 'Sex', 'Age_interval', 'Swab_result', 'Status', 'Smoker', 'Status_on_day_collection', 'Status_on_day_collection_summary', 'Days_from_onset', 'Site', 'time_after_LPS', 'Worst_Clinical_Status', 'Outcome', 'patient_id', 'batch'\n",
       "     var: 'names-0', 'n_cells-0', 'mt-0', 'n_cells_by_counts-0', 'mean_counts-0', 'log1p_mean_counts-0', 'pct_dropout_by_counts-0', 'total_counts-0', 'log1p_total_counts-0', 'highly_variable-0', 'means-0', 'dispersions-0', 'dispersions_norm-0', 'n_cells-1', 'mt-1', 'n_cells_by_counts-1', 'mean_counts-1', 'log1p_mean_counts-1', 'pct_dropout_by_counts-1', 'total_counts-1', 'log1p_total_counts-1', 'gene_ids-1', 'feature_types-1', 'genome-1', 'feature_types-2', 'mt-3', 'gene_ids-3', 'feature_types-3', 'genome-3', 'n_cells-0-3', 'n_cells_by_counts-0-3', 'mean_counts-0-3', 'log1p_mean_counts-0-3', 'pct_dropout_by_counts-0-3', 'total_counts-0-3', 'log1p_total_counts-0-3', 'highly_variable-0-3', 'means-0-3', 'dispersions-0-3', 'dispersions_norm-0-3', 'n_cells-1-3', 'n_cells_by_counts-1-3', 'mean_counts-1-3', 'log1p_mean_counts-1-3', 'pct_dropout_by_counts-1-3', 'total_counts-1-3', 'log1p_total_counts-1-3', 'highly_variable-1-3', 'means-1-3', 'dispersions-1-3', 'dispersions_norm-1-3', 'feature_types-4', 'highly_variable', 'means', 'dispersions', 'dispersions_norm'\n",
       "     uns: 'log1p'\n",
       "     layers: 'count')"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# divide hao in batches\n",
    "scrna1_1 = scrna1[scrna1.obs.Batch == 'Batch1']\n",
    "scrna1_2 = scrna1[scrna1.obs.Batch == 'Batch2']\n",
    "scrna1_1, scrna1_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(View of AnnData object with n_obs × n_vars = 21358 × 61\n",
       "     obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes', 'cell_type'\n",
       "     layers: 'count',\n",
       " View of AnnData object with n_obs × n_vars = 27825 × 61\n",
       "     obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes', 'cell_type'\n",
       "     layers: 'count')"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cite1_1 = cite1[cite1.obs.Batch == 'Batch1']\n",
    "cite1_2 = cite1[cite1.obs.Batch == 'Batch2']\n",
    "cite1_1, cite1_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(View of AnnData object with n_obs × n_vars = 2859 × 4000\n",
       "     obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt', 'cell_type', 'sample_id', 'full_clustering', 'initial_clustering', 'Resample', 'Collection_Day', 'Sex', 'Age_interval', 'Swab_result', 'Status', 'Smoker', 'Status_on_day_collection', 'Status_on_day_collection_summary', 'Days_from_onset', 'Site', 'time_after_LPS', 'Worst_Clinical_Status', 'Outcome', 'patient_id', 'batch', 'old_cell_type'\n",
       "     var: 'names-0', 'n_cells-0', 'mt-0', 'n_cells_by_counts-0', 'mean_counts-0', 'log1p_mean_counts-0', 'pct_dropout_by_counts-0', 'total_counts-0', 'log1p_total_counts-0', 'highly_variable-0', 'means-0', 'dispersions-0', 'dispersions_norm-0', 'n_cells-1', 'mt-1', 'n_cells_by_counts-1', 'mean_counts-1', 'log1p_mean_counts-1', 'pct_dropout_by_counts-1', 'total_counts-1', 'log1p_total_counts-1', 'gene_ids-1', 'feature_types-1', 'genome-1', 'feature_types-2', 'mt-3', 'gene_ids-3', 'feature_types-3', 'genome-3', 'n_cells-0-3', 'n_cells_by_counts-0-3', 'mean_counts-0-3', 'log1p_mean_counts-0-3', 'pct_dropout_by_counts-0-3', 'total_counts-0-3', 'log1p_total_counts-0-3', 'highly_variable-0-3', 'means-0-3', 'dispersions-0-3', 'dispersions_norm-0-3', 'n_cells-1-3', 'n_cells_by_counts-1-3', 'mean_counts-1-3', 'log1p_mean_counts-1-3', 'pct_dropout_by_counts-1-3', 'total_counts-1-3', 'log1p_total_counts-1-3', 'highly_variable-1-3', 'means-1-3', 'dispersions-1-3', 'dispersions_norm-1-3', 'feature_types-4', 'highly_variable', 'means', 'dispersions', 'dispersions_norm'\n",
       "     uns: 'log1p'\n",
       "     layers: 'count',\n",
       " View of AnnData object with n_obs × n_vars = 3475 × 4000\n",
       "     obs: 'nCount_ADT', 'nFeature_ADT', 'nCount_RNA', 'nFeature_RNA', 'orig.ident', 'lane', 'donor', 'time', 'celltype.l1', 'celltype.l2', 'celltype.l3', 'Phase', 'Batch', 'n_genes', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt', 'cell_type', 'sample_id', 'full_clustering', 'initial_clustering', 'Resample', 'Collection_Day', 'Sex', 'Age_interval', 'Swab_result', 'Status', 'Smoker', 'Status_on_day_collection', 'Status_on_day_collection_summary', 'Days_from_onset', 'Site', 'time_after_LPS', 'Worst_Clinical_Status', 'Outcome', 'patient_id', 'batch', 'old_cell_type'\n",
       "     var: 'names-0', 'n_cells-0', 'mt-0', 'n_cells_by_counts-0', 'mean_counts-0', 'log1p_mean_counts-0', 'pct_dropout_by_counts-0', 'total_counts-0', 'log1p_total_counts-0', 'highly_variable-0', 'means-0', 'dispersions-0', 'dispersions_norm-0', 'n_cells-1', 'mt-1', 'n_cells_by_counts-1', 'mean_counts-1', 'log1p_mean_counts-1', 'pct_dropout_by_counts-1', 'total_counts-1', 'log1p_total_counts-1', 'gene_ids-1', 'feature_types-1', 'genome-1', 'feature_types-2', 'mt-3', 'gene_ids-3', 'feature_types-3', 'genome-3', 'n_cells-0-3', 'n_cells_by_counts-0-3', 'mean_counts-0-3', 'log1p_mean_counts-0-3', 'pct_dropout_by_counts-0-3', 'total_counts-0-3', 'log1p_total_counts-0-3', 'highly_variable-0-3', 'means-0-3', 'dispersions-0-3', 'dispersions_norm-0-3', 'n_cells-1-3', 'n_cells_by_counts-1-3', 'mean_counts-1-3', 'log1p_mean_counts-1-3', 'pct_dropout_by_counts-1-3', 'total_counts-1-3', 'log1p_total_counts-1-3', 'highly_variable-1-3', 'means-1-3', 'dispersions-1-3', 'dispersions_norm-1-3', 'feature_types-4', 'highly_variable', 'means', 'dispersions', 'dispersions_norm'\n",
       "     uns: 'log1p'\n",
       "     layers: 'count')"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# divide sanger in batches\n",
    "scrna_query1_1 = scrna_query1[scrna_query1.obs.Batch == '0']\n",
    "scrna_query1_2 = scrna_query1[scrna_query1.obs.Batch == '1']\n",
    "scrna_query1_1, scrna_query1_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(View of AnnData object with n_obs × n_vars = 2859 × 32640\n",
       "     obs: 'nb_features', 'cell_type', 'batch', 'Batch', 'old_cell_type'\n",
       "     var: 'feature_types', 'genome', 'gene_ids-0', 'n_cells-0', 'commonness-0', 'prop_shared_cells-0', 'variability_score-0', 'gene_ids-1', 'n_cells-1', 'commonness-1', 'prop_shared_cells-1', 'variability_score-1'\n",
       "     uns: 'log1p'\n",
       "     layers: 'binary',\n",
       " View of AnnData object with n_obs × n_vars = 3475 × 32640\n",
       "     obs: 'nb_features', 'cell_type', 'batch', 'Batch', 'old_cell_type'\n",
       "     var: 'feature_types', 'genome', 'gene_ids-0', 'n_cells-0', 'commonness-0', 'prop_shared_cells-0', 'variability_score-0', 'gene_ids-1', 'n_cells-1', 'commonness-1', 'prop_shared_cells-1', 'variability_score-1'\n",
       "     uns: 'log1p'\n",
       "     layers: 'binary')"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "atac_query1_1 = atac_query1[atac_query1.obs.Batch == '0']\n",
    "atac_query1_2 = atac_query1[atac_query1.obs.Batch == '1']\n",
    "atac_query1_1, atac_query1_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/icb/litinetskaya/miniconda3/envs/multigrate/lib/python3.7/site-packages/anndata/_core/anndata.py:1210: ImplicitModificationWarning: Initializing view as actual.\n",
      "  \"Initializing view as actual.\", ImplicitModificationWarning\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'orig.ident' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'lane' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'donor' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'celltype.l1' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'celltype.l2' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'celltype.l3' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Phase' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Batch' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'sample_id' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'full_clustering' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'initial_clustering' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Resample' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Collection_Day' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Sex' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Age_interval' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Swab_result' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Status' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Smoker' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Status_on_day_collection' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Status_on_day_collection_summary' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Days_from_onset' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Site' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'time_after_LPS' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Worst_Clinical_Status' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Outcome' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'patient_id' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'orig.ident' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'lane' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'donor' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'celltype.l1' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'celltype.l2' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'celltype.l3' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Phase' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Batch' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'sample_id' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'full_clustering' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'initial_clustering' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Resample' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Collection_Day' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Sex' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Age_interval' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Swab_result' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Status' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Smoker' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Status_on_day_collection' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Status_on_day_collection_summary' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Days_from_onset' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Site' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'time_after_LPS' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Worst_Clinical_Status' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Outcome' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'patient_id' as categorical\n",
      "... storing 'orig.ident' as categorical\n",
      "... storing 'lane' as categorical\n",
      "... storing 'donor' as categorical\n",
      "... storing 'celltype.l1' as categorical\n",
      "... storing 'celltype.l2' as categorical\n",
      "... storing 'celltype.l3' as categorical\n",
      "... storing 'Phase' as categorical\n",
      "... storing 'Batch' as categorical\n",
      "... storing 'sample_id' as categorical\n",
      "... storing 'full_clustering' as categorical\n",
      "... storing 'initial_clustering' as categorical\n",
      "... storing 'Resample' as categorical\n",
      "... storing 'Collection_Day' as categorical\n",
      "... storing 'Sex' as categorical\n",
      "... storing 'Age_interval' as categorical\n",
      "... storing 'Swab_result' as categorical\n",
      "... storing 'Status' as categorical\n",
      "... storing 'Smoker' as categorical\n",
      "... storing 'Status_on_day_collection' as categorical\n",
      "... storing 'Status_on_day_collection_summary' as categorical\n",
      "... storing 'Days_from_onset' as categorical\n",
      "... storing 'Site' as categorical\n",
      "... storing 'time_after_LPS' as categorical\n",
      "... storing 'Worst_Clinical_Status' as categorical\n",
      "... storing 'Outcome' as categorical\n",
      "... storing 'patient_id' as categorical\n",
      "... storing 'old_cell_type' as categorical\n",
      "... storing 'old_cell_type' as categorical\n",
      "... storing 'orig.ident' as categorical\n",
      "... storing 'lane' as categorical\n",
      "... storing 'donor' as categorical\n",
      "... storing 'celltype.l1' as categorical\n",
      "... storing 'celltype.l2' as categorical\n",
      "... storing 'celltype.l3' as categorical\n",
      "... storing 'Phase' as categorical\n",
      "... storing 'Batch' as categorical\n",
      "... storing 'sample_id' as categorical\n",
      "... storing 'full_clustering' as categorical\n",
      "... storing 'initial_clustering' as categorical\n",
      "... storing 'Resample' as categorical\n",
      "... storing 'Collection_Day' as categorical\n",
      "... storing 'Sex' as categorical\n",
      "... storing 'Age_interval' as categorical\n",
      "... storing 'Swab_result' as categorical\n",
      "... storing 'Status' as categorical\n",
      "... storing 'Smoker' as categorical\n",
      "... storing 'Status_on_day_collection' as categorical\n",
      "... storing 'Status_on_day_collection_summary' as categorical\n",
      "... storing 'Days_from_onset' as categorical\n",
      "... storing 'Site' as categorical\n",
      "... storing 'time_after_LPS' as categorical\n",
      "... storing 'Worst_Clinical_Status' as categorical\n",
      "... storing 'Outcome' as categorical\n",
      "... storing 'patient_id' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'orig.ident' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'lane' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'donor' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'celltype.l1' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'celltype.l2' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'celltype.l3' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Phase' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Batch' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'sample_id' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'full_clustering' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'initial_clustering' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Resample' as categorical\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Collection_Day' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Sex' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Age_interval' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Swab_result' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Status' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Smoker' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Status_on_day_collection' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Status_on_day_collection_summary' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Days_from_onset' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Site' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'time_after_LPS' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Worst_Clinical_Status' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Outcome' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'patient_id' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'old_cell_type' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'orig.ident' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'lane' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'donor' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'celltype.l1' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'celltype.l2' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'celltype.l3' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Phase' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Batch' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'sample_id' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'full_clustering' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'initial_clustering' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Resample' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Collection_Day' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Sex' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Age_interval' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Swab_result' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Status' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Smoker' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Status_on_day_collection' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Status_on_day_collection_summary' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Days_from_onset' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Site' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'time_after_LPS' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Worst_Clinical_Status' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'Outcome' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'patient_id' as categorical\n",
      "Trying to set attribute `.obs` of view, copying.\n",
      "... storing 'old_cell_type' as categorical\n",
      "... storing 'orig.ident' as categorical\n",
      "... storing 'lane' as categorical\n",
      "... storing 'donor' as categorical\n",
      "... storing 'celltype.l1' as categorical\n",
      "... storing 'celltype.l2' as categorical\n",
      "... storing 'celltype.l3' as categorical\n",
      "... storing 'Phase' as categorical\n",
      "... storing 'Batch' as categorical\n",
      "... storing 'sample_id' as categorical\n",
      "... storing 'full_clustering' as categorical\n",
      "... storing 'initial_clustering' as categorical\n",
      "... storing 'Resample' as categorical\n",
      "... storing 'Collection_Day' as categorical\n",
      "... storing 'Sex' as categorical\n",
      "... storing 'Age_interval' as categorical\n",
      "... storing 'Swab_result' as categorical\n",
      "... storing 'Status' as categorical\n",
      "... storing 'Smoker' as categorical\n",
      "... storing 'Status_on_day_collection' as categorical\n",
      "... storing 'Status_on_day_collection_summary' as categorical\n",
      "... storing 'Days_from_onset' as categorical\n",
      "... storing 'Site' as categorical\n",
      "... storing 'time_after_LPS' as categorical\n",
      "... storing 'Worst_Clinical_Status' as categorical\n",
      "... storing 'Outcome' as categorical\n",
      "... storing 'patient_id' as categorical\n"
     ]
    }
   ],
   "source": [
    "scrna1_1.write('../data/q_to_r/scrna1.h5ad')\n",
    "scrna1_2.write('../data/q_to_r/scrna2.h5ad')\n",
    "cite1_1.write('../data/q_to_r/cite1.h5ad')\n",
    "cite1_2.write('../data/q_to_r/cite2.h5ad')\n",
    "scrna2.write('../data/q_to_r/scrna3.h5ad')\n",
    "atac2.write('../data/q_to_r/atac3.h5ad')\n",
    "scrna3.write('../data/q_to_r/scrna4.h5ad')\n",
    "cite3.write('../data/q_to_r/cite4.h5ad')\n",
    "scrna_query1_1.write('../data/q_to_r/scrna_q1.h5ad')\n",
    "scrna_query1_2.write('../data/q_to_r/scrna_q2.h5ad')\n",
    "atac_query1_1.write('../data/q_to_r/atac_q1.h5ad')\n",
    "atac_query1_2.write('../data/q_to_r/atac_q2.h5ad')\n",
    "scrna_query2.write('../data/q_to_r/scrna_q3.h5ad')\n",
    "cite_query2.write('../data/q_to_r/cite_q3.h5ad')"
   ]
  },
  {
   "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": 5
}
