YijiaChi commited on
Commit
1aacd08
·
verified ·
1 Parent(s): 868cea6

Upload cell-eval dataset folder

Browse files
.gitattributes CHANGED
@@ -58,3 +58,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
60
  cell-eval/tutorials/vcc/adata_Training.h5ad filter=lfs diff=lfs merge=lfs -text
 
 
 
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
60
  cell-eval/tutorials/vcc/adata_Training.h5ad filter=lfs diff=lfs merge=lfs -text
61
+ cell-eval/tutorials/vcc/cell-eval-tutorial-output-example.h5ad filter=lfs diff=lfs merge=lfs -text
62
+ cell-eval/tutorials/vcc/cell-eval-tutorial-output-example.prep.vcc filter=lfs diff=lfs merge=lfs -text
cell-eval/tutorials/vcc/.ipynb_checkpoints/vcc-checkpoint.ipynb ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "837a8ecd",
6
+ "metadata": {},
7
+ "source": [
8
+ "# VCC Submission Notebook\n",
9
+ "\n",
10
+ "Hello! \n",
11
+ "\n",
12
+ "This is a notebook that will help you prepare your predicted AnnData to be ready to be scored by `cell-eval` against a validation dataset.\n",
13
+ "\n",
14
+ "Before we begin you will need a few things:\n",
15
+ "\n",
16
+ "1. `cell-eval` installed and in your `$PATH` (see our [installation guide](https://github.com/ArcInstitute/cell-eval?tab=readme-ov-file#installation))\n",
17
+ "2. The number of expected cells / perturbation in the validation dataset (CSV) ([download](https://virtualcellchallenge.org/app))\n",
18
+ "3. The gene names to predict (CSV) ([download](https://virtualcellchallenge.org/app))\n",
19
+ "4. Your model predictions in an AnnData (h5ad)\n",
20
+ "5. (Optional) The training AnnData (if you are not predicting Non-Targeting Controls) ([download](https://virtualcellchallenge.org/app))\n",
21
+ "\n",
22
+ "\n",
23
+ "> Note: Your model predictions **may not exceed 100K cells total**"
24
+ ]
25
+ },
26
+ {
27
+ "cell_type": "markdown",
28
+ "id": "b5cc204d",
29
+ "metadata": {},
30
+ "source": [
31
+ "## Building an Example Submission\n",
32
+ "\n",
33
+ "For the purposes of this tutorial we will be generating **random predictions** and preparing them to be evaluated.\n",
34
+ "\n",
35
+ "We will create an AnnData with *random gene abundances* for each cell, where the number of cells for each perturbation matches the number of cells in the validation dataset."
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "markdown",
40
+ "id": "3e9c543f",
41
+ "metadata": {},
42
+ "source": [
43
+ "### Load in our Expected Counts"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": 2,
49
+ "id": "2d172eea",
50
+ "metadata": {},
51
+ "outputs": [
52
+ {
53
+ "name": "stdout",
54
+ "output_type": "stream",
55
+ "text": [
56
+ "Dimensions: (50, 3)\n"
57
+ ]
58
+ },
59
+ {
60
+ "data": {
61
+ "text/html": [
62
+ "<div><style>\n",
63
+ ".dataframe > thead > tr,\n",
64
+ ".dataframe > tbody > tr {\n",
65
+ " text-align: right;\n",
66
+ " white-space: pre-wrap;\n",
67
+ "}\n",
68
+ "</style>\n",
69
+ "<small>shape: (5, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>target_gene</th><th>n_cells</th><th>median_umi_per_cell</th></tr><tr><td>str</td><td>i64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;SH3BP4&quot;</td><td>2925</td><td>54551.0</td></tr><tr><td>&quot;ZNF581&quot;</td><td>2502</td><td>53803.5</td></tr><tr><td>&quot;ANXA6&quot;</td><td>2496</td><td>55175.0</td></tr><tr><td>&quot;PACSIN3&quot;</td><td>2101</td><td>54088.0</td></tr><tr><td>&quot;MGST1&quot;</td><td>2096</td><td>54217.5</td></tr></tbody></table></div>"
70
+ ],
71
+ "text/plain": [
72
+ "shape: (5, 3)\n",
73
+ "┌─────────────┬─────────┬─────────────────────┐\n",
74
+ "│ target_gene ┆ n_cells ┆ median_umi_per_cell │\n",
75
+ "│ --- ┆ --- ┆ --- │\n",
76
+ "│ str ┆ i64 ┆ f64 │\n",
77
+ "╞═════════════╪═════════╪═════════════════════╡\n",
78
+ "│ SH3BP4 ┆ 2925 ┆ 54551.0 │\n",
79
+ "│ ZNF581 ┆ 2502 ┆ 53803.5 │\n",
80
+ "│ ANXA6 ┆ 2496 ┆ 55175.0 │\n",
81
+ "│ PACSIN3 ┆ 2101 ┆ 54088.0 │\n",
82
+ "│ MGST1 ┆ 2096 ┆ 54217.5 │\n",
83
+ "└─────────────┴─────────┴─────────────────────┘"
84
+ ]
85
+ },
86
+ "execution_count": 2,
87
+ "metadata": {},
88
+ "output_type": "execute_result"
89
+ }
90
+ ],
91
+ "source": [
92
+ "import polars as pl\n",
93
+ "\n",
94
+ "# Define our path\n",
95
+ "pert_counts_path = \"/home/datahouse/yijia/Projects/VCC2025/VirtualCellChallenge2025/Downloads/vcc_data/pert_counts_Validation.csv\"\n",
96
+ "\n",
97
+ "# Read in the csv\n",
98
+ "pert_counts = pl.read_csv(pert_counts_path)\n",
99
+ "\n",
100
+ "# Show the dimensions\n",
101
+ "print(f\"Dimensions: {pert_counts.shape}\")\n",
102
+ "pert_counts.head()"
103
+ ]
104
+ },
105
+ {
106
+ "cell_type": "markdown",
107
+ "id": "34164d85",
108
+ "metadata": {},
109
+ "source": [
110
+ "### Load in our Expected Gene Names"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "execution_count": 3,
116
+ "id": "04e3cfad",
117
+ "metadata": {},
118
+ "outputs": [
119
+ {
120
+ "data": {
121
+ "text/plain": [
122
+ "array(['SAMD11', 'NOC2L', 'KLHL17', ..., 'MT-ND5', 'MT-ND6', 'MT-CYB'],\n",
123
+ " dtype=object)"
124
+ ]
125
+ },
126
+ "execution_count": 3,
127
+ "metadata": {},
128
+ "output_type": "execute_result"
129
+ }
130
+ ],
131
+ "source": [
132
+ "gene_names_path = \"/home/datahouse/yijia/Projects/VCC2025/VirtualCellChallenge2025/Downloads/vcc_data/gene_names.csv\"\n",
133
+ "\n",
134
+ "# Read this in and immediately convert to array\n",
135
+ "gene_names = pl.read_csv(gene_names_path, has_header=False).to_numpy().flatten()\n",
136
+ "\n",
137
+ "gene_names"
138
+ ]
139
+ },
140
+ {
141
+ "cell_type": "markdown",
142
+ "id": "b6895f5b",
143
+ "metadata": {},
144
+ "source": [
145
+ "### Define our random predictor"
146
+ ]
147
+ },
148
+ {
149
+ "cell_type": "code",
150
+ "execution_count": 15,
151
+ "id": "0262449f",
152
+ "metadata": {},
153
+ "outputs": [],
154
+ "source": [
155
+ "import numpy as np\n",
156
+ "import pandas as pd\n",
157
+ "from numpy.typing import NDArray\n",
158
+ "import anndata as ad\n",
159
+ "\n",
160
+ "\n",
161
+ "def random_predictor(\n",
162
+ " pert_names: NDArray[np.str_],\n",
163
+ " cell_counts: NDArray[np.int64],\n",
164
+ " gene_names: NDArray[np.str_],\n",
165
+ " max_count: int | float = 1e4,\n",
166
+ " log1p: bool = True,\n",
167
+ ") -> ad.AnnData:\n",
168
+ " \"\"\"Generate a random AnnData with the expected number of cells / perturbation.\n",
169
+ "\n",
170
+ " This is a dummy function that is meant to stand-in for a perturbation model.\n",
171
+ " \"\"\"\n",
172
+ " matrix = np.random.randint(\n",
173
+ " 0,\n",
174
+ " int(max_count),\n",
175
+ " size=(\n",
176
+ " cell_counts.sum(),\n",
177
+ " gene_names.size,\n",
178
+ " ),\n",
179
+ " )\n",
180
+ " if log1p:\n",
181
+ " matrix = np.log1p(matrix)\n",
182
+ " return ad.AnnData(\n",
183
+ " X=matrix,\n",
184
+ " obs=pd.DataFrame(\n",
185
+ " {\n",
186
+ " \"target_gene\": np.repeat(pert_names, cell_counts),\n",
187
+ " },\n",
188
+ " index=np.arange(cell_counts.sum()).astype(str),\n",
189
+ " ),\n",
190
+ " var=pd.DataFrame(index=gene_names),\n",
191
+ " )"
192
+ ]
193
+ },
194
+ {
195
+ "cell_type": "markdown",
196
+ "id": "d5dbd56d",
197
+ "metadata": {},
198
+ "source": [
199
+ "### Run our random predictor"
200
+ ]
201
+ },
202
+ {
203
+ "cell_type": "code",
204
+ "execution_count": 16,
205
+ "id": "1273bea1",
206
+ "metadata": {},
207
+ "outputs": [
208
+ {
209
+ "data": {
210
+ "text/plain": [
211
+ "AnnData object with n_obs × n_vars = 60751 × 18080\n",
212
+ " obs: 'target_gene'"
213
+ ]
214
+ },
215
+ "execution_count": 16,
216
+ "metadata": {},
217
+ "output_type": "execute_result"
218
+ }
219
+ ],
220
+ "source": [
221
+ "adata = random_predictor(\n",
222
+ " pert_names=pert_counts[\"target_gene\"].to_numpy(),\n",
223
+ " cell_counts=pert_counts[\"n_cells\"].to_numpy(),\n",
224
+ " gene_names=gene_names,\n",
225
+ ")\n",
226
+ "adata"
227
+ ]
228
+ },
229
+ {
230
+ "cell_type": "markdown",
231
+ "id": "9f9de9dd",
232
+ "metadata": {},
233
+ "source": [
234
+ "### Adding in Non-Targeting Controls if you are not predicting them\n",
235
+ "\n",
236
+ "Our evaluation framework expects non-targeting controls to be included in the predicted AnnData, but not all models may try to predict non-targeting controls.\n",
237
+ "If you are not predicting non-targeting controls, you can take the non-targeting from the training AnnData and just copy them over into your predicted AnnData for validation."
238
+ ]
239
+ },
240
+ {
241
+ "cell_type": "code",
242
+ "execution_count": 18,
243
+ "id": "3879267c",
244
+ "metadata": {},
245
+ "outputs": [],
246
+ "source": [
247
+ "# Define our path to the training anndata\n",
248
+ "tr_adata_path = \"/home/datahouse/yijia/Projects/VCC2025/VirtualCellChallenge2025/Downloads/vcc_data//adata_Training.h5ad\"\n",
249
+ "\n",
250
+ "# Read in the anndata\n",
251
+ "tr_adata = ad.read_h5ad(tr_adata_path)\n",
252
+ "\n",
253
+ "# Filter for non-targeting\n",
254
+ "ntc_adata = tr_adata[tr_adata.obs[\"target_gene\"] == \"non-targeting\"]\n",
255
+ "\n",
256
+ "# Append the non-targeting controls to the example anndata if they're missing\n",
257
+ "if \"non-targeting\" not in adata.obs[\"target_gene\"].unique():\n",
258
+ " assert np.all(adata.var_names.values == ntc_adata.var_names.values), (\n",
259
+ " \"Gene-Names are out of order or unequal\"\n",
260
+ " )\n",
261
+ " adata = ad.concat(\n",
262
+ " [\n",
263
+ " adata,\n",
264
+ " ntc_adata,\n",
265
+ " ]\n",
266
+ " )"
267
+ ]
268
+ },
269
+ {
270
+ "cell_type": "markdown",
271
+ "id": "6f19ac72",
272
+ "metadata": {},
273
+ "source": [
274
+ "### Write our predictions to some output path"
275
+ ]
276
+ },
277
+ {
278
+ "cell_type": "code",
279
+ "execution_count": 19,
280
+ "id": "386ee994",
281
+ "metadata": {},
282
+ "outputs": [],
283
+ "source": [
284
+ "adata.write_h5ad(\"./cell-eval-tutorial-output-example.h5ad\")"
285
+ ]
286
+ },
287
+ {
288
+ "cell_type": "markdown",
289
+ "id": "29cd57ef",
290
+ "metadata": {},
291
+ "source": [
292
+ "## Running `cell-eval prep`\n",
293
+ "\n",
294
+ "Now that we have our predictions, we will run `cell-eval` to prepare our AnnData for competition scoring."
295
+ ]
296
+ },
297
+ {
298
+ "cell_type": "markdown",
299
+ "id": "7716a83e",
300
+ "metadata": {},
301
+ "source": [
302
+ "```bash\n",
303
+ "cell-eval prep \\\n",
304
+ " -i ./example.h5ad \\\n",
305
+ " --genes ./gene_names.csv\n",
306
+ "```"
307
+ ]
308
+ },
309
+ {
310
+ "cell_type": "code",
311
+ "execution_count": 20,
312
+ "id": "e2d42201",
313
+ "metadata": {},
314
+ "outputs": [
315
+ {
316
+ "name": "stdout",
317
+ "output_type": "stream",
318
+ "text": [
319
+ "/home/datahouse/yijia/Projects/VCC2025/cell-eval/cell-eval/tutorials/vcc\n"
320
+ ]
321
+ }
322
+ ],
323
+ "source": [
324
+ "import os\n",
325
+ "print(os.getcwd())\n"
326
+ ]
327
+ },
328
+ {
329
+ "cell_type": "markdown",
330
+ "id": "6f938a60",
331
+ "metadata": {},
332
+ "source": [
333
+ "And that's it! Your model outputs will be output to path: `./example.prep.vcc` are ready for scoring."
334
+ ]
335
+ }
336
+ ],
337
+ "metadata": {
338
+ "kernelspec": {
339
+ "display_name": "Python 3 (ipykernel)",
340
+ "language": "python",
341
+ "name": "python3"
342
+ },
343
+ "language_info": {
344
+ "codemirror_mode": {
345
+ "name": "ipython",
346
+ "version": 3
347
+ },
348
+ "file_extension": ".py",
349
+ "mimetype": "text/x-python",
350
+ "name": "python",
351
+ "nbconvert_exporter": "python",
352
+ "pygments_lexer": "ipython3",
353
+ "version": "3.11.7"
354
+ }
355
+ },
356
+ "nbformat": 4,
357
+ "nbformat_minor": 5
358
+ }
cell-eval/tutorials/vcc/cell-eval-tutorial-output-example.h5ad ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d0f04d843caf6b7db26ec33e9b0299c0c5618a896dd20671b30a501f6536414
3
+ size 17196749727
cell-eval/tutorials/vcc/cell-eval-tutorial-output-example.prep.vcc ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7f23725fc638562cee1149dc00390cd105fd55024620ce5fc43b3c356148bc4a
3
+ size 3702784000
cell-eval/tutorials/vcc/vcc.ipynb ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "837a8ecd",
6
+ "metadata": {},
7
+ "source": [
8
+ "# VCC Submission Notebook\n",
9
+ "\n",
10
+ "Hello! \n",
11
+ "\n",
12
+ "This is a notebook that will help you prepare your predicted AnnData to be ready to be scored by `cell-eval` against a validation dataset.\n",
13
+ "\n",
14
+ "Before we begin you will need a few things:\n",
15
+ "\n",
16
+ "1. `cell-eval` installed and in your `$PATH` (see our [installation guide](https://github.com/ArcInstitute/cell-eval?tab=readme-ov-file#installation))\n",
17
+ "2. The number of expected cells / perturbation in the validation dataset (CSV) ([download](https://virtualcellchallenge.org/app))\n",
18
+ "3. The gene names to predict (CSV) ([download](https://virtualcellchallenge.org/app))\n",
19
+ "4. Your model predictions in an AnnData (h5ad)\n",
20
+ "5. (Optional) The training AnnData (if you are not predicting Non-Targeting Controls) ([download](https://virtualcellchallenge.org/app))\n",
21
+ "\n",
22
+ "\n",
23
+ "> Note: Your model predictions **may not exceed 100K cells total**"
24
+ ]
25
+ },
26
+ {
27
+ "cell_type": "markdown",
28
+ "id": "b5cc204d",
29
+ "metadata": {},
30
+ "source": [
31
+ "## Building an Example Submission\n",
32
+ "\n",
33
+ "For the purposes of this tutorial we will be generating **random predictions** and preparing them to be evaluated.\n",
34
+ "\n",
35
+ "We will create an AnnData with *random gene abundances* for each cell, where the number of cells for each perturbation matches the number of cells in the validation dataset."
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "markdown",
40
+ "id": "3e9c543f",
41
+ "metadata": {},
42
+ "source": [
43
+ "### Load in our Expected Counts"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": 1,
49
+ "id": "2d172eea",
50
+ "metadata": {},
51
+ "outputs": [
52
+ {
53
+ "name": "stdout",
54
+ "output_type": "stream",
55
+ "text": [
56
+ "Dimensions: (50, 3)\n"
57
+ ]
58
+ },
59
+ {
60
+ "data": {
61
+ "text/html": [
62
+ "<div><style>\n",
63
+ ".dataframe > thead > tr,\n",
64
+ ".dataframe > tbody > tr {\n",
65
+ " text-align: right;\n",
66
+ " white-space: pre-wrap;\n",
67
+ "}\n",
68
+ "</style>\n",
69
+ "<small>shape: (5, 3)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>target_gene</th><th>n_cells</th><th>median_umi_per_cell</th></tr><tr><td>str</td><td>i64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;SH3BP4&quot;</td><td>2925</td><td>54551.0</td></tr><tr><td>&quot;ZNF581&quot;</td><td>2502</td><td>53803.5</td></tr><tr><td>&quot;ANXA6&quot;</td><td>2496</td><td>55175.0</td></tr><tr><td>&quot;PACSIN3&quot;</td><td>2101</td><td>54088.0</td></tr><tr><td>&quot;MGST1&quot;</td><td>2096</td><td>54217.5</td></tr></tbody></table></div>"
70
+ ],
71
+ "text/plain": [
72
+ "shape: (5, 3)\n",
73
+ "┌─────────────┬─────────┬─────────────────────┐\n",
74
+ "│ target_gene ┆ n_cells ┆ median_umi_per_cell │\n",
75
+ "│ --- ┆ --- ┆ --- │\n",
76
+ "│ str ┆ i64 ┆ f64 │\n",
77
+ "╞═════════════╪═════════╪═════════════════════╡\n",
78
+ "│ SH3BP4 ┆ 2925 ┆ 54551.0 │\n",
79
+ "│ ZNF581 ┆ 2502 ┆ 53803.5 │\n",
80
+ "│ ANXA6 ┆ 2496 ┆ 55175.0 │\n",
81
+ "│ PACSIN3 ┆ 2101 ┆ 54088.0 │\n",
82
+ "│ MGST1 ┆ 2096 ┆ 54217.5 │\n",
83
+ "└─────────────┴─────────┴─────────────────────┘"
84
+ ]
85
+ },
86
+ "execution_count": 1,
87
+ "metadata": {},
88
+ "output_type": "execute_result"
89
+ }
90
+ ],
91
+ "source": [
92
+ "import polars as pl\n",
93
+ "\n",
94
+ "# Define our path\n",
95
+ "pert_counts_path = \"/home/datahouse/yijia/Projects/VCC2025/VirtualCellChallenge2025/Downloads/vcc_data/pert_counts_Validation.csv\"\n",
96
+ "\n",
97
+ "# Read in the csv\n",
98
+ "pert_counts = pl.read_csv(pert_counts_path)\n",
99
+ "\n",
100
+ "# Show the dimensions\n",
101
+ "print(f\"Dimensions: {pert_counts.shape}\")\n",
102
+ "pert_counts.head()"
103
+ ]
104
+ },
105
+ {
106
+ "cell_type": "markdown",
107
+ "id": "34164d85",
108
+ "metadata": {},
109
+ "source": [
110
+ "### Load in our Expected Gene Names"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "execution_count": 2,
116
+ "id": "04e3cfad",
117
+ "metadata": {},
118
+ "outputs": [
119
+ {
120
+ "data": {
121
+ "text/plain": [
122
+ "array(['SAMD11', 'NOC2L', 'KLHL17', ..., 'MT-ND5', 'MT-ND6', 'MT-CYB'],\n",
123
+ " dtype=object)"
124
+ ]
125
+ },
126
+ "execution_count": 2,
127
+ "metadata": {},
128
+ "output_type": "execute_result"
129
+ }
130
+ ],
131
+ "source": [
132
+ "gene_names_path = \"/home/datahouse/yijia/Projects/VCC2025/VirtualCellChallenge2025/Downloads/vcc_data/gene_names.csv\"\n",
133
+ "\n",
134
+ "# Read this in and immediately convert to array\n",
135
+ "gene_names = pl.read_csv(gene_names_path, has_header=False).to_numpy().flatten()\n",
136
+ "\n",
137
+ "gene_names"
138
+ ]
139
+ },
140
+ {
141
+ "cell_type": "markdown",
142
+ "id": "b6895f5b",
143
+ "metadata": {},
144
+ "source": [
145
+ "### Define our random predictor"
146
+ ]
147
+ },
148
+ {
149
+ "cell_type": "code",
150
+ "execution_count": 3,
151
+ "id": "0262449f",
152
+ "metadata": {},
153
+ "outputs": [],
154
+ "source": [
155
+ "import numpy as np\n",
156
+ "import pandas as pd\n",
157
+ "from numpy.typing import NDArray\n",
158
+ "import anndata as ad\n",
159
+ "\n",
160
+ "\n",
161
+ "def random_predictor(\n",
162
+ " pert_names: NDArray[np.str_],\n",
163
+ " cell_counts: NDArray[np.int64],\n",
164
+ " gene_names: NDArray[np.str_],\n",
165
+ " max_count: int | float = 1e4,\n",
166
+ " log1p: bool = True,\n",
167
+ ") -> ad.AnnData:\n",
168
+ " \"\"\"Generate a random AnnData with the expected number of cells / perturbation.\n",
169
+ "\n",
170
+ " This is a dummy function that is meant to stand-in for a perturbation model.\n",
171
+ " \"\"\"\n",
172
+ " matrix = np.random.randint(\n",
173
+ " 0,\n",
174
+ " int(max_count),\n",
175
+ " size=(\n",
176
+ " cell_counts.sum(),\n",
177
+ " gene_names.size,\n",
178
+ " ),\n",
179
+ " )\n",
180
+ " if log1p:\n",
181
+ " matrix = np.log1p(matrix)\n",
182
+ " return ad.AnnData(\n",
183
+ " X=matrix,\n",
184
+ " obs=pd.DataFrame(\n",
185
+ " {\n",
186
+ " \"target_gene\": np.repeat(pert_names, cell_counts),\n",
187
+ " },\n",
188
+ " index=np.arange(cell_counts.sum()).astype(str),\n",
189
+ " ),\n",
190
+ " var=pd.DataFrame(index=gene_names),\n",
191
+ " )"
192
+ ]
193
+ },
194
+ {
195
+ "cell_type": "markdown",
196
+ "id": "d5dbd56d",
197
+ "metadata": {},
198
+ "source": [
199
+ "### Run our random predictor"
200
+ ]
201
+ },
202
+ {
203
+ "cell_type": "code",
204
+ "execution_count": 4,
205
+ "id": "1273bea1",
206
+ "metadata": {},
207
+ "outputs": [
208
+ {
209
+ "data": {
210
+ "text/plain": [
211
+ "AnnData object with n_obs × n_vars = 60751 × 18080\n",
212
+ " obs: 'target_gene'"
213
+ ]
214
+ },
215
+ "execution_count": 4,
216
+ "metadata": {},
217
+ "output_type": "execute_result"
218
+ }
219
+ ],
220
+ "source": [
221
+ "adata = random_predictor(\n",
222
+ " pert_names=pert_counts[\"target_gene\"].to_numpy(),\n",
223
+ " cell_counts=pert_counts[\"n_cells\"].to_numpy(),\n",
224
+ " gene_names=gene_names,\n",
225
+ ")\n",
226
+ "adata"
227
+ ]
228
+ },
229
+ {
230
+ "cell_type": "markdown",
231
+ "id": "9f9de9dd",
232
+ "metadata": {},
233
+ "source": [
234
+ "### Adding in Non-Targeting Controls if you are not predicting them\n",
235
+ "\n",
236
+ "Our evaluation framework expects non-targeting controls to be included in the predicted AnnData, but not all models may try to predict non-targeting controls.\n",
237
+ "If you are not predicting non-targeting controls, you can take the non-targeting from the training AnnData and just copy them over into your predicted AnnData for validation."
238
+ ]
239
+ },
240
+ {
241
+ "cell_type": "code",
242
+ "execution_count": 5,
243
+ "id": "3879267c",
244
+ "metadata": {},
245
+ "outputs": [],
246
+ "source": [
247
+ "# Define our path to the training anndata\n",
248
+ "tr_adata_path = \"/home/datahouse/yijia/Projects/VCC2025/VirtualCellChallenge2025/Downloads/vcc_data//adata_Training.h5ad\"\n",
249
+ "\n",
250
+ "# Read in the anndata\n",
251
+ "tr_adata = ad.read_h5ad(tr_adata_path)\n",
252
+ "\n",
253
+ "# Filter for non-targeting\n",
254
+ "ntc_adata = tr_adata[tr_adata.obs[\"target_gene\"] == \"non-targeting\"]\n",
255
+ "\n",
256
+ "# Append the non-targeting controls to the example anndata if they're missing\n",
257
+ "if \"non-targeting\" not in adata.obs[\"target_gene\"].unique():\n",
258
+ " assert np.all(adata.var_names.values == ntc_adata.var_names.values), (\n",
259
+ " \"Gene-Names are out of order or unequal\"\n",
260
+ " )\n",
261
+ " adata = ad.concat(\n",
262
+ " [\n",
263
+ " adata,\n",
264
+ " ntc_adata,\n",
265
+ " ]\n",
266
+ " )"
267
+ ]
268
+ },
269
+ {
270
+ "cell_type": "markdown",
271
+ "id": "6f19ac72",
272
+ "metadata": {},
273
+ "source": [
274
+ "### Write our predictions to some output path"
275
+ ]
276
+ },
277
+ {
278
+ "cell_type": "code",
279
+ "execution_count": 6,
280
+ "id": "386ee994",
281
+ "metadata": {},
282
+ "outputs": [],
283
+ "source": [
284
+ "adata.write_h5ad(\"./cell-eval-tutorial-output-example.h5ad\")"
285
+ ]
286
+ },
287
+ {
288
+ "cell_type": "markdown",
289
+ "id": "29cd57ef",
290
+ "metadata": {},
291
+ "source": [
292
+ "## Running `cell-eval prep`\n",
293
+ "\n",
294
+ "Now that we have our predictions, we will run `cell-eval` to prepare our AnnData for competition scoring."
295
+ ]
296
+ },
297
+ {
298
+ "cell_type": "markdown",
299
+ "id": "7716a83e",
300
+ "metadata": {},
301
+ "source": [
302
+ "```bash\n",
303
+ "cell-eval prep \\\n",
304
+ " -i ./example.h5ad \\\n",
305
+ " --genes ./gene_names.csv\n",
306
+ "```"
307
+ ]
308
+ },
309
+ {
310
+ "cell_type": "code",
311
+ "execution_count": 7,
312
+ "id": "e2d42201",
313
+ "metadata": {},
314
+ "outputs": [
315
+ {
316
+ "name": "stdout",
317
+ "output_type": "stream",
318
+ "text": [
319
+ "/home/datahouse/yijia/Projects/VCC2025/cell-eval/cell-eval/tutorials/vcc\n"
320
+ ]
321
+ }
322
+ ],
323
+ "source": [
324
+ "import os\n",
325
+ "print(os.getcwd())\n"
326
+ ]
327
+ },
328
+ {
329
+ "cell_type": "markdown",
330
+ "id": "6f938a60",
331
+ "metadata": {},
332
+ "source": [
333
+ "And that's it! Your model outputs will be output to path: `./example.prep.vcc` are ready for scoring."
334
+ ]
335
+ }
336
+ ],
337
+ "metadata": {
338
+ "kernelspec": {
339
+ "display_name": "Python 3 (ipykernel)",
340
+ "language": "python",
341
+ "name": "python3"
342
+ },
343
+ "language_info": {
344
+ "codemirror_mode": {
345
+ "name": "ipython",
346
+ "version": 3
347
+ },
348
+ "file_extension": ".py",
349
+ "mimetype": "text/x-python",
350
+ "name": "python",
351
+ "nbconvert_exporter": "python",
352
+ "pygments_lexer": "ipython3",
353
+ "version": "3.11.7"
354
+ }
355
+ },
356
+ "nbformat": 4,
357
+ "nbformat_minor": 5
358
+ }