{ "cells": [ { "cell_type": "markdown", "id": "a91bca46-c056-4784-8c6c-b0f5d3f33496", "metadata": { "tags": [] }, "source": [ "## Tokenizing .loom or .h5ad single cell RNA-seq data to rank value encoding .dataset format" ] }, { "cell_type": "markdown", "id": "350e6252-b783-494b-9767-f087eb868a15", "metadata": {}, "source": [ "#### Input data is a directory with .loom or .h5ad files containing raw counts from single cell RNAseq data, including all genes detected in the transcriptome without feature selection. The input file type is specified by the argument file_format in the tokenize_data function.\n", "\n", "#### The discussion below references the .loom file format, but the analagous labels are required for .h5ad files, just that they will be column instead of row attributes and vice versa due to the transposed format of the two file types.\n", "\n", "#### Genes should be labeled with Ensembl IDs (loom row attribute \"ensembl_id\"), which provide a unique identifer for conversion to tokens. Other forms of gene annotations (e.g. gene names) can be converted to Ensembl IDs via Ensembl Biomart. Cells should be labeled with the total read count in the cell (loom column attribute \"n_counts\") to be used for normalization.\n", "\n", "#### No cell metadata is required, but custom cell attributes may be passed onto the tokenized dataset by providing a dictionary of custom attributes to be added, which is formatted as loom_col_attr_name : desired_dataset_col_attr_name. For example, if the original .loom dataset has column attributes \"cell_type\" and \"organ_major\" and one would like to retain these attributes as labels in the tokenized dataset with the new names \"cell_type\" and \"organ\", respectively, the following custom attribute dictionary should be provided: {\"cell_type\": \"cell_type\", \"organ_major\": \"organ\"}. \n", "\n", "#### Additionally, if the original .loom file contains a cell column attribute called \"filter_pass\", this column will be used as a binary indicator of whether to include these cells in the tokenized data. All cells with \"1\" in this attribute will be tokenized, whereas the others will be excluded. One may use this column to indicate QC filtering or other criteria for selection for inclusion in the final tokenized dataset.\n", "\n", "#### If one's data is in other formats besides .loom or .h5ad, one can use the relevant tools (such as Anndata tools) to convert the file to a .loom or .h5ad format prior to running the transcriptome tokenizer." ] }, { "cell_type": "code", "execution_count": null, "id": "080fdd9c-0c48-4d5d-a254-52b6c53cdf78", "metadata": {}, "outputs": [], "source": [ "from geneformer import TranscriptomeTokenizer" ] }, { "cell_type": "code", "execution_count": null, "id": "37205758-aa52-4443-a383-0638519ee8a9", "metadata": {}, "outputs": [], "source": [ "tk = TranscriptomeTokenizer({\"cell_type\": \"cell_type\", \"organ_major\": \"organ\"}, nproc=16)\n", "tk.tokenize_data(\"loom_data_directory\", \n", " \"output_directory\", \n", " \"output_prefix\", \n", " file_format=\"loom\")" ] } ], "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 }