{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Flow cytometry simulation. \n",
"Using ``NBNode`` as basis enables the simulation of (flow) cytometry data. Cytometry data consists of an unordered matrix of n ``cells`` and p ``features``. The ordering of cells in the matrix does not hold any significant information, except in cases where data corruption has occurred during the experiment.\n",
"\n",
"As an example, we previously utilized a cell matrix originating from the Beckman Coulter ``DURAClone IM T Cell Subsets Antibody Panel``. This particular panel measures 10 markers in fluorochrome combinations that provide robust population identification, including CD3, CD4, CD8, CD27, CD28, CD45, CD45RA, CD57, CD197 (CCR7), CD279 (PD-1). Additionally, forward scatter and side scatter are usually measured, increasing the number of ``features`` per cell to 13. \n",
"\n",
"According to their ``feature`` values, ``cells`` can be classified (\"gated\") into cell types, e.g. ``CD4+ central memory T cells`` or ``CD27+ CD28+ CD4+ T cells``. Within one cell type, ``features`` do still vary. In this package, we use ``cell population`` for any defined set of cells. \n",
"\n",
"Our class ``FlowSimulationTree`` uses an existing gating applied to multiple samples and simulates two major parts: \n",
"\n",
" 1. How many ``cells`` are of which ``cell population``\n",
" 2. How are cell ``features`` distributed _within_ one ``cell population``\n",
" \n",
"In this example, we will use data from 48 healthy human peripheral blood samples stained with the DURAClone IM T Cell Subsets Tube (Beckman Coulter GmbH). \n",
"The data is available under [zenodo 7883353](https://doi.org/10.5281/zenodo.7883353). \n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Synthetic data based on previous samples\n",
"\n",
"To enable the analysis also with data supplied with package, I supply the final result ``flowsim_tree.pickle`` which has done downloading gating and initiating the simulation. \n",
"\n",
"First, download the data. "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%%script false --no-raise-error\n",
"\n",
"# This downloading takes about 1.5 minutes\n",
"\n",
"# From https://github.com/zenodo/zenodo/issues/1888\n",
"import os\n",
"\n",
"import requests\n",
"\n",
"# params = {\"access_token\": \"ZENODO_ACCESS_TOKEN\"} # only necessary until public\n",
"params = {}\n",
"\n",
"record_id = \"7883353\"\n",
"\n",
"r = requests.get(\n",
" f\"https://zenodo.org/api/records/{record_id}\", params=params\n",
")\n",
"print(r.json())\n",
"download_urls = [f[\"links\"][\"self\"] for f in r.json()[\"files\"]]\n",
"filenames = [f[\"key\"] for f in r.json()[\"files\"]]\n",
"\n",
"print(r.status_code)\n",
"print(download_urls)\n",
"\n",
"outdir = \"example_data/asinh.align_manual.CD3_Gate\"\n",
"os.makedirs(outdir, exist_ok=True)\n",
"\n",
"for filename, url in zip(filenames, download_urls):\n",
" print(\"Downloading:\", filename)\n",
" r = requests.get(url, params=params)\n",
" with open(os.path.join(outdir, filename), \"wb\") as f:\n",
" f.write(r.content)\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"The (pre-defined) tree for this dataset is ``nbtree.tree_complete_aligned_v2()``"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"%%script false --no-raise-error\n",
"\n",
"import nbnode.nbnode_trees as nbtree\n",
"complete_tree = nbtree.tree_complete_aligned_v2()\n",
"complete_tree.pretty_print()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"``nbtree.tree_complete_aligned_v2`` has specific ideas about the naming of \n",
"the markers, so we need to use the same names here.\n",
"\n",
"``new_colnames`` replaces the column names in all CSV files, regardless of how \n",
"they were named before, so use with caution!\n",
"\n",
"``gate_csv()`` now places all cells from all samples in the ``NBNode``. "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"%%script false --no-raise-error\n",
"\n",
"# This gate_csv takes about a minute\n",
"from nbnode.apply.gate_csv import gate_csv\n",
"all_files = [\n",
" os.path.join(outdir, file_x)\n",
" for file_x in os.listdir(outdir)\n",
" ]\n",
"new_colnames = [\n",
" \"FS\",\n",
" \"FS.0\",\n",
" \"SS\",\n",
" \"CD45RA\",\n",
" \"CCR7\",\n",
" \"CD28\",\n",
" \"PD1\",\n",
" \"CD27\",\n",
" \"CD4\",\n",
" \"CD8\",\n",
" \"CD3\",\n",
" \"CD57\",\n",
" \"CD45\",\n",
" ]\n",
"celltree_gated = gate_csv(\n",
" csv=all_files,\n",
" celltree=complete_tree,\n",
" new_colnames=new_colnames,\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"%%script false --no-raise-error\n",
"\n",
"celltree_gated.pretty_print()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"After we have the number of cells per node, we can generate a Dirichlet-based simulation. In particular, the number of cells per node are described by a single Dirichlet distribution containing a concentration parameter for every leaf node. "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"%%script false --no-raise-error\n",
"\n",
"from nbnode.simulation.FlowSimulationTree import FlowSimulationTreeDirichlet\n",
"\n",
"flowsim_tree = FlowSimulationTreeDirichlet(\n",
" rootnode=celltree_gated,\n",
" include_features=new_colnames,\n",
")\n",
"\n",
"from nbnode.io.pickle_open_dump import pickle_open_dump\n",
"\n",
"pickle_open_dump(flowsim_tree, \"flowsim_tree.pickle\")\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import os \n",
"import pickle\n",
"with open(os.path.join(os.pardir, os.pardir, \"tests\", \"testdata\", \"flowcytometry\", \"flowsim_tree.pickle\"), \"rb\") as f:\n",
" flowsim_tree = pickle.load(f)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"That's it. We can now simulate synthetic flow cytometry samples. "
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" FS | \n",
" FS.0 | \n",
" SS | \n",
" CD45RA | \n",
" CCR7 | \n",
" CD28 | \n",
" PD1 | \n",
" CD27 | \n",
" CD4 | \n",
" CD8 | \n",
" CD3 | \n",
" CD57 | \n",
" CD45 | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.100577 | \n",
" 5.251694 | \n",
" -0.287347 | \n",
" 0.065961 | \n",
" 0.659882 | \n",
" 0.955657 | \n",
" 1.205756 | \n",
" 0.564757 | \n",
" 0.998757 | \n",
" 0.028991 | \n",
" 0.049317 | \n",
" 0.044155 | \n",
" -0.168126 | \n",
"
\n",
" \n",
" | 1 | \n",
" -0.092387 | \n",
" 5.286552 | \n",
" -0.061012 | \n",
" 0.007936 | \n",
" 0.567971 | \n",
" 1.060524 | \n",
" 0.914231 | \n",
" 0.944080 | \n",
" 1.109905 | \n",
" -0.007508 | \n",
" -0.070442 | \n",
" 0.025814 | \n",
" 0.349142 | \n",
"
\n",
" \n",
" | 2 | \n",
" -0.159748 | \n",
" 5.295267 | \n",
" -0.008783 | \n",
" -0.022918 | \n",
" 0.773974 | \n",
" 1.353215 | \n",
" 0.590003 | \n",
" 0.732128 | \n",
" 1.040836 | \n",
" 0.065331 | \n",
" -0.086695 | \n",
" -0.058003 | \n",
" 0.352973 | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.036379 | \n",
" 5.286429 | \n",
" -0.355162 | \n",
" 0.022301 | \n",
" 0.555761 | \n",
" 1.093256 | \n",
" 1.016961 | \n",
" 0.729056 | \n",
" 0.925360 | \n",
" 0.085008 | \n",
" 0.100495 | \n",
" -0.051198 | \n",
" -0.029892 | \n",
"
\n",
" \n",
" | 4 | \n",
" -0.211879 | \n",
" 5.305992 | \n",
" -0.224904 | \n",
" -0.010840 | \n",
" 0.883872 | \n",
" 1.357975 | \n",
" 1.194074 | \n",
" 1.329266 | \n",
" 0.886225 | \n",
" 0.041453 | \n",
" -0.734879 | \n",
" 0.003398 | \n",
" 0.009937 | \n",
"
\n",
" \n",
" | 5 | \n",
" 0.037094 | \n",
" 5.235038 | \n",
" -0.212276 | \n",
" 0.514944 | \n",
" 0.924698 | \n",
" 0.973519 | \n",
" 0.950437 | \n",
" 0.984918 | \n",
" 1.038688 | \n",
" 0.063404 | \n",
" -0.441071 | \n",
" -0.025791 | \n",
" -0.398935 | \n",
"
\n",
" \n",
" | 6 | \n",
" -0.236324 | \n",
" 5.226253 | \n",
" -0.254201 | \n",
" 0.772118 | \n",
" 1.087614 | \n",
" 0.953043 | \n",
" 0.559132 | \n",
" 1.006041 | \n",
" 0.903030 | \n",
" 0.079715 | \n",
" 0.196283 | \n",
" -0.033585 | \n",
" -0.073690 | \n",
"
\n",
" \n",
" | 7 | \n",
" -0.044698 | \n",
" 5.232621 | \n",
" -0.174454 | \n",
" 0.569029 | \n",
" 1.018878 | \n",
" 0.909895 | \n",
" 0.714083 | \n",
" 1.076313 | \n",
" 1.044681 | \n",
" 0.078261 | \n",
" 0.222197 | \n",
" -0.030222 | \n",
" 0.158465 | \n",
"
\n",
" \n",
" | 8 | \n",
" 0.274186 | \n",
" 5.271703 | \n",
" 0.091757 | \n",
" 0.426830 | \n",
" -0.053408 | \n",
" -0.130320 | \n",
" 0.889216 | \n",
" -0.187032 | \n",
" 0.013959 | \n",
" 1.186677 | \n",
" -0.058428 | \n",
" 0.947983 | \n",
" -0.061106 | \n",
"
\n",
" \n",
" | 9 | \n",
" 0.368384 | \n",
" 5.290500 | \n",
" -0.148017 | \n",
" -0.016317 | \n",
" -0.096373 | \n",
" 0.959208 | \n",
" 0.616525 | \n",
" 0.484474 | \n",
" 0.039499 | \n",
" -0.003198 | \n",
" 0.573195 | \n",
" 0.695084 | \n",
" -0.030929 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" FS FS.0 SS CD45RA CCR7 CD28 PD1 \n",
"0 0.100577 5.251694 -0.287347 0.065961 0.659882 0.955657 1.205756 \\\n",
"1 -0.092387 5.286552 -0.061012 0.007936 0.567971 1.060524 0.914231 \n",
"2 -0.159748 5.295267 -0.008783 -0.022918 0.773974 1.353215 0.590003 \n",
"3 0.036379 5.286429 -0.355162 0.022301 0.555761 1.093256 1.016961 \n",
"4 -0.211879 5.305992 -0.224904 -0.010840 0.883872 1.357975 1.194074 \n",
"5 0.037094 5.235038 -0.212276 0.514944 0.924698 0.973519 0.950437 \n",
"6 -0.236324 5.226253 -0.254201 0.772118 1.087614 0.953043 0.559132 \n",
"7 -0.044698 5.232621 -0.174454 0.569029 1.018878 0.909895 0.714083 \n",
"8 0.274186 5.271703 0.091757 0.426830 -0.053408 -0.130320 0.889216 \n",
"9 0.368384 5.290500 -0.148017 -0.016317 -0.096373 0.959208 0.616525 \n",
"\n",
" CD27 CD4 CD8 CD3 CD57 CD45 \n",
"0 0.564757 0.998757 0.028991 0.049317 0.044155 -0.168126 \n",
"1 0.944080 1.109905 -0.007508 -0.070442 0.025814 0.349142 \n",
"2 0.732128 1.040836 0.065331 -0.086695 -0.058003 0.352973 \n",
"3 0.729056 0.925360 0.085008 0.100495 -0.051198 -0.029892 \n",
"4 1.329266 0.886225 0.041453 -0.734879 0.003398 0.009937 \n",
"5 0.984918 1.038688 0.063404 -0.441071 -0.025791 -0.398935 \n",
"6 1.006041 0.903030 0.079715 0.196283 -0.033585 -0.073690 \n",
"7 1.076313 1.044681 0.078261 0.222197 -0.030222 0.158465 \n",
"8 -0.187032 0.013959 1.186677 -0.058428 0.947983 -0.061106 \n",
"9 0.484474 0.039499 -0.003198 0.573195 0.695084 -0.030929 "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"flowsim_tree.sample(n_cells=10)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of cells per population in the synthetic sample\n",
"\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 298.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0\n",
" ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0\n",
"/AllCells/DN 84.0\n",
"/AllCells/DP 0.0\n",
"Name: 0, Length: 96, dtype: float64\n",
"\n",
"\n",
"\n",
"Synthetic sample\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" FS | \n",
" FS.0 | \n",
" SS | \n",
" CD45RA | \n",
" CCR7 | \n",
" CD28 | \n",
" PD1 | \n",
" CD27 | \n",
" CD4 | \n",
" CD8 | \n",
" CD3 | \n",
" CD57 | \n",
" CD45 | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" -0.199053 | \n",
" 5.234598 | \n",
" -0.088241 | \n",
" -0.034998 | \n",
" 0.924329 | \n",
" 1.131150 | \n",
" 1.082737 | \n",
" 0.809666 | \n",
" 1.125293 | \n",
" 0.004234 | \n",
" 0.046163 | \n",
" -0.045944 | \n",
" 0.179582 | \n",
"
\n",
" \n",
" | 1 | \n",
" -0.008096 | \n",
" 5.277367 | \n",
" 0.184243 | \n",
" 0.056715 | \n",
" 0.681012 | \n",
" 0.935260 | \n",
" 0.782681 | \n",
" 1.024696 | \n",
" 1.124938 | \n",
" -0.051580 | \n",
" -0.774571 | \n",
" -0.036563 | \n",
" 0.035795 | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.031465 | \n",
" 5.147636 | \n",
" 0.214739 | \n",
" 0.009059 | \n",
" 0.498950 | \n",
" 1.033221 | \n",
" 0.657734 | \n",
" 0.879537 | \n",
" 0.999712 | \n",
" 0.055606 | \n",
" -0.289094 | \n",
" -0.055068 | \n",
" 0.119610 | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.205881 | \n",
" 5.244811 | \n",
" -0.124324 | \n",
" -0.077907 | \n",
" 0.594776 | \n",
" 1.187281 | \n",
" 0.837427 | \n",
" 0.892707 | \n",
" 0.987820 | \n",
" 0.037409 | \n",
" 0.041813 | \n",
" -0.041016 | \n",
" -0.032496 | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.009315 | \n",
" 5.210594 | \n",
" -0.185055 | \n",
" 0.002598 | \n",
" 0.657654 | \n",
" 1.181162 | \n",
" 0.950851 | \n",
" 1.259253 | \n",
" 1.112355 | \n",
" 0.025556 | \n",
" -0.008730 | \n",
" -0.000847 | \n",
" -0.078750 | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | 995 | \n",
" -0.159198 | \n",
" 5.304853 | \n",
" 0.272190 | \n",
" -0.230301 | \n",
" 0.271408 | \n",
" 0.809975 | \n",
" 0.973990 | \n",
" 0.149426 | \n",
" -0.036235 | \n",
" -0.036501 | \n",
" 0.595494 | \n",
" 0.777754 | \n",
" -0.411414 | \n",
"
\n",
" \n",
" | 996 | \n",
" -0.209859 | \n",
" 5.266154 | \n",
" 0.135413 | \n",
" 0.382660 | \n",
" 0.265313 | \n",
" 1.075741 | \n",
" 1.255181 | \n",
" 0.844357 | \n",
" -0.004307 | \n",
" -0.002984 | \n",
" -0.164177 | \n",
" -0.372914 | \n",
" -0.011075 | \n",
"
\n",
" \n",
" | 997 | \n",
" -0.077003 | \n",
" 5.277108 | \n",
" 0.339912 | \n",
" 0.050631 | \n",
" 0.568426 | \n",
" 0.513111 | \n",
" 0.259577 | \n",
" 0.814484 | \n",
" 0.058262 | \n",
" -0.021971 | \n",
" 0.919959 | \n",
" 0.512811 | \n",
" -0.023790 | \n",
"
\n",
" \n",
" | 998 | \n",
" 0.015126 | \n",
" 5.278076 | \n",
" 0.214904 | \n",
" 0.111095 | \n",
" 0.130813 | \n",
" 0.388185 | \n",
" 0.078628 | \n",
" 0.316861 | \n",
" -0.033330 | \n",
" 0.009760 | \n",
" 0.600114 | \n",
" 0.737948 | \n",
" 0.521447 | \n",
"
\n",
" \n",
" | 999 | \n",
" 0.144214 | \n",
" 5.218433 | \n",
" 0.261650 | \n",
" 0.407119 | \n",
" 0.179927 | \n",
" 0.320780 | \n",
" 0.522724 | \n",
" 0.805193 | \n",
" 0.035672 | \n",
" 0.024522 | \n",
" 0.070480 | \n",
" -0.048929 | \n",
" -0.143095 | \n",
"
\n",
" \n",
"
\n",
"
1000 rows × 13 columns
\n",
"
"
],
"text/plain": [
" FS FS.0 SS CD45RA CCR7 CD28 PD1 \n",
"0 -0.199053 5.234598 -0.088241 -0.034998 0.924329 1.131150 1.082737 \\\n",
"1 -0.008096 5.277367 0.184243 0.056715 0.681012 0.935260 0.782681 \n",
"2 0.031465 5.147636 0.214739 0.009059 0.498950 1.033221 0.657734 \n",
"3 0.205881 5.244811 -0.124324 -0.077907 0.594776 1.187281 0.837427 \n",
"4 0.009315 5.210594 -0.185055 0.002598 0.657654 1.181162 0.950851 \n",
".. ... ... ... ... ... ... ... \n",
"995 -0.159198 5.304853 0.272190 -0.230301 0.271408 0.809975 0.973990 \n",
"996 -0.209859 5.266154 0.135413 0.382660 0.265313 1.075741 1.255181 \n",
"997 -0.077003 5.277108 0.339912 0.050631 0.568426 0.513111 0.259577 \n",
"998 0.015126 5.278076 0.214904 0.111095 0.130813 0.388185 0.078628 \n",
"999 0.144214 5.218433 0.261650 0.407119 0.179927 0.320780 0.522724 \n",
"\n",
" CD27 CD4 CD8 CD3 CD57 CD45 \n",
"0 0.809666 1.125293 0.004234 0.046163 -0.045944 0.179582 \n",
"1 1.024696 1.124938 -0.051580 -0.774571 -0.036563 0.035795 \n",
"2 0.879537 0.999712 0.055606 -0.289094 -0.055068 0.119610 \n",
"3 0.892707 0.987820 0.037409 0.041813 -0.041016 -0.032496 \n",
"4 1.259253 1.112355 0.025556 -0.008730 -0.000847 -0.078750 \n",
".. ... ... ... ... ... ... \n",
"995 0.149426 -0.036235 -0.036501 0.595494 0.777754 -0.411414 \n",
"996 0.844357 -0.004307 -0.002984 -0.164177 -0.372914 -0.011075 \n",
"997 0.814484 0.058262 -0.021971 0.919959 0.512811 -0.023790 \n",
"998 0.316861 -0.033330 0.009760 0.600114 0.737948 0.521447 \n",
"999 0.805193 0.035672 0.024522 0.070480 -0.048929 -0.143095 \n",
"\n",
"[1000 rows x 13 columns]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"synthetic_sample, cell_numbers = flowsim_tree.sample(n_cells=1000, return_sampled_cell_numbers=True)\n",
"print(\"Number of cells per population in the synthetic sample\\n\")\n",
"print(cell_numbers)\n",
"\n",
"print(\"\\n\\n\\nSynthetic sample\")\n",
"synthetic_sample"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"If you do not need the actual cell ``features`` but only the number of cells per ``cell population``, you can do that with ``sample_populations()``"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 11.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 3.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 305.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 3.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0\n",
" ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0\n",
"/AllCells/DN 68.0\n",
"/AllCells/DP 12.0\n",
"Name: 0, Length: 96, dtype: float64"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cell_numbers = flowsim_tree.sample_populations(n_cells=1000)\n",
"cell_numbers"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Internally: \n",
"\n",
" 1. ``sample_populations()`` is called to generate the number of cells per leaf \n",
" 2. ``multivariate_normal()`` generates the cell ``features`` for each cell\n",
"\n",
" You can also set a seed for reproducibility. "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" FS FS.0 SS CD45RA CCR7 CD28 PD1 \n",
"0 0.033016 5.212589 0.027994 -0.042323 1.068687 1.230491 0.727421 \\\n",
"1 -0.034233 5.219806 0.041332 0.009111 0.016646 1.218523 0.445606 \n",
"2 0.395116 5.366544 0.085398 0.737223 0.762656 0.641986 1.200716 \n",
"\n",
" CD27 CD4 CD8 CD3 CD57 CD45 \n",
"0 0.667649 1.017606 -0.012887 -0.232470 -0.015077 0.049724 \n",
"1 0.971163 1.167465 0.033722 0.081410 0.019712 -0.191248 \n",
"2 1.028306 -0.014907 0.892293 -0.686076 -0.011778 0.000069 \n",
" FS FS.0 SS CD45RA CCR7 CD28 PD1 \n",
"0 0.033016 5.212589 0.027994 -0.042323 1.068687 1.230491 0.727421 \\\n",
"1 -0.034233 5.219806 0.041332 0.009111 0.016646 1.218523 0.445606 \n",
"2 0.395116 5.366544 0.085398 0.737223 0.762656 0.641986 1.200716 \n",
"\n",
" CD27 CD4 CD8 CD3 CD57 CD45 \n",
"0 0.667649 1.017606 -0.012887 -0.232470 -0.015077 0.049724 \n",
"1 0.971163 1.167465 0.033722 0.081410 0.019712 -0.191248 \n",
"2 1.028306 -0.014907 0.892293 -0.686076 -0.011778 0.000069 \n"
]
}
],
"source": [
"flowsim_tree.set_seed(42)\n",
"synthetic_sample = flowsim_tree.sample(n_cells=3)\n",
"print(synthetic_sample)\n",
"\n",
"flowsim_tree.set_seed(42)\n",
"synthetic_sample = flowsim_tree.sample(n_cells=3)\n",
"print(synthetic_sample)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Per default, the normal distribution is based on a diagonal covariance matrix estimated on the cells per leaf node. However, you can enable the full covariance matrix!"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" FS FS.0 SS CD45RA CCR7 CD28 PD1 \n",
"0 0.033016 5.212589 0.027994 -0.042323 1.068687 1.230491 0.727421 \\\n",
"1 -0.034233 5.219806 0.041332 0.009111 0.016646 1.218523 0.445606 \n",
"2 0.395116 5.366544 0.085398 0.737223 0.762656 0.641986 1.200716 \n",
"\n",
" CD27 CD4 CD8 CD3 CD57 CD45 \n",
"0 0.667649 1.017606 -0.012887 -0.232470 -0.015077 0.049724 \n",
"1 0.971163 1.167465 0.033722 0.081410 0.019712 -0.191248 \n",
"2 1.028306 -0.014907 0.892293 -0.686076 -0.011778 0.000069 \n",
" FS FS.0 SS CD45RA CCR7 CD28 PD1 \n",
"0 -0.014040 5.287691 0.113469 -0.056042 0.963664 1.316469 0.788263 \\\n",
"1 0.077410 5.221344 0.198341 -0.028692 0.049742 1.251280 0.402444 \n",
"2 -0.093948 5.399214 0.514198 1.252213 1.269626 0.644032 0.538064 \n",
"\n",
" CD27 CD4 CD8 CD3 CD57 CD45 \n",
"0 1.189001 1.073660 0.097426 -0.041899 0.009045 -0.067505 \n",
"1 0.653476 0.899301 0.023174 -0.265431 0.006454 -0.508050 \n",
"2 1.183130 0.016804 1.130555 -0.224201 0.028751 0.131174 \n"
]
}
],
"source": [
"flowsim_tree.set_seed(42)\n",
"# default\n",
"synthetic_sample = flowsim_tree.sample(n_cells=3, use_only_diagonal_covmat=True) \n",
"print(synthetic_sample)\n",
"\n",
"flowsim_tree.set_seed(42)\n",
"synthetic_sample = flowsim_tree.sample(n_cells=3, use_only_diagonal_covmat=False)\n",
"print(synthetic_sample)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Synthetic data with effects\n",
"\n",
"Previously, our ability was limited to mimicing the original dataset. However, we can also introduce effects in any ``cell population``! This means we can modify the proportion of cells derived from a particular ``cell population`` in a synthesized sample. \n",
"Specifically, we defined the proportion of cells in a population using a Dirichlet distribution and its corresponding concentration parameters. By altering these parameters, we can adjust the number of cells in the population.\n",
"\n",
"Note that we are not changing how the cells are samples _within_ a leaf node!\n",
"\n",
"\n",
"\n",
"We show two ways to simulate different effects: \n",
"\n",
"1. ``TreeMeanRelative()``: Change any ``cell population`` by a relative amount. \n",
"2. ``TreeMeanDistributionSampler()``: Force any distribution on a single ``cell population``\n",
"\n",
"``TreeMeanRelative`` changes the concentration of a ``cell population`` by a certain factor (e.g. old = 173.2, new = old*2) and all other concentration parameters decrease (by a factor) such that the overall sum of concentration parameters remains equal. \n",
"\n",
"``TreeMeanDistributionSampler()`` first samples a _target_ proportion from a given distribution and then sets the concentration parameter such that on average the cell population contains this proportion. Again, the sum of concentration parameters remains equal."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### ``TreeMeanRelative``\n",
"\n",
"The following sets up a ``TreeMeanRelative`` where the cell population ``/AllCells/DN`` is changed by the factor 1 (therefore remains equal). \n",
"``n_samples`` is set to 2 and ``n_cells`` to 100. \n",
"\n",
"Therefore, calling ``tmr.sample()`` generates two samples with the original distribution, 100 cells each. \n",
"``tmr.sample()`` returns the number of cells per leaf population for both samples, the parameters after changing (the original tree is not changed) and the actually sampled samples. "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" sample_0 | \n",
" sample_1 | \n",
"
\n",
" \n",
" \n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- | \n",
" 31.0 | \n",
" 29.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- | \n",
" 1.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- | \n",
" 0.0 | \n",
" 1.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/DN | \n",
" 6.0 | \n",
" 6.0 | \n",
"
\n",
" \n",
" | /AllCells/DP | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
96 rows × 2 columns
\n",
"
"
],
"text/plain": [
" sample_0 sample_1\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.0 0.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 31.0 29.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 1.0 0.0\n",
"... ... ...\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 1.0\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0\n",
"/AllCells/DN 6.0 6.0\n",
"/AllCells/DP 0.0 0.0\n",
"\n",
"[96 rows x 2 columns]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from nbnode.simulation.TreeMeanRelative import TreeMeanRelative\n",
"tmr = TreeMeanRelative(\n",
" flowsim_tree,\n",
" change_pop_mean_proportional={\"/AllCells/DN\": 1},\n",
" n_samples=2,\n",
" n_cells=100,\n",
" verbose=False\n",
")\n",
"print(tmr)\n",
"true_popcounts, changed_parameters, sampled_samples = tmr.sample()\n",
"\n",
"true_popcounts"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.901580\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.295210\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 48.203633\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.091623\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.096534\n",
" ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.159252\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.153660\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.125163\n",
"/AllCells/DN 15.218566\n",
"/AllCells/DP 1.755718\n",
"Name: 0, Length: 96, dtype: float64"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"changed_parameters[\"alpha\"] # these are the concentration parameters of the Dirichlet distribution"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"There are 2 synthetic samples, showing only the first\n",
"\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" FS | \n",
" FS.0 | \n",
" SS | \n",
" CD45RA | \n",
" CCR7 | \n",
" CD28 | \n",
" PD1 | \n",
" CD27 | \n",
" CD4 | \n",
" CD8 | \n",
" CD3 | \n",
" CD57 | \n",
" CD45 | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.062235 | \n",
" 5.241828 | \n",
" 0.167840 | \n",
" -0.084488 | \n",
" 0.462969 | \n",
" 1.327377 | \n",
" 1.020327 | \n",
" 0.735205 | \n",
" 0.919547 | \n",
" -0.024936 | \n",
" -0.459670 | \n",
" -0.024190 | \n",
" -0.155744 | \n",
"
\n",
" \n",
" | 1 | \n",
" -0.137097 | \n",
" 5.211038 | \n",
" 0.006071 | \n",
" -0.013674 | \n",
" 0.631770 | \n",
" 1.354644 | \n",
" 0.924415 | \n",
" 1.071354 | \n",
" 0.909430 | \n",
" -0.011694 | \n",
" -0.594609 | \n",
" -0.015247 | \n",
" -0.368281 | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.049543 | \n",
" 5.226160 | \n",
" -0.092377 | \n",
" 0.032866 | \n",
" 0.720488 | \n",
" 1.218761 | \n",
" 0.788295 | \n",
" 1.015296 | \n",
" 1.006380 | \n",
" 0.065456 | \n",
" -0.138280 | \n",
" 0.082154 | \n",
" 0.100491 | \n",
"
\n",
" \n",
" | 3 | \n",
" -0.161587 | \n",
" 5.303274 | \n",
" -0.203429 | \n",
" -0.063234 | \n",
" 0.272455 | \n",
" 1.249179 | \n",
" 0.712787 | \n",
" 1.112724 | \n",
" 1.045490 | \n",
" 0.031186 | \n",
" -0.482921 | \n",
" 0.040894 | \n",
" -0.401152 | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.153456 | \n",
" 5.171440 | \n",
" 0.188800 | \n",
" 0.084201 | \n",
" 0.742456 | \n",
" 1.389247 | \n",
" 0.397038 | \n",
" 0.904283 | \n",
" 1.021047 | \n",
" 0.004681 | \n",
" -0.283981 | \n",
" -0.004825 | \n",
" -0.402051 | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | 95 | \n",
" 0.315077 | \n",
" 5.217177 | \n",
" 0.494209 | \n",
" -0.770656 | \n",
" -0.407820 | \n",
" 0.650297 | \n",
" 1.125016 | \n",
" 0.144094 | \n",
" -0.011654 | \n",
" 0.032542 | \n",
" 0.723826 | \n",
" 1.004760 | \n",
" 0.156519 | \n",
"
\n",
" \n",
" | 96 | \n",
" 0.534101 | \n",
" 5.270793 | \n",
" 0.460711 | \n",
" 0.347915 | \n",
" 0.157224 | \n",
" 0.784490 | \n",
" 1.131765 | \n",
" 0.869825 | \n",
" 0.019530 | \n",
" -0.018556 | \n",
" 0.217103 | \n",
" 0.367984 | \n",
" 0.458230 | \n",
"
\n",
" \n",
" | 97 | \n",
" -0.226989 | \n",
" 5.252685 | \n",
" -0.189814 | \n",
" 0.154086 | \n",
" -0.156006 | \n",
" 0.536826 | \n",
" 1.165235 | \n",
" 0.703251 | \n",
" 0.030829 | \n",
" -0.052641 | \n",
" 0.138474 | \n",
" 0.634439 | \n",
" 0.154382 | \n",
"
\n",
" \n",
" | 98 | \n",
" -0.001238 | \n",
" 5.322612 | \n",
" 0.424035 | \n",
" 0.193686 | \n",
" 0.277735 | \n",
" 1.124228 | \n",
" 0.598610 | \n",
" 0.624192 | \n",
" 0.010864 | \n",
" -0.030898 | \n",
" 0.231010 | \n",
" -0.259944 | \n",
" 0.003429 | \n",
"
\n",
" \n",
" | 99 | \n",
" 0.108700 | \n",
" 5.239704 | \n",
" -0.103004 | \n",
" 0.554299 | \n",
" 0.218544 | \n",
" 0.567261 | \n",
" 0.524959 | \n",
" 0.422115 | \n",
" -0.107181 | \n",
" -0.006251 | \n",
" 0.420655 | \n",
" 0.294118 | \n",
" -0.431249 | \n",
"
\n",
" \n",
"
\n",
"
100 rows × 13 columns
\n",
"
"
],
"text/plain": [
" FS FS.0 SS CD45RA CCR7 CD28 PD1 \n",
"0 0.062235 5.241828 0.167840 -0.084488 0.462969 1.327377 1.020327 \\\n",
"1 -0.137097 5.211038 0.006071 -0.013674 0.631770 1.354644 0.924415 \n",
"2 0.049543 5.226160 -0.092377 0.032866 0.720488 1.218761 0.788295 \n",
"3 -0.161587 5.303274 -0.203429 -0.063234 0.272455 1.249179 0.712787 \n",
"4 0.153456 5.171440 0.188800 0.084201 0.742456 1.389247 0.397038 \n",
".. ... ... ... ... ... ... ... \n",
"95 0.315077 5.217177 0.494209 -0.770656 -0.407820 0.650297 1.125016 \n",
"96 0.534101 5.270793 0.460711 0.347915 0.157224 0.784490 1.131765 \n",
"97 -0.226989 5.252685 -0.189814 0.154086 -0.156006 0.536826 1.165235 \n",
"98 -0.001238 5.322612 0.424035 0.193686 0.277735 1.124228 0.598610 \n",
"99 0.108700 5.239704 -0.103004 0.554299 0.218544 0.567261 0.524959 \n",
"\n",
" CD27 CD4 CD8 CD3 CD57 CD45 \n",
"0 0.735205 0.919547 -0.024936 -0.459670 -0.024190 -0.155744 \n",
"1 1.071354 0.909430 -0.011694 -0.594609 -0.015247 -0.368281 \n",
"2 1.015296 1.006380 0.065456 -0.138280 0.082154 0.100491 \n",
"3 1.112724 1.045490 0.031186 -0.482921 0.040894 -0.401152 \n",
"4 0.904283 1.021047 0.004681 -0.283981 -0.004825 -0.402051 \n",
".. ... ... ... ... ... ... \n",
"95 0.144094 -0.011654 0.032542 0.723826 1.004760 0.156519 \n",
"96 0.869825 0.019530 -0.018556 0.217103 0.367984 0.458230 \n",
"97 0.703251 0.030829 -0.052641 0.138474 0.634439 0.154382 \n",
"98 0.624192 0.010864 -0.030898 0.231010 -0.259944 0.003429 \n",
"99 0.422115 -0.107181 -0.006251 0.420655 0.294118 -0.431249 \n",
"\n",
"[100 rows x 13 columns]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(f\"There are {len(sampled_samples)} synthetic samples, showing only the first\\n\")\n",
"sampled_samples[0]"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Increasing a specific proportion on average increases the respective cell population's number of cells: "
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"tmr_base = TreeMeanRelative(\n",
" flowsim_tree,\n",
" change_pop_mean_proportional={\"/AllCells/DN\": 1},\n",
" n_samples=10,\n",
" n_cells=100,\n",
" verbose=False\n",
")\n",
"tmr_ridiculously_changed = TreeMeanRelative(\n",
" flowsim_tree,\n",
" change_pop_mean_proportional={\"/AllCells/DN\": 10},\n",
" n_samples=10,\n",
" n_cells=100,\n",
" verbose=False\n",
")\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"You can check the changed parameters when sampling from the distribution: "
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.901580\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.295210\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 48.203633\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.091623\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.096534\n",
" ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.159252\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.153660\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.125163\n",
"/AllCells/DN 15.218566\n",
"/AllCells/DP 1.755718\n",
"Name: 0, Length: 96, dtype: float64"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"true_popcounts, changed_parameters, sampled_samples = tmr_base.sample()\n",
"r_true_popcounts, r_changed_parameters, r_sampled_samples = tmr_ridiculously_changed.sample()\n",
"\n",
"changed_parameters[\"alpha\"]"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.169073\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.055361\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 9.039610\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.017182\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.018103\n",
" ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.029865\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.028816\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.023472\n",
"/AllCells/DN 152.185662\n",
"/AllCells/DP 0.329249\n",
"Name: 0, Length: 96, dtype: float64"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"r_changed_parameters[\"alpha\"]"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"We observe that the concentration parameter of ``/AllCells/DN`` strongly increased! Therefore also the number of cells from that population changed"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" sample_0 | \n",
" sample_1 | \n",
" sample_2 | \n",
" sample_3 | \n",
" sample_4 | \n",
" sample_5 | \n",
" sample_6 | \n",
" sample_7 | \n",
" sample_8 | \n",
" sample_9 | \n",
"
\n",
" \n",
" \n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- | \n",
" 31.0 | \n",
" 29.0 | \n",
" 36.0 | \n",
" 31.0 | \n",
" 22.0 | \n",
" 30.0 | \n",
" 29.0 | \n",
" 24.0 | \n",
" 29.0 | \n",
" 31.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/DN | \n",
" 6.0 | \n",
" 6.0 | \n",
" 7.0 | \n",
" 7.0 | \n",
" 17.0 | \n",
" 9.0 | \n",
" 8.0 | \n",
" 13.0 | \n",
" 12.0 | \n",
" 5.0 | \n",
"
\n",
" \n",
" | /AllCells/DP | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 2.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 2.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
96 rows × 10 columns
\n",
"
"
],
"text/plain": [
" sample_0 sample_1 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.0 0.0 \\\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 31.0 29.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 1.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 1.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 6.0 6.0 \n",
"/AllCells/DP 0.0 0.0 \n",
"\n",
" sample_2 sample_3 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 1.0 1.0 \\\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 36.0 31.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 7.0 7.0 \n",
"/AllCells/DP 1.0 2.0 \n",
"\n",
" sample_4 sample_5 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.0 0.0 \\\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 22.0 30.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 17.0 9.0 \n",
"/AllCells/DP 0.0 0.0 \n",
"\n",
" sample_6 sample_7 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 1.0 0.0 \\\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 29.0 24.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 8.0 13.0 \n",
"/AllCells/DP 0.0 0.0 \n",
"\n",
" sample_8 sample_9 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 29.0 31.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 12.0 5.0 \n",
"/AllCells/DP 2.0 0.0 \n",
"\n",
"[96 rows x 10 columns]"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"true_popcounts"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" sample_0 | \n",
" sample_1 | \n",
" sample_2 | \n",
" sample_3 | \n",
" sample_4 | \n",
" sample_5 | \n",
" sample_6 | \n",
" sample_7 | \n",
" sample_8 | \n",
" sample_9 | \n",
"
\n",
" \n",
" \n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- | \n",
" 4.0 | \n",
" 4.0 | \n",
" 6.0 | \n",
" 4.0 | \n",
" 3.0 | \n",
" 4.0 | \n",
" 5.0 | \n",
" 3.0 | \n",
" 6.0 | \n",
" 5.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/DN | \n",
" 86.0 | \n",
" 90.0 | \n",
" 90.0 | \n",
" 90.0 | \n",
" 83.0 | \n",
" 85.0 | \n",
" 82.0 | \n",
" 89.0 | \n",
" 85.0 | \n",
" 85.0 | \n",
"
\n",
" \n",
" | /AllCells/DP | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
96 rows × 10 columns
\n",
"
"
],
"text/plain": [
" sample_0 sample_1 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.0 0.0 \\\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 4.0 4.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 86.0 90.0 \n",
"/AllCells/DP 0.0 0.0 \n",
"\n",
" sample_2 sample_3 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.0 0.0 \\\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 6.0 4.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 90.0 90.0 \n",
"/AllCells/DP 0.0 0.0 \n",
"\n",
" sample_4 sample_5 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.0 0.0 \\\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 3.0 4.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 83.0 85.0 \n",
"/AllCells/DP 0.0 0.0 \n",
"\n",
" sample_6 sample_7 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.0 0.0 \\\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 5.0 3.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 82.0 89.0 \n",
"/AllCells/DP 0.0 0.0 \n",
"\n",
" sample_8 sample_9 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 6.0 5.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 85.0 85.0 \n",
"/AllCells/DP 0.0 0.0 \n",
"\n",
"[96 rows x 10 columns]"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"r_true_popcounts"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### ``TreeMeanDistributionSampler``\n",
"\n",
"The following sets up a ``TreeMeanDistributionSampler`` where the cell population ``/AllCells/DN`` is sampled from a normal distribution with mean of the original data and a standard deviation of 1 (default). \n",
"``n_samples`` is set to 2 and ``n_cells`` to 100. \n",
"\n",
"Therefore, calling ``tmr.sample()`` generates two samples with the values from a normal distribution with a mean of 8.28% being in that population, a standard deviation of 1. The value from that normal distribution is then set as target for the Dirichlet distribution, and 100 cells are synthesized. \n",
"\n",
"\n",
"``tmr.sample()`` returns the number of cells per leaf population for both samples, the parameters after changing (the original tree is not changed) and the actually sampled samples. "
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.08279977774316377\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/gugl/.conda_envs/nbnode_pyscaffold/lib/python3.8/site-packages/nbnode/simulation/sim_target.py:90: UserWarning: Changing more than 1 population is NOT setting the means to the specifiedvalues - only the LAST value will be exactly the set percentage\n",
" warnings.warn(\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" sample_0 | \n",
" sample_1 | \n",
"
\n",
" \n",
" \n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- | \n",
" 32.0 | \n",
" 29.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- | \n",
" 0.0 | \n",
" 1.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/DN | \n",
" 6.0 | \n",
" 8.0 | \n",
"
\n",
" \n",
" | /AllCells/DP | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
96 rows × 2 columns
\n",
"
"
],
"text/plain": [
" sample_0 sample_1\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.0 0.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 32.0 29.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 0.0\n",
"... ... ...\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 1.0\n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0\n",
"/AllCells/DN 6.0 8.0\n",
"/AllCells/DP 0.0 0.0\n",
"\n",
"[96 rows x 2 columns]"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from nbnode.simulation.TreeMeanDistributionSampler import TreeMeanDistributionSampler\n",
"\n",
"tmds = TreeMeanDistributionSampler(\n",
" flowsim_tree,\n",
" population_name_to_change=\"/AllCells/DN\",\n",
" n_samples=2,\n",
" n_cells=100,\n",
" verbose=False,\n",
")\n",
"(\n",
" all_true_popcounts,\n",
" all_changed_parameters,\n",
" all_sampled_samples,\n",
" all_targets,\n",
") = tmds.sample()\n",
"\n",
"\n",
"\n",
"print(flowsim_tree.pop_mean(\"/AllCells/DN\"))\n",
"all_true_popcounts"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternatively, you can insert any population distribution with a function ``mean_distribution`` taking one argument (``original_mean``) and returning a class with a ``.sample()`` method which can be casted to ``float``. \n",
"\n",
"Internally, the ``target_mean_distribution`` is set to ``mean_distribution(original_mean)`` of the original population. \n",
"Then for every of the ``n_samples``, a single value is sampled by ``float(target_mean_distribution.sample())`` and this value is set as mean of the Dirichlet distribution for the ``population_name_to_change``. \n",
"\n",
"We included a ``PseudoTorchDistributionNormal`` with the relevant method, but you can use any distribution from [pytorch-distributions](https://pytorch.org/docs/stable/distributions.html). \n",
"\n",
"In the following example, we introduce a much higher variance on one population by basing it on a normal distribution with scale 10. "
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/gugl/.conda_envs/nbnode_pyscaffold/lib/python3.8/site-packages/nbnode/simulation/sim_target.py:90: UserWarning: Changing more than 1 population is NOT setting the means to the specifiedvalues - only the LAST value will be exactly the set percentage\n",
" warnings.warn(\n",
"/home/gugl/.conda_envs/nbnode_pyscaffold/lib/python3.8/site-packages/nbnode/simulation/sim_target.py:90: UserWarning: Changing more than 1 population is NOT setting the means to the specifiedvalues - only the LAST value will be exactly the set percentage\n",
" warnings.warn(\n",
"/home/gugl/.conda_envs/nbnode_pyscaffold/lib/python3.8/site-packages/nbnode/simulation/sim_target.py:90: UserWarning: Changing more than 1 population is NOT setting the means to the specifiedvalues - only the LAST value will be exactly the set percentage\n",
" warnings.warn(\n",
"/home/gugl/.conda_envs/nbnode_pyscaffold/lib/python3.8/site-packages/nbnode/simulation/sim_target.py:90: UserWarning: Changing more than 1 population is NOT setting the means to the specifiedvalues - only the LAST value will be exactly the set percentage\n",
" warnings.warn(\n",
"/home/gugl/.conda_envs/nbnode_pyscaffold/lib/python3.8/site-packages/nbnode/simulation/sim_target.py:90: UserWarning: Changing more than 1 population is NOT setting the means to the specifiedvalues - only the LAST value will be exactly the set percentage\n",
" warnings.warn(\n",
"/home/gugl/.conda_envs/nbnode_pyscaffold/lib/python3.8/site-packages/nbnode/simulation/sim_target.py:90: UserWarning: Changing more than 1 population is NOT setting the means to the specifiedvalues - only the LAST value will be exactly the set percentage\n",
" warnings.warn(\n",
"/home/gugl/.conda_envs/nbnode_pyscaffold/lib/python3.8/site-packages/nbnode/simulation/sim_target.py:90: UserWarning: Changing more than 1 population is NOT setting the means to the specifiedvalues - only the LAST value will be exactly the set percentage\n",
" warnings.warn(\n",
"/home/gugl/.conda_envs/nbnode_pyscaffold/lib/python3.8/site-packages/nbnode/simulation/sim_target.py:90: UserWarning: Changing more than 1 population is NOT setting the means to the specifiedvalues - only the LAST value will be exactly the set percentage\n",
" warnings.warn(\n",
"/home/gugl/.conda_envs/nbnode_pyscaffold/lib/python3.8/site-packages/nbnode/simulation/sim_target.py:90: UserWarning: Changing more than 1 population is NOT setting the means to the specifiedvalues - only the LAST value will be exactly the set percentage\n",
" warnings.warn(\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" sample_0 | \n",
" sample_1 | \n",
" sample_2 | \n",
" sample_3 | \n",
" sample_4 | \n",
" sample_5 | \n",
" sample_6 | \n",
" sample_7 | \n",
" sample_8 | \n",
" sample_9 | \n",
"
\n",
" \n",
" \n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ | \n",
" 23.0 | \n",
" 40.0 | \n",
" 50.0 | \n",
" 125.0 | \n",
" 23.0 | \n",
" 81.0 | \n",
" 32.0 | \n",
" 50.0 | \n",
" 29.0 | \n",
" 81.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 22.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 23.0 | \n",
" 1.0 | \n",
" 4.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- | \n",
" 2671.0 | \n",
" 2698.0 | \n",
" 2865.0 | \n",
" 2693.0 | \n",
" 2262.0 | \n",
" 2362.0 | \n",
" 3006.0 | \n",
" 2262.0 | \n",
" 2621.0 | \n",
" 2837.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ | \n",
" 0.0 | \n",
" 32.0 | \n",
" 32.0 | \n",
" 2.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 3.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- | \n",
" 27.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 4.0 | \n",
" 14.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ | \n",
" 0.0 | \n",
" 13.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 3.0 | \n",
" 14.0 | \n",
" 0.0 | \n",
" 9.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- | \n",
" 0.0 | \n",
" 165.0 | \n",
" 0.0 | \n",
" 4.0 | \n",
" 24.0 | \n",
" 6.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- | \n",
" 44.0 | \n",
" 4.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | /AllCells/DN | \n",
" 529.0 | \n",
" 111.0 | \n",
" 2215.0 | \n",
" 1092.0 | \n",
" 524.0 | \n",
" 1056.0 | \n",
" 0.0 | \n",
" 1677.0 | \n",
" 954.0 | \n",
" 497.0 | \n",
"
\n",
" \n",
" | /AllCells/DP | \n",
" 96.0 | \n",
" 86.0 | \n",
" 28.0 | \n",
" 102.0 | \n",
" 3.0 | \n",
" 119.0 | \n",
" 59.0 | \n",
" 70.0 | \n",
" 242.0 | \n",
" 19.0 | \n",
"
\n",
" \n",
"
\n",
"
96 rows × 10 columns
\n",
"
"
],
"text/plain": [
" sample_0 sample_1 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 23.0 40.0 \\\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 2671.0 2698.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 32.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 27.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 13.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 165.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 44.0 4.0 \n",
"/AllCells/DN 529.0 111.0 \n",
"/AllCells/DP 96.0 86.0 \n",
"\n",
" sample_2 sample_3 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 50.0 125.0 \\\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 2865.0 2693.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 32.0 2.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 4.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 2215.0 1092.0 \n",
"/AllCells/DP 28.0 102.0 \n",
"\n",
" sample_4 sample_5 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 23.0 81.0 \\\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 22.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 2262.0 2362.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 4.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 3.0 14.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 24.0 6.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 1.0 \n",
"/AllCells/DN 524.0 1056.0 \n",
"/AllCells/DP 3.0 119.0 \n",
"\n",
" sample_6 sample_7 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 32.0 50.0 \\\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.0 23.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 3006.0 2262.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 14.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 9.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 1.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 0.0 1677.0 \n",
"/AllCells/DP 59.0 70.0 \n",
"\n",
" sample_8 sample_9 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 29.0 81.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 1.0 4.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 2621.0 2837.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.0 3.0 \n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.0 0.0 \n",
"... ... ... \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1+ 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57+/PD1- 0.0 0.0 \n",
"/AllCells/CD4-/CD8+/naive/CD27-/CD28-/CD57- 0.0 0.0 \n",
"/AllCells/DN 954.0 497.0 \n",
"/AllCells/DP 242.0 19.0 \n",
"\n",
"[96 rows x 10 columns]"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from nbnode.simulation.TreeMeanDistributionSampler import PseudoTorchDistributionNormal\n",
"\n",
"tmds_custom = TreeMeanDistributionSampler(\n",
" flowsim_tree,\n",
" population_name_to_change=\"/AllCells/DN\",\n",
" mean_distribution=lambda original_mean: PseudoTorchDistributionNormal(\n",
" loc=original_mean, scale=10\n",
" ),\n",
" n_samples=10,\n",
" n_cells=10000,\n",
" verbose=False,\n",
")\n",
"(\n",
" all_true_popcounts,\n",
" all_changed_parameters,\n",
" all_sampled_samples,\n",
" all_targets,\n",
") = tmds_custom.sample()\n",
"\n",
"all_true_popcounts\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### FlowSimulationTree methods and attributes\n",
"\n",
"``FlowSimulationTree`` has a number of interesting methods and attributes. \n",
"\n",
"``flowsim_tree.estimate_population_distribution()``\n",
" Given node percentages per sample for all lefa nodes estimate their corresponding dirichlet parameters\n",
"\n",
"``flowsim_tree.remove_population()``\n",
" You can remove a population from the Dirichlet distribution. No cells are going to be sampled from that one and the corresponding concentration parameter is removed (not redistributed). \n"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"import os \n",
"import pickle\n",
"with open(os.path.join(os.pardir, os.pardir, \"tests\", \"testdata\", \"flowcytometry\", \"flowsim_tree.pickle\"), \"rb\") as f:\n",
" flowsim_tree = pickle.load(f)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"183.79960241689196"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Precision is equal to the total sum of concentration parameters\n",
"flowsim_tree.precision"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1+ 0.901580\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57+/PD1- 0.295210\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28+/CD57- 48.203633\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57+/PD1+ 0.091623\n",
"/AllCells/CD4+/CD8-/Tcm/CD27+/CD28-/CD57- 0.096534\n",
" ... \n",
"/AllCells/CD4+/CD8-/Tem/CD27-/CD28+ 3.228699\n",
"/AllCells/CD4+/CD8-/Tem/CD27-/CD28- 0.530434\n",
"/AllCells/CD4+/CD8-/Tem 11.384744\n",
"/AllCells/CD4+/CD8- 120.537038\n",
"/AllCells 183.799602\n",
"Name: 0, Length: 139, dtype: float64"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# concentration parameters for all populations, also intermediate populations\n",
"flowsim_tree.alpha_all"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['/AllCells/CD4+/CD8-/naive/CD27+/CD28+/CD57+/PD1+', '/AllCells/CD4+/CD8-/naive/CD27+/CD28+/CD57+/PD1-', '/AllCells/CD4+/CD8-/naive/CD27+/CD28+/CD57-', '/AllCells/CD4+/CD8-/naive/CD27+/CD28-/CD57+/PD1+', '/AllCells/CD4+/CD8-/naive/CD27+/CD28-/CD57+/PD1-', '/AllCells/CD4+/CD8-/naive/CD27+/CD28-/CD57-', '/AllCells/CD4+/CD8-/naive/CD27-/CD28+/CD57+/PD1+', '/AllCells/CD4+/CD8-/naive/CD27-/CD28+/CD57+/PD1-', '/AllCells/CD4+/CD8-/naive/CD27-/CD28+/CD57-', '/AllCells/CD4+/CD8-/naive/CD27-/CD28-/CD57+/PD1+', '/AllCells/CD4+/CD8-/naive/CD27-/CD28-/CD57+/PD1-', '/AllCells/CD4+/CD8-/naive/CD27-/CD28-/CD57-']\n"
]
},
{
"data": {
"text/plain": [
"['/AllCells/CD4+/CD8-/naive/CD27+/CD28+/CD57+/PD1+',\n",
" '/AllCells/CD4+/CD8-/naive/CD27+/CD28+/CD57+/PD1-',\n",
" '/AllCells/CD4+/CD8-/naive/CD27+/CD28+/CD57-',\n",
" '/AllCells/CD4+/CD8-/naive/CD27+/CD28-/CD57+/PD1+',\n",
" '/AllCells/CD4+/CD8-/naive/CD27+/CD28-/CD57+/PD1-',\n",
" '/AllCells/CD4+/CD8-/naive/CD27+/CD28-/CD57-',\n",
" '/AllCells/CD4+/CD8-/naive/CD27-/CD28+/CD57+/PD1+',\n",
" '/AllCells/CD4+/CD8-/naive/CD27-/CD28+/CD57+/PD1-',\n",
" '/AllCells/CD4+/CD8-/naive/CD27-/CD28+/CD57-',\n",
" '/AllCells/CD4+/CD8-/naive/CD27-/CD28-/CD57+/PD1+',\n",
" '/AllCells/CD4+/CD8-/naive/CD27-/CD28-/CD57+/PD1-',\n",
" '/AllCells/CD4+/CD8-/naive/CD27-/CD28-/CD57-']"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# All leaf node names (i.e. populations) corresponding to the given population\n",
"print(flowsim_tree.pop_leafnode_names(\"/AllCells/CD4+/CD8-/naive\"))\n",
"\n",
"# Also works directly with NBNodes\n",
"flowsim_tree.pop_leafnode_names(flowsim_tree.rootnode_structure[\"/AllCells/CD4+/CD8-/naive\"])"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"AllCells (counter:0)\n",
"├── DN (counter:0)\n",
"├── DP (counter:0)\n",
"├── CD4-/CD8+ (counter:0)\n",
"│ ├── naive (counter:0)\n",
"│ │ ├── CD27+/CD28+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ │ └── CD57- (counter:0)\n",
"│ │ ├── CD27+/CD28- (counter:0)\n",
"│ │ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ │ └── CD57- (counter:0)\n",
"│ │ ├── CD27-/CD28+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ │ └── CD57- (counter:0)\n",
"│ │ └── CD27-/CD28- (counter:0)\n",
"│ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ └── CD57- (counter:0)\n",
"│ ├── Tcm (counter:0)\n",
"│ │ ├── CD27+/CD28+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ │ └── CD57- (counter:0)\n",
"│ │ ├── CD27+/CD28- (counter:0)\n",
"│ │ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ │ └── CD57- (counter:0)\n",
"│ │ ├── CD27-/CD28+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ │ └── CD57- (counter:0)\n",
"│ │ └── CD27-/CD28- (counter:0)\n",
"│ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ └── CD57- (counter:0)\n",
"│ ├── Temra (counter:0)\n",
"│ │ ├── CD27+/CD28+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ │ └── CD57- (counter:0)\n",
"│ │ ├── CD27+/CD28- (counter:0)\n",
"│ │ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ │ └── CD57- (counter:0)\n",
"│ │ ├── CD27-/CD28+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ │ └── CD57- (counter:0)\n",
"│ │ └── CD27-/CD28- (counter:0)\n",
"│ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ └── CD57- (counter:0)\n",
"│ └── Tem (counter:0)\n",
"│ ├── CD27+/CD28+ (counter:0)\n",
"│ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ └── CD57- (counter:0)\n",
"│ ├── CD27+/CD28- (counter:0)\n",
"│ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ └── CD57- (counter:0)\n",
"│ ├── CD27-/CD28+ (counter:0)\n",
"│ │ ├── CD57+/PD1+ (counter:0)\n",
"│ │ ├── CD57+/PD1- (counter:0)\n",
"│ │ └── CD57- (counter:0)\n",
"│ └── CD27-/CD28- (counter:0)\n",
"│ ├── CD57+/PD1+ (counter:0)\n",
"│ ├── CD57+/PD1- (counter:0)\n",
"│ └── CD57- (counter:0)\n",
"└── CD4+/CD8- (counter:0)\n",
" ├── naive (counter:0)\n",
" │ ├── CD27+/CD28+ (counter:0)\n",
" │ │ ├── CD57+/PD1+ (counter:0)\n",
" │ │ ├── CD57+/PD1- (counter:0)\n",
" │ │ └── CD57- (counter:0)\n",
" │ ├── CD27+/CD28- (counter:0)\n",
" │ │ ├── CD57+/PD1+ (counter:0)\n",
" │ │ ├── CD57+/PD1- (counter:0)\n",
" │ │ └── CD57- (counter:0)\n",
" │ ├── CD27-/CD28+ (counter:0)\n",
" │ │ ├── CD57+/PD1+ (counter:0)\n",
" │ │ ├── CD57+/PD1- (counter:0)\n",
" │ │ └── CD57- (counter:0)\n",
" │ └── CD27-/CD28- (counter:0)\n",
" │ ├── CD57+/PD1+ (counter:0)\n",
" │ ├── CD57+/PD1- (counter:0)\n",
" │ └── CD57- (counter:0)\n",
" ├── Tcm (counter:0)\n",
" │ ├── CD27+/CD28+ (counter:0)\n",
" │ │ ├── CD57+/PD1+ (counter:0)\n",
" │ │ ├── CD57+/PD1- (counter:0)\n",
" │ │ └── CD57- (counter:0)\n",
" │ ├── CD27+/CD28- (counter:0)\n",
" │ │ ├── CD57+/PD1+ (counter:0)\n",
" │ │ ├── CD57+/PD1- (counter:0)\n",
" │ │ └── CD57- (counter:0)\n",
" │ ├── CD27-/CD28+ (counter:0)\n",
" │ │ ├── CD57+/PD1+ (counter:0)\n",
" │ │ ├── CD57+/PD1- (counter:0)\n",
" │ │ └── CD57- (counter:0)\n",
" │ └── CD27-/CD28- (counter:0)\n",
" │ ├── CD57+/PD1+ (counter:0)\n",
" │ ├── CD57+/PD1- (counter:0)\n",
" │ └── CD57- (counter:0)\n",
" ├── Temra (counter:0)\n",
" │ ├── CD27+/CD28+ (counter:0)\n",
" │ │ ├── CD57+/PD1+ (counter:0)\n",
" │ │ ├── CD57+/PD1- (counter:0)\n",
" │ │ └── CD57- (counter:0)\n",
" │ ├── CD27+/CD28- (counter:0)\n",
" │ │ ├── CD57+/PD1+ (counter:0)\n",
" │ │ ├── CD57+/PD1- (counter:0)\n",
" │ │ └── CD57- (counter:0)\n",
" │ ├── CD27-/CD28+ (counter:0)\n",
" │ │ ├── CD57+/PD1+ (counter:0)\n",
" │ │ ├── CD57+/PD1- (counter:0)\n",
" │ │ └── CD57- (counter:0)\n",
" │ └── CD27-/CD28- (counter:0)\n",
" │ ├── CD57+/PD1+ (counter:0)\n",
" │ ├── CD57+/PD1- (counter:0)\n",
" │ └── CD57- (counter:0)\n",
" └── Tem (counter:0)\n",
" ├── CD27+/CD28+ (counter:0)\n",
" │ ├── CD57+/PD1+ (counter:0)\n",
" │ ├── CD57+/PD1- (counter:0)\n",
" │ └── CD57- (counter:0)\n",
" ├── CD27+/CD28- (counter:0)\n",
" │ ├── CD57+/PD1+ (counter:0)\n",
" │ ├── CD57+/PD1- (counter:0)\n",
" │ └── CD57- (counter:0)\n",
" ├── CD27-/CD28+ (counter:0)\n",
" │ ├── CD57+/PD1+ (counter:0)\n",
" │ ├── CD57+/PD1- (counter:0)\n",
" │ └── CD57- (counter:0)\n",
" └── CD27-/CD28- (counter:0)\n",
" ├── CD57+/PD1+ (counter:0)\n",
" ├── CD57+/PD1- (counter:0)\n",
" └── CD57- (counter:0)\n"
]
}
],
"source": [
"flowsim_tree.rootnode_structure.pretty_print()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"54.5458005721906"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Concentration parameter for a single population\n",
"flowsim_tree.pop_alpha(\"/AllCells/CD4+/CD8-/naive\")"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.2967677832537989"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Mean for a single population\n",
"flowsim_tree.pop_mean(\"/AllCells/CD4+/CD8-/naive\")"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"91.89980120844596\n",
"0.5000000000000001\n"
]
}
],
"source": [
"# Set the new mean of the Dirichlet distribution for a single population\n",
"flowsim_tree.new_pop_mean(\"/AllCells/CD4+/CD8-/naive\", 0.5)\n",
"print(flowsim_tree.pop_alpha(\"/AllCells/CD4+/CD8-/naive\"))\n",
"print(flowsim_tree.pop_mean(\"/AllCells/CD4+/CD8-/naive\"))\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"The previous command ``new_pop_mean`` actively changes the whole dirichlet distribution. \n",
"It is usually important to reset the changed parameters to the original values. You can do this easily with \n",
"``reset_populations``"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"54.5458005721906\n",
"0.2967677832537989\n"
]
}
],
"source": [
"flowsim_tree.reset_populations()\n",
"print(flowsim_tree.pop_alpha(\"/AllCells/CD4+/CD8-/naive\"))\n",
"print(flowsim_tree.pop_mean(\"/AllCells/CD4+/CD8-/naive\"))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.8.16"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}