1111.html 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. <!DOCTYPE html>
  2. <html lang="en" data-default-color-scheme=auto>
  3. <head><!-- hexo injector head_begin start -->
  4. <script async src="https://analytics.umami.is/script.js" data-website-id="e59ec28a-c9a7-4104-9e62-a9f7eb3fac0b"></script>
  5. <!-- hexo injector head_begin end -->
  6. <meta charset="UTF-8">
  7. <link rel="apple-touch-icon" sizes="76x76" href="https://img.limour.top/2023/08/29/64ee07361815a.webp">
  8. <link rel="icon" href="https://img.limour.top/2023/08/29/64ee07361815a.webp">
  9. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  10. <meta http-equiv="x-ua-compatible" content="ie=edge">
  11. <meta name="theme-color" content="#2f4154">
  12. <meta name="author" content="Limour">
  13. <meta name="keywords" content="">
  14. <meta name="description" content="前置要求pyscenic (一) 转录因子分析 pySCENIC aertslab&#x2F;pySCENIC第一步 准备数据库 设置工作目录 123456789101112import os# 配置数据路径root_path &#x3D; os.path.expanduser(&quot;~&#x2F;zlliu&#x2F;R_output&#x2F;21.10.23.pyscenic&quot;) # 配置结果保存路径output">
  15. <meta property="og:type" content="article">
  16. <meta property="og:title" content="pyscenic (二) 转录因子分析">
  17. <meta property="og:url" content="https://b.limour.top/1111.html">
  18. <meta property="og:site_name" content="Limour&#39;s Blog">
  19. <meta property="og:description" content="前置要求pyscenic (一) 转录因子分析 pySCENIC aertslab&#x2F;pySCENIC第一步 准备数据库 设置工作目录 123456789101112import os# 配置数据路径root_path &#x3D; os.path.expanduser(&quot;~&#x2F;zlliu&#x2F;R_output&#x2F;21.10.23.pyscenic&quot;) # 配置结果保存路径output">
  20. <meta property="og:locale" content="en_US">
  21. <meta property="article:published_time" content="2021-10-23T05:42:47.000Z">
  22. <meta property="article:modified_time" content="2023-09-01T13:32:00.625Z">
  23. <meta property="article:author" content="Limour">
  24. <meta name="twitter:card" content="summary_large_image">
  25. <title>pyscenic (二) 转录因子分析 - Limour&#39;s Blog</title>
  26. <link rel="stylesheet" href="https://jscdn.limour.top/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" />
  27. <link rel="stylesheet" href="https://jscdn.limour.top/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
  28. <link rel="stylesheet" href="https://jscdn.limour.top/npm/hint.css@2.7.0/hint.min.css" />
  29. <link rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />
  30. <!-- 主题依赖的图标库,不要自行修改 -->
  31. <!-- Do not modify the link that theme dependent icons -->
  32. <link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">
  33. <link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">
  34. <link rel="stylesheet" href="/css/main.css" />
  35. <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  36. <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  37. <link rel="stylesheet" href="/theme-inject/custom.css">
  38. <script id="fluid-configs">
  39. var Fluid = window.Fluid || {};
  40. Fluid.ctx = Object.assign({}, Fluid.ctx)
  41. var CONFIG = {"hostname":"b.limour.top","root":"/","version":"1.9.5-a","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":"§"},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"https://jscdn.limour.top/gh/Limour-dev/Sakurairo_Vision/load_svg/inload.svg","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};
  42. if (CONFIG.web_analytics.follow_dnt) {
  43. var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
  44. Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
  45. }
  46. </script>
  47. <script src="/js/utils.js" ></script>
  48. <script src="/js/color-schema.js" ></script>
  49. <meta name="generator" content="Hexo 6.3.0"></head>
  50. <body>
  51. <header>
  52. <div class="header-inner" style="height: 70vh;">
  53. <nav id="navbar" class="navbar fixed-top navbar-expand-lg navbar-dark scrolling-navbar">
  54. <div class="container">
  55. <a class="navbar-brand" href="/">
  56. <strong>Limour&#39;s Blog</strong>
  57. </a>
  58. <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
  59. data-target="#navbarSupportedContent"
  60. aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  61. <div class="animated-icon"><span></span><span></span><span></span></div>
  62. </button>
  63. <!-- Collapsible content -->
  64. <div class="collapse navbar-collapse" id="navbarSupportedContent">
  65. <ul class="navbar-nav ml-auto text-center">
  66. <li class="nav-item">
  67. <a class="nav-link" href="/">
  68. <i class="iconfont icon-home-fill"></i>
  69. <span>Home</span>
  70. </a>
  71. </li>
  72. <li class="nav-item">
  73. <a class="nav-link" href="/archives/">
  74. <i class="iconfont icon-archive-fill"></i>
  75. <span>Archives</span>
  76. </a>
  77. </li>
  78. <li class="nav-item" id="search-btn">
  79. <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
  80. <i class="iconfont icon-search"></i>
  81. </a>
  82. </li>
  83. <li class="nav-item" id="color-toggle-btn">
  84. <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
  85. <i class="iconfont icon-dark" id="color-toggle-icon"></i>
  86. </a>
  87. </li>
  88. </ul>
  89. </div>
  90. </div>
  91. </nav>
  92. <div id="banner" class="banner" parallax=true
  93. style="background: url('https://img.limour.top/2023/08/29/64ee08e108638.webp') no-repeat center center; background-size: cover;">
  94. <div class="full-bg-img">
  95. <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
  96. <div class="banner-text text-center fade-in-up">
  97. <div class="h2">
  98. <span id="subtitle" data-typed-text="pyscenic (二) 转录因子分析"></span>
  99. </div>
  100. <div class="mt-3">
  101. <span class="post-meta">
  102. <i class="iconfont icon-date-fill" aria-hidden="true"></i>
  103. <time datetime="2021-10-23 13:42" pubdate>
  104. October 23, 2021 pm
  105. </time>
  106. </span>
  107. </div>
  108. <div class="mt-1">
  109. <span class="post-meta mr-2">
  110. <i class="iconfont icon-chart"></i>
  111. 4.4k words
  112. </span>
  113. <span class="post-meta mr-2">
  114. <i class="iconfont icon-clock-fill"></i>
  115. 37 mins
  116. </span>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. </header>
  124. <main>
  125. <div class="container-fluid nopadding-x">
  126. <div class="row nomargin-x">
  127. <div class="side-col d-none d-lg-block col-lg-2">
  128. </div>
  129. <div class="col-lg-8 nopadding-x-md">
  130. <div class="container nopadding-x-md" id="board-ctn">
  131. <div id="board">
  132. <article class="post-content mx-auto">
  133. <h1 id="seo-header">pyscenic (二) 转录因子分析</h1>
  134. <div class="markdown-body">
  135. <h2 id="前置要求"><a href="#前置要求" class="headerlink" title="前置要求"></a>前置要求</h2><p><a target="_blank" rel="noopener" href="https://limour.top/1063.html">pyscenic (一) 转录因子分析</a></p>
  136. <p><a target="_blank" rel="noopener" href="https://pyscenic.readthedocs.io/en/latest/index.html">pySCENIC</a></p>
  137. <h4 id="aertslab-pySCENIC"><a href="#aertslab-pySCENIC" class="headerlink" title="aertslab&#x2F;pySCENIC"></a><a target="_blank" rel="noopener" href="https://github.com/aertslab">aertslab</a>&#x2F;<strong><a target="_blank" rel="noopener" href="https://github.com/aertslab/pySCENIC">pySCENIC</a></strong></h4><h2 id="第一步-准备数据库"><a href="#第一步-准备数据库" class="headerlink" title="第一步 准备数据库"></a>第一步 准备数据库</h2><ul>
  138. <li>设置工作目录</li>
  139. </ul>
  140. <figure class="highlight pf"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs pf">import <span class="hljs-keyword">os</span><br><span class="hljs-comment"># 配置数据路径</span><br>root_path = <span class="hljs-keyword">os</span>.path.expanduser(<span class="hljs-string">&quot;~/zlliu/R_output/21.10.23.pyscenic&quot;</span>)<br> <br><span class="hljs-comment"># 配置结果保存路径</span><br>output_path = root_path<br>if not <span class="hljs-keyword">os</span>.path.isdir(output_path):<br> <span class="hljs-keyword">os</span>.makedirs(output_path)<br><br><span class="hljs-comment"># 设置工作目录,输出文件将保存在此目录下</span><br><span class="hljs-keyword">os</span>.chdir(output_path) <br><span class="hljs-keyword">os</span>.getcwd()<br></code></pre></td></tr></table></figure>
  141. <ul>
  142. <li>下载智人的转录因子列表 <a target="_blank" rel="noopener" href="https://github.com/aertslab/pySCENIC/tree/master/resources">https://github.com/aertslab/pySCENIC/tree/master/resources</a></li>
  143. </ul>
  144. <figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk">!wget https:<span class="hljs-regexp">//</span>raw.githubusercontent.com<span class="hljs-regexp">/aertslab/</span>pySCENIC<span class="hljs-regexp">/master/</span>resources/hs_hgnc_tfs.txt<br></code></pre></td></tr></table></figure>
  145. <ul>
  146. <li>下载 annotations file <a target="_blank" rel="noopener" href="https://pyscenic.readthedocs.io/en/latest/installation.html#auxiliary-datasets">https://pyscenic.readthedocs.io/en/latest/installation.html#auxiliary-datasets</a></li>
  147. </ul>
  148. <figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk">!wget https:<span class="hljs-regexp">//</span>resources.aertslab.org<span class="hljs-regexp">/cistarget/m</span>otif2tf/motifs-v9-nr.hgnc-m0.<span class="hljs-number">001</span>-o0.<span class="hljs-number">0</span>.tbl<br></code></pre></td></tr></table></figure>
  149. <ul>
  150. <li>下载 Auxiliary datasets <a target="_blank" rel="noopener" href="https://resources.aertslab.org/cistarget/">https://resources.aertslab.org/cistarget/</a></li>
  151. </ul>
  152. <figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk">!wget https:<span class="hljs-regexp">//</span>resources.aertslab.org<span class="hljs-regexp">/cistarget/</span>databases<span class="hljs-regexp">/homo_sapiens/</span>hg38<span class="hljs-regexp">/refseq_r80/m</span>c9nr<span class="hljs-regexp">/gene_based/</span>hg38__refseq-r80__10kb_up_and_down_tss.mc9nr.feather<br></code></pre></td></tr></table></figure>
  153. <h2 id="第二步-输出-ex-matrix"><a href="#第二步-输出-ex-matrix" class="headerlink" title="第二步 输出 ex_matrix"></a>第二步 输出 ex_matrix</h2><figure class="highlight lua"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs lua">%%R<br><span class="hljs-built_in">require</span>(Seurat)<br>SeuratObject = subset(SeuratObject, CellType == <span class="hljs-string">&#x27;fibroblast&#x27;</span>)<br><span class="hljs-built_in">write</span>.csv(as.matrix(SeuratObject<span class="hljs-string">[[&#x27;RNA&#x27;]]</span>@counts), file = <span class="hljs-string">&quot;ex_matrix.csv&quot;</span>)<br>cellInfo = SeuratObject@metadata<br></code></pre></td></tr></table></figure>
  154. <h2 id="第三步-计算"><a href="#第三步-计算" class="headerlink" title="第三步 计算"></a>第三步 计算</h2><ul>
  155. <li>导入包和数据</li>
  156. </ul>
  157. <figure class="highlight elm"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs elm"><span class="hljs-keyword">import</span> glob<br><span class="hljs-keyword">import</span> pickle<br><span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd<br><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np<br> <br><span class="hljs-title">from</span> dask.diagnostics <span class="hljs-keyword">import</span> ProgressBar<br> <br><span class="hljs-title">from</span> arboreto.utils <span class="hljs-keyword">import</span> load_tf_names<br><span class="hljs-title">from</span> arboreto.algo <span class="hljs-keyword">import</span> grnboost2<br> <br><span class="hljs-title">from</span> ctxcore.rnkdb <span class="hljs-keyword">import</span> FeatherRankingDatabase <span class="hljs-keyword">as</span> RankingDatabase<br><span class="hljs-title">from</span> pyscenic.utils <span class="hljs-keyword">import</span> modules_from_adjacencies, load_motifs<br><span class="hljs-title">from</span> pyscenic.prune <span class="hljs-keyword">import</span> prune2df, df2regulons<br><span class="hljs-title">from</span> pyscenic.aucell <span class="hljs-keyword">import</span> aucell<br> <br><span class="hljs-keyword">import</span> seaborn <span class="hljs-keyword">as</span> sns<br></code></pre></td></tr></table></figure>
  158. <figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs routeros">SC_EXP_FNAME = <span class="hljs-string">&#x27;ex_matrix.csv&#x27;</span><br>TFS_FNAME = <span class="hljs-string">&#x27;hs_hgnc_tfs.txt&#x27;</span><br>DATABASES_GLOB = <span class="hljs-string">&quot;hg38*.mc9nr.feather&quot;</span><br>MOTIF_ANNOTATIONS_FNAME = <span class="hljs-string">&#x27;motifs-v9-nr.hgnc-m0.001-o0.0.tbl&#x27;</span><br><br>ex_matrix = pd.read_csv(SC_EXP_FNAME, <span class="hljs-attribute">sep</span>=<span class="hljs-string">&#x27;,&#x27;</span>, <span class="hljs-attribute">header</span>=0, <span class="hljs-attribute">index_col</span>=0).T<br>ex_matrix.shape<br><br>tf_names = load_tf_names(TFS_FNAME)<br><br>db_fnames = glob.glob(DATABASES_GLOB)<br>def name(fname):<br> return os.path.splitext(os.path.basename(fname))[0]<br>dbs = [RankingDatabase(<span class="hljs-attribute">fname</span>=fname, <span class="hljs-attribute">name</span>=name(fname)) <span class="hljs-keyword">for</span> fname <span class="hljs-keyword">in</span> db_fnames]<br>dbs<br></code></pre></td></tr></table></figure>
  159. <ul>
  160. <li>计算 grn</li>
  161. </ul>
  162. <figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs routeros">adjacencies = grnboost2(ex_matrix, <span class="hljs-attribute">tf_names</span>=tf_names, <span class="hljs-attribute">verbose</span>=<span class="hljs-literal">True</span>)<br></code></pre></td></tr></table></figure>
  163. <figure class="highlight sml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sml"><span class="hljs-keyword">with</span> <span class="hljs-keyword">open</span>(<span class="hljs-symbol">&#x27;adjacencies</span>.pydata&#x27;,<span class="hljs-symbol">&#x27;wb&#x27;</span>) <span class="hljs-keyword">as</span> f:<br> pickle.dump(adjacencies,f)<br></code></pre></td></tr></table></figure>
  164. <ul>
  165. <li>计算 ctx</li>
  166. </ul>
  167. <figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs reasonml">modules = <span class="hljs-built_in">list</span>(modules<span class="hljs-constructor">_from_adjacencies(<span class="hljs-params">adjacencies</span>, <span class="hljs-params">ex_matrix</span>)</span>)<br><span class="hljs-keyword">with</span> <span class="hljs-constructor">ProgressBar()</span>:<br> df = prune2df(dbs, modules, MOTIF_ANNOTATIONS_FNAME)<br>regulons = df2regulons(df)<br></code></pre></td></tr></table></figure>
  168. <figure class="highlight sml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs sml"><span class="hljs-keyword">with</span> <span class="hljs-keyword">open</span>(<span class="hljs-symbol">&#x27;modules</span>.pydata&#x27;,<span class="hljs-symbol">&#x27;wb&#x27;</span>) <span class="hljs-keyword">as</span> f:<br> pickle.dump(modules,f)<br><span class="hljs-keyword">with</span> <span class="hljs-keyword">open</span>(<span class="hljs-symbol">&#x27;df</span>.pydata&#x27;,<span class="hljs-symbol">&#x27;wb&#x27;</span>) <span class="hljs-keyword">as</span> f:<br> pickle.dump(df,f)<br><span class="hljs-keyword">with</span> <span class="hljs-keyword">open</span>(<span class="hljs-symbol">&#x27;regulons</span>.pydata&#x27;,<span class="hljs-symbol">&#x27;wb&#x27;</span>) <span class="hljs-keyword">as</span> f:<br> pickle.dump(regulons,f)<br></code></pre></td></tr></table></figure>
  169. <ul>
  170. <li>计算 AUCell</li>
  171. </ul>
  172. <figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs ini"><span class="hljs-attr">regulons</span> = [r.rename(r.name.replace(<span class="hljs-string">&#x27;(+)&#x27;</span>,<span class="hljs-string">&#x27; (&#x27;</span>+str(len(r))+<span class="hljs-string">&#x27;g)&#x27;</span>)) for r in regulons] <span class="hljs-comment"># 第四步 导入方法二</span><br><span class="hljs-attr">auc_mtx</span> = aucell(ex_matrix, regulons, num_workers=<span class="hljs-number">4</span>)<br></code></pre></td></tr></table></figure>
  173. <figure class="highlight sml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sml"><span class="hljs-keyword">with</span> <span class="hljs-keyword">open</span>(<span class="hljs-symbol">&#x27;auc_mtx</span>.pydata&#x27;,<span class="hljs-symbol">&#x27;wb&#x27;</span>) <span class="hljs-keyword">as</span> f:<br> pickle.dump(auc_mtx,f)<br></code></pre></td></tr></table></figure>
  174. <h2 id="第四步-导入R中出图"><a href="#第四步-导入R中出图" class="headerlink" title="第四步 导入R中出图"></a>第四步 导入R中出图</h2><p><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/eccfe2d1b2c7">pySCENIC</a></p>
  175. <ul>
  176. <li>导入方法一 (不推荐)</li>
  177. </ul>
  178. <figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs pgsql"><span class="hljs-keyword">from</span> pyscenic.export <span class="hljs-keyword">import</span> export2loom<br># regulons = [r.<span class="hljs-keyword">rename</span>(r.name.replace(<span class="hljs-string">&#x27;(+)&#x27;</span>,<span class="hljs-string">&#x27; (&#x27;</span>+str(len(r))+<span class="hljs-string">&#x27;g)&#x27;</span>)) <span class="hljs-keyword">for</span> r <span class="hljs-keyword">in</span> regulons]<br>export2loom(ex_mtx = ex_matrix, auc_mtx = auc_mtx, regulons=regulons, out_fname = &quot;results.loom&quot;)<br></code></pre></td></tr></table></figure>
  179. <figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs reasonml">%%R<br>require(ggplot2)<br>require(SCENIC)<br>require(SCopeLoomR)<br><br>loom &lt;- <span class="hljs-keyword">open</span><span class="hljs-constructor">_loom(<span class="hljs-string">&quot;results.loom&quot;</span>, <span class="hljs-params">mode</span>=<span class="hljs-string">&quot;r&quot;</span>)</span><br><br># Read information from loom file:<br>regulons_incidMat &lt;- get<span class="hljs-constructor">_regulons(<span class="hljs-params">loom</span>)</span><br>regulons &lt;- regulons<span class="hljs-constructor">ToGeneLists(<span class="hljs-params">regulons_incidMat</span>)</span><br>regulonsAUC &lt;- get<span class="hljs-constructor">_regulonsAuc(<span class="hljs-params">loom</span>)</span><br>regulonsAucThresholds &lt;- get<span class="hljs-constructor">_regulonThresholds(<span class="hljs-params">loom</span>)</span><br>embeddings &lt;- get<span class="hljs-constructor">_embeddings(<span class="hljs-params">loom</span>)</span><br><br>exprMat &lt;- get<span class="hljs-constructor">_dgem(<span class="hljs-params">loom</span>)</span><br>cellInfo &lt;- get<span class="hljs-constructor">_cellAnnotation(<span class="hljs-params">loom</span>)</span><br>clusterings &lt;- get<span class="hljs-constructor">_clusterings_withName(<span class="hljs-params">loom</span>)</span><br><br>close<span class="hljs-constructor">_loom(<span class="hljs-params">loom</span>)</span><br></code></pre></td></tr></table></figure>
  180. <ul>
  181. <li>导入方法二 (推荐)</li>
  182. </ul>
  183. <figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs reasonml">auc_mtx.<span class="hljs-keyword">to</span><span class="hljs-constructor">_csv(&#x27;<span class="hljs-params">auc_mtx</span>.<span class="hljs-params">tsv</span>&#x27;)</span><br></code></pre></td></tr></table></figure>
  184. <figure class="highlight zephir"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs zephir">%%R<br><span class="hljs-keyword">require</span>(ggplot2)<br><span class="hljs-keyword">require</span>(SCENIC)<br><span class="hljs-keyword">require</span>(SCopeLoomR)<br><span class="hljs-keyword">require</span>(AUCell)<br><br>regulonAUC &lt;- importAUCfromText(<span class="hljs-string">&#x27;auc_mtx.tsv&#x27;</span>)<br>regulonAUC &lt;- regulonAUC[onlyNonDuplicatedExtended(rownames(regulonAUC)),]<br># cellInfo = SeuratObject@metadata<br>regulonActivity_byCellType &lt;- sapply(split(rownames(cellInfo), cellInfo$CellType),<br> <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(cells)</span> <span class="hljs-title">rowMeans</span><span class="hljs-params">(getAUC<span class="hljs-params">(regulonAUC)</span>[,cells])</span>)</span><br><span class="hljs-function"><span class="hljs-title">regulonActivity_byCellType_Scaled</span> &lt;- <span class="hljs-title">t</span><span class="hljs-params">(scale<span class="hljs-params">(t<span class="hljs-params">(regulonActivity_byCellType)</span>, center = T, scale=T)</span>)</span></span><br><span class="hljs-function"><span class="hljs-title">pheatmap</span>::<span class="hljs-title">pheatmap</span><span class="hljs-params">(regulonActivity_byCellType_Scaled, #fontsize_row=<span class="hljs-number">3</span>, </span></span><br><span class="hljs-params"><span class="hljs-function"> color=colorRampPalette<span class="hljs-params">(c<span class="hljs-params">(<span class="hljs-string">&quot;blue&quot;</span>,<span class="hljs-string">&quot;white&quot;</span>,<span class="hljs-string">&quot;red&quot;</span>)</span>)</span><span class="hljs-params">(<span class="hljs-number">100</span>)</span>, breaks=seq<span class="hljs-params">(<span class="hljs-number">-3</span>, <span class="hljs-number">3</span>, length.out = <span class="hljs-number">100</span>)</span>,</span></span><br><span class="hljs-params"><span class="hljs-function"> treeheight_row=<span class="hljs-number">10</span>, treeheight_col=<span class="hljs-number">10</span>, border_color=NA)</span></span><br></code></pre></td></tr></table></figure>
  185. <p><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/b0fd795ad05c">SCENIC—Single Cell rEgulatory Network Inference and Clustering</a></p>
  186. </div>
  187. <hr/>
  188. <div>
  189. <div class="post-metas my-3">
  190. <div class="post-meta mr-3 d-flex align-items-center">
  191. <i class="iconfont icon-category"></i>
  192. <span class="category-chains">
  193. <span class="category-chain">
  194. <a href="/categories/%E5%8D%95%E7%BB%86%E8%83%9E%E4%B8%8B%E6%B8%B8%E5%88%86%E6%9E%90/" class="category-chain-item">单细胞下游分析</a>
  195. </span>
  196. <span class="category-chain">
  197. <a href="/categories/%E7%94%9F%E7%89%A9%E4%BF%A1%E6%81%AF%E5%AD%A6/" class="category-chain-item">生物信息学</a>
  198. </span>
  199. </span>
  200. </div>
  201. </div>
  202. <div class="license-box my-3">
  203. <div class="license-title">
  204. <div>pyscenic (二) 转录因子分析</div>
  205. <div>https://b.limour.top/1111.html</div>
  206. </div>
  207. <div class="license-meta">
  208. <div class="license-meta-item">
  209. <div>Author</div>
  210. <div>Limour</div>
  211. </div>
  212. <div class="license-meta-item license-meta-date">
  213. <div>Posted on</div>
  214. <div>October 23, 2021</div>
  215. </div>
  216. <div class="license-meta-item">
  217. <div>Licensed under</div>
  218. <div>
  219. <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  220. <span class="hint--top hint--rounded" aria-label="BY - Attribution">
  221. <i class="iconfont icon-by"></i>
  222. </span>
  223. </a>
  224. <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  225. <span class="hint--top hint--rounded" aria-label="NC - Non-commercial">
  226. <i class="iconfont icon-nc"></i>
  227. </span>
  228. </a>
  229. <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  230. <span class="hint--top hint--rounded" aria-label="SA - Share-alike">
  231. <i class="iconfont icon-sa"></i>
  232. </span>
  233. </a>
  234. </div>
  235. </div>
  236. </div>
  237. <div class="license-icon iconfont"></div>
  238. </div>
  239. <div class="post-prevnext my-3">
  240. <article class="post-prev col-6">
  241. <a href="/1116.html" title="Oracle 开启IPv6">
  242. <i class="iconfont icon-arrowleft"></i>
  243. <span class="hidden-mobile">Oracle 开启IPv6</span>
  244. <span class="visible-mobile">Previous</span>
  245. </a>
  246. </article>
  247. <article class="post-next col-6">
  248. <a href="/1102.html" title="复旦高性能计算 (七) Python调用R">
  249. <span class="hidden-mobile">复旦高性能计算 (七) Python调用R</span>
  250. <span class="visible-mobile">Next</span>
  251. <i class="iconfont icon-arrowright"></i>
  252. </a>
  253. </article>
  254. </div>
  255. </div>
  256. <article id="comments" lazyload>
  257. <div id="waline"></div>
  258. <script type="text/javascript">
  259. Fluid.utils.loadComments('#waline', function() {
  260. Fluid.utils.createCssLink('https://cdn.staticfile.org/waline/2.15.5/waline.min.css')
  261. Fluid.utils.createScript('https://cdn.staticfile.org/waline/2.15.5/waline.min.js', function() {
  262. var options = Object.assign(
  263. {"serverURL":"https://comments.limour.top","path":"window.location.pathname","meta":["nick","mail","link"],"requiredMeta":["nick"],"lang":"zh-CN","emoji":["https://jscdn.limour.top/gh/walinejs/emojis/weibo"],"dark":"html[data-user-color-scheme=\"dark\"]","wordLimit":0,"pageSize":10},
  264. {
  265. el: '#waline',
  266. path: window.location.pathname
  267. }
  268. )
  269. Waline.init(options);
  270. Fluid.utils.waitElementVisible('#waline .vcontent', () => {
  271. var imgSelector = '#waline .vcontent img:not(.vemoji)';
  272. Fluid.plugins.imageCaption(imgSelector);
  273. Fluid.plugins.fancyBox(imgSelector);
  274. })
  275. });
  276. });
  277. </script>
  278. <noscript>Please enable JavaScript to view the comments</noscript>
  279. </article>
  280. </article>
  281. </div>
  282. </div>
  283. </div>
  284. <div class="side-col d-none d-lg-block col-lg-2">
  285. <aside class="sidebar" style="margin-left: -1rem">
  286. <div id="toc">
  287. <p class="toc-header">
  288. <i class="iconfont icon-list"></i>
  289. <span>Table of Contents</span>
  290. </p>
  291. <div class="toc-body" id="toc-body"></div>
  292. </div>
  293. </aside>
  294. </div>
  295. </div>
  296. </div>
  297. <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
  298. <i class="iconfont icon-arrowup" aria-hidden="true"></i>
  299. </a>
  300. <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
  301. aria-hidden="true">
  302. <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
  303. <div class="modal-content">
  304. <div class="modal-header text-center">
  305. <h4 class="modal-title w-100 font-weight-bold">Search</h4>
  306. <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
  307. <span aria-hidden="true">&times;</span>
  308. </button>
  309. </div>
  310. <div class="modal-body mx-3">
  311. <div class="md-form mb-5">
  312. <input type="text" id="local-search-input" class="form-control validate">
  313. <label data-error="x" data-success="v" for="local-search-input">Keyword</label>
  314. </div>
  315. <div class="list-group" id="local-search-result"></div>
  316. </div>
  317. </div>
  318. </div>
  319. </div>
  320. </main>
  321. <footer>
  322. <div class="footer-inner">
  323. <div class="footer-content">
  324. <a target="_blank" rel="nofollow noopener" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=43130202000203"><img src="https://img.limour.top/2023/08/27/64eadeb81d6a0.webp" srcset="https://jscdn.limour.top/gh/Limour-dev/Sakurairo_Vision/load_svg/inload.svg" lazyload>湘公网安备 43130202000203号 </a> <a target="_blank" rel="nofollow noopener" href="https://beian.miit.gov.cn/">湘ICP备20008299号 </a> <a target="_blank" rel="nofollow noopener" href="https://icp.gov.moe/?keyword=20210128">萌ICP备20210128号</a> <br> <a href="https://www.foreverblog.cn/" target="_blank"> <img src="https://img.foreverblog.cn/logo_en_default.png" srcset="https://jscdn.limour.top/gh/Limour-dev/Sakurairo_Vision/load_svg/inload.svg" lazyload alt="" style="width:auto;height:24px"> </a> <br> <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/limour-blog/archives-b" target="_blank" rel="nofollow noopener"><span>SRC</span></a>
  325. </div>
  326. </div>
  327. </footer>
  328. <!-- Scripts -->
  329. <script src="https://jscdn.limour.top/npm/nprogress@0.2.0/nprogress.min.js" ></script>
  330. <link rel="stylesheet" href="https://jscdn.limour.top/npm/nprogress@0.2.0/nprogress.min.css" />
  331. <script>
  332. NProgress.configure({"showSpinner":false,"trickleSpeed":100})
  333. NProgress.start()
  334. window.addEventListener('load', function() {
  335. NProgress.done();
  336. })
  337. </script>
  338. <script src="https://jscdn.limour.top/npm/jquery@3.6.4/dist/jquery.min.js" ></script>
  339. <script src="https://jscdn.limour.top/npm/bootstrap@4.6.1/dist/js/bootstrap.min.js" ></script>
  340. <script src="/js/events.js" ></script>
  341. <script src="/js/plugins.js" ></script>
  342. <script src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  343. <script>
  344. (function (window, document) {
  345. var typing = Fluid.plugins.typing;
  346. var subtitle = document.getElementById('subtitle');
  347. if (!subtitle || !typing) {
  348. return;
  349. }
  350. var text = subtitle.getAttribute('data-typed-text');
  351. typing(text);
  352. })(window, document);
  353. </script>
  354. <script src="/js/img-lazyload.js" ></script>
  355. <script>
  356. Fluid.utils.createScript('https://jscdn.limour.top/npm/tocbot@4.20.1/dist/tocbot.min.js', function() {
  357. var toc = jQuery('#toc');
  358. if (toc.length === 0 || !window.tocbot) { return; }
  359. var boardCtn = jQuery('#board-ctn');
  360. var boardTop = boardCtn.offset().top;
  361. window.tocbot.init(Object.assign({
  362. tocSelector : '#toc-body',
  363. contentSelector : '.markdown-body',
  364. linkClass : 'tocbot-link',
  365. activeLinkClass : 'tocbot-active-link',
  366. listClass : 'tocbot-list',
  367. isCollapsedClass: 'tocbot-is-collapsed',
  368. collapsibleClass: 'tocbot-is-collapsible',
  369. scrollSmooth : true,
  370. includeTitleTags: true,
  371. headingsOffset : -boardTop,
  372. }, CONFIG.toc));
  373. if (toc.find('.toc-list-item').length > 0) {
  374. toc.css('visibility', 'visible');
  375. }
  376. Fluid.events.registerRefreshCallback(function() {
  377. if ('tocbot' in window) {
  378. tocbot.refresh();
  379. var toc = jQuery('#toc');
  380. if (toc.length === 0 || !tocbot) {
  381. return;
  382. }
  383. if (toc.find('.toc-list-item').length > 0) {
  384. toc.css('visibility', 'visible');
  385. }
  386. }
  387. });
  388. });
  389. </script>
  390. <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>
  391. <script>Fluid.plugins.codeWidget();</script>
  392. <script>
  393. Fluid.utils.createScript('https://jscdn.limour.top/npm/anchor-js@4.3.1/anchor.min.js', function() {
  394. window.anchors.options = {
  395. placement: CONFIG.anchorjs.placement,
  396. visible : CONFIG.anchorjs.visible
  397. };
  398. if (CONFIG.anchorjs.icon) {
  399. window.anchors.options.icon = CONFIG.anchorjs.icon;
  400. }
  401. var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
  402. var res = [];
  403. for (var item of el) {
  404. res.push('.markdown-body > ' + item.trim());
  405. }
  406. if (CONFIG.anchorjs.placement === 'left') {
  407. window.anchors.options.class = 'anchorjs-link-left';
  408. }
  409. window.anchors.add(res.join(', '));
  410. Fluid.events.registerRefreshCallback(function() {
  411. if ('anchors' in window) {
  412. anchors.removeAll();
  413. var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
  414. var res = [];
  415. for (var item of el) {
  416. res.push('.markdown-body > ' + item.trim());
  417. }
  418. if (CONFIG.anchorjs.placement === 'left') {
  419. anchors.options.class = 'anchorjs-link-left';
  420. }
  421. anchors.add(res.join(', '));
  422. }
  423. });
  424. });
  425. </script>
  426. <script>
  427. Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
  428. Fluid.plugins.fancyBox();
  429. });
  430. </script>
  431. <script>Fluid.plugins.imageCaption();</script>
  432. <script src="/js/local-search.js" ></script>
  433. <!-- 主题的启动项,将它保持在最底部 -->
  434. <!-- the boot of the theme, keep it at the bottom -->
  435. <script src="/js/boot.js" ></script>
  436. <noscript>
  437. <div class="noscript-warning">Blog works best with JavaScript enabled</div>
  438. </noscript>
  439. <!-- hexo injector body_end start -->
  440. <script defer src="/theme-inject/timeliness.js"></script>
  441. <!-- hexo injector body_end end --></body>
  442. </html>