{ "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={\"disease\":([\"dcm\"],[\"nf\"],[\"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 }