diff --git a/jupyter-book/introduction/interoperability.ipynb b/jupyter-book/introduction/interoperability.ipynb index b0de1d65..1bdf712a 100644 --- a/jupyter-book/introduction/interoperability.ipynb +++ b/jupyter-book/introduction/interoperability.ipynb @@ -45,8 +45,10 @@ "import tempfile\n", "import os\n", "import rpy2.robjects\n", + "import anndata2ri\n", "from scipy.sparse import csr_matrix\n", "\n", + "anndata2ri.activate()\n", "%load_ext rpy2.ipython" ] }, @@ -120,8 +122,14 @@ "name": "stderr", "output_type": "stream", "text": [ - "/Users/luke.zappia/miniconda3/envs/interoperability/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n" + "/Users/luke.zappia/miniconda3/envs/interoperability/lib/python3.9/site-packages/umap/distances.py:1063: NumbaDeprecationWarning: \u001b[1mThe 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.\u001b[0m\n", + " @numba.jit()\n", + "/Users/luke.zappia/miniconda3/envs/interoperability/lib/python3.9/site-packages/umap/distances.py:1071: NumbaDeprecationWarning: \u001b[1mThe 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.\u001b[0m\n", + " @numba.jit()\n", + "/Users/luke.zappia/miniconda3/envs/interoperability/lib/python3.9/site-packages/umap/distances.py:1086: NumbaDeprecationWarning: \u001b[1mThe 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.\u001b[0m\n", + " @numba.jit()\n", + "/Users/luke.zappia/miniconda3/envs/interoperability/lib/python3.9/site-packages/umap/umap_.py:660: NumbaDeprecationWarning: \u001b[1mThe 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.\u001b[0m\n", + " @numba.jit()\n" ] }, { @@ -348,6 +356,15 @@ "output_type": "stream", "text": [ "R[write to console]: Converting H5AD to H5Seurat...\n", + "\n", + "R[write to console]: The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,\n", + "which was just loaded, will retire in October 2023.\n", + "Please refer to R-spatial evolution reports for details, especially\n", + "https://r-spatial.org/r/2023/05/15/evolution4.html.\n", + "It may be desirable to make the sf package available;\n", + "package maintainers should consider adding sf to Suggests:.\n", + "The sp package is now running under evolution status 2\n", + " (status 2 uses the sf package in place of rgdal)\n", "\n" ] }, @@ -588,14 +605,14 @@ "class: SingleCellExperiment \n", "dim: 2000 100 \n", "metadata(0):\n", - "assays(2): counts logcounts\n", + "assays(2): X logcounts\n", "rownames(2000): Gene-0 Gene-1 ... Gene-1998 Gene-1999\n", "rowData names(0):\n", "colnames(100): Cell_0 Cell_1 ... Cell_98 Cell_99\n", "colData names(9): n_genes_by_counts log1p_n_genes_by_counts ...\n", " pct_counts_in_top_500_genes ident\n", "reducedDimNames(2): PCA UMAP\n", - "mainExpName: RNA\n", + "mainExpName: NULL\n", "altExpNames(0):\n" ] } @@ -647,43 +664,29 @@ "name": "stdout", "output_type": "stream", "text": [ - "10 x 10 sparse Matrix of class \"dgCMatrix\"\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "R[write to console]: [[ suppressing 10 column names ‘Cell_0’, ‘Cell_1’, ‘Cell_2’ ... ]]\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " \n", - "Gene-0 618.1942 . . . 949.6983 . 608.6559\n", - "Gene-1 . 594.1473 575.2669 . 1392.9609 595.4419 1214.5455\n", - "Gene-2 1231.7654 594.1473 . 617.6376 . 595.4419 1214.5455\n", - "Gene-3 618.1942 . 575.2669 617.6376 598.4406 . 608.6559\n", - "Gene-4 . 594.1473 575.2669 . . 595.4419 963.3034\n", - "Gene-5 618.1942 594.1473 . . 598.4406 . . \n", - "Gene-6 977.4848 . 575.2669 1230.5427 598.4406 . 608.6559\n", - "Gene-7 . . . 617.6376 . . . \n", - "Gene-8 . . 918.1847 . 598.4406 945.0467 . \n", - "Gene-9 977.4848 1191.4993 918.1847 617.6376 949.6983 945.0467 . \n", - " \n", - "Gene-0 956.9127 . . \n", - "Gene-1 956.9127 1008.0197 942.5265\n", - "Gene-2 1208.2042 640.4155 . \n", - "Gene-3 956.9127 1467.0044 593.2510\n", - "Gene-4 . 640.4155 . \n", - "Gene-5 956.9127 640.4155 . \n", - "Gene-6 956.9127 1008.0197 942.5265\n", - "Gene-7 603.1238 640.4155 . \n", - "Gene-8 603.1238 . 942.5265\n", - "Gene-9 1208.2042 . . \n" + "10 x 10 sparse Matrix of class \"dgCMatrix\"\n", + " \n", + " [1,] . 625.3202 . 593.0955 601.1306 628.6514 1230.1163\n", + " [2,] 1196.7954 985.8732 . 593.0955 . 628.6514 976.7754\n", + " [3,] . . . 593.0955 . . 618.4087\n", + " [4,] 597.5137 625.3202 608.1254 . 601.1306 . 618.4087\n", + " [5,] . 625.3202 963.3317 . . . 618.4087\n", + " [6,] . 625.3202 608.1254 593.0955 601.1306 . 976.7754\n", + " [7,] 597.5137 . 1215.2093 . . 1247.1100 618.4087\n", + " [8,] . 625.3202 . 593.0955 . . 618.4087\n", + " [9,] 597.5137 985.8732 963.3317 . . . 976.7754\n", + "[10,] . 985.8732 . 593.0955 1202.7475 991.2440 . \n", + " \n", + " [1,] 614.4039 1405.3720 612.9151\n", + " [2,] 614.4039 . . \n", + " [3,] 614.4039 959.8685 612.9151\n", + " [4,] 971.4187 605.9740 612.9151\n", + " [5,] . 605.9740 . \n", + " [6,] 614.4039 605.9740 . \n", + " [7,] 614.4039 . . \n", + " [8,] 971.4187 605.9740 . \n", + " [9,] . . 612.9151\n", + "[10,] . . 612.9151\n" ] } ], @@ -725,8 +728,8 @@ { "data": { "text/plain": [ - "<2000x100 sparse matrix of type ''\n", - "\twith 126271 stored elements in Compressed Sparse Column format>" + "<2000x100 sparse matrix of type ''\n", + "\twith 126516 stored elements in Compressed Sparse Column format>" ] }, "execution_count": 8, @@ -736,10 +739,9 @@ ], "source": [ "counts_mat = adata.layers[\"counts\"].T\n", - "# rpy2.robjects.globalenv[\"counts_mat\"] = counts_mat\n", - "# cpm = rpy2.robjects.r(\"scuttle::calculateCPM(counts_mat)\")\n", - "# cpm\n", - "counts_mat" + "rpy2.robjects.globalenv[\"counts_mat\"] = counts_mat\n", + "cpm = rpy2.robjects.r(\"scuttle::calculateCPM(counts_mat)\")\n", + "cpm" ] }, { @@ -754,29 +756,33 @@ "cell_type": "code", "execution_count": 9, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "NULL\n" - ] - } - ], + "outputs": [], "source": [ - "%%R\n", + "%%R -i counts_mat -o magic_cpm\n", "# R code running using IPython magic\n", - "# magic_cpm <- scuttle::calculateCPM(counts_mat)" + "magic_cpm <- scuttle::calculateCPM(counts_mat)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "<2000x100 sparse matrix of type ''\n", + "\twith 126516 stored elements in Compressed Sparse Column format>" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Python code accessing the results\n", - "# magic_cpm" + "magic_cpm" ] }, { @@ -786,16 +792,40 @@ "source": [ "This is the approach you will most commonly see in later chapters. For more information about using **rpy2** please refer to [the documentation](https://rpy2.github.io/doc/latest/html/index.html).\n", "\n", - "To work with single-cell data in this way the [**anndata2ri** package](https://icb-anndata2ri.readthedocs-hosted.com/en/latest/) is especially useful. This is an extension to **rpy2** which allows R to see `AnnData` objects as `SingleCellExperiment` objects. This avoids unnecessary conversion and makes it easy to run R code on a Python object." + "To work with single-cell data in this way the [**anndata2ri** package](https://icb-anndata2ri.readthedocs-hosted.com/en/latest/) is especially useful. This is an extension to **rpy2** which allows R to see `AnnData` objects as `SingleCellExperiment` objects. This avoids unnecessary conversion and makes it easy to run R code on a Python object. It also enables the conversion of sparse **scipy** matrices like we saw above." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/luke.zappia/miniconda3/envs/interoperability/lib/python3.9/functools.py:888: NotConvertedWarning: Conversion 'py2rpy' not defined for objects of type ''\n", + " return dispatch(args[0].__class__)(*args, **kw)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + " sum detected total\n", + "Cell_0 2021 1279 2021\n", + "Cell_1 1914 1242 1914\n", + "Cell_2 1995 1248 1995\n", + "Cell_3 2044 1285 2044\n", + "Cell_4 2009 1277 2009\n", + "Cell_5 1916 1237 1916\n" + ] + } + ], "source": [ - "# USING AN R FUNCTION ON AN ANNDATA" + "%%R -i adata\n", + "qc <- scuttle::perCellQCMetrics(adata)\n", + "head(qc)" ] }, { @@ -830,7 +860,7 @@ "output_type": "stream", "text": [ "List (26 items)\n", - "\n" + "\n" ] } ], @@ -1115,81 +1145,91 @@ "Click to view session information\n", "
\n",
        "-----\n",
-       "anndata             0.8.0\n",
-       "numpy               1.23.5\n",
-       "rpy2                3.5.10\n",
-       "scanpy              1.9.1\n",
-       "scipy               1.10.1\n",
+       "anndata             0.9.2\n",
+       "anndata2ri          1.2\n",
+       "numpy               1.24.4\n",
+       "rpy2                3.5.11\n",
+       "scanpy              1.9.3\n",
+       "scipy               1.9.3\n",
        "session_info        1.0.0\n",
        "-----\n",
        "
\n", "
\n", "Click to view modules imported as dependencies\n", "
\n",
-       "PIL                         9.4.0\n",
+       "CoreFoundation              NA\n",
+       "Foundation                  NA\n",
+       "PIL                         10.0.0\n",
+       "PyObjCTools                 NA\n",
        "anyio                       NA\n",
        "appnope                     0.1.3\n",
        "argcomplete                 NA\n",
+       "arrow                       1.2.3\n",
        "asttokens                   NA\n",
-       "attr                        22.2.0\n",
+       "attr                        23.1.0\n",
+       "attrs                       23.1.0\n",
        "babel                       2.12.1\n",
        "backcall                    0.2.0\n",
        "beta_ufunc                  NA\n",
        "binom_ufunc                 NA\n",
-       "brotli                      NA\n",
-       "certifi                     2022.12.07\n",
+       "brotli                      1.0.9\n",
+       "certifi                     2023.07.22\n",
        "cffi                        1.15.1\n",
-       "charset_normalizer          3.1.0\n",
+       "charset_normalizer          3.2.0\n",
        "colorama                    0.4.6\n",
-       "comm                        0.1.3\n",
+       "comm                        0.1.4\n",
        "cycler                      0.10.0\n",
        "cython_runtime              NA\n",
        "dateutil                    2.8.2\n",
-       "debugpy                     1.6.6\n",
+       "debugpy                     1.6.8\n",
        "decorator                   5.1.1\n",
        "defusedxml                  0.7.1\n",
        "executing                   1.2.0\n",
        "fastjsonschema              NA\n",
-       "h5py                        3.8.0\n",
+       "fqdn                        NA\n",
+       "h5py                        3.9.0\n",
        "hypergeom_ufunc             NA\n",
        "idna                        3.4\n",
        "importlib_metadata          NA\n",
-       "invgauss_ufunc              NA\n",
-       "ipykernel                   6.22.0\n",
+       "importlib_resources         NA\n",
+       "ipykernel                   6.25.0\n",
        "ipython_genutils            0.2.0\n",
-       "jedi                        0.18.2\n",
+       "ipywidgets                  8.1.0\n",
+       "isoduration                 NA\n",
+       "jedi                        0.19.0\n",
        "jinja2                      3.1.2\n",
-       "joblib                      1.2.0\n",
+       "joblib                      1.3.0\n",
        "json5                       NA\n",
-       "jsonschema                  4.17.3\n",
-       "jupyter_events              0.6.3\n",
-       "jupyter_server              2.5.0\n",
-       "jupyterlab_server           2.22.0\n",
+       "jsonpointer                 2.0\n",
+       "jsonschema                  4.18.6\n",
+       "jsonschema_specifications   NA\n",
+       "jupyter_events              0.7.0\n",
+       "jupyter_server              2.7.0\n",
+       "jupyterlab_server           2.24.0\n",
        "kiwisolver                  1.4.4\n",
-       "llvmlite                    0.39.1\n",
-       "markupsafe                  2.1.2\n",
-       "matplotlib                  3.6.3\n",
+       "llvmlite                    0.40.1\n",
+       "markupsafe                  2.1.3\n",
+       "matplotlib                  3.7.2\n",
        "mpl_toolkits                NA\n",
-       "natsort                     8.3.1\n",
-       "nbformat                    5.8.0\n",
+       "natsort                     8.4.0\n",
+       "nbformat                    5.9.2\n",
        "nbinom_ufunc                NA\n",
        "ncf_ufunc                   NA\n",
-       "nct_ufunc                   NA\n",
-       "ncx2_ufunc                  NA\n",
-       "numba                       0.56.4\n",
-       "packaging                   23.0\n",
-       "pandas                      1.5.3\n",
+       "numba                       0.57.1\n",
+       "objc                        9.2\n",
+       "overrides                   NA\n",
+       "packaging                   23.1\n",
+       "pandas                      2.0.3\n",
        "parso                       0.8.3\n",
        "pexpect                     4.8.0\n",
        "pickleshare                 0.7.5\n",
        "pkg_resources               NA\n",
-       "platformdirs                3.2.0\n",
+       "platformdirs                3.10.0\n",
        "prometheus_client           NA\n",
-       "prompt_toolkit              3.0.38\n",
-       "psutil                      5.9.4\n",
+       "prompt_toolkit              3.0.39\n",
+       "psutil                      5.9.5\n",
        "ptyprocess                  0.7.0\n",
        "pure_eval                   0.2.2\n",
-       "pvectorc                    NA\n",
        "pycparser                   2.21\n",
        "pydev_ipython               NA\n",
        "pydevconsole                NA\n",
@@ -1197,54 +1237,54 @@
        "pydevd_file_utils           NA\n",
        "pydevd_plugins              NA\n",
        "pydevd_tracing              NA\n",
-       "pygments                    2.14.0\n",
-       "pynndescent                 0.5.8\n",
+       "pygments                    2.15.1\n",
+       "pynndescent                 0.5.10\n",
        "pyparsing                   3.0.9\n",
-       "pyrsistent                  NA\n",
        "pythonjsonlogger            NA\n",
        "pytz                        2023.3\n",
-       "pytz_deprecation_shim       NA\n",
-       "requests                    2.28.2\n",
+       "referencing                 NA\n",
+       "requests                    2.31.0\n",
        "rfc3339_validator           0.1.4\n",
        "rfc3986_validator           0.1.1\n",
+       "rpds                        NA\n",
        "rpycall                     NA\n",
        "rpytools                    NA\n",
        "send2trash                  NA\n",
-       "setuptools                  67.6.1\n",
        "six                         1.16.0\n",
-       "skewnorm_ufunc              NA\n",
-       "sklearn                     1.2.2\n",
+       "sklearn                     1.3.0\n",
        "sniffio                     1.3.0\n",
        "socks                       1.7.1\n",
        "stack_data                  0.6.2\n",
-       "threadpoolctl               3.1.0\n",
-       "tornado                     6.2\n",
+       "threadpoolctl               3.2.0\n",
+       "tornado                     6.3.2\n",
        "tqdm                        4.65.0\n",
        "traitlets                   5.9.0\n",
        "typing_extensions           NA\n",
        "tzlocal                     NA\n",
        "umap                        0.5.3\n",
-       "urllib3                     1.26.15\n",
+       "uri_template                NA\n",
+       "urllib3                     2.0.4\n",
        "wcwidth                     0.2.6\n",
-       "websocket                   1.5.1\n",
+       "webcolors                   1.13\n",
+       "websocket                   1.6.1\n",
        "yaml                        6.0\n",
        "zipp                        NA\n",
-       "zmq                         25.0.2\n",
+       "zmq                         25.1.0\n",
        "zoneinfo                    NA\n",
        "
\n", "
\n", "
\n",
        "-----\n",
-       "IPython             8.12.0\n",
-       "jupyter_client      8.1.0\n",
-       "jupyter_core        5.3.0\n",
+       "IPython             8.14.0\n",
+       "jupyter_client      8.3.0\n",
+       "jupyter_core        5.3.1\n",
        "jupyterlab          3.6.3\n",
-       "notebook            6.5.3\n",
+       "notebook            6.5.4\n",
        "-----\n",
        "Python 3.9.16 | packaged by conda-forge | (main, Feb  1 2023, 21:42:20) [Clang 14.0.6 ]\n",
-       "macOS-12.6.3-x86_64-i386-64bit\n",
+       "macOS-13.4.1-x86_64-i386-64bit\n",
        "-----\n",
-       "Session information updated at 2023-04-03 18:08\n",
+       "Session information updated at 2023-08-08 12:03\n",
        "
\n", "" ], diff --git a/jupyter-book/introduction/interoperability_environment.yml b/jupyter-book/introduction/interoperability_environment.yml index e09c5dcb..af16e215 100644 --- a/jupyter-book/introduction/interoperability_environment.yml +++ b/jupyter-book/introduction/interoperability_environment.yml @@ -7,18 +7,20 @@ dependencies: - conda-forge::python=3.9.16 - conda-forge::jupyterlab=3.6.3 - conda-forge::scanpy=1.9.3 - - anndata2ri=1.1 + - anndata2ri=1.2 - bioconductor-basilisk=1.9.12 - bioconductor-scuttle=1.8.0 - bioconductor-singlecellexperiment=1.20.0 - bioconductor-zellkonverter=1.8.0 + - ipywidgets=8.1.0 - r-base=4.2 + - r-hdf5r=1.3.8 - r-remotes=2.4.2 - - r-reticulate=1.26 + - r-reticulate=1.30 - r-sessioninfo=1.2.2 - r-seurat=4.3.0 - r-seuratobject=4.1.3 - - rpy2=3.5.10 + - rpy2=3.5.11 - session-info=1.0.0 # Additional R packages installed manually using {remotes} # remotes::install_github("mojaveazure/seurat-disk@9b89970eac2a3bd770e744f63c7763419486b14c")