{"id":654,"date":"2025-11-21T09:27:38","date_gmt":"2025-11-21T01:27:38","guid":{"rendered":"https:\/\/www.kz-hub.tech\/?p=654"},"modified":"2025-11-21T09:27:38","modified_gmt":"2025-11-21T01:27:38","slug":"%e4%bd%bf%e7%94%a8regdiffusion%e6%9b%bf%e4%bb%a3pyscenic%e7%9a%84-grnboost2-genie3-%e8%bf%9b%e8%a1%8c%e5%9f%ba%e5%9b%a0%e8%b0%83%e6%8e%a7%e7%bd%91%e7%bb%9c%e5%88%86%e6%9e%90grn","status":"publish","type":"post","link":"https:\/\/www.kz-hub.tech\/index.php\/2025\/11\/21\/%e4%bd%bf%e7%94%a8regdiffusion%e6%9b%bf%e4%bb%a3pyscenic%e7%9a%84-grnboost2-genie3-%e8%bf%9b%e8%a1%8c%e5%9f%ba%e5%9b%a0%e8%b0%83%e6%8e%a7%e7%bd%91%e7%bb%9c%e5%88%86%e6%9e%90grn\/","title":{"rendered":"\u4f7f\u7528RegDiffusion\u66ff\u4ee3pySCENIC\u7684 GRNBoost2 &#038; GENIE3 \u8fdb\u884c\u57fa\u56e0\u8c03\u63a7\u7f51\u7edc\u5206\u6790(GRN)"},"content":{"rendered":"<p>\u5b98\u7f51\u94fe\u63a5\uff1a<a href=\"https:\/\/tuftsbcb.github.io\/RegDiffusion\/downstream_with_pyscenic.html\">https:\/\/tuftsbcb.github.io\/RegDiffusion\/downstream_with_pyscenic.html<\/a><\/p>\n<h2>1. Gene Regulatory Network (GRN) Inference (python3.12)<\/h2>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u4f4e\u7248\u672cpython\u7684scanpy\u65e0\u6cd5\u8bfb\u53d6SeuratV5\u8f6c\u6362\u540e\u7684h5ad\uff0c\u4ee5\u4e0b\u4ee3\u7801\u4ec5\u5728python3.12\u7684scanpy\u8fd0\u884c\u6d4b\u8bd5\u8fc7<\/p>\n<pre><code>import numpy as np\nimport pandas as pd\nimport scanpy as sc\nimport regdiffusion as rd\nimport loompy as lp\n\nh5ad_path = f&#039;16samples_Merged_AllCells_Annotated_Final.h5ad&#039;\ncisdb_path = f&#039;\/home\/zhoukaiwen\/database\/cisTarget\/hg38_10kbp_up_10kbp_down_full_tx_v10_clust.genes_vs_motifs.rankings.feather&#039;\n\n# Load data\nadata = sc.read_h5ad(h5ad_path)\n\n# Filter the gene not present in the cisTargetDB\ncisdb = pd.read_feather(cisdb_path)\nadata = adata[:, adata.var_names.isin(cisdb.columns)]\nadata\n\n# .X has been normalized so we need to get from the counts layer.\n# Counts is stored in a sparse matrix so we need to turn it to an array and \n# then perform log + 1 transformation.\nx = adata.layers[&quot;counts&quot;].toarray()\nx = np.log(x+1.0)\n\n# run RegDiffusionTrainer\nrd_trainer = rd.RegDiffusionTrainer(x)\nrd_trainer.train()\n\n# Extract edges from GRN\n## Now we focus on edges with weight &gt; 50 percentile. \ngrn = rd_trainer.get_grn(adata.var_names, top_gene_percentile=50)\n\n## Here for each gene, we are going to extract all edges\nedgelist = grn.extract_edgelist(k=-1, workers=4) # By default, k=20. If you want to extract all edges, you can set k=-1\nedgelist.columns = [&#039;TF&#039;, &#039;target&#039;, &#039;importance&#039;]\nedgelist.to_csv(f&#039;grn_naive.tsv&#039;, sep=&#039;\\t&#039;, index=False)\n\n## check edgelist.  \nedgelist\n\nlp.create(\n    filename=f&#039;mtx.loom&#039;,\n    layers={&quot;&quot;: x.transpose()},\n    row_attrs={&quot;Gene&quot;: list(adata.var_names)},\n    col_attrs={&quot;CellID&quot;: list(adata.obs_names)}\n)<\/code><\/pre>\n<p>\u7531\u4e8e\u670d\u52a1\u5668\u6ca1\u6709\u5f00\u653e\u663e\u5361\u8282\u70b9\uff0c\u672c\u6570\u636e11w\u7ec6\u80de\uff0c10\u6838cpu\u8fd0\u884c\u9700\u7ea630h\u5de6\u53f3<\/p>\n<h2>2. Prunning and AUCell Calculation in PySCENIC (python3.7)<\/h2>\n<p>\u6b64\u5904\u9700\u8981\u5b89\u88c5\u5728conda\u4e2d\u65b0\u5efapython3.7\u73af\u5883\u5b89\u88c5pySCENIC<\/p>\n<pre><code>#!\/bin\/bash\n#SBATCH --ntasks 4\n#SBATCH -N 1\n#SBATCH -o RunpySCENIC2.o\n#SBATCH -e RunpySCENIC2.o\n#SBATCH --job-name=pySCENIC2\nsource \/home\/zhoukaiwen\/software\/anaconda3\/bin\/activate\nconda activate pyscenic\n\ndir=\/home\/zhoukaiwen\/database\/cisTarget\ntfs=$dir\/hs_hgnc_tfs.txt\nfeather=$dir\/hg38_10kbp_up_10kbp_down_full_tx_v10_clust.genes_vs_motifs.rankings.feather\ntbl=$dir\/motifs-v10nr_clust-nr.hgnc-m0.001-o0.0.tbl\nls $tfs  $feather  $tbl\n\n# \u6b64\u5904\u5bfc\u5165\u4e0a\u4e00\u6b65\u7684\u7ed3\u679c\ngrn_fp=grn_naive.tsv\nexp_mtx_fp=mtx.loom\n\npyscenic ctx \\\n$grn_fp $feather \\\n--annotations_fname $tbl \\\n--expression_mtx_fname $exp_mtx_fp  \\\n--mode &quot;dask_multiprocessing&quot; \\\n--output ctx.csv \\\n--num_workers 10 \\\n--mask_dropouts\n\necho pyscenic step3.2 ctx done\n\npyscenic aucell \\\n$exp_mtx_fp \\\nctx.csv \\\n--output 16samples_Merged_AllCells_Annotated_Final_pyscenic_Result.loom \\\n--num_workers 10\n\necho pyscenic step3.3 aucell done<\/code><\/pre>\n<p>\u540e\u7eed\u9009\u62e9\u7528scanpy\u6216seurat\u53ef\u89c6\u5316<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b98\u7f51\u94fe\u63a5\uff1ahttps:\/\/tuftsbcb.github.io\/RegDiffusion\/downstream&#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-654","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\/654","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=654"}],"version-history":[{"count":1,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/654\/revisions"}],"predecessor-version":[{"id":655,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/654\/revisions\/655"}],"wp:attachment":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/media?parent=654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/categories?post=654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/tags?post=654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}