File size: 3,649 Bytes
1c2f864
 
 
 
 
 
 
 
 
 
 
 
 
 
 
acd253c
1c2f864
 
 
 
 
 
 
 
 
 
acd253c
 
 
 
 
 
 
 
 
c2679c4
 
 
 
acd253c
 
 
 
1c2f864
 
 
 
 
 
 
 
 
 
 
acd253c
 
 
1c2f864
 
 
 
acd253c
1c2f864
 
 
 
 
acd253c
 
 
 
1c2f864
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e10ac0c9-40ce-41fb-b6fa-3d62b76f2e57",
   "metadata": {},
   "outputs": [],
   "source": [
    "from geneformer import InSilicoPerturber\n",
    "from geneformer import InSilicoPerturberStats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "67b44366-f255-4415-a865-6a27a8ffcce7",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# in silico perturbation in deletion mode to determine genes whose \n",
    "# deletion in the dilated cardiomyopathy (dcm) state significantly shifts\n",
    "# the embedding towards non-failing (nf) state\n",
    "isp = InSilicoPerturber(perturb_type=\"delete\",\n",
    "                        perturb_rank_shift=None,\n",
    "                        genes_to_perturb=\"all\",\n",
    "                        combos=0,\n",
    "                        anchor_gene=None,\n",
    "                        model_type=\"CellClassifier\",\n",
    "                        num_classes=3,\n",
    "                        emb_mode=\"cell\",\n",
    "                        cell_emb_style=\"mean_pool\",\n",
    "                        filter_data={\"cell_type\":[\"Cardiomyocyte1\",\"Cardiomyocyte2\",\"Cardiomyocyte3\"]},\n",
    "                        cell_states_to_model={'state_key': 'disease', \n",
    "                                              'start_state': 'dcm', \n",
    "                                              'goal_state': 'nf', \n",
    "                                              'alt_states': ['hcm']},\n",
    "                        max_ncells=2000,\n",
    "                        emb_layer=0,\n",
    "                        forward_batch_size=400,\n",
    "                        nproc=16)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0525a663-871a-4ce0-a135-cc203817ffa9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# outputs intermediate files from in silico perturbation\n",
    "isp.perturb_data(\"path/to/model\",\n",
    "                 \"path/to/input_data\",\n",
    "                 \"path/to/output_directory\",\n",
    "                 \"output_prefix\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8aadabb-516a-4dc0-b307-6de880e64e26",
   "metadata": {},
   "outputs": [],
   "source": [
    "ispstats = InSilicoPerturberStats(mode=\"goal_state_shift\",\n",
    "                                  genes_perturbed=\"all\",\n",
    "                                  combos=0,\n",
    "                                  anchor_gene=None,\n",
    "                                  cell_states_to_model={\"disease\":([\"dcm\"],[\"nf\"],[\"hcm\"])})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ffecfae6-e737-43e3-99e9-fa37ff46610b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# extracts data from intermediate files and processes stats to output in final .csv\n",
    "ispstats.get_stats(\"path/to/input_data\",\n",
    "                   None,\n",
    "                   \"path/to/output_directory\",\n",
    "                   \"output_prefix\")"
   ]
  }
 ],
 "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.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}