{"id":311,"date":"2024-11-06T08:45:54","date_gmt":"2024-11-06T00:45:54","guid":{"rendered":"https:\/\/www.kz-hub.tech\/?p=311"},"modified":"2024-11-06T11:42:38","modified_gmt":"2024-11-06T03:42:38","slug":"%e5%8d%95%e7%bb%86%e8%83%9eseurath5h5adloom","status":"publish","type":"post","link":"https:\/\/www.kz-hub.tech\/index.php\/2024\/11\/06\/%e5%8d%95%e7%bb%86%e8%83%9eseurath5h5adloom\/","title":{"rendered":"\u5355\u7ec6\u80deSeurat>h5>h5ad>loom"},"content":{"rendered":"<h5>Seurat&gt;h5 (R\u7684Dior\u5305)<\/h5>\n<pre><code class=\"language-bash\"># \u9996\u5148\u5728\uff5e\/.bashrc\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff0c\u9632\u6b62\u6587\u4ef6\u53ea\u80fd\u8bfb\/\u5199\nexport HDF5_USE_FILE_LOCKING=&quot;FALSE&quot;\nexport RHDF5_USE_FILE_LOCKING=&quot;FALSE&quot;\n\n# \u7136\u540e\u9700\u8981\u521b\u5efaconda\u73af\u5883\nconda create -n dior\nconda activate dior\nconda install anndata==0.6.19 scipy==1.2.1 -c bioconda\nconda install loompy -c bioconda<\/code><\/pre>\n<pre><code class=\"language-R\">conda activate dior\nR\n\nlibrary(Seurat)\nlibrary(dior)\nlibrary(SeuratDisk)\nlibrary(sceasy)\nuse_condaenv(&#039;sceasy&#039;)\nloompy &lt;- reticulate::import(&#039;loompy&#039;)\n\nseurat_obj &lt;- readRDS(&quot;seurat_obj.rds&quot;)\nseurat_obj = DietSeurat(\n  seurat_obj,\n  counts = TRUE, # so, raw counts save to adata.raw.X\n  data = TRUE, # so, log1p counts save to adata.X\n  scale.data = FALSE, # set to false, or else will save to adata.X\n  features = rownames(seurat_obj), # export all genes, not just top highly variable genes\n  assays = &quot;RNA&quot;,\n  dimreducs = c(&quot;pca&quot;,&quot;umap&quot;),\n  graphs = c(&quot;RNA_nn&quot;, &quot;RNA_snn&quot;), # to RNA_nn -&gt; distances, RNA_snn -&gt; connectivities\n  misc = TRUE\n)\n\n# step 2: factor to character, or else your factor will be number in adata\ni &lt;- sapply(seurat_obj@meta.data, is.factor)\nseurat_obj@meta.data[i] &lt;- lapply(seurat_obj@meta.data[i], as.character)\n\n# step 3: convert\n# in R\ndior::write_h5(seurat_obj, file=&#039;seurat_obj.h5&#039;, object.type = &#039;seurat&#039;)\n<\/code><\/pre>\n<h4>h5&gt;h5ad(Python\u7684scanpy+diopy)<\/h4>\n<pre><code>import diopy as diopy\nadata = diopy.input.read_h5(file = &#039;seurat_obj.h5&#039;)\nadata.write(&quot;seurat_obj.h5ad&quot;)\nadata.write_loom(&quot;seurat_obj.loom&quot;,write_obsm_varm=True)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Seurat&gt;h5 (R\u7684Dior\u5305) # \u9996\u5148\u5728\uff5e\/.bashrc\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff0c\u9632\u6b62\u6587\u4ef6\u53ea\u80fd\u8bfb\/\u5199 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-311","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/comments?post=311"}],"version-history":[{"count":7,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/311\/revisions"}],"predecessor-version":[{"id":318,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/311\/revisions\/318"}],"wp:attachment":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/media?parent=311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/categories?post=311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/tags?post=311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}