{"id":560,"date":"2025-06-11T10:48:30","date_gmt":"2025-06-11T02:48:30","guid":{"rendered":"https:\/\/www.kz-hub.tech\/?p=560"},"modified":"2025-10-28T09:16:25","modified_gmt":"2025-10-28T01:16:25","slug":"pyscenic%e7%9a%84%e5%ae%89%e8%a3%85%e5%8f%8a%e8%bf%90%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/www.kz-hub.tech\/index.php\/2025\/06\/11\/pyscenic%e7%9a%84%e5%ae%89%e8%a3%85%e5%8f%8a%e8%bf%90%e8%a1%8c\/","title":{"rendered":"pySCENIC\u7684\u5b89\u88c5\u53ca\u8fd0\u884c"},"content":{"rendered":"<h3>1.\u5b89\u88c5pyscenic<\/h3>\n<pre><code># \u53c2\u8003\uff1ahttps:\/\/cloud.tencent.com\/developer\/article\/2228252\n# \u9700\u8981\u4e00\u4e9b\u4f9d\u8d56\nconda create -n pyscenic python=3.7 \nconda activate pyscenic \n\nmamba install -y numpy scanpy\nmamba install -y -c anaconda cytoolz\n\npip install pyscenic <\/code><\/pre>\n<h3>2. \u6570\u636e\u5e93\u914d\u7f6e<\/h3>\n<pre><code>https:\/\/resources.aertslab.org\/cistarget\/\n\u4e0b\u8f7d\uff1a\n1. databases\/homo_sapiens\/hg38\/refseq_r80\/mc_v10_clust\/gene_based\/hg38_10kbp_up_10kbp_down_full_tx_v10_clust.genes_vs_motifs.rankings.feather\n2. motif2tf\/motifs-v10nr_clust-nr.hgnc-m0.001-o0.0.tbl\n3. tf_lists\/allTFs_hg38.txt\n<\/code><\/pre>\n<h3>3. R\u5305\u5b89\u88c5<\/h3>\n<pre><code>## SCENIC\u9700\u8981\u4e00\u4e9b\u4f9d\u8d56\u5305\uff0c\u5148\u5b89\u88c5\u597d\ninstall.package(&quot;BiocManager&quot;)\nBiocManager::install(c(&quot;AUCell&quot;, &quot;RcisTarget&quot;,&quot;GENIE3&quot;,&quot;zoo&quot;, &quot;mixtools&quot;, &quot;rbokeh&quot;,&quot;DT&quot;, &quot;NMF&quot;, &quot;pheatmap&quot;, &quot;R2HTML&quot;, &quot;Rtsne&quot;,&quot;doMC&quot;, &quot;doRNG&quot;,&quot;scRNAseq&quot;))\ndevtools::install_github(&quot;aertslab\/SCopeLoomR&quot;, build_vignettes = TRUE)\ndevtools::install_github(&quot;aertslab\/SCENIC&quot;)\nBiocManager::install(&quot;Seurat&quot;)\n#check\nlibrary(SCENIC)\npackageVersion(&quot;SCENIC&quot;)<\/code><\/pre>\n<h3>4. \u5206\u6b65\u9aa4\u8fd0\u884cpySCENIC<\/h3>\n<h4>4.1 Step1. R\u4e2d\u5bfc\u51fa\u8868\u8fbe\u77e9\u9635<\/h4>\n<pre><code>library(Seurat)\nlibrary(data.table)\nSeurat_obj &lt;- readRDS(&quot;\/home\/zhoukaiwen\/Path\/To\/EXAMPLE.rds&quot;)\ntmp_matrix &lt;- as.data.frame(GetAssayData(Seurat_obj,slot=&quot;counts&quot;))\nfwrite(tmp_matrix,file = &quot;EXAMPLE_input.csv&quot;, col.names=T, row.names=T, sep=&#039;,&#039;, quote=F)<\/code><\/pre>\n<h4>4.2 Step2. Python\u4e2d\u5c06\u8868\u8fbe\u77e9\u9635\u5bfc\u51fa\u4e3aloom\u683c\u5f0f<\/h4>\n<pre><code>import os, sys\nos.getcwd()\nos.listdir(os.getcwd()) \n\nimport loompy as lp\nimport numpy as np\nimport scanpy as sc\nx=sc.read_csv(&quot;EXAMPLE_input.csv&quot;)\nrow_attrs = {&quot;Gene&quot;: np.array(x.obs_names),}\ncol_attrs = {&quot;CellID&quot;: np.array(x.var_names)}\nlp.create(&quot;EXAMPLE_input.loom&quot;,x.X,row_attrs,col_attrs)<\/code><\/pre>\n<h4>4.3 Step3. \u6b63\u5f0f\u8fd0\u884cpySCENIC<\/h4>\n<pre><code># \u4e0d\u540c\u7269\u79cd\u7684\u6570\u636e\u5e93\u4e0d\u4e00\u6837\uff0c\u8fd9\u91cc\u662f\u4eba\u7c7b\u662fhuman \ndir=\/home\/zhoukaiwen\/database\/cisTarget\ntfs=$dir\/hs_hgnc_tfs.txt\nfeather=$dir\/hg19-tss-centered-10kb-7species.mc9nr.genes_vs_motifs.rankings.feather\ntbl=$dir\/motifs-v9-nr.hgnc-m0.001-o0.0.tbl \n# \u4e00\u5b9a\u8981\u4fdd\u8bc1\u4e0a\u9762\u7684\u6570\u636e\u5e93\u6587\u4ef6\u5b8c\u6574\u65e0\u8bef\u54e6 \ninput_loom=EXAMPLE_input.loom\nls $tfs  $feather  $tbl  \n\npyscenic grn \\\n--num_workers 8 \\\n--output grn.tsv \\\n--method grnboost2 \\\n$input_loom  $tfs \n\necho pyscenic step3.1 grn done\n\npyscenic ctx \\\ngrn.tsv $feather \\\n--annotations_fname $tbl \\\n--expression_mtx_fname $input_loom  \\\n--mode &quot;dask_multiprocessing&quot; \\\n--output ctx.csv \\\n--num_workers 8  \\\n--mask_dropouts\n\necho pyscenic step3.2 ctx done\n\npyscenic aucell \\\n$input_loom \\\nctx.csv \\\n--output EXAMPLE_output.loom \\\n--num_workers 10 \n\necho pyscenic step3.3 aucell done<\/code><\/pre>\n<h4>4.4 R \u4e2d\u53ef\u89c6\u5316<\/h4>\n<pre><code>library(SCENIC)\npackageVersion(&quot;SCENIC&quot;)  \nlibrary(SCopeLoomR)\nlibrary(Seurat)\nlibrary(SeuratWrappers)\nscenicLoomPath=&#039;out_SCENIC.loom&#039;\nloom &lt;- open_loom(scenicLoomPath)\n# Read information from loom file: \nregulons_incidMat &lt;- get_regulons(loom, column.attr.name=&quot;Regulons&quot;)\nregulons &lt;- regulonsToGeneLists(regulons_incidMat)\nregulonAUC &lt;- get_regulons_AUC(loom, column.attr.name=&quot;RegulonsAUC&quot;) \nsce=readRDS(&quot;PD1_cancer.rds&quot;)\nsce\n\nlibrary(pheatmap) \nn=t(scale(t( getAUC(regulonAUC[,] )))) # &#039;scale&#039;\u53ef\u4ee5\u5bf9log-ratio\u6570\u503c\u8fdb\u884c\u5f52\u4e00\u5316\nn[n&gt;2]=2 \nn[n&lt; -2]= -2\nn[1:4,1:4]\ndim(n) \nac=data.frame(group= as.character( Idents(sce)))\nn[1:4,1:4]\nn=n[,colnames(n) %in% colnames(sce)]\nrownames(ac)=colnames(n) \n#cg=read.table(&#039;choose_tf.txt&#039;)[,1]\n#cg\n#cg_n=n[rownames(n) %in% cg,]\ncg_n &lt;- n\n#p1&lt;-pheatmap(cg_n,show_colnames =F,show_rownames = T,annotation_col=ac)\ntable(ac$group)\n\n#p2&lt;-pheatmap(cg_n,show_colnames =F,show_rownames = T,annotation_col=ac)\npheatmap(cg_n,show_colnames =F,show_rownames = T,\n         annotation_col=ac,\n         filename = &#039;heatmap_choose_regulon.png&#039;)\ndev.off()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1.\u5b89\u88c5pyscenic # \u53c2\u8003\uff1ahttps:\/\/cloud.tencent.com\/developer\/a&#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-560","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\/560","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=560"}],"version-history":[{"count":5,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/560\/revisions"}],"predecessor-version":[{"id":648,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/560\/revisions\/648"}],"wp:attachment":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/media?parent=560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/categories?post=560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/tags?post=560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}