Skip to content

Commit

Permalink
Deploying to gh-pages from @ b41480e 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
LouiseDck committed Sep 11, 2024
1 parent 25568d6 commit 515affb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
24 changes: 12 additions & 12 deletions book/in_memory/rpy2.html
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,18 @@ <h2 data-number="4.1" class="anchored" data-anchor-id="rpy2-basic-functionality"
<div class="cell-output cell-output-stdout">
<pre><code>
0%| | 0.00/9.82M [00:00&lt;?, ?B/s]
0%| | 8.00k/9.82M [00:00&lt;02:09, 79.5kB/s]
0%| | 32.0k/9.82M [00:00&lt;01:01, 168kB/s]
1%| | 96.0k/9.82M [00:00&lt;00:27, 369kB/s]
2%|2 | 208k/9.82M [00:00&lt;00:15, 644kB/s]
4%|4 | 424k/9.82M [00:00&lt;00:08, 1.15MB/s]
9%|8 | 872k/9.82M [00:00&lt;00:04, 2.20MB/s]
18%|#7 | 1.72M/9.82M [00:00&lt;00:02, 4.23MB/s]
34%|###4 | 3.34M/9.82M [00:00&lt;00:00, 7.32MB/s]
53%|#####2 | 5.17M/9.82M [00:00&lt;00:00, 10.6MB/s]
65%|######4 | 6.34M/9.82M [00:01&lt;00:00, 10.9MB/s]
88%|########7 | 8.62M/9.82M [00:01&lt;00:00, 14.3MB/s]
100%|##########| 9.82M/9.82M [00:01&lt;00:00, 8.42MB/s]</code></pre>
0%| | 8.00k/9.82M [00:00&lt;03:15, 52.6kB/s]
0%| | 32.0k/9.82M [00:00&lt;01:31, 112kB/s]
1%| | 96.0k/9.82M [00:00&lt;00:41, 248kB/s]
2%|1 | 192k/9.82M [00:00&lt;00:25, 392kB/s]
4%|3 | 400k/9.82M [00:00&lt;00:13, 728kB/s]
8%|8 | 816k/9.82M [00:00&lt;00:06, 1.38MB/s]
17%|#6 | 1.62M/9.82M [00:01&lt;00:03, 2.70MB/s]
29%|##9 | 2.88M/9.82M [00:01&lt;00:01, 4.26MB/s]
51%|##### | 4.98M/9.82M [00:01&lt;00:00, 7.40MB/s]
70%|######9 | 6.83M/9.82M [00:01&lt;00:00, 8.85MB/s]
91%|######### | 8.90M/9.82M [00:01&lt;00:00, 10.3MB/s]
100%|##########| 9.82M/9.82M [00:01&lt;00:00, 5.73MB/s]</code></pre>
</div>
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a><span class="cf">with</span> anndata2ri.converter.context():</span>
Expand Down
2 changes: 1 addition & 1 deletion search.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"href": "book/in_memory/rpy2.html",
"title": "4  Rpy2",
"section": "",
"text": "4.1 Rpy2: basic functionality\nRpy2 is a foreign function interface to R. It can be used in the following way:\nimport rpy2\nimport rpy2.robjects as robjects\n\n/home/runner/work/polygloty/polygloty/renv/python/virtualenvs/renv-python-3.12/lib/python3.12/site-packages/rpy2/rinterface_lib/embedded.py:276: UserWarning: R was initialized outside of rpy2 (R_NilValue != NULL). Trying to use it nevertheless.\n warnings.warn(msg)\nR was initialized outside of rpy2 (R_NilValue != NULL). Trying to use it nevertheless.\n\nvector = robjects.IntVector([1,2,3])\nrsum = robjects.r['sum']\n\nrsum(vector)\n\n\n IntVector with 1 elements.\n \n\n\n\n6\nLuckily, we’re not restricted to just calling R functions and creating R objects. The real power of this in-memory interoperability lies in the conversion of Python objects to R objects to call R functions on, and then to the conversion of the results back to Python objects.\nRpy2 requires specific conversion rules for different Python objects. It is straightforward to create R vectors from corresponding Python lists:\nstr_vector = robjects.StrVector(['abc', 'def', 'ghi'])\nflt_vector = robjects.FloatVector([0.3, 0.8, 0.7])\nint_vector = robjects.IntVector([1, 2, 3])\nmtx = robjects.r.matrix(robjects.IntVector(range(10)), nrow=5)\nHowever, for single cell biology, the objects that are most interesting to convert are (count) matrices, arrays and dataframes. In order to do this, you need to import the corresponding rpy2 modules and specify the conversion context.\nimport numpy as np\n\nfrom rpy2.robjects import numpy2ri\nfrom rpy2.robjects import default_converter\n\nrd_m = np.random.random((10, 7))\n\nwith (default_converter + numpy2ri.converter).context():\n mtx2 = robjects.r.matrix(rd_m, nrow = 10)\nimport pandas as pd\n\nfrom rpy2.robjects import pandas2ri\n\npd_df = pd.DataFrame({'int_values': [1,2,3],\n 'str_values': ['abc', 'def', 'ghi']})\n\nwith (default_converter + pandas2ri.converter).context():\n pd_df_r = robjects.DataFrame(pd_df)\nOne big limitation of rpy2 is the inability to convert sparse matrices: there is no built-in conversion module for scipy. The anndata2ri package provides, apart from functionality to convert SingleCellExperiment objects to an anndata objects, functions to convert sparse matrices.\nimport scipy as sp\n\nfrom anndata2ri import scipy2ri\n\nsparse_matrix = sp.sparse.csc_matrix(rd_m)\n\nwith (default_converter + scipy2ri.converter).context():\n sp_r = scipy2ri.py2rpy(sparse_matrix)\nWe will showcase how to use anndata2ri to convert an anndata object to a SingleCellExperiment object and vice versa as well:\nimport anndata as ad\nimport scanpy.datasets as scd\n\nimport anndata2ri\n\nadata_paul = scd.paul15()\n\n\n 0%| | 0.00/9.82M [00:00&lt;?, ?B/s]\n 0%| | 8.00k/9.82M [00:00&lt;02:09, 79.5kB/s]\n 0%| | 32.0k/9.82M [00:00&lt;01:01, 168kB/s] \n 1%| | 96.0k/9.82M [00:00&lt;00:27, 369kB/s]\n 2%|2 | 208k/9.82M [00:00&lt;00:15, 644kB/s] \n 4%|4 | 424k/9.82M [00:00&lt;00:08, 1.15MB/s]\n 9%|8 | 872k/9.82M [00:00&lt;00:04, 2.20MB/s]\n 18%|#7 | 1.72M/9.82M [00:00&lt;00:02, 4.23MB/s]\n 34%|###4 | 3.34M/9.82M [00:00&lt;00:00, 7.32MB/s]\n 53%|#####2 | 5.17M/9.82M [00:00&lt;00:00, 10.6MB/s]\n 65%|######4 | 6.34M/9.82M [00:01&lt;00:00, 10.9MB/s]\n 88%|########7 | 8.62M/9.82M [00:01&lt;00:00, 14.3MB/s]\n100%|##########| 9.82M/9.82M [00:01&lt;00:00, 8.42MB/s]\n\n\nwith anndata2ri.converter.context():\n sce = anndata2ri.py2rpy(adata_paul)\n ad2 = anndata2ri.rpy2py(sce)",
"text": "4.1 Rpy2: basic functionality\nRpy2 is a foreign function interface to R. It can be used in the following way:\nimport rpy2\nimport rpy2.robjects as robjects\n\n/home/runner/work/polygloty/polygloty/renv/python/virtualenvs/renv-python-3.12/lib/python3.12/site-packages/rpy2/rinterface_lib/embedded.py:276: UserWarning: R was initialized outside of rpy2 (R_NilValue != NULL). Trying to use it nevertheless.\n warnings.warn(msg)\nR was initialized outside of rpy2 (R_NilValue != NULL). Trying to use it nevertheless.\n\nvector = robjects.IntVector([1,2,3])\nrsum = robjects.r['sum']\n\nrsum(vector)\n\n\n IntVector with 1 elements.\n \n\n\n\n6\nLuckily, we’re not restricted to just calling R functions and creating R objects. The real power of this in-memory interoperability lies in the conversion of Python objects to R objects to call R functions on, and then to the conversion of the results back to Python objects.\nRpy2 requires specific conversion rules for different Python objects. It is straightforward to create R vectors from corresponding Python lists:\nstr_vector = robjects.StrVector(['abc', 'def', 'ghi'])\nflt_vector = robjects.FloatVector([0.3, 0.8, 0.7])\nint_vector = robjects.IntVector([1, 2, 3])\nmtx = robjects.r.matrix(robjects.IntVector(range(10)), nrow=5)\nHowever, for single cell biology, the objects that are most interesting to convert are (count) matrices, arrays and dataframes. In order to do this, you need to import the corresponding rpy2 modules and specify the conversion context.\nimport numpy as np\n\nfrom rpy2.robjects import numpy2ri\nfrom rpy2.robjects import default_converter\n\nrd_m = np.random.random((10, 7))\n\nwith (default_converter + numpy2ri.converter).context():\n mtx2 = robjects.r.matrix(rd_m, nrow = 10)\nimport pandas as pd\n\nfrom rpy2.robjects import pandas2ri\n\npd_df = pd.DataFrame({'int_values': [1,2,3],\n 'str_values': ['abc', 'def', 'ghi']})\n\nwith (default_converter + pandas2ri.converter).context():\n pd_df_r = robjects.DataFrame(pd_df)\nOne big limitation of rpy2 is the inability to convert sparse matrices: there is no built-in conversion module for scipy. The anndata2ri package provides, apart from functionality to convert SingleCellExperiment objects to an anndata objects, functions to convert sparse matrices.\nimport scipy as sp\n\nfrom anndata2ri import scipy2ri\n\nsparse_matrix = sp.sparse.csc_matrix(rd_m)\n\nwith (default_converter + scipy2ri.converter).context():\n sp_r = scipy2ri.py2rpy(sparse_matrix)\nWe will showcase how to use anndata2ri to convert an anndata object to a SingleCellExperiment object and vice versa as well:\nimport anndata as ad\nimport scanpy.datasets as scd\n\nimport anndata2ri\n\nadata_paul = scd.paul15()\n\n\n 0%| | 0.00/9.82M [00:00&lt;?, ?B/s]\n 0%| | 8.00k/9.82M [00:00&lt;03:15, 52.6kB/s]\n 0%| | 32.0k/9.82M [00:00&lt;01:31, 112kB/s] \n 1%| | 96.0k/9.82M [00:00&lt;00:41, 248kB/s]\n 2%|1 | 192k/9.82M [00:00&lt;00:25, 392kB/s] \n 4%|3 | 400k/9.82M [00:00&lt;00:13, 728kB/s]\n 8%|8 | 816k/9.82M [00:00&lt;00:06, 1.38MB/s]\n 17%|#6 | 1.62M/9.82M [00:01&lt;00:03, 2.70MB/s]\n 29%|##9 | 2.88M/9.82M [00:01&lt;00:01, 4.26MB/s]\n 51%|##### | 4.98M/9.82M [00:01&lt;00:00, 7.40MB/s]\n 70%|######9 | 6.83M/9.82M [00:01&lt;00:00, 8.85MB/s]\n 91%|######### | 8.90M/9.82M [00:01&lt;00:00, 10.3MB/s]\n100%|##########| 9.82M/9.82M [00:01&lt;00:00, 5.73MB/s]\n\n\nwith anndata2ri.converter.context():\n sce = anndata2ri.py2rpy(adata_paul)\n ad2 = anndata2ri.rpy2py(sce)",
"crumbs": [
"In-memory interoperability",
"<span class='chapter-number'>4</span>  <span class='chapter-title'>Rpy2</span>"
Expand Down
36 changes: 18 additions & 18 deletions sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,74 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://saeyslab.github.io/polygloty/index.html</loc>
<lastmod>2024-09-11T19:57:09.780Z</lastmod>
<lastmod>2024-09-11T19:56:54.341Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/introduction.html</loc>
<lastmod>2024-09-11T19:57:09.776Z</lastmod>
<lastmod>2024-09-11T19:56:54.333Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/usecase/index.html</loc>
<lastmod>2024-09-11T19:57:09.776Z</lastmod>
<lastmod>2024-09-11T19:56:54.333Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/in_memory/pitfalls.html</loc>
<lastmod>2024-09-11T19:57:09.776Z</lastmod>
<lastmod>2024-09-11T19:56:54.333Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/in_memory/rpy2.html</loc>
<lastmod>2024-09-11T19:57:09.776Z</lastmod>
<lastmod>2024-09-11T19:56:54.333Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/in_memory/reticulate.html</loc>
<lastmod>2024-09-11T19:57:09.776Z</lastmod>
<lastmod>2024-09-11T19:56:54.333Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/disk_based/file_formats.html</loc>
<lastmod>2024-09-11T19:57:09.772Z</lastmod>
<lastmod>2024-09-11T19:56:54.329Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/disk_based/disk_based_pipelines.html</loc>
<lastmod>2024-09-11T19:57:09.772Z</lastmod>
<lastmod>2024-09-11T19:56:54.329Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/workflow_frameworks/review.html</loc>
<lastmod>2024-09-11T19:57:09.780Z</lastmod>
<lastmod>2024-09-11T19:56:54.337Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/workflow_frameworks/qualities.html</loc>
<lastmod>2024-09-11T19:57:09.780Z</lastmod>
<lastmod>2024-09-11T19:56:54.337Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/workflow_frameworks/quality_assessment.html</loc>
<lastmod>2024-09-11T19:57:09.780Z</lastmod>
<lastmod>2024-09-11T19:56:54.337Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/workflow_frameworks/viash_nextflow.html</loc>
<lastmod>2024-09-11T19:57:09.780Z</lastmod>
<lastmod>2024-09-11T19:56:54.337Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/workflow_frameworks/best_practices.html</loc>
<lastmod>2024-09-11T19:57:09.776Z</lastmod>
<lastmod>2024-09-11T19:56:54.333Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/book_slides.html</loc>
<lastmod>2024-09-11T19:57:09.772Z</lastmod>
<lastmod>2024-09-11T19:56:54.329Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/references.html</loc>
<lastmod>2024-09-11T19:57:09.776Z</lastmod>
<lastmod>2024-09-11T19:56:54.333Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/in_memory/index.html</loc>
<lastmod>2024-09-11T19:57:09.776Z</lastmod>
<lastmod>2024-09-11T19:56:54.333Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/disk_based/index.html</loc>
<lastmod>2024-09-11T19:57:09.772Z</lastmod>
<lastmod>2024-09-11T19:56:54.329Z</lastmod>
</url>
<url>
<loc>https://saeyslab.github.io/polygloty/book/workflow_frameworks/index.html</loc>
<lastmod>2024-09-11T19:57:09.780Z</lastmod>
<lastmod>2024-09-11T19:56:54.337Z</lastmod>
</url>
</urlset>

0 comments on commit 515affb

Please sign in to comment.