{ "cells": [ { "cell_type": "markdown", "id": "7aebcdc1", "metadata": {}, "source": [ "# Format Conversion" ] }, { "cell_type": "markdown", "id": "106316f4", "metadata": {}, "source": [ "This section introduces how to do format conversion, so that you can work with other spatial tools while using Stereopy." ] }, { "cell_type": "markdown", "id": "4dd89129", "metadata": {}, "source": [ "## Working with Scanpy" ] }, { "attachments": {}, "cell_type": "markdown", "id": "90f184f0", "metadata": {}, "source": [ "IO module provides the function `stereo.io.stereo_to_anndata` to convert StereoExpData object into Anndata and output the corresponding `.h5ad` file." ] }, { "cell_type": "code", "execution_count": null, "id": "54a8af2f", "metadata": {}, "outputs": [], "source": [ "import stereo as st\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "\n", "# read the GEF file\n", "data_path = './SS200000135TL_D1.tissue.gef'\n", "data = st.io.read_gef(file_path=data_path, bin_size=50)\n", "data.tl.raw_checkpoint()\n", "\n", "# remember to set flavor as scanpy \n", "adata = st.io.stereo_to_anndata(data,flavor='scanpy',output='scanpy_out.h5ad')" ] }, { "cell_type": "markdown", "id": "9d242f95", "metadata": {}, "source": [ "## Working with Seurat" ] }, { "attachments": {}, "cell_type": "markdown", "id": "1fe92781", "metadata": {}, "source": [ "If you want to get the normalizetion result and convert the output `.h5ad` into the `.rds` file, you need to save raw data before performing normalization. Otherwise, it will raise errors during conversion. Conversion process mainly includes two steps." ] }, { "attachments": {}, "cell_type": "markdown", "id": "4dac3bf4", "metadata": {}, "source": [ "### Ouput H5ad" ] }, { "cell_type": "code", "execution_count": null, "id": "281eac2a", "metadata": {}, "outputs": [], "source": [ "import stereo as st\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "\n", "# read the GEF file\n", "data_path = './SS200000135TL_D1.tissue.gef'\n", "data = st.io.read_gef(file_path=data_path, bin_size=50)\n", "data.tl.cal_qc()\n", "data.tl.raw_checkpoint()\n", "\n", "# remember to set flavor as seurat \n", "adata = st.io.stereo_to_anndata(data,flavor='seurat',output='seurat_out.h5ad')" ] }, { "attachments": {}, "cell_type": "markdown", "id": "aac977b9", "metadata": {}, "source": [ "### H5ad to RDS" ] }, { "attachments": {}, "cell_type": "markdown", "id": "8459f063", "metadata": {}, "source": [ "The output `.h5ad` could be converted into `.rds` file by [h5ad2rds.R](https://github.com/STOmics/Stereopy/blob/work/docs/source/_static/h5ad2rds.R). " ] }, { "cell_type": "markdown", "id": "a837ebee", "metadata": {}, "source": [ "Run this command line in your own R environment:" ] }, { "cell_type": "code", "execution_count": null, "id": "a61c631f", "metadata": {}, "outputs": [], "source": [ "Rscript h5ad2rds.R --infile --outfile " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.2" }, "vscode": { "interpreter": { "hash": "70dbeb2a90198859cd91b6ea0f3adc73d66939fe301617b631d99dfc954c0323" } } }, "nbformat": 4, "nbformat_minor": 5 }