886.html 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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="12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210">
  15. <meta property="og:type" content="article">
  16. <meta property="og:title" content="Seurat (五) 简单总结">
  17. <meta property="og:url" content="https://b.limour.top/886.html">
  18. <meta property="og:site_name" content="Limour&#39;s Blog">
  19. <meta property="og:description" content="12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210">
  20. <meta property="og:locale" content="en_US">
  21. <meta property="article:published_time" content="2021-10-04T12:43:00.000Z">
  22. <meta property="article:modified_time" content="2023-09-01T13:32:00.589Z">
  23. <meta property="article:author" content="Limour">
  24. <meta name="twitter:card" content="summary_large_image">
  25. <title>Seurat (五) 简单总结 - 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="Seurat (五) 简单总结"></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-04 20:43" pubdate>
  104. October 4, 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. 20k words
  112. </span>
  113. <span class="post-meta mr-2">
  114. <i class="iconfont icon-clock-fill"></i>
  115. 170 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">Seurat (五) 简单总结</h1>
  134. <div class="markdown-body">
  135. <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><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br></pre></td><td class="code"><pre><code class="hljs reasonml">library(Matrix)<br>library(Seurat)<br>library(plyr)<br>library(dplyr)<br>library(patchwork)<br>library(purrr)<br><br>library(RColorBrewer)<br>library(ggplot2)<br>library(ggrepel)<br>blank_theme &lt;- theme<span class="hljs-constructor">_minimal()</span>+<br> theme(<br> axis.title.x = element<span class="hljs-constructor">_blank()</span>,<br> axis.text.x=element<span class="hljs-constructor">_blank()</span>,<br> axis.title.y = element<span class="hljs-constructor">_blank()</span>,<br> axis.text.y=element<span class="hljs-constructor">_blank()</span>,<br> panel.border = element<span class="hljs-constructor">_blank()</span>,<br> panel.grid=element<span class="hljs-constructor">_blank()</span>,<br> axis.ticks = element<span class="hljs-constructor">_blank()</span>,<br> plot.title=element<span class="hljs-constructor">_text(<span class="hljs-params">size</span>=14, <span class="hljs-params">face</span>=<span class="hljs-string">&quot;bold&quot;</span>,<span class="hljs-params">hjust</span> = 0.5)</span><br> )<br>col_Paired &lt;- color<span class="hljs-constructor">RampPalette(<span class="hljs-params">brewer</span>.<span class="hljs-params">pal</span>(12, <span class="hljs-string">&quot;Paired&quot;</span>)</span>)<br>f_pie &lt;- <span class="hljs-keyword">function</span>(lc_x, lc_main, lc_x_p = <span class="hljs-number">1.3</span>, lc_r = T)&#123;<br> lc_cols &lt;- col<span class="hljs-constructor">_Paired(<span class="hljs-params">length</span>(<span class="hljs-params">lc_x</span>)</span>)<br> lc_v &lt;- <span class="hljs-keyword">as</span>.vector(<span class="hljs-number">100</span>*lc_x)<br> lc_df &lt;- data.frame(<span class="hljs-keyword">type</span> = names(lc_x), nums = lc_v)<br> lc_df &lt;- lc_df<span class="hljs-literal">[<span class="hljs-identifier">order</span>(<span class="hljs-identifier">lc_df$type</span>),]</span><br> lc_percent = sprintf(&#x27;%<span class="hljs-number">0.2</span>f%%&#x27;,lc_df$nums)<br> <span class="hljs-keyword">if</span>(lc_r)&#123;<br> lc_df$pos &lt;- <span class="hljs-keyword">with</span>(lc_df, <span class="hljs-number">100</span>-cumsum(nums)+nums/<span class="hljs-number">2</span>)<br> &#125;<span class="hljs-keyword">else</span>&#123;<br> lc_df$pos &lt;- <span class="hljs-keyword">with</span>(lc_df, cumsum(nums)-nums/<span class="hljs-number">2</span>)<br> &#125; <br> lc_pie &lt;- ggplot(data = lc_df, mapping = aes(x = <span class="hljs-number">1</span>, y = nums, fill = <span class="hljs-keyword">type</span>)) + geom<span class="hljs-constructor">_bar(<span class="hljs-params">stat</span> = &#x27;<span class="hljs-params">identity</span>&#x27;)</span><br># print(lc_df)<br># print(lc_pie)<br> lc_pie &lt;- lc_pie + coord<span class="hljs-constructor">_polar(<span class="hljs-string">&quot;y&quot;</span>, <span class="hljs-params">start</span>=0, <span class="hljs-params">direction</span> = 1)</span> + scale<span class="hljs-constructor">_fill_manual(<span class="hljs-params">values</span>=<span class="hljs-params">lc_cols</span>)</span> + blank_theme <br> lc_pie &lt;- lc_pie + geom<span class="hljs-constructor">_text_repel(<span class="hljs-params">aes</span>(<span class="hljs-params">x</span> = <span class="hljs-params">lc_x_p</span>, <span class="hljs-params">y</span>=<span class="hljs-params">pos</span>)</span>,label= lc_percent, force = T, <br> arrow = arrow(length=<span class="hljs-built_in">unit</span>(<span class="hljs-number">0.01</span>, <span class="hljs-string">&quot;npc&quot;</span>)), segment.color = <span class="hljs-string">&quot;#cccccc&quot;</span>, segment.size = <span class="hljs-number">0.5</span>)<br> lc_pie &lt;- lc_pie + labs(title = lc_main)<br> lc_pie<br>&#125;<br><br>f_pie_metaN &lt;- <span class="hljs-keyword">function</span>(sObject, lc_group.by)&#123;<br> tp_data &lt;- prop.table(table(sObject<span class="hljs-literal">[[<span class="hljs-identifier">lc_group</span>.<span class="hljs-identifier">by</span>]</span>]))<br> f<span class="hljs-constructor">_pie(<span class="hljs-params">tp_data</span>, <span class="hljs-params">sprintf</span>(&#x27;Proportion <span class="hljs-params">of</span> %<span class="hljs-params">s</span>&#x27;, <span class="hljs-params">lc_group</span>.<span class="hljs-params">by</span>)</span>)<br>&#125;<br><br>f_UMAP_more &lt;- <span class="hljs-keyword">function</span>(sObject, lc_group.by, lc_reduction=<span class="hljs-string">&quot;umap&quot;</span>)&#123;<br> res &lt;- (<span class="hljs-constructor">DimPlot(<span class="hljs-params">sObject</span>, <span class="hljs-params">reduction</span> = <span class="hljs-params">lc_reduction</span>, <span class="hljs-params">group</span>.<span class="hljs-params">by</span> = <span class="hljs-params">lc_group</span>.<span class="hljs-params">by</span>[1], <span class="hljs-params">label</span> = T, <span class="hljs-params">repel</span> = T, <span class="hljs-params">label</span>.<span class="hljs-params">size</span> = 6)</span> + <br> labs(title = lc_group.by<span class="hljs-literal">[<span class="hljs-number">1</span>]</span>))<br> <span class="hljs-keyword">for</span>(lc_i <span class="hljs-keyword">in</span> <span class="hljs-number">2</span>:length(lc_group.by))&#123;<br> res &lt;- res/<br> (<span class="hljs-constructor">DimPlot(<span class="hljs-params">sObject</span>, <span class="hljs-params">reduction</span> = <span class="hljs-params">lc_reduction</span>, <span class="hljs-params">group</span>.<span class="hljs-params">by</span> = <span class="hljs-params">lc_group</span>.<span class="hljs-params">by</span>[<span class="hljs-params">lc_i</span>], <span class="hljs-params">label</span> = T, <span class="hljs-params">repel</span> = T, <span class="hljs-params">label</span>.<span class="hljs-params">size</span> = 6)</span> + <br> labs(title = lc_group.by<span class="hljs-literal">[<span class="hljs-identifier">lc_i</span>]</span>))<br> &#125;<br> res<br>&#125;<br><br>f_br_cluster_f &lt;- <span class="hljs-keyword">function</span>(sObject, lc_groupN)&#123;<br> lc_filter &lt;- unlist(unique(sObject<span class="hljs-literal">[[<span class="hljs-identifier">lc_groupN</span>]</span>]))<br> lc_filter &lt;- lc_filter<span class="hljs-literal">[!<span class="hljs-identifier">is</span>.<span class="hljs-identifier">na</span>(<span class="hljs-identifier">lc_filter</span>)]</span><br> lc_filter<br>&#125;<br><br>f_br_cluster &lt;- <span class="hljs-keyword">function</span>(sObject, lc_groupN, lc_labelN, lc_prop = F)&#123;<br> lc_all &lt;- unique(sObject<span class="hljs-literal">[[<span class="hljs-identifier">lc_labelN</span>]</span>])<br> rownames(lc_all) &lt;- lc_all<span class="hljs-literal">[[<span class="hljs-number">1</span>]</span>]<br> colnames(lc_all) &lt;- <span class="hljs-string">&quot;CB&quot;</span><br> lc_tp &lt;- <span class="hljs-constructor">SplitObject(<span class="hljs-params">subset</span>(<span class="hljs-params">x</span> = <span class="hljs-params">sObject</span>, !!<span class="hljs-params">sym</span>(<span class="hljs-params">lc_groupN</span>)</span>%<span class="hljs-keyword">in</span>%f<span class="hljs-constructor">_br_cluster_f(<span class="hljs-params">sObject</span>, <span class="hljs-params">lc_groupN</span>)</span>), split.by = lc_groupN)<br> <span class="hljs-keyword">for</span>(lc_i <span class="hljs-keyword">in</span> <span class="hljs-number">1</span>:length(lc_tp))&#123;<br> <span class="hljs-keyword">if</span>(lc_prop)&#123;<br> lc_tp<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>] &lt;- prop.table(table(lc_tp<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>]<span class="hljs-literal">[[<span class="hljs-identifier">lc_labelN</span>]</span>]))<br> &#125;<span class="hljs-keyword">else</span>&#123;<br> lc_tp<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>] &lt;- table(lc_tp<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>]<span class="hljs-literal">[[<span class="hljs-identifier">lc_labelN</span>]</span>])<br> &#125;<br> &#125;<br> <span class="hljs-keyword">for</span>(lc_name <span class="hljs-keyword">in</span> names(lc_tp))&#123;<br> lc_all<span class="hljs-literal">[[<span class="hljs-identifier">lc_name</span>]</span>] = <span class="hljs-number">0</span><br> lc_all<span class="hljs-literal">[<span class="hljs-identifier">names</span>(<span class="hljs-identifier">lc_tp</span>[[<span class="hljs-identifier">lc_name</span>]</span>]), lc_name] = lc_tp<span class="hljs-literal">[[<span class="hljs-identifier">lc_name</span>]</span>]<br> &#125;<br> lc_all<span class="hljs-literal">[,-<span class="hljs-number">1</span>]</span><br>&#125;<br> <br>f_q2l &lt;- <span class="hljs-keyword">function</span>(lc_q)&#123;<br> res &lt;- NULL<br> <span class="hljs-keyword">for</span>(lc_c <span class="hljs-keyword">in</span> colnames(lc_q))&#123;<br> <span class="hljs-keyword">for</span>(lc_r <span class="hljs-keyword">in</span> rownames(lc_q))&#123;<br> res &lt;- rbind(res, c(group=lc_c, label=lc_r, value=lc_q<span class="hljs-literal">[<span class="hljs-identifier">lc_r</span>,<span class="hljs-identifier">lc_c</span>]</span>))<br> &#125;<br> &#125;<br> res &lt;- data.frame(res)<br> res$value = <span class="hljs-keyword">as</span>.numeric(res$value)<br> res<br>&#125;<br> <br>library(RColorBrewer)<br>library(ggplot2)<br>col_Paired &lt;- color<span class="hljs-constructor">RampPalette(<span class="hljs-params">brewer</span>.<span class="hljs-params">pal</span>(12, <span class="hljs-string">&quot;Paired&quot;</span>)</span>)<br>f_q_frequnency &lt;- <span class="hljs-keyword">function</span>(lc_q)&#123;<br> ggplot(f<span class="hljs-constructor">_q2l(<span class="hljs-params">lc_q</span>)</span>,mapping = aes(group,value,fill=label))+<br> geom<span class="hljs-constructor">_bar(<span class="hljs-params">stat</span>=&#x27;<span class="hljs-params">identity</span>&#x27;,<span class="hljs-params">position</span>=&#x27;<span class="hljs-params">fill</span>&#x27;)</span> + scale<span class="hljs-constructor">_fill_manual(<span class="hljs-params">values</span>= <span class="hljs-params">col_Paired</span>(<span class="hljs-params">nrow</span>(<span class="hljs-params">lc_q</span>)</span>))+<br> labs(x = &#x27;group&#x27;,y = &#x27;frequnency&#x27;) +<br> theme(axis.title =element<span class="hljs-constructor">_text(<span class="hljs-params">size</span> = 16)</span>,axis.text =element<span class="hljs-constructor">_text(<span class="hljs-params">size</span> = 14, <span class="hljs-params">color</span> = &#x27;<span class="hljs-params">black</span>&#x27;)</span>)+<br> theme(axis.text.x = element<span class="hljs-constructor">_text(<span class="hljs-params">angle</span> = 45, <span class="hljs-params">hjust</span> = 1)</span>)+coord<span class="hljs-constructor">_flip()</span> <br>&#125;<br><br>f_DEG_Volcano &lt;- <span class="hljs-keyword">function</span>(lc_logFC, lc_p, lc_gene, Threshold_logFC = <span class="hljs-number">1</span>, Threshold_p = <span class="hljs-number">0.05</span>, lc_rep=<span class="hljs-number">1</span>:<span class="hljs-number">10</span>)&#123;<br> col_vector = rep(rgb(<span class="hljs-number">108</span>, <span class="hljs-number">200</span>, <span class="hljs-number">228</span>, maxColorValue = <span class="hljs-number">255</span>), length(lc_logFC))<br> col_vector<span class="hljs-literal">[<span class="hljs-identifier">lc_p</span> &lt; T<span class="hljs-identifier">hreshold_p</span> &amp; <span class="hljs-identifier">lc_logFC</span> &gt; T<span class="hljs-identifier">hreshold_logFC</span>]</span> = rgb(<span class="hljs-number">226</span>, <span class="hljs-number">61</span>, <span class="hljs-number">75</span>, maxColorValue = <span class="hljs-number">255</span>)<br> col_vector<span class="hljs-literal">[<span class="hljs-identifier">lc_p</span> &lt; T<span class="hljs-identifier">hreshold_p</span> &amp; <span class="hljs-identifier">lc_logFC</span> &lt; -T<span class="hljs-identifier">hreshold_logFC</span>]</span> = rgb(<span class="hljs-number">232</span>, <span class="hljs-number">168</span>, <span class="hljs-number">71</span>, maxColorValue = <span class="hljs-number">255</span>)<br> lc_p<span class="hljs-literal">[<span class="hljs-identifier">lc_p</span> &lt; <span class="hljs-number">1e-10</span>]</span> = <span class="hljs-number">1e-10</span><br> lc_p<span class="hljs-literal">[<span class="hljs-identifier">lc_p</span> &gt; <span class="hljs-number">1</span> <span class="hljs-identifier">is</span>.<span class="hljs-identifier">na</span>(<span class="hljs-identifier">lc_p</span>)]</span> = <span class="hljs-number">1</span><br> df = data.frame(logFC &lt;- lc_logFC, `-log10(P)` &lt;- -log10(lc_p), col &lt;- col_vector, gene &lt;- lc_gene)<br> colnames(df) &lt;- c(&#x27;logFC&#x27;, &#x27;-log10(P)&#x27;, <span class="hljs-string">&quot;col&quot;</span>, <span class="hljs-string">&quot;gene&quot;</span>)<br> lc_tp_logFC &lt;- df$logFC<br> lc_tp_logFC<span class="hljs-literal">[<span class="hljs-identifier">lc_p</span>&gt;=T<span class="hljs-identifier">hreshold_p</span>]</span> = <span class="hljs-number">0</span><br> lc_idx &lt;- order(lc_tp_logFC)<span class="hljs-literal">[<span class="hljs-identifier">c</span>(<span class="hljs-identifier">lc_rep</span>, <span class="hljs-identifier">length</span>(<span class="hljs-identifier">lc_gene</span>)+<span class="hljs-number">1</span>-<span class="hljs-identifier">lc_rep</span>)]</span><br> df$logFC<span class="hljs-literal">[<span class="hljs-identifier">df$logFC</span> &gt; <span class="hljs-number">10</span>]</span> = <span class="hljs-number">10</span><br> df$logFC<span class="hljs-literal">[<span class="hljs-identifier">df$logFC</span> &lt; -<span class="hljs-number">10</span>]</span> = -<span class="hljs-number">10</span><br> res &lt;- ggplot<span class="hljs-literal">()</span> + geom<span class="hljs-constructor">_point(<span class="hljs-params">aes</span>(<span class="hljs-params">logFC</span>, `-<span class="hljs-params">log10</span>(P)</span>`, col=<span class="hljs-constructor">I(<span class="hljs-params">col</span>)</span>), data = df) <br> res &lt;- res + theme<span class="hljs-constructor">_bw()</span> + theme(panel.grid=element<span class="hljs-constructor">_line(<span class="hljs-params">colour</span>=NA)</span>)<br> res &lt;- res + geom<span class="hljs-constructor">_hline(<span class="hljs-params">yintercept</span>=-<span class="hljs-params">log10</span>(Threshold_p)</span>, linetype=<span class="hljs-string">&quot;longdash&quot;</span>)<br> res &lt;- res + geom<span class="hljs-constructor">_vline(<span class="hljs-params">xintercept</span>=<span class="hljs-params">c</span>(Threshold_logFC, -Threshold_logFC)</span>, linetype=<span class="hljs-string">&quot;longdash&quot;</span>)<br> res &lt;- res + geom<span class="hljs-constructor">_text_repel(<span class="hljs-params">data</span>=<span class="hljs-params">df</span>[<span class="hljs-params">lc_idx</span>,],<span class="hljs-params">aes</span>(<span class="hljs-params">logFC</span>,`-<span class="hljs-params">log10</span>(P)</span>`,label=gene), force=T, max.overlaps=Inf)<br> res<br>&#125;<br><br>f_cluster_averages &lt;- <span class="hljs-keyword">function</span>(lc_scRNA, lc_metaN=&#x27;ident&#x27;)&#123;<br> # 切分出Clusters<br> lc_clusters &lt;- <span class="hljs-constructor">SplitObject(<span class="hljs-params">lc_scRNA</span>, <span class="hljs-params">split</span>.<span class="hljs-params">by</span> = <span class="hljs-params">lc_metaN</span>)</span><br> <span class="hljs-keyword">for</span> (lc_i <span class="hljs-keyword">in</span> <span class="hljs-number">1</span>:length(lc_clusters))&#123;<br> lc_clusters<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>] &lt;- lc_clusters<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>]<span class="hljs-literal">[[<span class="hljs-identifier">lc_clusters</span>[[<span class="hljs-identifier">lc_i</span>]</span>]@active.assay]]@scale.data<br> &#125;<br> <span class="hljs-keyword">for</span> (lc_i <span class="hljs-keyword">in</span> <span class="hljs-number">1</span>:length(lc_clusters))&#123;<br> lc_clusters<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>] &lt;- apply(lc_clusters<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>],<span class="hljs-number">1</span>,mean)<br> &#125;<br> lc_clusters &lt;- data.frame(lc_clusters)<br> scale(lc_clusters)<br>&#125;<br> <br>library(clusterProfiler)<br>library(pheatmap)<br>library(ggdendro)<br>f_DEG_hclust &lt;- <span class="hljs-keyword">function</span>(lc_counts)&#123;<br> ggdendrogram(hclust(dist(t(lc_counts))), rotate = T, size = <span class="hljs-number">3</span>)+theme(axis.text = element<span class="hljs-constructor">_text(<span class="hljs-params">size</span>=14,<span class="hljs-params">face</span> = <span class="hljs-string">&quot;bold&quot;</span>)</span>)<br>&#125;<br><br>f_DEG_pheatmap_choose_matrix &lt;- <span class="hljs-keyword">function</span>(lc_tp_d, lc_significant_markers, lc_n = <span class="hljs-number">120</span>, Threshold_logFC = <span class="hljs-number">1</span>)&#123;<br> res &lt;- subset(lc_significant_markers, abs(avg_log2FC) &gt; Threshold_logFC)<br> res &lt;- res<span class="hljs-literal">[<span class="hljs-identifier">order</span>(<span class="hljs-identifier">abs</span>(<span class="hljs-identifier">res$avg_log2FC</span>), <span class="hljs-identifier">decreasing</span> = T),]</span><br> res &lt;- head(unique(res$gene), n = lc_n)<br> res &lt;- lc_tp_d<span class="hljs-literal">[<span class="hljs-identifier">res</span>,]</span><br> res<br>&#125;<br><br>require(ggplotify)<br>f_DEG_pheatmap &lt;- <span class="hljs-keyword">function</span>(choose_matrix)&#123;<br> choose_matrix = t(scale(t(choose_matrix)))<br> <span class="hljs-keyword">as</span>.ggplot(pheatmap(choose_matrix))<br>&#125;<br><br>f_prepare4CSOmap &lt;- <span class="hljs-keyword">function</span>(lc_scRNA, lc_csomap_data_dir, lc_className)&#123;<br> lc_csomap_data_dir &lt;- system(paste(<span class="hljs-string">&quot;echo&quot;</span>, lc_csomap_data_dir), intern = T)<br> <span class="hljs-keyword">if</span>(!file.exists(lc_csomap_data_dir))&#123;dir.create(lc_csomap_data_dir)&#125;<br> # 导出label.txt<br> labels &lt;- lc_scRNA<span class="hljs-literal">[[<span class="hljs-identifier">lc_className</span>]</span>]<br> labels$cells &lt;- gsub(<span class="hljs-string">&quot;-&quot;</span>, <span class="hljs-string">&quot;.&quot;</span> ,rownames(labels)) # TPM的colnames 不知为何导出时被替换了,这里也替换一下<br> labels$labels &lt;- <span class="hljs-keyword">as</span>.character(labels<span class="hljs-literal">[[<span class="hljs-identifier">lc_className</span>]</span>])<br> rownames(labels) &lt;- NULL<br> labels = labels<span class="hljs-literal">[,<span class="hljs-identifier">c</span>(&quot;<span class="hljs-identifier">cells</span>&quot;, &quot;<span class="hljs-identifier">labels</span>&quot;)]</span><br> write.table(labels, file.path(lc_csomap_data_dir, <span class="hljs-string">&quot;label.txt&quot;</span>), row.names = F, sep = <span class="hljs-string">&quot;\t&quot;</span>, quote = F) # 不要引号<br> <br> # copy <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">LR_pairs</span>.</span></span>txt<br> file.copy(from = file.path(lc_csomap_data_dir,<span class="hljs-string">&quot;..&quot;</span>,<span class="hljs-string">&quot;demo&quot;</span>,<span class="hljs-string">&quot;LR_pairs.txt&quot;</span>), <span class="hljs-keyword">to</span> = file.path(lc_csomap_data_dir, <span class="hljs-string">&quot;LR_pairs.txt&quot;</span>))<br> <br> # 导出<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">TPM</span>.</span></span>txt<br> tpm &lt;- exp(lc_scRNA<span class="hljs-literal">[[&#x27;RNA&#x27;]</span>]@data)<br> tpm &lt;- tpm - <span class="hljs-number">1</span><br> tpm &lt;- tpm*<span class="hljs-number">100</span> # <span class="hljs-number">1E4</span> <span class="hljs-keyword">to</span> <span class="hljs-number">1E6</span><br> colnames(tpm)<span class="hljs-literal">[<span class="hljs-number">1</span>]</span> = paste0(<span class="hljs-character">&#x27;T&#x27;</span>, colnames(tpm)<span class="hljs-literal">[<span class="hljs-number">1</span>]</span>) # 预留\t位置<br> write.table(tpm, file.path(lc_csomap_data_dir, <span class="hljs-string">&quot;TPM.txt&quot;</span>), sep = <span class="hljs-string">&quot;\t&quot;</span>, quote = F) # 不要引号<br> <br> lc_fix &lt;- tempfile<span class="hljs-literal">()</span><br> lc_py &lt;- sprintf(&#x27;<br>import mmap, os<br> <br>def mapfile(filename, *args, size=None, **kwargs):<br> file = <span class="hljs-keyword">open</span>(filename, *args, **kwargs)<br> <span class="hljs-keyword">if</span> size is None: size = os.path.getsize(filename)<br> return mmap.mmap(file.fileno<span class="hljs-literal">()</span>, size)<br> <br>path = <span class="hljs-string">&quot;%s&quot;</span><br>print(path, <span class="hljs-string">&quot;%s&quot;</span>)<br>f = mapfile(path,<span class="hljs-string">&quot;r+&quot;</span>, size=<span class="hljs-number">10</span>)<br>f<span class="hljs-literal">[<span class="hljs-number">0</span>:<span class="hljs-number">1</span>]</span> = b<span class="hljs-string">&quot;\t&quot;</span><br>print(f<span class="hljs-literal">[:]</span>)<br>f.close<span class="hljs-literal">()</span><br>print(<span class="hljs-string">&quot;Done&quot;</span>)<br>&#x27;, file.path(lc_csomap_data_dir, <span class="hljs-string">&quot;TPM.txt&quot;</span>), lc_fix)<br> print(lc_py)<br> cat(file=lc_fix, lc_py)<br> print(system(paste(<span class="hljs-string">&quot;python3&quot;</span>, lc_fix), intern = T))<br>&#125;<br><br>f_prepare4cellphoneDB &lt;- <span class="hljs-keyword">function</span>(lc_scRNA, lc_dir, lc_className)&#123;<br> <span class="hljs-keyword">if</span> (!file.exists(lc_dir))&#123;dir.create(lc_dir)&#125;<br> # 生成 count.txt <br> write.table(<span class="hljs-keyword">as</span>.matrix(lc_scRNA@assays$RNA@data), file.path(lc_dir,&#x27;cellphonedb_count.txt&#x27;), sep=<span class="hljs-character">&#x27;\t&#x27;</span>, quote=F)<br> # 生成 meta.txt<br> lc_meta_data &lt;- cbind(rownames(lc_scRNA@meta.data), lc_scRNA@meta.data<span class="hljs-literal">[, <span class="hljs-identifier">lc_className</span>, <span class="hljs-identifier">drop</span>=F]</span>)<br> lc_meta_data &lt;- <span class="hljs-keyword">as</span>.matrix(lc_meta_data)<br> lc_meta_data<span class="hljs-literal">[<span class="hljs-identifier">is</span>.<span class="hljs-identifier">na</span>(<span class="hljs-identifier">lc_meta_data</span>)]</span> = <span class="hljs-string">&quot;Unkown&quot;</span> # 细胞类型中不能有NA<br> write.table(lc_meta_data, file.path(lc_dir,&#x27;cellphonedb_meta.txt&#x27;), sep=<span class="hljs-character">&#x27;\t&#x27;</span>, quote=F, row.names=F)<br>&#125;<br><br>f_image_output &lt;- <span class="hljs-keyword">function</span>(fileName, image, width=<span class="hljs-number">1920</span>, height=<span class="hljs-number">1080</span>, lc_pdf=T, lc_resolution=<span class="hljs-number">72</span>)&#123;<br> <span class="hljs-keyword">if</span>(lc_pdf)&#123;<br> width = width<span class="hljs-operator"> / </span>lc_resolution<br> height = height<span class="hljs-operator"> / </span>lc_resolution<br> pdf(paste(fileName, <span class="hljs-string">&quot;.pdf&quot;</span>, sep=<span class="hljs-string">&quot;&quot;</span>), width = width, height = height)<br> &#125;<span class="hljs-keyword">else</span>&#123;<br> png(paste(fileName, <span class="hljs-string">&quot;.png&quot;</span>, sep=<span class="hljs-string">&quot;&quot;</span>), width = width, height = height)<br> &#125;<br> print(image)<br> dev.off<span class="hljs-literal">()</span><br>&#125;<br> <br># Rearrange data column sequence<br>library(dplyr)<br>f_cDB_order_sequence &lt;- <span class="hljs-keyword">function</span>(lc_df)&#123;<br> da &lt;- data.frame<span class="hljs-literal">()</span><br> df &lt;- subset(lc_df, receptor_a<span class="hljs-operator"> == </span>&#x27;True&#x27; &amp; receptor_b<span class="hljs-operator"> == </span>&#x27;False&#x27; receptor_a<span class="hljs-operator"> == </span>&#x27;False&#x27; &amp; receptor_b<span class="hljs-operator"> == </span>&#x27;True&#x27;)<br> <span class="hljs-keyword">for</span>(i <span class="hljs-keyword">in</span> <span class="hljs-number">1</span>:length(df$gene_a))&#123;<br> sub_data &lt;- df<span class="hljs-literal">[<span class="hljs-identifier">i</span>, ]</span><br> <span class="hljs-keyword">if</span>(sub_data$receptor_b==&#x27;False&#x27;)&#123;<br> <span class="hljs-keyword">if</span>(sub_data$receptor_a==&#x27;True&#x27;)&#123;<br> old_names &lt;- colnames(sub_data)<br> my_list &lt;- strsplit(old_names<span class="hljs-literal">[-<span class="hljs-identifier">c</span>(<span class="hljs-number">1</span>:<span class="hljs-number">11</span>)]</span>, split=<span class="hljs-string">&quot;\\&quot;</span>)<br> my_character &lt;- paste(sapply(my_list, &#x27;<span class="hljs-literal">[[&#x27;, <span class="hljs-number">2L</span>), <span class="hljs-identifier">sapply</span>(<span class="hljs-identifier">my_list</span>, &#x27;[[&#x27;, <span class="hljs-number">1L</span>), <span class="hljs-identifier">sep</span>=&#x27;&#x27;)</span><br><span class="hljs-literal"> <span class="hljs-identifier">new_names</span> &lt;- <span class="hljs-identifier">c</span>(<span class="hljs-identifier">names</span>(<span class="hljs-identifier">sub_data</span>)[<span class="hljs-number">1</span>:<span class="hljs-number">4</span>]</span>, &#x27;gene_b&#x27;, &#x27;gene_a&#x27;, &#x27;secreted&#x27;, &#x27;receptor_b&#x27;, &#x27;receptor_a&#x27;, <span class="hljs-string">&quot;annotation_strategy&quot;</span>, <span class="hljs-string">&quot;is_integrin&quot;</span>, my_character)<br> sub_data = dplyr::select(sub_data, new_names)<br> # print(&#x27;Change sequence!!!&#x27;)<br> names(sub_data) &lt;- old_names<br> da = rbind(da, sub_data) <br> &#125;<br> &#125;<span class="hljs-keyword">else</span>&#123;<br> da = rbind(da, sub_data)<br> &#125;<br> &#125;<br> return(da)<br>&#125;<br> <br>f_cDB_mergePandM &lt;- <span class="hljs-keyword">function</span>(means_order, pvals_order)&#123;<br> means_sub &lt;- means_order<span class="hljs-literal">[, <span class="hljs-identifier">c</span>(&#x27;<span class="hljs-identifier">interacting_pair</span>&#x27;, <span class="hljs-identifier">colnames</span>(<span class="hljs-identifier">means_order</span>)[-<span class="hljs-identifier">c</span>(<span class="hljs-number">1</span>:<span class="hljs-number">11</span>)]</span>)]<br> pvals_sub &lt;- pvals_order<span class="hljs-literal">[, <span class="hljs-identifier">c</span>(&#x27;<span class="hljs-identifier">interacting_pair</span>&#x27;, <span class="hljs-identifier">colnames</span>(<span class="hljs-identifier">means_order</span>)[-<span class="hljs-identifier">c</span>(<span class="hljs-number">1</span>:<span class="hljs-number">11</span>)]</span>)]<br> means_gather &lt;- tidyr::gather(means_sub, celltype, mean_expression, names(means_sub)<span class="hljs-literal">[-<span class="hljs-number">1</span>]</span>)<br> pvals_gather &lt;- tidyr::gather(pvals_sub, celltype, pval, names(pvals_sub)<span class="hljs-literal">[-<span class="hljs-number">1</span>]</span>)<br> mean_pval &lt;- dplyr::left<span class="hljs-constructor">_join(<span class="hljs-params">means_gather</span>, <span class="hljs-params">pvals_gather</span>, <span class="hljs-params">by</span> = <span class="hljs-params">c</span>(&#x27;<span class="hljs-params">interacting_pair</span>&#x27;, &#x27;<span class="hljs-params">celltype</span>&#x27;)</span>)<br> mean_pval<br>&#125;<br> <br>f_readcellphoneDB &lt;- <span class="hljs-keyword">function</span>(lc_dir)&#123;<br> res = <span class="hljs-built_in">list</span><span class="hljs-literal">()</span><br> res$pvals &lt;- f<span class="hljs-constructor">_cDB_order_sequence(<span class="hljs-params">read</span>.<span class="hljs-params">delim</span>(<span class="hljs-params">file</span>.<span class="hljs-params">path</span>(<span class="hljs-params">lc_dir</span>, <span class="hljs-string">&quot;out&quot;</span>,<span class="hljs-string">&quot;pvalues.txt&quot;</span>)</span>, check.names = FALSE))<br> res$means &lt;- f<span class="hljs-constructor">_cDB_order_sequence(<span class="hljs-params">read</span>.<span class="hljs-params">delim</span>(<span class="hljs-params">file</span>.<span class="hljs-params">path</span>(<span class="hljs-params">lc_dir</span>, <span class="hljs-string">&quot;out&quot;</span>, <span class="hljs-string">&quot;means.txt&quot;</span>)</span>, check.names = FALSE))<br> res$s_means &lt;- read.delim(file.path(lc_dir, <span class="hljs-string">&quot;out&quot;</span>, <span class="hljs-string">&quot;significant_means.txt&quot;</span>), check.names = FALSE)<br> res$m_p &lt;- f<span class="hljs-constructor">_cDB_mergePandM(<span class="hljs-params">res$means</span>, <span class="hljs-params">res$pvals</span>)</span><br> lc_tp &lt;- res$m_p %&gt;% dplyr::select(interacting_pair, celltype, pval) %&gt;% tidyr::spread(key=celltype, value=pval)<br> lc_sig_pairs &lt;- lc_tp<span class="hljs-literal">[<span class="hljs-identifier">which</span>(<span class="hljs-identifier">rowSums</span>(<span class="hljs-identifier">lc_tp</span>&lt;=<span class="hljs-number">0.05</span>)!=<span class="hljs-number">0</span>), ]</span><br> res$s_m_p &lt;- subset(res$m_p, interacting_pair %<span class="hljs-keyword">in</span>% lc_sig_pairs$interacting_pair)<br> res<br>&#125;<br> <br>f_cDB_dotplot &lt;- <span class="hljs-keyword">function</span>(lc_m_p)&#123;<br> lc_m_p %&gt;% ggplot(aes(x=interacting_pair, y=celltype)) +<br> # geom<span class="hljs-constructor">_point(<span class="hljs-params">aes</span>(<span class="hljs-params">color</span>=<span class="hljs-params">log2</span>(<span class="hljs-params">mean_expression</span>)</span>, size=pval)) +<br> # scale<span class="hljs-constructor">_size(<span class="hljs-params">trans</span> = &#x27;<span class="hljs-params">reverse</span>&#x27;)</span> +<br> geom<span class="hljs-constructor">_point(<span class="hljs-params">aes</span>(<span class="hljs-params">color</span>=<span class="hljs-params">log2</span>(<span class="hljs-params">mean_expression</span>)</span>, size=-log10(pval+<span class="hljs-number">1</span>*<span class="hljs-number">10</span>^-<span class="hljs-number">3</span>)) ) +<br> guides(colour = guide<span class="hljs-constructor">_colourbar(<span class="hljs-params">order</span> = 1)</span>,size = guide<span class="hljs-constructor">_legend(<span class="hljs-params">order</span> = 2)</span>) +<br> labs(x=&#x27;&#x27;, y=&#x27;&#x27;) +<br> scale<span class="hljs-constructor">_color_gradientn(<span class="hljs-params">name</span>=&#x27;Expression <span class="hljs-params">level</span> \<span class="hljs-params">n</span>(<span class="hljs-params">log2</span> <span class="hljs-params">mean</span> <span class="hljs-params">expression</span> \<span class="hljs-params">nmolecule1</span>, <span class="hljs-params">molecule2</span>)</span>&#x27;, colours = terrain.colors(<span class="hljs-number">100</span>)) +<br> # scale<span class="hljs-constructor">_color_gradient2(&#x27;Expression <span class="hljs-params">level</span> \<span class="hljs-params">n</span>(<span class="hljs-params">log2</span> <span class="hljs-params">mean</span> <span class="hljs-params">expression</span> \<span class="hljs-params">nmolecule1</span>, <span class="hljs-params">molecule2</span>)</span>&#x27;, low = &#x27;blue&#x27;, mid = &#x27;yellow&#x27;, high = &#x27;red&#x27;) +<br> theme(axis.text.x= element<span class="hljs-constructor">_text(<span class="hljs-params">angle</span>=45, <span class="hljs-params">hjust</span>=1)</span>) +<br> # coord<span class="hljs-constructor">_flip()</span> +<br> theme(<br> panel.border = element<span class="hljs-constructor">_rect(<span class="hljs-params">color</span> = &#x27;<span class="hljs-params">black</span>&#x27;, <span class="hljs-params">fill</span> = NA)</span>,<br> panel.grid.major.x = element<span class="hljs-constructor">_blank()</span>,<br> panel.grid.major.y = element<span class="hljs-constructor">_blank()</span>,<br> panel.grid.minor.x = element<span class="hljs-constructor">_blank()</span>,<br> panel.grid.minor.y = element<span class="hljs-constructor">_blank()</span>,<br> panel.background = element<span class="hljs-constructor">_blank()</span>,<br> axis.title.x = element<span class="hljs-constructor">_blank()</span>,<br> axis.title.y = element<span class="hljs-constructor">_blank()</span>,<br> axis.ticks = element<span class="hljs-constructor">_blank()</span><br> # plot.title = element<span class="hljs-constructor">_text(<span class="hljs-params">hjust</span> = 0.5)</span>,<br> # legend.position = &#x27;bottom&#x27; # guides(fill = guide<span class="hljs-constructor">_legend(<span class="hljs-params">label</span>.<span class="hljs-params">position</span> = <span class="hljs-string">&quot;bottom&quot;</span>)</span>)<br> # legend.position = <span class="hljs-string">&quot;bottom&quot;</span><br> # axis.text.y.right = element<span class="hljs-constructor">_text(<span class="hljs-params">angle</span>=270, <span class="hljs-params">hjust</span>=0.5)</span><br> ) +<br> theme(legend.key.size = <span class="hljs-built_in">unit</span>(<span class="hljs-number">0.4</span>, &#x27;cm&#x27;), #change legend key size<br> # legend.key.height = <span class="hljs-built_in">unit</span>(<span class="hljs-number">1</span>, &#x27;cm&#x27;), #change legend key height<br> # legend.key.width = <span class="hljs-built_in">unit</span>(<span class="hljs-number">1</span>, &#x27;cm&#x27;), #change legend key width<br> legend.title = element<span class="hljs-constructor">_text(<span class="hljs-params">size</span>=9)</span>, #change legend title font size<br> legend.text = element<span class="hljs-constructor">_text(<span class="hljs-params">size</span>=8)</span>) #change legend text font size<br>&#125;<br><br></code></pre></td></tr></table></figure>
  136. <figure class="highlight cmake"><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></pre></td><td class="code"><pre><code class="hljs cmake"><span class="hljs-comment"># 配置数据和mark基因表的路径</span><br>root_path = <span class="hljs-string">&quot;~/zlliu/R_data/hBLA&quot;</span><br> <br><span class="hljs-comment"># 配置结果保存路径</span><br>output_path = <span class="hljs-string">&quot;~/zlliu/R_data/21.10.04.split&quot;</span><br><span class="hljs-keyword">if</span> (!<span class="hljs-keyword">file</span>.<span class="hljs-keyword">exists</span>(output_path))&#123;dir.create(output_path)&#125;<br> <br><span class="hljs-comment"># 设置工作目录,输出文件将保存在此目录下</span><br>setwd(output_path)<br>getwd()<br></code></pre></td></tr></table></figure>
  137. <figure class="highlight mipsasm"><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 mipsasm"><span class="hljs-comment"># 1、读取数据</span><br><span class="hljs-keyword">scRNA </span>= readRDS(<span class="hljs-string">&quot;~/zlliu/R_output/21.09.21.SingleR/scRNA.rds&quot;</span>)<br><span class="hljs-keyword">scRNA </span>&lt;- <span class="hljs-keyword">subset(x </span>= <span class="hljs-keyword">scRNA, </span>!!sym(<span class="hljs-string">&quot;Region&quot;</span>)%in%f_br_cluster_f(<span class="hljs-keyword">scRNA, </span><span class="hljs-string">&quot;Region&quot;</span>))<br><span class="hljs-keyword">scRNA@meta.data</span><br></code></pre></td></tr></table></figure>
  138. <figure class="highlight stylus"><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 stylus"><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">12</span>, repr.plot.height=<span class="hljs-number">6</span>)</span></span><br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(ggrepel.max.overlaps = Inf)</span></span><br><span class="hljs-function"><span class="hljs-title">f_pie_metaN</span><span class="hljs-params">(scRNA, <span class="hljs-string">&quot;Region&quot;</span>)</span></span> + <span class="hljs-built_in">f_pie_metaN</span>(scRNA, <span class="hljs-string">&quot;hM1_hmca_class&quot;</span>)<br></code></pre></td></tr></table></figure>
  139. <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><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><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs lua">n_ExN &lt;- c(<span class="hljs-string">&#x27;L4 IT&#x27;</span>,<span class="hljs-string">&#x27;L5 IT&#x27;</span>,<span class="hljs-string">&#x27;L5 ET&#x27;</span>,<span class="hljs-string">&#x27;IT&#x27;</span>,<span class="hljs-string">&#x27;L6b&#x27;</span>,<span class="hljs-string">&#x27;L5/6 IT Car3&#x27;</span>,<span class="hljs-string">&#x27;L6 IT&#x27;</span>,<span class="hljs-string">&#x27;L2/3 IT&#x27;</span>,<span class="hljs-string">&#x27;L5/6 NP&#x27;</span>,<span class="hljs-string">&#x27;L6 IT Car3&#x27;</span>,<span class="hljs-string">&#x27;L6 CT&#x27;</span>)<br> <br>n_InN &lt;- c(<span class="hljs-string">&#x27;Lamp5&#x27;</span>,<span class="hljs-string">&#x27;Pvalb&#x27;</span>,<span class="hljs-string">&#x27;Sst&#x27;</span>,<span class="hljs-string">&#x27;Vip&#x27;</span>,<span class="hljs-string">&#x27;Sncg&#x27;</span>)<br> <br>n_NoN &lt;- c(<span class="hljs-string">&#x27;Astro&#x27;</span>,<span class="hljs-string">&#x27;PAX6&#x27;</span>,<span class="hljs-string">&#x27;Endo&#x27;</span>,<span class="hljs-string">&#x27;Micro-PVM&#x27;</span>,<span class="hljs-string">&#x27;OPC&#x27;</span>,<span class="hljs-string">&#x27;Oligo&#x27;</span>,<span class="hljs-string">&#x27;Pericyte&#x27;</span>,<span class="hljs-string">&#x27;VLMC&#x27;</span>)<br> <br>n_groups &lt;- list(NoN=n_NoN, ExN=n_ExN, InN=n_InN)<br> <br>f_listUpdateRe &lt;- <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(lc_obj, lc_bool, lc_item)</span></span>&#123;<br> lc_obj[lc_bool] &lt;- <span class="hljs-built_in">rep</span>(lc_item,times=sum(lc_bool))<br> lc_obj<br>&#125;<br> <br>f_grouplabel &lt;- <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(lc_meta.data, lc_groups)</span></span>&#123;<br> res &lt;- lc_meta.data<span class="hljs-string">[[1]]</span><br> <span class="hljs-keyword">for</span>(lc_g <span class="hljs-keyword">in</span> names(lc_groups))&#123;<br> lc_bool = (res %<span class="hljs-keyword">in</span>% lc_groups<span class="hljs-string">[[lc_g]]</span>)<br> <span class="hljs-keyword">for</span>(c_n <span class="hljs-keyword">in</span> colnames(lc_meta.data))&#123;<br> lc_bool = lc_bool (lc_meta.data<span class="hljs-string">[[c_n]]</span> %<span class="hljs-keyword">in</span>% lc_groups<span class="hljs-string">[[lc_g]]</span>)<br> &#125;<br> res &lt;- f_listUpdateRe(res, lc_bool, lc_g)<br> &#125;<br> names(res) &lt;- rownames(lc_meta.data)<br> res<br>&#125;<br></code></pre></td></tr></table></figure>
  140. <figure class="highlight stylus"><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></pre></td><td class="code"><pre><code class="hljs stylus"><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">9</span>, repr.plot.height=<span class="hljs-number">5</span>)</span></span><br>tp_test &lt;- <span class="hljs-built_in">f_br_cluster</span>(scRNA, <span class="hljs-string">&#x27;Region&#x27;</span>, <span class="hljs-string">&#x27;hM1_hmca_class&#x27;</span>)<br><span class="hljs-function"><span class="hljs-title">f_q_frequnency</span><span class="hljs-params">(tp_test)</span></span><br>friedman<span class="hljs-selector-class">.test</span>(as<span class="hljs-selector-class">.matrix</span>(tp_test))<br>chisq<span class="hljs-selector-class">.test</span>(as<span class="hljs-selector-class">.matrix</span>(tp_test), simulate<span class="hljs-selector-class">.p</span><span class="hljs-selector-class">.value</span> = TRUE)<br>fisher<span class="hljs-selector-class">.test</span>(as<span class="hljs-selector-class">.matrix</span>(tp_test), simulate<span class="hljs-selector-class">.p</span><span class="hljs-selector-class">.value</span> = TRUE)<br>tp_test<br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">9</span>, repr.plot.height=<span class="hljs-number">9</span>)</span></span><br><span class="hljs-function"><span class="hljs-title">f_UMAP_more</span><span class="hljs-params">(scRNA, c(<span class="hljs-string">&#x27;hM1_class&#x27;</span>, <span class="hljs-string">&#x27;hmca_class&#x27;</span>)</span></span>)<br><span class="hljs-function"><span class="hljs-title">f_UMAP_more</span><span class="hljs-params">(scRNA, c(<span class="hljs-string">&#x27;hM1_hmca_class&#x27;</span>, <span class="hljs-string">&#x27;Region&#x27;</span>)</span></span>)<br></code></pre></td></tr></table></figure>
  141. <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></pre></td><td class="code"><pre><code class="hljs lua">scRNA<span class="hljs-string">[[&#x27;n_groups&#x27;]]</span> &lt;- f_grouplabel(scRNA<span class="hljs-string">[[c(&quot;hM1_hmca_class&quot;)]]</span>, n_groups)<br>sc_Neuron &lt;- subset(x = scRNA, n_groups %<span class="hljs-keyword">in</span>% c(<span class="hljs-string">&quot;InN&quot;</span>, <span class="hljs-string">&quot;ExN&quot;</span>))<br>sc_Neuron &lt;- subset(x = sc_Neuron, !!sym(<span class="hljs-string">&quot;Region&quot;</span>)%<span class="hljs-keyword">in</span>%f_br_cluster_f(sc_Neuron, <span class="hljs-string">&quot;Region&quot;</span>))<br></code></pre></td></tr></table></figure>
  142. <figure class="highlight stylus"><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 stylus"><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">12</span>, repr.plot.height=<span class="hljs-number">6</span>)</span></span><br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(ggrepel.max.overlaps = Inf)</span></span><br><span class="hljs-function"><span class="hljs-title">f_pie_metaN</span><span class="hljs-params">(sc_Neuron, <span class="hljs-string">&quot;Region&quot;</span>)</span></span> + <span class="hljs-built_in">f_pie_metaN</span>(sc_Neuron, <span class="hljs-string">&quot;hM1_hmca_class&quot;</span>)<br><br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">9</span>, repr.plot.height=<span class="hljs-number">5</span>)</span></span><br>tp_test &lt;- <span class="hljs-built_in">f_br_cluster</span>(sc_Neuron, <span class="hljs-string">&#x27;Region&#x27;</span>, <span class="hljs-string">&#x27;hM1_hmca_class&#x27;</span>)<br><span class="hljs-function"><span class="hljs-title">f_q_frequnency</span><span class="hljs-params">(tp_test)</span></span><br>friedman<span class="hljs-selector-class">.test</span>(as<span class="hljs-selector-class">.matrix</span>(tp_test))<br>chisq<span class="hljs-selector-class">.test</span>(as<span class="hljs-selector-class">.matrix</span>(tp_test), simulate<span class="hljs-selector-class">.p</span><span class="hljs-selector-class">.value</span> = TRUE)<br>fisher<span class="hljs-selector-class">.test</span>(as<span class="hljs-selector-class">.matrix</span>(tp_test), simulate<span class="hljs-selector-class">.p</span><span class="hljs-selector-class">.value</span> = TRUE)<br>tp_test<br><br></code></pre></td></tr></table></figure>
  143. <figure class="highlight stylus"><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></pre></td><td class="code"><pre><code class="hljs stylus">sc_Neuron_ExN &lt;- <span class="hljs-built_in">subset</span>(x = sc_Neuron, n_groups == <span class="hljs-string">&quot;ExN&quot;</span>)<br><br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">12</span>, repr.plot.height=<span class="hljs-number">6</span>)</span></span><br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(ggrepel.max.overlaps = Inf)</span></span><br><span class="hljs-function"><span class="hljs-title">f_pie_metaN</span><span class="hljs-params">(sc_Neuron_ExN, <span class="hljs-string">&quot;Region&quot;</span>)</span></span> + <span class="hljs-built_in">f_pie_metaN</span>(sc_Neuron_ExN, <span class="hljs-string">&quot;hM1_hmca_class&quot;</span>)<br><br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">9</span>, repr.plot.height=<span class="hljs-number">5</span>)</span></span><br>tp_test &lt;- <span class="hljs-built_in">f_br_cluster</span>(sc_Neuron_ExN, <span class="hljs-string">&#x27;Region&#x27;</span>, <span class="hljs-string">&#x27;hM1_hmca_class&#x27;</span>)<br><span class="hljs-function"><span class="hljs-title">f_q_frequnency</span><span class="hljs-params">(tp_test)</span></span><br>friedman<span class="hljs-selector-class">.test</span>(as<span class="hljs-selector-class">.matrix</span>(tp_test))<br>chisq<span class="hljs-selector-class">.test</span>(as<span class="hljs-selector-class">.matrix</span>(tp_test), simulate<span class="hljs-selector-class">.p</span><span class="hljs-selector-class">.value</span> = TRUE)<br>fisher<span class="hljs-selector-class">.test</span>(as<span class="hljs-selector-class">.matrix</span>(tp_test), simulate<span class="hljs-selector-class">.p</span><span class="hljs-selector-class">.value</span> = TRUE)<br>tp_test<br><br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">9</span>, repr.plot.height=<span class="hljs-number">9</span>)</span></span><br><span class="hljs-function"><span class="hljs-title">f_UMAP_more</span><span class="hljs-params">(sc_Neuron_ExN, c(<span class="hljs-string">&#x27;hM1_class&#x27;</span>, <span class="hljs-string">&#x27;hmca_class&#x27;</span>)</span></span>)<br><span class="hljs-function"><span class="hljs-title">f_UMAP_more</span><span class="hljs-params">(sc_Neuron_ExN, c(<span class="hljs-string">&#x27;hM1_hmca_class&#x27;</span>, <span class="hljs-string">&#x27;Region&#x27;</span>)</span></span>)<br><br></code></pre></td></tr></table></figure>
  144. <figure class="highlight stylus"><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></pre></td><td class="code"><pre><code class="hljs stylus">sc_Neuron_InN &lt;- <span class="hljs-built_in">subset</span>(x = sc_Neuron, n_groups == <span class="hljs-string">&quot;InN&quot;</span>)<br><br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">12</span>, repr.plot.height=<span class="hljs-number">6</span>)</span></span><br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(ggrepel.max.overlaps = Inf)</span></span><br><span class="hljs-function"><span class="hljs-title">f_pie_metaN</span><span class="hljs-params">(sc_Neuron_InN, <span class="hljs-string">&quot;Region&quot;</span>)</span></span> + <span class="hljs-built_in">f_pie_metaN</span>(sc_Neuron_InN, <span class="hljs-string">&quot;hM1_hmca_class&quot;</span>)<br><br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">9</span>, repr.plot.height=<span class="hljs-number">5</span>)</span></span><br>tp_test &lt;- <span class="hljs-built_in">f_br_cluster</span>(sc_Neuron_InN, <span class="hljs-string">&#x27;Region&#x27;</span>, <span class="hljs-string">&#x27;hM1_hmca_class&#x27;</span>)<br><span class="hljs-function"><span class="hljs-title">f_q_frequnency</span><span class="hljs-params">(tp_test)</span></span><br>friedman<span class="hljs-selector-class">.test</span>(as<span class="hljs-selector-class">.matrix</span>(tp_test))<br>chisq<span class="hljs-selector-class">.test</span>(as<span class="hljs-selector-class">.matrix</span>(tp_test), simulate<span class="hljs-selector-class">.p</span><span class="hljs-selector-class">.value</span> = TRUE)<br>fisher<span class="hljs-selector-class">.test</span>(as<span class="hljs-selector-class">.matrix</span>(tp_test), simulate<span class="hljs-selector-class">.p</span><span class="hljs-selector-class">.value</span> = TRUE)<br>tp_test<br><br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">9</span>, repr.plot.height=<span class="hljs-number">9</span>)</span></span><br><span class="hljs-function"><span class="hljs-title">f_UMAP_more</span><span class="hljs-params">(sc_Neuron_InN, c(<span class="hljs-string">&#x27;hM1_class&#x27;</span>, <span class="hljs-string">&#x27;hmca_class&#x27;</span>)</span></span>)<br><span class="hljs-function"><span class="hljs-title">f_UMAP_more</span><span class="hljs-params">(sc_Neuron_InN, c(<span class="hljs-string">&#x27;hM1_hmca_class&#x27;</span>, <span class="hljs-string">&#x27;Region&#x27;</span>)</span></span>)<br><br></code></pre></td></tr></table></figure>
  145. <figure class="highlight stylus"><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 stylus"><span class="hljs-function"><span class="hljs-title">Idents</span><span class="hljs-params">(sc_Neuron)</span></span> &lt;- sc_Neuron<span class="hljs-selector-attr">[[<span class="hljs-string">&#x27;hM1_hmca_class&#x27;</span>]</span>]<br>all_markers &lt;- <span class="hljs-built_in">FindAllMarkers</span>(sc_Neuron, min<span class="hljs-selector-class">.pct</span> = <span class="hljs-number">0.25</span>, logfc<span class="hljs-selector-class">.threshold</span> = <span class="hljs-number">0.25</span>)<br>significant_markers &lt;- <span class="hljs-built_in">subset</span>(all_markers, subset = p_val_adj&lt;<span class="hljs-number">0.05</span>)<br><br></code></pre></td></tr></table></figure>
  146. <figure class="highlight stylus"><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 stylus"><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">12</span>, repr.plot.height=<span class="hljs-number">6</span>)</span></span><br>tp_d &lt;- <span class="hljs-built_in">f_cluster_averages</span>(sc_Neuron, <span class="hljs-string">&quot;hM1_hmca_class&quot;</span>)<br>tp_d_br &lt;- <span class="hljs-built_in">f_cluster_averages</span>(sc_Neuron, <span class="hljs-string">&quot;Region&quot;</span>)<br><span class="hljs-function"><span class="hljs-title">f_DEG_hclust</span><span class="hljs-params">(tp_d)</span></span> + <span class="hljs-built_in">f_DEG_hclust</span>(tp_d_br)<br></code></pre></td></tr></table></figure>
  147. <figure class="highlight stylus"><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 stylus"><span class="hljs-function"><span class="hljs-title">Idents</span><span class="hljs-params">(sc_Neuron)</span></span> &lt;- sc_Neuron<span class="hljs-selector-attr">[[<span class="hljs-string">&#x27;hM1_hmca_class&#x27;</span>]</span>]<br>all_markers &lt;- <span class="hljs-built_in">FindAllMarkers</span>(sc_Neuron, min<span class="hljs-selector-class">.pct</span> = <span class="hljs-number">0.25</span>, logfc<span class="hljs-selector-class">.threshold</span> = <span class="hljs-number">0.25</span>)<br>significant_markers &lt;- <span class="hljs-built_in">subset</span>(all_markers, subset = p_val_adj&lt;<span class="hljs-number">0.05</span>)<br><br></code></pre></td></tr></table></figure>
  148. <figure class="highlight stylus"><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 stylus"><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">9</span>, repr.plot.height=<span class="hljs-number">30</span>)</span></span><br>p1 &lt;- <span class="hljs-built_in">f_DEG_pheatmap</span>(<span class="hljs-built_in">f_DEG_pheatmap_choose_matrix</span>(tp_d, significant_markers))<br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">9</span>, repr.plot.height=<span class="hljs-number">30</span>)</span></span><br>p2 &lt;- <span class="hljs-built_in">f_DEG_pheatmap</span>(<span class="hljs-built_in">f_DEG_pheatmap_choose_matrix</span>(tp_d_br, significant_markers_br, Threshold_logFC = <span class="hljs-number">0.1</span>))<br><span class="hljs-function"><span class="hljs-title">options</span><span class="hljs-params">(repr.plot.width=<span class="hljs-number">18</span>, repr.plot.height=<span class="hljs-number">30</span>)</span></span><br>p1 + p2<br></code></pre></td></tr></table></figure>
  149. <figure class="highlight stylus"><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 stylus"><span class="hljs-function"><span class="hljs-title">f_prepare4cellphoneDB</span><span class="hljs-params">(sc_Neuron,<span class="hljs-string">&quot;Neuron&quot;</span>, <span class="hljs-string">&quot;hM1_hmca_class&quot;</span>)</span></span><br><span class="hljs-function"><span class="hljs-title">f_prepare4cellphoneDB</span><span class="hljs-params">(sc_Neuron,<span class="hljs-string">&quot;Neuron_br&quot;</span>, <span class="hljs-string">&quot;Region&quot;</span>)</span></span><br><span class="hljs-function"><span class="hljs-title">f_prepare4CSOmap</span><span class="hljs-params">(sc_Neuron, <span class="hljs-string">&quot;~/CSOmap/data/zlliu_s_Neuron&quot;</span>, <span class="hljs-string">&quot;hM1_hmca_class&quot;</span>)</span></span><br><span class="hljs-function"><span class="hljs-title">f_prepare4CSOmap</span><span class="hljs-params">(sc_Neuron, <span class="hljs-string">&quot;~/CSOmap/data/zlliu_s_Neuron_br&quot;</span>, <span class="hljs-string">&quot;Region&quot;</span>)</span></span><br></code></pre></td></tr></table></figure>
  150. <figure class="highlight bash"><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></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-meta">#!/bin/bash</span><br><span class="hljs-comment">#PBS -q batch</span><br><span class="hljs-comment">#PBS -V</span><br><span class="hljs-comment">#PBS -o /home/rqzhang/cellphonedb.out</span><br><span class="hljs-comment">#PBS -e /home/rqzhang/cellphonedb.err</span><br><span class="hljs-comment">#PBS -l nodes=1:ppn=32</span><br><span class="hljs-comment">#PBS -r y</span><br> <br><span class="hljs-built_in">cd</span> /home/rqzhang/zlliu/R_data/21.10.04.<span class="hljs-built_in">split</span>/Neuron<br>cellphonedb method statistical_analysis cellphonedb_meta.txt cellphonedb_count.txt --counts-data=gene_name --threads=32<br>cellphonedb plot dot_plot<br>cellphonedb plot heatmap_plot cellphonedb_meta.txt<br><br><span class="hljs-built_in">cd</span> /home/rqzhang/zlliu/R_data/21.10.04.<span class="hljs-built_in">split</span>/Neuron_br<br>cellphonedb method statistical_analysis cellphonedb_meta.txt cellphonedb_count.txt --counts-data=gene_name --threads=32<br>cellphonedb plot dot_plot<br>cellphonedb plot heatmap_plot cellphonedb_meta.txt<br><br></code></pre></td></tr></table></figure>
  151. <figure class="highlight bash"><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></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-meta">#!/bin/bash</span><br><span class="hljs-comment">#PBS -q batch</span><br><span class="hljs-comment">#PBS -V</span><br><span class="hljs-comment">#PBS -o /home/rqzhang/zlliu/PBS/CSOmap/CSOmap.out</span><br><span class="hljs-comment">#PBS -e /home/rqzhang/zlliu/PBS/CSOmap/CSOmap.err</span><br><span class="hljs-comment">#PBS -l nodes=1:ppn=1</span><br><span class="hljs-comment">#PBS -r y</span><br><span class="hljs-built_in">cd</span> /home/rqzhang/CSOmap/code<br>matlab -nodisplay -r <span class="hljs-string">&quot;runme(&#x27;zlliu_s_Neuron&#x27;);exit&quot;</span><br>matlab -nodisplay -r <span class="hljs-string">&quot;runme(&#x27;zlliu_s_Neuron_br&#x27;);exit&quot;</span><br><span class="hljs-built_in">echo</span> <span class="hljs-variable">$HOME</span><br></code></pre></td></tr></table></figure>
  152. <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">n_d &lt;- f<span class="hljs-constructor">_readcellphoneDB(&#x27;Neuron&#x27;)</span><br>tp_img &lt;- f<span class="hljs-constructor">_cDB_dotplot(<span class="hljs-params">subset</span>(<span class="hljs-params">n_d$s_m_p</span>, <span class="hljs-params">pval</span>&lt;0.05)</span>)<br>f<span class="hljs-constructor">_image_output(&#x27;Neuron&#x27;,<span class="hljs-params">tp_img</span>, <span class="hljs-params">width</span> = 1080,<span class="hljs-params">height</span> = 1080)</span><br><br></code></pre></td></tr></table></figure>
  153. <h2 id="更新"><a href="#更新" class="headerlink" title="更新"></a>更新</h2><figure class="highlight stylus"><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></pre></td><td class="code"><pre><code class="hljs stylus">f_prepare4cellphoneDB_sp &lt;- <span class="hljs-built_in">function</span>(lc_scRNA, lc_dir, lc_className, lc_groupN)&#123;<br> <span class="hljs-keyword">if</span> (!file<span class="hljs-selector-class">.exists</span>(lc_dir))&#123;dir<span class="hljs-selector-class">.create</span>(lc_dir)&#125;<br> lc_clusters &lt;- <span class="hljs-built_in">SplitObject</span>(lc_scRNA, split<span class="hljs-selector-class">.by</span> = lc_groupN)<br> <span class="hljs-built_in">for</span>(lc_g <span class="hljs-keyword">in</span> <span class="hljs-built_in">names</span>(lc_clusters))&#123;<br> c_dir = file<span class="hljs-selector-class">.path</span>(lc_dir,lc_g)<br> <span class="hljs-keyword">if</span> (!file<span class="hljs-selector-class">.exists</span>(c_dir))&#123;dir<span class="hljs-selector-class">.create</span>(c_dir)&#125;<br> <span class="hljs-built_in">f_prepare4cellphoneDB</span>(lc_clusters<span class="hljs-selector-attr">[[lc_g]</span>], c_dir, lc_className)<br> &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>
  154. <figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs stylus"><span class="hljs-function"><span class="hljs-title">f_prepare4cellphoneDB_sp</span><span class="hljs-params">(sc_Neuron,<span class="hljs-string">&quot;Neuron_br_sp&quot;</span>, <span class="hljs-string">&quot;hM1_hmca_class&quot;</span>, <span class="hljs-string">&quot;Region&quot;</span>)</span></span><br></code></pre></td></tr></table></figure>
  155. </div>
  156. <hr/>
  157. <div>
  158. <div class="post-metas my-3">
  159. <div class="post-meta mr-3 d-flex align-items-center">
  160. <i class="iconfont icon-category"></i>
  161. <span class="category-chains">
  162. <span class="category-chain">
  163. <a href="/categories/%E7%94%9F%E7%89%A9%E4%BF%A1%E6%81%AF%E5%AD%A6/" class="category-chain-item">生物信息学</a>
  164. </span>
  165. <span class="category-chain">
  166. <a href="/categories/Seurat%E6%95%99%E7%A8%8B/" class="category-chain-item">Seurat教程</a>
  167. </span>
  168. </span>
  169. </div>
  170. </div>
  171. <div class="license-box my-3">
  172. <div class="license-title">
  173. <div>Seurat (五) 简单总结</div>
  174. <div>https://b.limour.top/886.html</div>
  175. </div>
  176. <div class="license-meta">
  177. <div class="license-meta-item">
  178. <div>Author</div>
  179. <div>Limour</div>
  180. </div>
  181. <div class="license-meta-item license-meta-date">
  182. <div>Posted on</div>
  183. <div>October 4, 2021</div>
  184. </div>
  185. <div class="license-meta-item">
  186. <div>Licensed under</div>
  187. <div>
  188. <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  189. <span class="hint--top hint--rounded" aria-label="BY - Attribution">
  190. <i class="iconfont icon-by"></i>
  191. </span>
  192. </a>
  193. <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  194. <span class="hint--top hint--rounded" aria-label="NC - Non-commercial">
  195. <i class="iconfont icon-nc"></i>
  196. </span>
  197. </a>
  198. <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  199. <span class="hint--top hint--rounded" aria-label="SA - Share-alike">
  200. <i class="iconfont icon-sa"></i>
  201. </span>
  202. </a>
  203. </div>
  204. </div>
  205. </div>
  206. <div class="license-icon iconfont"></div>
  207. </div>
  208. <div class="post-prevnext my-3">
  209. <article class="post-prev col-6">
  210. <a href="/892.html" title="TCGA (三) 两组间DEGs分析">
  211. <i class="iconfont icon-arrowleft"></i>
  212. <span class="hidden-mobile">TCGA (三) 两组间DEGs分析</span>
  213. <span class="visible-mobile">Previous</span>
  214. </a>
  215. </article>
  216. <article class="post-next col-6">
  217. <a href="/873.html" title="Seurat (四) 差异基因分析">
  218. <span class="hidden-mobile">Seurat (四) 差异基因分析</span>
  219. <span class="visible-mobile">Next</span>
  220. <i class="iconfont icon-arrowright"></i>
  221. </a>
  222. </article>
  223. </div>
  224. </div>
  225. <article id="comments" lazyload>
  226. <div id="waline"></div>
  227. <script type="text/javascript">
  228. Fluid.utils.loadComments('#waline', function() {
  229. Fluid.utils.createCssLink('https://cdn.staticfile.org/waline/2.15.5/waline.min.css')
  230. Fluid.utils.createScript('https://cdn.staticfile.org/waline/2.15.5/waline.min.js', function() {
  231. var options = Object.assign(
  232. {"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},
  233. {
  234. el: '#waline',
  235. path: window.location.pathname
  236. }
  237. )
  238. Waline.init(options);
  239. Fluid.utils.waitElementVisible('#waline .vcontent', () => {
  240. var imgSelector = '#waline .vcontent img:not(.vemoji)';
  241. Fluid.plugins.imageCaption(imgSelector);
  242. Fluid.plugins.fancyBox(imgSelector);
  243. })
  244. });
  245. });
  246. </script>
  247. <noscript>Please enable JavaScript to view the comments</noscript>
  248. </article>
  249. </article>
  250. </div>
  251. </div>
  252. </div>
  253. <div class="side-col d-none d-lg-block col-lg-2">
  254. <aside class="sidebar" style="margin-left: -1rem">
  255. <div id="toc">
  256. <p class="toc-header">
  257. <i class="iconfont icon-list"></i>
  258. <span>Table of Contents</span>
  259. </p>
  260. <div class="toc-body" id="toc-body"></div>
  261. </div>
  262. </aside>
  263. </div>
  264. </div>
  265. </div>
  266. <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
  267. <i class="iconfont icon-arrowup" aria-hidden="true"></i>
  268. </a>
  269. <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
  270. aria-hidden="true">
  271. <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
  272. <div class="modal-content">
  273. <div class="modal-header text-center">
  274. <h4 class="modal-title w-100 font-weight-bold">Search</h4>
  275. <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
  276. <span aria-hidden="true">&times;</span>
  277. </button>
  278. </div>
  279. <div class="modal-body mx-3">
  280. <div class="md-form mb-5">
  281. <input type="text" id="local-search-input" class="form-control validate">
  282. <label data-error="x" data-success="v" for="local-search-input">Keyword</label>
  283. </div>
  284. <div class="list-group" id="local-search-result"></div>
  285. </div>
  286. </div>
  287. </div>
  288. </div>
  289. </main>
  290. <footer>
  291. <div class="footer-inner">
  292. <div class="footer-content">
  293. <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>
  294. </div>
  295. </div>
  296. </footer>
  297. <!-- Scripts -->
  298. <script src="https://jscdn.limour.top/npm/nprogress@0.2.0/nprogress.min.js" ></script>
  299. <link rel="stylesheet" href="https://jscdn.limour.top/npm/nprogress@0.2.0/nprogress.min.css" />
  300. <script>
  301. NProgress.configure({"showSpinner":false,"trickleSpeed":100})
  302. NProgress.start()
  303. window.addEventListener('load', function() {
  304. NProgress.done();
  305. })
  306. </script>
  307. <script src="https://jscdn.limour.top/npm/jquery@3.6.4/dist/jquery.min.js" ></script>
  308. <script src="https://jscdn.limour.top/npm/bootstrap@4.6.1/dist/js/bootstrap.min.js" ></script>
  309. <script src="/js/events.js" ></script>
  310. <script src="/js/plugins.js" ></script>
  311. <script src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  312. <script>
  313. (function (window, document) {
  314. var typing = Fluid.plugins.typing;
  315. var subtitle = document.getElementById('subtitle');
  316. if (!subtitle || !typing) {
  317. return;
  318. }
  319. var text = subtitle.getAttribute('data-typed-text');
  320. typing(text);
  321. })(window, document);
  322. </script>
  323. <script src="/js/img-lazyload.js" ></script>
  324. <script>
  325. Fluid.utils.createScript('https://jscdn.limour.top/npm/tocbot@4.20.1/dist/tocbot.min.js', function() {
  326. var toc = jQuery('#toc');
  327. if (toc.length === 0 || !window.tocbot) { return; }
  328. var boardCtn = jQuery('#board-ctn');
  329. var boardTop = boardCtn.offset().top;
  330. window.tocbot.init(Object.assign({
  331. tocSelector : '#toc-body',
  332. contentSelector : '.markdown-body',
  333. linkClass : 'tocbot-link',
  334. activeLinkClass : 'tocbot-active-link',
  335. listClass : 'tocbot-list',
  336. isCollapsedClass: 'tocbot-is-collapsed',
  337. collapsibleClass: 'tocbot-is-collapsible',
  338. scrollSmooth : true,
  339. includeTitleTags: true,
  340. headingsOffset : -boardTop,
  341. }, CONFIG.toc));
  342. if (toc.find('.toc-list-item').length > 0) {
  343. toc.css('visibility', 'visible');
  344. }
  345. Fluid.events.registerRefreshCallback(function() {
  346. if ('tocbot' in window) {
  347. tocbot.refresh();
  348. var toc = jQuery('#toc');
  349. if (toc.length === 0 || !tocbot) {
  350. return;
  351. }
  352. if (toc.find('.toc-list-item').length > 0) {
  353. toc.css('visibility', 'visible');
  354. }
  355. }
  356. });
  357. });
  358. </script>
  359. <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>
  360. <script>Fluid.plugins.codeWidget();</script>
  361. <script>
  362. Fluid.utils.createScript('https://jscdn.limour.top/npm/anchor-js@4.3.1/anchor.min.js', function() {
  363. window.anchors.options = {
  364. placement: CONFIG.anchorjs.placement,
  365. visible : CONFIG.anchorjs.visible
  366. };
  367. if (CONFIG.anchorjs.icon) {
  368. window.anchors.options.icon = CONFIG.anchorjs.icon;
  369. }
  370. var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
  371. var res = [];
  372. for (var item of el) {
  373. res.push('.markdown-body > ' + item.trim());
  374. }
  375. if (CONFIG.anchorjs.placement === 'left') {
  376. window.anchors.options.class = 'anchorjs-link-left';
  377. }
  378. window.anchors.add(res.join(', '));
  379. Fluid.events.registerRefreshCallback(function() {
  380. if ('anchors' in window) {
  381. anchors.removeAll();
  382. var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
  383. var res = [];
  384. for (var item of el) {
  385. res.push('.markdown-body > ' + item.trim());
  386. }
  387. if (CONFIG.anchorjs.placement === 'left') {
  388. anchors.options.class = 'anchorjs-link-left';
  389. }
  390. anchors.add(res.join(', '));
  391. }
  392. });
  393. });
  394. </script>
  395. <script>
  396. Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
  397. Fluid.plugins.fancyBox();
  398. });
  399. </script>
  400. <script>Fluid.plugins.imageCaption();</script>
  401. <script src="/js/local-search.js" ></script>
  402. <!-- 主题的启动项,将它保持在最底部 -->
  403. <!-- the boot of the theme, keep it at the bottom -->
  404. <script src="/js/boot.js" ></script>
  405. <noscript>
  406. <div class="noscript-warning">Blog works best with JavaScript enabled</div>
  407. </noscript>
  408. <!-- hexo injector body_end start -->
  409. <script defer src="/theme-inject/timeliness.js"></script>
  410. <!-- hexo injector body_end end --></body>
  411. </html>