123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701 |
- <!DOCTYPE html>
- <html lang="en" data-default-color-scheme=auto>
- <head><!-- hexo injector head_begin start -->
- <script async src="https://analytics.umami.is/script.js" data-website-id="e59ec28a-c9a7-4104-9e62-a9f7eb3fac0b"></script>
- <!-- hexo injector head_begin end -->
- <meta charset="UTF-8">
- <link rel="apple-touch-icon" sizes="76x76" href="https://img.limour.top/2023/08/29/64ee07361815a.webp">
- <link rel="icon" href="https://img.limour.top/2023/08/29/64ee07361815a.webp">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
- <meta http-equiv="x-ua-compatible" content="ie=edge">
-
- <meta name="theme-color" content="#2f4154">
- <meta name="author" content="Limour">
- <meta name="keywords" content="">
-
- <meta name="description" content="12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210">
- <meta property="og:type" content="article">
- <meta property="og:title" content="Seurat (五) 简单总结">
- <meta property="og:url" content="https://b.limour.top/886.html">
- <meta property="og:site_name" content="Limour's Blog">
- <meta property="og:description" content="12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210">
- <meta property="og:locale" content="en_US">
- <meta property="article:published_time" content="2021-10-04T12:43:00.000Z">
- <meta property="article:modified_time" content="2023-09-01T13:32:00.589Z">
- <meta property="article:author" content="Limour">
- <meta name="twitter:card" content="summary_large_image">
-
-
-
- <title>Seurat (五) 简单总结 - Limour's Blog</title>
- <link rel="stylesheet" href="https://jscdn.limour.top/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" />
- <link rel="stylesheet" href="https://jscdn.limour.top/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
- <link rel="stylesheet" href="https://jscdn.limour.top/npm/hint.css@2.7.0/hint.min.css" />
- <link rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />
- <!-- 主题依赖的图标库,不要自行修改 -->
- <!-- Do not modify the link that theme dependent icons -->
- <link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">
- <link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">
- <link rel="stylesheet" href="/css/main.css" />
- <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
-
- <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
-
-
- <link rel="stylesheet" href="/theme-inject/custom.css">
- <script id="fluid-configs">
- var Fluid = window.Fluid || {};
- Fluid.ctx = Object.assign({}, Fluid.ctx)
- 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};
- if (CONFIG.web_analytics.follow_dnt) {
- var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
- Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
- }
- </script>
- <script src="/js/utils.js" ></script>
- <script src="/js/color-schema.js" ></script>
-
-
- <meta name="generator" content="Hexo 6.3.0"></head>
- <body>
-
- <header>
-
- <div class="header-inner" style="height: 70vh;">
- <nav id="navbar" class="navbar fixed-top navbar-expand-lg navbar-dark scrolling-navbar">
- <div class="container">
- <a class="navbar-brand" href="/">
- <strong>Limour's Blog</strong>
- </a>
- <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
- data-target="#navbarSupportedContent"
- aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
- <div class="animated-icon"><span></span><span></span><span></span></div>
- </button>
- <!-- Collapsible content -->
- <div class="collapse navbar-collapse" id="navbarSupportedContent">
- <ul class="navbar-nav ml-auto text-center">
-
-
-
-
-
- <li class="nav-item">
- <a class="nav-link" href="/">
- <i class="iconfont icon-home-fill"></i>
- <span>Home</span>
- </a>
- </li>
-
-
-
-
-
-
- <li class="nav-item">
- <a class="nav-link" href="/archives/">
- <i class="iconfont icon-archive-fill"></i>
- <span>Archives</span>
- </a>
- </li>
-
-
-
- <li class="nav-item" id="search-btn">
- <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
- <i class="iconfont icon-search"></i>
- </a>
- </li>
-
-
-
- <li class="nav-item" id="color-toggle-btn">
- <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
- <i class="iconfont icon-dark" id="color-toggle-icon"></i>
- </a>
- </li>
-
- </ul>
- </div>
- </div>
- </nav>
-
- <div id="banner" class="banner" parallax=true
- style="background: url('https://img.limour.top/2023/08/29/64ee08e108638.webp') no-repeat center center; background-size: cover;">
- <div class="full-bg-img">
- <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
- <div class="banner-text text-center fade-in-up">
- <div class="h2">
-
- <span id="subtitle" data-typed-text="Seurat (五) 简单总结"></span>
-
- </div>
-
-
- <div class="mt-3">
-
-
- <span class="post-meta">
- <i class="iconfont icon-date-fill" aria-hidden="true"></i>
- <time datetime="2021-10-04 20:43" pubdate>
- October 4, 2021 pm
- </time>
- </span>
-
- </div>
- <div class="mt-1">
-
- <span class="post-meta mr-2">
- <i class="iconfont icon-chart"></i>
-
- 20k words
-
- </span>
-
-
- <span class="post-meta mr-2">
- <i class="iconfont icon-clock-fill"></i>
-
-
-
- 170 mins
-
- </span>
-
-
-
- </div>
-
- </div>
-
- </div>
- </div>
- </div>
- </div>
- </header>
- <main>
-
-
- <div class="container-fluid nopadding-x">
- <div class="row nomargin-x">
- <div class="side-col d-none d-lg-block col-lg-2">
-
- </div>
- <div class="col-lg-8 nopadding-x-md">
- <div class="container nopadding-x-md" id="board-ctn">
- <div id="board">
- <article class="post-content mx-auto">
- <h1 id="seo-header">Seurat (五) 简单总结</h1>
-
-
- <div class="markdown-body">
-
- <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 <- 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">"bold"</span>,<span class="hljs-params">hjust</span> = 0.5)</span><br> )<br>col_Paired <- color<span class="hljs-constructor">RampPalette(<span class="hljs-params">brewer</span>.<span class="hljs-params">pal</span>(12, <span class="hljs-string">"Paired"</span>)</span>)<br>f_pie <- <span class="hljs-keyword">function</span>(lc_x, lc_main, lc_x_p = <span class="hljs-number">1.3</span>, lc_r = T){<br> lc_cols <- col<span class="hljs-constructor">_Paired(<span class="hljs-params">length</span>(<span class="hljs-params">lc_x</span>)</span>)<br> lc_v <- <span class="hljs-keyword">as</span>.vector(<span class="hljs-number">100</span>*lc_x)<br> lc_df <- data.frame(<span class="hljs-keyword">type</span> = names(lc_x), nums = lc_v)<br> lc_df <- 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('%<span class="hljs-number">0.2</span>f%%',lc_df$nums)<br> <span class="hljs-keyword">if</span>(lc_r){<br> lc_df$pos <- <span class="hljs-keyword">with</span>(lc_df, <span class="hljs-number">100</span>-cumsum(nums)+nums/<span class="hljs-number">2</span>)<br> }<span class="hljs-keyword">else</span>{<br> lc_df$pos <- <span class="hljs-keyword">with</span>(lc_df, cumsum(nums)-nums/<span class="hljs-number">2</span>)<br> } <br> lc_pie <- 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> = '<span class="hljs-params">identity</span>')</span><br># print(lc_df)<br># print(lc_pie)<br> lc_pie <- lc_pie + coord<span class="hljs-constructor">_polar(<span class="hljs-string">"y"</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 <- 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">"npc"</span>)), segment.color = <span class="hljs-string">"#cccccc"</span>, segment.size = <span class="hljs-number">0.5</span>)<br> lc_pie <- lc_pie + labs(title = lc_main)<br> lc_pie<br>}<br><br>f_pie_metaN <- <span class="hljs-keyword">function</span>(sObject, lc_group.by){<br> tp_data <- 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>('Proportion <span class="hljs-params">of</span> %<span class="hljs-params">s</span>', <span class="hljs-params">lc_group</span>.<span class="hljs-params">by</span>)</span>)<br>}<br><br>f_UMAP_more <- <span class="hljs-keyword">function</span>(sObject, lc_group.by, lc_reduction=<span class="hljs-string">"umap"</span>){<br> res <- (<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)){<br> res <- 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> }<br> res<br>}<br><br>f_br_cluster_f <- <span class="hljs-keyword">function</span>(sObject, lc_groupN){<br> lc_filter <- unlist(unique(sObject<span class="hljs-literal">[[<span class="hljs-identifier">lc_groupN</span>]</span>]))<br> lc_filter <- 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>}<br><br>f_br_cluster <- <span class="hljs-keyword">function</span>(sObject, lc_groupN, lc_labelN, lc_prop = F){<br> lc_all <- unique(sObject<span class="hljs-literal">[[<span class="hljs-identifier">lc_labelN</span>]</span>])<br> rownames(lc_all) <- lc_all<span class="hljs-literal">[[<span class="hljs-number">1</span>]</span>]<br> colnames(lc_all) <- <span class="hljs-string">"CB"</span><br> lc_tp <- <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)){<br> <span class="hljs-keyword">if</span>(lc_prop){<br> lc_tp<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>] <- 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> }<span class="hljs-keyword">else</span>{<br> lc_tp<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>] <- 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> }<br> }<br> <span class="hljs-keyword">for</span>(lc_name <span class="hljs-keyword">in</span> names(lc_tp)){<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> }<br> lc_all<span class="hljs-literal">[,-<span class="hljs-number">1</span>]</span><br>}<br> <br>f_q2l <- <span class="hljs-keyword">function</span>(lc_q){<br> res <- NULL<br> <span class="hljs-keyword">for</span>(lc_c <span class="hljs-keyword">in</span> colnames(lc_q)){<br> <span class="hljs-keyword">for</span>(lc_r <span class="hljs-keyword">in</span> rownames(lc_q)){<br> res <- 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> }<br> }<br> res <- data.frame(res)<br> res$value = <span class="hljs-keyword">as</span>.numeric(res$value)<br> res<br>}<br> <br>library(RColorBrewer)<br>library(ggplot2)<br>col_Paired <- color<span class="hljs-constructor">RampPalette(<span class="hljs-params">brewer</span>.<span class="hljs-params">pal</span>(12, <span class="hljs-string">"Paired"</span>)</span>)<br>f_q_frequnency <- <span class="hljs-keyword">function</span>(lc_q){<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>='<span class="hljs-params">identity</span>',<span class="hljs-params">position</span>='<span class="hljs-params">fill</span>')</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 = 'group',y = 'frequnency') +<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> = '<span class="hljs-params">black</span>')</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>}<br><br>f_DEG_Volcano <- <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>){<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> < T<span class="hljs-identifier">hreshold_p</span> & <span class="hljs-identifier">lc_logFC</span> > 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> < T<span class="hljs-identifier">hreshold_p</span> & <span class="hljs-identifier">lc_logFC</span> < -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> < <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> > <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 <- lc_logFC, `-log10(P)` <- -log10(lc_p), col <- col_vector, gene <- lc_gene)<br> colnames(df) <- c('logFC', '-log10(P)', <span class="hljs-string">"col"</span>, <span class="hljs-string">"gene"</span>)<br> lc_tp_logFC <- df$logFC<br> lc_tp_logFC<span class="hljs-literal">[<span class="hljs-identifier">lc_p</span>>=T<span class="hljs-identifier">hreshold_p</span>]</span> = <span class="hljs-number">0</span><br> lc_idx <- 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> > <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> < -<span class="hljs-number">10</span>]</span> = -<span class="hljs-number">10</span><br> res <- 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 <- 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 <- 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">"longdash"</span>)<br> res <- 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">"longdash"</span>)<br> res <- 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>}<br><br>f_cluster_averages <- <span class="hljs-keyword">function</span>(lc_scRNA, lc_metaN='ident'){<br> # 切分出Clusters<br> lc_clusters <- <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)){<br> lc_clusters<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>] <- 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> }<br> <span class="hljs-keyword">for</span> (lc_i <span class="hljs-keyword">in</span> <span class="hljs-number">1</span>:length(lc_clusters)){<br> lc_clusters<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>] <- apply(lc_clusters<span class="hljs-literal">[[<span class="hljs-identifier">lc_i</span>]</span>],<span class="hljs-number">1</span>,mean)<br> }<br> lc_clusters <- data.frame(lc_clusters)<br> scale(lc_clusters)<br>}<br> <br>library(clusterProfiler)<br>library(pheatmap)<br>library(ggdendro)<br>f_DEG_hclust <- <span class="hljs-keyword">function</span>(lc_counts){<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">"bold"</span>)</span>)<br>}<br><br>f_DEG_pheatmap_choose_matrix <- <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>){<br> res <- subset(lc_significant_markers, abs(avg_log2FC) > Threshold_logFC)<br> res <- 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 <- head(unique(res$gene), n = lc_n)<br> res <- lc_tp_d<span class="hljs-literal">[<span class="hljs-identifier">res</span>,]</span><br> res<br>}<br><br>require(ggplotify)<br>f_DEG_pheatmap <- <span class="hljs-keyword">function</span>(choose_matrix){<br> choose_matrix = t(scale(t(choose_matrix)))<br> <span class="hljs-keyword">as</span>.ggplot(pheatmap(choose_matrix))<br>}<br><br>f_prepare4CSOmap <- <span class="hljs-keyword">function</span>(lc_scRNA, lc_csomap_data_dir, lc_className){<br> lc_csomap_data_dir <- system(paste(<span class="hljs-string">"echo"</span>, lc_csomap_data_dir), intern = T)<br> <span class="hljs-keyword">if</span>(!file.exists(lc_csomap_data_dir)){dir.create(lc_csomap_data_dir)}<br> # 导出label.txt<br> labels <- lc_scRNA<span class="hljs-literal">[[<span class="hljs-identifier">lc_className</span>]</span>]<br> labels$cells <- gsub(<span class="hljs-string">"-"</span>, <span class="hljs-string">"."</span> ,rownames(labels)) # TPM的colnames 不知为何导出时被替换了,这里也替换一下<br> labels$labels <- <span class="hljs-keyword">as</span>.character(labels<span class="hljs-literal">[[<span class="hljs-identifier">lc_className</span>]</span>])<br> rownames(labels) <- NULL<br> labels = labels<span class="hljs-literal">[,<span class="hljs-identifier">c</span>("<span class="hljs-identifier">cells</span>", "<span class="hljs-identifier">labels</span>")]</span><br> write.table(labels, file.path(lc_csomap_data_dir, <span class="hljs-string">"label.txt"</span>), row.names = F, sep = <span class="hljs-string">"\t"</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">".."</span>,<span class="hljs-string">"demo"</span>,<span class="hljs-string">"LR_pairs.txt"</span>), <span class="hljs-keyword">to</span> = file.path(lc_csomap_data_dir, <span class="hljs-string">"LR_pairs.txt"</span>))<br> <br> # 导出<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">TPM</span>.</span></span>txt<br> tpm <- exp(lc_scRNA<span class="hljs-literal">[['RNA']</span>]@data)<br> tpm <- tpm - <span class="hljs-number">1</span><br> tpm <- 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">'T'</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">"TPM.txt"</span>), sep = <span class="hljs-string">"\t"</span>, quote = F) # 不要引号<br> <br> lc_fix <- tempfile<span class="hljs-literal">()</span><br> lc_py <- sprintf('<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">"%s"</span><br>print(path, <span class="hljs-string">"%s"</span>)<br>f = mapfile(path,<span class="hljs-string">"r+"</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">"\t"</span><br>print(f<span class="hljs-literal">[:]</span>)<br>f.close<span class="hljs-literal">()</span><br>print(<span class="hljs-string">"Done"</span>)<br>', file.path(lc_csomap_data_dir, <span class="hljs-string">"TPM.txt"</span>), lc_fix)<br> print(lc_py)<br> cat(file=lc_fix, lc_py)<br> print(system(paste(<span class="hljs-string">"python3"</span>, lc_fix), intern = T))<br>}<br><br>f_prepare4cellphoneDB <- <span class="hljs-keyword">function</span>(lc_scRNA, lc_dir, lc_className){<br> <span class="hljs-keyword">if</span> (!file.exists(lc_dir)){dir.create(lc_dir)}<br> # 生成 count.txt <br> write.table(<span class="hljs-keyword">as</span>.matrix(lc_scRNA@assays$RNA@data), file.path(lc_dir,'cellphonedb_count.txt'), sep=<span class="hljs-character">'\t'</span>, quote=F)<br> # 生成 meta.txt<br> lc_meta_data <- 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 <- <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">"Unkown"</span> # 细胞类型中不能有NA<br> write.table(lc_meta_data, file.path(lc_dir,'cellphonedb_meta.txt'), sep=<span class="hljs-character">'\t'</span>, quote=F, row.names=F)<br>}<br><br>f_image_output <- <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>){<br> <span class="hljs-keyword">if</span>(lc_pdf){<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">".pdf"</span>, sep=<span class="hljs-string">""</span>), width = width, height = height)<br> }<span class="hljs-keyword">else</span>{<br> png(paste(fileName, <span class="hljs-string">".png"</span>, sep=<span class="hljs-string">""</span>), width = width, height = height)<br> }<br> print(image)<br> dev.off<span class="hljs-literal">()</span><br>}<br> <br># Rearrange data column sequence<br>library(dplyr)<br>f_cDB_order_sequence <- <span class="hljs-keyword">function</span>(lc_df){<br> da <- data.frame<span class="hljs-literal">()</span><br> df <- subset(lc_df, receptor_a<span class="hljs-operator"> == </span>'True' & receptor_b<span class="hljs-operator"> == </span>'False' receptor_a<span class="hljs-operator"> == </span>'False' & receptor_b<span class="hljs-operator"> == </span>'True')<br> <span class="hljs-keyword">for</span>(i <span class="hljs-keyword">in</span> <span class="hljs-number">1</span>:length(df$gene_a)){<br> sub_data <- df<span class="hljs-literal">[<span class="hljs-identifier">i</span>, ]</span><br> <span class="hljs-keyword">if</span>(sub_data$receptor_b=='False'){<br> <span class="hljs-keyword">if</span>(sub_data$receptor_a=='True'){<br> old_names <- colnames(sub_data)<br> my_list <- 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">"\\"</span>)<br> my_character <- paste(sapply(my_list, '<span class="hljs-literal">[[', <span class="hljs-number">2L</span>), <span class="hljs-identifier">sapply</span>(<span class="hljs-identifier">my_list</span>, '[[', <span class="hljs-number">1L</span>), <span class="hljs-identifier">sep</span>='')</span><br><span class="hljs-literal"> <span class="hljs-identifier">new_names</span> <- <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>, 'gene_b', 'gene_a', 'secreted', 'receptor_b', 'receptor_a', <span class="hljs-string">"annotation_strategy"</span>, <span class="hljs-string">"is_integrin"</span>, my_character)<br> sub_data = dplyr::select(sub_data, new_names)<br> # print('Change sequence!!!')<br> names(sub_data) <- old_names<br> da = rbind(da, sub_data) <br> }<br> }<span class="hljs-keyword">else</span>{<br> da = rbind(da, sub_data)<br> }<br> }<br> return(da)<br>}<br> <br>f_cDB_mergePandM <- <span class="hljs-keyword">function</span>(means_order, pvals_order){<br> means_sub <- means_order<span class="hljs-literal">[, <span class="hljs-identifier">c</span>('<span class="hljs-identifier">interacting_pair</span>', <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 <- pvals_order<span class="hljs-literal">[, <span class="hljs-identifier">c</span>('<span class="hljs-identifier">interacting_pair</span>', <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 <- tidyr::gather(means_sub, celltype, mean_expression, names(means_sub)<span class="hljs-literal">[-<span class="hljs-number">1</span>]</span>)<br> pvals_gather <- tidyr::gather(pvals_sub, celltype, pval, names(pvals_sub)<span class="hljs-literal">[-<span class="hljs-number">1</span>]</span>)<br> mean_pval <- 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>('<span class="hljs-params">interacting_pair</span>', '<span class="hljs-params">celltype</span>')</span>)<br> mean_pval<br>}<br> <br>f_readcellphoneDB <- <span class="hljs-keyword">function</span>(lc_dir){<br> res = <span class="hljs-built_in">list</span><span class="hljs-literal">()</span><br> res$pvals <- 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">"out"</span>,<span class="hljs-string">"pvalues.txt"</span>)</span>, check.names = FALSE))<br> res$means <- 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">"out"</span>, <span class="hljs-string">"means.txt"</span>)</span>, check.names = FALSE))<br> res$s_means <- read.delim(file.path(lc_dir, <span class="hljs-string">"out"</span>, <span class="hljs-string">"significant_means.txt"</span>), check.names = FALSE)<br> res$m_p <- 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 <- res$m_p %>% dplyr::select(interacting_pair, celltype, pval) %>% tidyr::spread(key=celltype, value=pval)<br> lc_sig_pairs <- 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><=<span class="hljs-number">0.05</span>)!=<span class="hljs-number">0</span>), ]</span><br> res$s_m_p <- subset(res$m_p, interacting_pair %<span class="hljs-keyword">in</span>% lc_sig_pairs$interacting_pair)<br> res<br>}<br> <br>f_cDB_dotplot <- <span class="hljs-keyword">function</span>(lc_m_p){<br> lc_m_p %>% 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> = '<span class="hljs-params">reverse</span>')</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='', y='') +<br> scale<span class="hljs-constructor">_color_gradientn(<span class="hljs-params">name</span>='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>', colours = terrain.colors(<span class="hljs-number">100</span>)) +<br> # scale<span class="hljs-constructor">_color_gradient2('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>', low = 'blue', mid = 'yellow', high = 'red') +<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> = '<span class="hljs-params">black</span>', <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 = 'bottom' # guides(fill = guide<span class="hljs-constructor">_legend(<span class="hljs-params">label</span>.<span class="hljs-params">position</span> = <span class="hljs-string">"bottom"</span>)</span>)<br> # legend.position = <span class="hljs-string">"bottom"</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>, 'cm'), #change legend key size<br> # legend.key.height = <span class="hljs-built_in">unit</span>(<span class="hljs-number">1</span>, 'cm'), #change legend key height<br> # legend.key.width = <span class="hljs-built_in">unit</span>(<span class="hljs-number">1</span>, 'cm'), #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>}<br><br></code></pre></td></tr></table></figure>
- <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">"~/zlliu/R_data/hBLA"</span><br> <br><span class="hljs-comment"># 配置结果保存路径</span><br>output_path = <span class="hljs-string">"~/zlliu/R_data/21.10.04.split"</span><br><span class="hljs-keyword">if</span> (!<span class="hljs-keyword">file</span>.<span class="hljs-keyword">exists</span>(output_path)){dir.create(output_path)}<br> <br><span class="hljs-comment"># 设置工作目录,输出文件将保存在此目录下</span><br>setwd(output_path)<br>getwd()<br></code></pre></td></tr></table></figure>
- <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">"~/zlliu/R_output/21.09.21.SingleR/scRNA.rds"</span>)<br><span class="hljs-keyword">scRNA </span><- <span class="hljs-keyword">subset(x </span>= <span class="hljs-keyword">scRNA, </span>!!sym(<span class="hljs-string">"Region"</span>)%in%f_br_cluster_f(<span class="hljs-keyword">scRNA, </span><span class="hljs-string">"Region"</span>))<br><span class="hljs-keyword">scRNA@meta.data</span><br></code></pre></td></tr></table></figure>
- <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">"Region"</span>)</span></span> + <span class="hljs-built_in">f_pie_metaN</span>(scRNA, <span class="hljs-string">"hM1_hmca_class"</span>)<br></code></pre></td></tr></table></figure>
- <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 <- c(<span class="hljs-string">'L4 IT'</span>,<span class="hljs-string">'L5 IT'</span>,<span class="hljs-string">'L5 ET'</span>,<span class="hljs-string">'IT'</span>,<span class="hljs-string">'L6b'</span>,<span class="hljs-string">'L5/6 IT Car3'</span>,<span class="hljs-string">'L6 IT'</span>,<span class="hljs-string">'L2/3 IT'</span>,<span class="hljs-string">'L5/6 NP'</span>,<span class="hljs-string">'L6 IT Car3'</span>,<span class="hljs-string">'L6 CT'</span>)<br> <br>n_InN <- c(<span class="hljs-string">'Lamp5'</span>,<span class="hljs-string">'Pvalb'</span>,<span class="hljs-string">'Sst'</span>,<span class="hljs-string">'Vip'</span>,<span class="hljs-string">'Sncg'</span>)<br> <br>n_NoN <- c(<span class="hljs-string">'Astro'</span>,<span class="hljs-string">'PAX6'</span>,<span class="hljs-string">'Endo'</span>,<span class="hljs-string">'Micro-PVM'</span>,<span class="hljs-string">'OPC'</span>,<span class="hljs-string">'Oligo'</span>,<span class="hljs-string">'Pericyte'</span>,<span class="hljs-string">'VLMC'</span>)<br> <br>n_groups <- list(NoN=n_NoN, ExN=n_ExN, InN=n_InN)<br> <br>f_listUpdateRe <- <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(lc_obj, lc_bool, lc_item)</span></span>{<br> lc_obj[lc_bool] <- <span class="hljs-built_in">rep</span>(lc_item,times=sum(lc_bool))<br> lc_obj<br>}<br> <br>f_grouplabel <- <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(lc_meta.data, lc_groups)</span></span>{<br> res <- 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)){<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)){<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> }<br> res <- f_listUpdateRe(res, lc_bool, lc_g)<br> }<br> names(res) <- rownames(lc_meta.data)<br> res<br>}<br></code></pre></td></tr></table></figure>
- <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 <- <span class="hljs-built_in">f_br_cluster</span>(scRNA, <span class="hljs-string">'Region'</span>, <span class="hljs-string">'hM1_hmca_class'</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">'hM1_class'</span>, <span class="hljs-string">'hmca_class'</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">'hM1_hmca_class'</span>, <span class="hljs-string">'Region'</span>)</span></span>)<br></code></pre></td></tr></table></figure>
- <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">[['n_groups']]</span> <- f_grouplabel(scRNA<span class="hljs-string">[[c("hM1_hmca_class")]]</span>, n_groups)<br>sc_Neuron <- subset(x = scRNA, n_groups %<span class="hljs-keyword">in</span>% c(<span class="hljs-string">"InN"</span>, <span class="hljs-string">"ExN"</span>))<br>sc_Neuron <- subset(x = sc_Neuron, !!sym(<span class="hljs-string">"Region"</span>)%<span class="hljs-keyword">in</span>%f_br_cluster_f(sc_Neuron, <span class="hljs-string">"Region"</span>))<br></code></pre></td></tr></table></figure>
- <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">"Region"</span>)</span></span> + <span class="hljs-built_in">f_pie_metaN</span>(sc_Neuron, <span class="hljs-string">"hM1_hmca_class"</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 <- <span class="hljs-built_in">f_br_cluster</span>(sc_Neuron, <span class="hljs-string">'Region'</span>, <span class="hljs-string">'hM1_hmca_class'</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>
- <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 <- <span class="hljs-built_in">subset</span>(x = sc_Neuron, n_groups == <span class="hljs-string">"ExN"</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">"Region"</span>)</span></span> + <span class="hljs-built_in">f_pie_metaN</span>(sc_Neuron_ExN, <span class="hljs-string">"hM1_hmca_class"</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 <- <span class="hljs-built_in">f_br_cluster</span>(sc_Neuron_ExN, <span class="hljs-string">'Region'</span>, <span class="hljs-string">'hM1_hmca_class'</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">'hM1_class'</span>, <span class="hljs-string">'hmca_class'</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">'hM1_hmca_class'</span>, <span class="hljs-string">'Region'</span>)</span></span>)<br><br></code></pre></td></tr></table></figure>
- <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 <- <span class="hljs-built_in">subset</span>(x = sc_Neuron, n_groups == <span class="hljs-string">"InN"</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">"Region"</span>)</span></span> + <span class="hljs-built_in">f_pie_metaN</span>(sc_Neuron_InN, <span class="hljs-string">"hM1_hmca_class"</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 <- <span class="hljs-built_in">f_br_cluster</span>(sc_Neuron_InN, <span class="hljs-string">'Region'</span>, <span class="hljs-string">'hM1_hmca_class'</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">'hM1_class'</span>, <span class="hljs-string">'hmca_class'</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">'hM1_hmca_class'</span>, <span class="hljs-string">'Region'</span>)</span></span>)<br><br></code></pre></td></tr></table></figure>
- <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> <- sc_Neuron<span class="hljs-selector-attr">[[<span class="hljs-string">'hM1_hmca_class'</span>]</span>]<br>all_markers <- <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 <- <span class="hljs-built_in">subset</span>(all_markers, subset = p_val_adj<<span class="hljs-number">0.05</span>)<br><br></code></pre></td></tr></table></figure>
- <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 <- <span class="hljs-built_in">f_cluster_averages</span>(sc_Neuron, <span class="hljs-string">"hM1_hmca_class"</span>)<br>tp_d_br <- <span class="hljs-built_in">f_cluster_averages</span>(sc_Neuron, <span class="hljs-string">"Region"</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>
- <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> <- sc_Neuron<span class="hljs-selector-attr">[[<span class="hljs-string">'hM1_hmca_class'</span>]</span>]<br>all_markers <- <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 <- <span class="hljs-built_in">subset</span>(all_markers, subset = p_val_adj<<span class="hljs-number">0.05</span>)<br><br></code></pre></td></tr></table></figure>
- <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 <- <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 <- <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>
- <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">"Neuron"</span>, <span class="hljs-string">"hM1_hmca_class"</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">"Neuron_br"</span>, <span class="hljs-string">"Region"</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">"~/CSOmap/data/zlliu_s_Neuron"</span>, <span class="hljs-string">"hM1_hmca_class"</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">"~/CSOmap/data/zlliu_s_Neuron_br"</span>, <span class="hljs-string">"Region"</span>)</span></span><br></code></pre></td></tr></table></figure>
- <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>
- <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">"runme('zlliu_s_Neuron');exit"</span><br>matlab -nodisplay -r <span class="hljs-string">"runme('zlliu_s_Neuron_br');exit"</span><br><span class="hljs-built_in">echo</span> <span class="hljs-variable">$HOME</span><br></code></pre></td></tr></table></figure>
- <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 <- f<span class="hljs-constructor">_readcellphoneDB('Neuron')</span><br>tp_img <- 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><0.05)</span>)<br>f<span class="hljs-constructor">_image_output('Neuron',<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>
- <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 <- <span class="hljs-built_in">function</span>(lc_scRNA, lc_dir, lc_className, lc_groupN){<br> <span class="hljs-keyword">if</span> (!file<span class="hljs-selector-class">.exists</span>(lc_dir)){dir<span class="hljs-selector-class">.create</span>(lc_dir)}<br> lc_clusters <- <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)){<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)){dir<span class="hljs-selector-class">.create</span>(c_dir)}<br> <span class="hljs-built_in">f_prepare4cellphoneDB</span>(lc_clusters<span class="hljs-selector-attr">[[lc_g]</span>], c_dir, lc_className)<br> }<br>}<br><br></code></pre></td></tr></table></figure>
- <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">"Neuron_br_sp"</span>, <span class="hljs-string">"hM1_hmca_class"</span>, <span class="hljs-string">"Region"</span>)</span></span><br></code></pre></td></tr></table></figure>
-
- </div>
-
- <hr/>
- <div>
- <div class="post-metas my-3">
-
- <div class="post-meta mr-3 d-flex align-items-center">
- <i class="iconfont icon-category"></i>
-
- <span class="category-chains">
-
-
-
- <span class="category-chain">
-
- <a href="/categories/%E7%94%9F%E7%89%A9%E4%BF%A1%E6%81%AF%E5%AD%A6/" class="category-chain-item">生物信息学</a>
-
-
- </span>
-
-
-
- <span class="category-chain">
-
- <a href="/categories/Seurat%E6%95%99%E7%A8%8B/" class="category-chain-item">Seurat教程</a>
-
-
- </span>
-
-
- </span>
- </div>
-
-
- </div>
-
-
- <div class="license-box my-3">
- <div class="license-title">
- <div>Seurat (五) 简单总结</div>
- <div>https://b.limour.top/886.html</div>
- </div>
- <div class="license-meta">
-
- <div class="license-meta-item">
- <div>Author</div>
- <div>Limour</div>
- </div>
-
-
- <div class="license-meta-item license-meta-date">
- <div>Posted on</div>
- <div>October 4, 2021</div>
- </div>
-
-
-
- <div class="license-meta-item">
- <div>Licensed under</div>
- <div>
-
-
-
- <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
- <span class="hint--top hint--rounded" aria-label="BY - Attribution">
- <i class="iconfont icon-by"></i>
- </span>
- </a>
-
- <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
- <span class="hint--top hint--rounded" aria-label="NC - Non-commercial">
- <i class="iconfont icon-nc"></i>
- </span>
- </a>
-
- <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
- <span class="hint--top hint--rounded" aria-label="SA - Share-alike">
- <i class="iconfont icon-sa"></i>
- </span>
- </a>
-
-
- </div>
- </div>
-
- </div>
- <div class="license-icon iconfont"></div>
- </div>
-
- <div class="post-prevnext my-3">
- <article class="post-prev col-6">
-
-
- <a href="/892.html" title="TCGA (三) 两组间DEGs分析">
- <i class="iconfont icon-arrowleft"></i>
- <span class="hidden-mobile">TCGA (三) 两组间DEGs分析</span>
- <span class="visible-mobile">Previous</span>
- </a>
-
- </article>
- <article class="post-next col-6">
-
-
- <a href="/873.html" title="Seurat (四) 差异基因分析">
- <span class="hidden-mobile">Seurat (四) 差异基因分析</span>
- <span class="visible-mobile">Next</span>
- <i class="iconfont icon-arrowright"></i>
- </a>
-
- </article>
- </div>
-
- </div>
-
-
-
- <article id="comments" lazyload>
-
- <div id="waline"></div>
- <script type="text/javascript">
- Fluid.utils.loadComments('#waline', function() {
- Fluid.utils.createCssLink('https://cdn.staticfile.org/waline/2.15.5/waline.min.css')
- Fluid.utils.createScript('https://cdn.staticfile.org/waline/2.15.5/waline.min.js', function() {
- var options = Object.assign(
- {"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},
- {
- el: '#waline',
- path: window.location.pathname
- }
- )
- Waline.init(options);
- Fluid.utils.waitElementVisible('#waline .vcontent', () => {
- var imgSelector = '#waline .vcontent img:not(.vemoji)';
- Fluid.plugins.imageCaption(imgSelector);
- Fluid.plugins.fancyBox(imgSelector);
- })
- });
- });
- </script>
- <noscript>Please enable JavaScript to view the comments</noscript>
- </article>
-
- </article>
- </div>
- </div>
- </div>
- <div class="side-col d-none d-lg-block col-lg-2">
-
- <aside class="sidebar" style="margin-left: -1rem">
- <div id="toc">
- <p class="toc-header">
- <i class="iconfont icon-list"></i>
- <span>Table of Contents</span>
- </p>
- <div class="toc-body" id="toc-body"></div>
- </div>
- </aside>
- </div>
- </div>
- </div>
-
-
-
-
-
-
-
- <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
- <i class="iconfont icon-arrowup" aria-hidden="true"></i>
- </a>
-
-
- <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
- aria-hidden="true">
- <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
- <div class="modal-content">
- <div class="modal-header text-center">
- <h4 class="modal-title w-100 font-weight-bold">Search</h4>
- <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- </div>
- <div class="modal-body mx-3">
- <div class="md-form mb-5">
- <input type="text" id="local-search-input" class="form-control validate">
- <label data-error="x" data-success="v" for="local-search-input">Keyword</label>
- </div>
- <div class="list-group" id="local-search-result"></div>
- </div>
- </div>
- </div>
- </div>
-
-
- </main>
- <footer>
- <div class="footer-inner">
-
- <div class="footer-content">
- <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>
- </div>
-
-
-
-
- </div>
- </footer>
- <!-- Scripts -->
-
- <script src="https://jscdn.limour.top/npm/nprogress@0.2.0/nprogress.min.js" ></script>
- <link rel="stylesheet" href="https://jscdn.limour.top/npm/nprogress@0.2.0/nprogress.min.css" />
- <script>
- NProgress.configure({"showSpinner":false,"trickleSpeed":100})
- NProgress.start()
- window.addEventListener('load', function() {
- NProgress.done();
- })
- </script>
- <script src="https://jscdn.limour.top/npm/jquery@3.6.4/dist/jquery.min.js" ></script>
- <script src="https://jscdn.limour.top/npm/bootstrap@4.6.1/dist/js/bootstrap.min.js" ></script>
- <script src="/js/events.js" ></script>
- <script src="/js/plugins.js" ></script>
- <script src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
- <script>
- (function (window, document) {
- var typing = Fluid.plugins.typing;
- var subtitle = document.getElementById('subtitle');
- if (!subtitle || !typing) {
- return;
- }
- var text = subtitle.getAttribute('data-typed-text');
-
- typing(text);
-
- })(window, document);
- </script>
-
- <script src="/js/img-lazyload.js" ></script>
-
-
- <script>
- Fluid.utils.createScript('https://jscdn.limour.top/npm/tocbot@4.20.1/dist/tocbot.min.js', function() {
- var toc = jQuery('#toc');
- if (toc.length === 0 || !window.tocbot) { return; }
- var boardCtn = jQuery('#board-ctn');
- var boardTop = boardCtn.offset().top;
- window.tocbot.init(Object.assign({
- tocSelector : '#toc-body',
- contentSelector : '.markdown-body',
- linkClass : 'tocbot-link',
- activeLinkClass : 'tocbot-active-link',
- listClass : 'tocbot-list',
- isCollapsedClass: 'tocbot-is-collapsed',
- collapsibleClass: 'tocbot-is-collapsible',
- scrollSmooth : true,
- includeTitleTags: true,
- headingsOffset : -boardTop,
- }, CONFIG.toc));
- if (toc.find('.toc-list-item').length > 0) {
- toc.css('visibility', 'visible');
- }
- Fluid.events.registerRefreshCallback(function() {
- if ('tocbot' in window) {
- tocbot.refresh();
- var toc = jQuery('#toc');
- if (toc.length === 0 || !tocbot) {
- return;
- }
- if (toc.find('.toc-list-item').length > 0) {
- toc.css('visibility', 'visible');
- }
- }
- });
- });
- </script>
- <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>
- <script>Fluid.plugins.codeWidget();</script>
-
- <script>
- Fluid.utils.createScript('https://jscdn.limour.top/npm/anchor-js@4.3.1/anchor.min.js', function() {
- window.anchors.options = {
- placement: CONFIG.anchorjs.placement,
- visible : CONFIG.anchorjs.visible
- };
- if (CONFIG.anchorjs.icon) {
- window.anchors.options.icon = CONFIG.anchorjs.icon;
- }
- var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
- var res = [];
- for (var item of el) {
- res.push('.markdown-body > ' + item.trim());
- }
- if (CONFIG.anchorjs.placement === 'left') {
- window.anchors.options.class = 'anchorjs-link-left';
- }
- window.anchors.add(res.join(', '));
- Fluid.events.registerRefreshCallback(function() {
- if ('anchors' in window) {
- anchors.removeAll();
- var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
- var res = [];
- for (var item of el) {
- res.push('.markdown-body > ' + item.trim());
- }
- if (CONFIG.anchorjs.placement === 'left') {
- anchors.options.class = 'anchorjs-link-left';
- }
- anchors.add(res.join(', '));
- }
- });
- });
- </script>
-
- <script>
- Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
- Fluid.plugins.fancyBox();
- });
- </script>
- <script>Fluid.plugins.imageCaption();</script>
- <script src="/js/local-search.js" ></script>
- <!-- 主题的启动项,将它保持在最底部 -->
- <!-- the boot of the theme, keep it at the bottom -->
- <script src="/js/boot.js" ></script>
-
- <noscript>
- <div class="noscript-warning">Blog works best with JavaScript enabled</div>
- </noscript>
- <!-- hexo injector body_end start -->
- <script defer src="/theme-inject/timeliness.js"></script>
- <!-- hexo injector body_end end --></body>
- </html>
|