Christina Theodoris
commited on
Commit
·
1c2f864
1
Parent(s):
ee963ba
Add in silico perturbation example notebook.
Browse files
examples/in_silico_perturbation.ipynb
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"id": "e10ac0c9-40ce-41fb-b6fa-3d62b76f2e57",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"from geneformer import InSilicoPerturber\n",
|
| 11 |
+
"from geneformer import InSilicoPerturberStats"
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"cell_type": "code",
|
| 16 |
+
"execution_count": 2,
|
| 17 |
+
"id": "67b44366-f255-4415-a865-6a27a8ffcce7",
|
| 18 |
+
"metadata": {
|
| 19 |
+
"tags": []
|
| 20 |
+
},
|
| 21 |
+
"outputs": [],
|
| 22 |
+
"source": [
|
| 23 |
+
"# in silico perturbation in deletion mode to determine genes whose \n",
|
| 24 |
+
"# deletion in the dilated cardiomyopathy (dcm) state significantly shifts\n",
|
| 25 |
+
"# the embedding towards non-failing (nf) state\n",
|
| 26 |
+
"isp = InSilicoPerturber(perturb_type=\"delete\",\n",
|
| 27 |
+
" perturb_rank_shift=None,\n",
|
| 28 |
+
" genes_to_perturb=\"all\",\n",
|
| 29 |
+
" combos=0,\n",
|
| 30 |
+
" anchor_gene=None,\n",
|
| 31 |
+
" model_type=\"CellClassifier\",\n",
|
| 32 |
+
" num_classes=3,\n",
|
| 33 |
+
" emb_mode=\"cell\",\n",
|
| 34 |
+
" cell_emb_style=\"mean_pool\",\n",
|
| 35 |
+
" filter_data={\"cell_type\":[\"Cardiomyocyte1\",\"Cardiomyocyte2\",\"Cardiomyocyte3\"]},\n",
|
| 36 |
+
" cell_states_to_model={\"disease\":([\"dcm\"],[\"nf\"],[\"hcm\"])},\n",
|
| 37 |
+
" max_ncells=2000,\n",
|
| 38 |
+
" emb_layer=0,\n",
|
| 39 |
+
" forward_batch_size=400,\n",
|
| 40 |
+
" nproc=16,\n",
|
| 41 |
+
" save_raw_data=True)"
|
| 42 |
+
]
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"cell_type": "code",
|
| 46 |
+
"execution_count": null,
|
| 47 |
+
"id": "0525a663-871a-4ce0-a135-cc203817ffa9",
|
| 48 |
+
"metadata": {},
|
| 49 |
+
"outputs": [],
|
| 50 |
+
"source": [
|
| 51 |
+
"# outputs intermediate files from in silico perturbation\n",
|
| 52 |
+
"isp.perturb_data(\"path/to/model\",\n",
|
| 53 |
+
" \"path/to/input_data\",\n",
|
| 54 |
+
" \"path/to/output_directory\",\n",
|
| 55 |
+
" \"output_prefix\")"
|
| 56 |
+
]
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"cell_type": "code",
|
| 60 |
+
"execution_count": 2,
|
| 61 |
+
"id": "f8aadabb-516a-4dc0-b307-6de880e64e26",
|
| 62 |
+
"metadata": {},
|
| 63 |
+
"outputs": [],
|
| 64 |
+
"source": [
|
| 65 |
+
"ispstats = InSilicoPerturberStats(mode=\"goal_state_shift\",\n",
|
| 66 |
+
" combos=0,\n",
|
| 67 |
+
" anchor_gene=None,\n",
|
| 68 |
+
" cell_states_to_model={\"disease\":([\"dcm\"],[\"nf\"],[\"hcm\"])})"
|
| 69 |
+
]
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
"cell_type": "code",
|
| 73 |
+
"execution_count": null,
|
| 74 |
+
"id": "ffecfae6-e737-43e3-99e9-fa37ff46610b",
|
| 75 |
+
"metadata": {},
|
| 76 |
+
"outputs": [],
|
| 77 |
+
"source": [
|
| 78 |
+
"# extracts data from intermediate files and processes stats to output in final .csv\n",
|
| 79 |
+
"ispstats.get_stats(\"path/to/input_data\",\n",
|
| 80 |
+
" None,\n",
|
| 81 |
+
" \"path/to/output_directory\",\n",
|
| 82 |
+
" \"output_prefix\")"
|
| 83 |
+
]
|
| 84 |
+
}
|
| 85 |
+
],
|
| 86 |
+
"metadata": {
|
| 87 |
+
"kernelspec": {
|
| 88 |
+
"display_name": "Python 3 (ipykernel)",
|
| 89 |
+
"language": "python",
|
| 90 |
+
"name": "python3"
|
| 91 |
+
},
|
| 92 |
+
"language_info": {
|
| 93 |
+
"codemirror_mode": {
|
| 94 |
+
"name": "ipython",
|
| 95 |
+
"version": 3
|
| 96 |
+
},
|
| 97 |
+
"file_extension": ".py",
|
| 98 |
+
"mimetype": "text/x-python",
|
| 99 |
+
"name": "python",
|
| 100 |
+
"nbconvert_exporter": "python",
|
| 101 |
+
"pygments_lexer": "ipython3",
|
| 102 |
+
"version": "3.10.11"
|
| 103 |
+
}
|
| 104 |
+
},
|
| 105 |
+
"nbformat": 4,
|
| 106 |
+
"nbformat_minor": 5
|
| 107 |
+
}
|