forked from GregorySchwartz/too-many-cells
-
Notifications
You must be signed in to change notification settings - Fork 2
/
too-many-peaks.html
803 lines (724 loc) · 32.6 KB
/
too-many-peaks.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><code>too-many-peaks</code> Walkthrough</title>
<meta name="generator" content="Org mode" />
<meta name="author" content="Gregory W. Schwartz" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: auto;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline; margin-top: 14px;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-hledger:before { content: 'hledger'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.equation-container {
display: table;
text-align: center;
width: 100%;
}
.equation {
vertical-align: middle;
}
.equation-label {
display: table-cell;
text-align: right;
vertical-align: middle;
}
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
</style>
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/htmlize.css"/>
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/readtheorg.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/lib/js/jquery.stickytableheaders.min.js"></script>
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/js/readtheorg.js"></script>
<script type="text/javascript">
// @license magnet:?xt=urn:btih:e95b018ef3580986a04669f1b5879592219e2a7a&dn=public-domain.txt Public Domain
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.classList.add("code-highlighted");
target.classList.add("code-highlighted");
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.classList.remove("code-highlighted");
target.classList.remove("code-highlighted");
}
}
/*]]>*///-->
// @license-end
</script>
</head>
<body>
<div id="content">
<h1 class="title"><code>too-many-peaks</code> Walkthrough</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org61aa89a">Install <code>too-many-peaks</code></a>
<ul>
<li><a href="#orgc47071c">Install <code>too-many-cells</code></a></li>
<li><a href="#org2fdf012">Adding to path (with stack installation)</a></li>
<li><a href="#org3181d12">Testing the installation</a></li>
</ul>
</li>
<li><a href="#orgd0045f0">Data download</a>
<ul>
<li><a href="#orgbf4dfbc">Download peripheral blood mononuclear cells</a></li>
</ul>
</li>
<li><a href="#orga7fd7f2">Tree creation with <code>too-many-peaks</code></a>
<ul>
<li><a href="#orgb52cf4d">Initial tree creation</a></li>
</ul>
</li>
<li><a href="#org8e697eb">Finding peaks</a>
<ul>
<li><a href="#org755ef98">Pruning the tree</a></li>
<li><a href="#orgf2077f2">Peak calling</a></li>
</ul>
</li>
<li><a href="#orgc471568">Identify NK cells</a></li>
<li><a href="#org3fa3d40">Motifs</a></li>
</ul>
</div>
</div>
<p>
This is an instructional example of using <code>too-many-peaks</code> meant to demonstrate
typical usage.
</p>
<p>
For more information about <code>too-many-peaks</code> and <code>too-many-cells</code>:
</p>
<p>
<a href="https://gregoryschwartz.github.io/too-many-cells/">Website</a>
</p>
<p>
See <a href="https://github.com/GregorySchwartz/too-many-cells">https://github.com/GregorySchwartz/too-many-cells</a> for latest version.
</p>
<div id="outline-container-org61aa89a" class="outline-2">
<h2 id="org61aa89a">Install <code>too-many-peaks</code></h2>
<div class="outline-text-2" id="text-org61aa89a">
</div>
<div id="outline-container-orgc47071c" class="outline-3">
<h3 id="orgc47071c">Install <code>too-many-cells</code></h3>
<div class="outline-text-3" id="text-orgc47071c">
<p>
<code>too-many-peaks</code> is an extension included in <code>too-many-cells</code>, so you should
follow instructions on <a href="https://gregoryschwartz.github.io/too-many-cells/">https://gregoryschwartz.github.io/too-many-cells/</a> for
details on <code>too-many-cells</code>. First, clone the <code>too-many-cells</code> repository.
</p>
<div class="org-src-container">
<pre class="src src-sh">git clone https://github.com/GregorySchwartz/too-many-cells.git
</pre>
</div>
<p>
Enter the folder and install with <a href="https://nixos.org/nix/">nix</a>.
</p>
<div class="org-src-container">
<pre class="src src-sh"><span style="color: #ff8700;">cd</span> ./too-many-cells
nix-env -f default.nix -i too-many-cells
</pre>
</div>
</div>
</div>
<div id="outline-container-org2fdf012" class="outline-3">
<h3 id="org2fdf012">Adding to path (with stack installation)</h3>
<div class="outline-text-3" id="text-org2fdf012">
<p>
If using stack, the resulting binary will install to <code>~/.local/bin</code>. Add to
<code>$PATH</code> so you can invoke the command from anywhere!
</p>
<div class="org-src-container">
<pre class="src src-sh"><span style="color: #ff8700;">export</span> <span style="color: #87afaf;">PATH</span>=$<span style="color: #87afaf;">HOME</span>/.local/bin:$<span style="color: #87afaf;">PATH</span>
</pre>
</div>
<p>
This command will only work in the current shell. To permanently add to path,
add the previous line to <code>~/.bashrc</code> or <code>~/.profile</code>.
</p>
</div>
</div>
<div id="outline-container-org3181d12" class="outline-3">
<h3 id="org3181d12">Testing the installation</h3>
<div class="outline-text-3" id="text-org3181d12">
<p>
Test to see if the installation worked when in path:
</p>
<div class="org-src-container">
<pre class="src src-sh">too-many-cells -h
</pre>
</div>
<pre class="example" id="org0070c7a">
too-many-cells, Gregory W. Schwartz. Clusters and analyzes single cell data.
Usage: too-many-cells (make-tree | interactive | differential | diversity |
paths | classify | peaks | motifs | matrix-output)
Available options:
-h,--help Show this help text
Available commands:
make-tree
interactive
differential
diversity
paths
classify
peaks
motifs
matrix-output
</pre>
<p>
Here, seeing <code>too-many-cells peaks</code> denotes the correct version of
<code>too-many-cells</code> to use <code>too-many-peaks</code>.
</p>
</div>
</div>
</div>
<div id="outline-container-orgd0045f0" class="outline-2">
<h2 id="orgd0045f0">Data download</h2>
<div class="outline-text-2" id="text-orgd0045f0">
</div>
<div id="outline-container-orgbf4dfbc" class="outline-3">
<h3 id="orgbf4dfbc">Download peripheral blood mononuclear cells</h3>
<div class="outline-text-3" id="text-orgbf4dfbc">
<p>
We are going to see if we can identify T cells in a collection of peripheral
blood mononuclear cells. We'll need data from 10x, specifically
<a href="https://support.10xgenomics.com/single-cell-atac/datasets/1.2.0/atac_v1_pbmc_5k">https://support.10xgenomics.com/single-cell-atac/datasets/1.2.0/atac_v1_pbmc_5k</a>
as a quick, illustrative example here. We can use the peak matrix or make our
own from the fragment file, so let's do the latter:
</p>
<div class="org-src-container">
<pre class="src src-shell"><span style="color: #767676;"># </span><span style="color: #767676;">Make the data directory</span>
mkdir -p data/pbmc
<span style="color: #767676;"># </span><span style="color: #767676;">Enter the directory</span>
<span style="color: #ff8700;">cd</span> ./data/pbmc
<span style="color: #767676;"># </span><span style="color: #767676;">Download the data</span>
wget <span style="color: #afaf00;">"https://cf.10xgenomics.com/samples/cell-atac/1.2.0/atac_v1_pbmc_5k/atac_v1_pbmc_5k_fragments.tsv.gz"</span>
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-orga7fd7f2" class="outline-2">
<h2 id="orga7fd7f2">Tree creation with <code>too-many-peaks</code></h2>
<div class="outline-text-2" id="text-orga7fd7f2">
</div>
<div id="outline-container-orgb52cf4d" class="outline-3">
<h3 id="orgb52cf4d">Initial tree creation</h3>
<div class="outline-text-3" id="text-orgb52cf4d">
<p>
We now have everything we need for initial runs with <code>too-many-peaks</code>! Let's begin
by building a tree (ignore <code>printf</code> throughout this document, they are just
reporting the resulting file). All of the capabilities of <code>too-many-cells</code> are
available to us, so check out the <code>too-many-cells</code> <a href="../workshop/workshop.html">workshop</a> for more details on
coloring, labels, and joining together multiple data sets.
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells make-tree <span style="color: #afaf00;">\</span>
--matrix-path ./data/pbmc/atac_v1_pbmc_5k_fragments.tsv.gz <span style="color: #afaf00;">\</span>
--filter-thresholds <span style="color: #afaf00;">"(1000, 1)"</span> <span style="color: #afaf00;">\</span>
--binwidth <span style="color: #d787af;">5000</span> <span style="color: #afaf00;">\</span>
--lsa <span style="color: #d787af;">50</span> <span style="color: #afaf00;">\</span>
--normalization NoneNorm <span style="color: #afaf00;">\</span>
--output out <span style="color: #afaf00;">\</span>
--matrix-output mat <span style="color: #afaf00;">\</span>
> clusters.csv
<span style="color: #ff8700;">printf</span> <span style="color: #afaf00;">"./out/dendrogram.svg"</span>
</pre>
</div>
<div id="orga6b265e" class="figure">
<p><object type="image/svg+xml" data="./out/dendrogram.svg" class="org-svg">
Sorry, your browser does not support SVG.</object>
</p>
</div>
<p>
The initial tree is built! It tells us the tree structure and the number of
cells in each leaf. Here, we used <code>--binwidth</code> to specify the width in bp of the
genome to define features. We used <code>--filter-thresholds</code> to specify that each
cell must have 1000 fragments and each bin must have at least 1 fragment.
Importantly, we could also use <code>--cell-whitelist-file</code> to specify exact cells we
want to include (as a list of barcodes) as Cell Ranger will output a peak matrix
with barcodes believed to be cells, but for now we will just use these simple
thresholds. Also of importance are blacklist regions which can be ignored
through <code>--blacklist-regions-file</code> using a file like
<a href="http://mitra.stanford.edu/kundaje/akundaje/release/blacklists/hg19-human/Anshul_Hg19UltraHighSignalArtifactRegions.bed.gz">http://mitra.stanford.edu/kundaje/akundaje/release/blacklists/hg19-human/Anshul_Hg19UltraHighSignalArtifactRegions.bed.gz</a>.
Lastly, <code>--lsa 50</code> speeds things up by using dimensionality reduction on the
matrix and also helps filter features, but needs <code>--normalization NoneNorm</code> to
make sure we aren't transforming the data in unexpected ways.
</p>
<p>
Importantly, we also specified <code>--matrix-output</code> for a folder to output the
generated matrix in (calculated from the fragment file). This step will make
subsequent steps faster as we can just input that matrix path.
</p>
</div>
</div>
</div>
<div id="outline-container-org8e697eb" class="outline-2">
<h2 id="org8e697eb">Finding peaks</h2>
<div class="outline-text-2" id="text-org8e697eb">
</div>
<div id="outline-container-org755ef98" class="outline-3">
<h3 id="org755ef98">Pruning the tree</h3>
<div class="outline-text-3" id="text-org755ef98">
<p>
Now we want to define more precise features for each leaf, so we will trade in
our bins for peaks. Before that, however, many peak finding algorithms require a
minimum of ~200 cells to assign peaks, so we will first prune the tree. While we
could have specified a minimum cell value in our initial run, it's good to have
the entire tree just in case we want to prune differently. <b>Note</b>:
We use <code>--prior</code> from now on so we don't need to calculate the tree all over
again. This argument makes things much faster!
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells make-tree <span style="color: #afaf00;">\</span>
--prior out <span style="color: #afaf00;">\</span>
--min-size <span style="color: #d787af;">200</span> <span style="color: #afaf00;">\</span>
--output out_min_200 <span style="color: #afaf00;">\</span>
> clusters_min_200.csv
<span style="color: #ff8700;">printf</span> <span style="color: #afaf00;">"./out_min_200/dendrogram.svg"</span>
</pre>
</div>
<div id="org348764e" class="figure">
<p><object type="image/svg+xml" data="./out_min_200/dendrogram.svg" class="org-svg">
Sorry, your browser does not support SVG.</object>
</p>
</div>
</div>
</div>
<div id="outline-container-orgf2077f2" class="outline-3">
<h3 id="orgf2077f2">Peak calling</h3>
<div class="outline-text-3" id="text-orgf2077f2">
<p>
Now we are ready to call our peaks using MACS2 (or any other program specified
by <code>--peak-call-command</code>).
MACS2 needs the chromosome sizes for our data, so we will quickly fetch those.
</p>
<div class="org-src-container">
<pre class="src src-shell"><span style="color: #ff8700;">cd</span> ./data
wget <span style="color: #afaf00;">"http://hgdownload.cse.ucsc.edu/goldenpath/hg19/bigZips/hg19.chrom.sizes"</span>
<span style="color: #ff8700;">printf</span> <span style="color: #afaf00;">"./data/hg19.chrom.sizes"</span>
</pre>
</div>
<p>
<a href="./data/hg19.chrom.sizes">./data/hg19.chrom.sizes</a>
</p>
<p>
Now we can find peaks for every node!
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells peaks <span style="color: #afaf00;">\</span>
--prior out_min_200 <span style="color: #afaf00;">\</span>
--fragments-path ./data/pbmc/atac_v1_pbmc_5k_fragments.tsv.gz <span style="color: #afaf00;">\</span>
--all-nodes <span style="color: #afaf00;">\</span>
--genome ./data/hg19.chrom.sizes <span style="color: #afaf00;">\</span>
--bedgraph <span style="color: #afaf00;">\</span>
-o out_min_200_peaks <span style="color: #afaf00;">\</span>
+RTS -N6
</pre>
</div>
<p>
By default, this command will find peaks for all leaves as this is a
time-consuming process. <code>--all-nodes</code> tells <code>too-many-peaks</code> to find peaks for
every node, including internal ones. We can specify individual nodes with
<code>=--peak-node</code>, but we need to also use <code>--all-nodes</code> if that node is internal.
If we had labels, we can find peaks for specific subsets of cells in nodes using
<code>--peak-node-labels</code> as well!
</p>
<p>
<code>--bedgraph</code> tells the program to output bdg files for easy plotting of tracks,
and <code>+RTS -N6</code>, specified at the end of the command, tells <code>too-many-peaks</code> how
many cores to use.
</p>
<p>
The specified output folder will contain many files, such as:
</p>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">File</th>
<th scope="col" class="org-left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left"><code>out_min_200_peaks/cluster_fragments</code></td>
<td class="org-left"><code>fragments.tsv.gz</code> files for each node.</td>
</tr>
<tr>
<td class="org-left"><code>out_min_200_peaks/cluster_bedgraphs</code></td>
<td class="org-left">Bedgraphs and bigwigs if specified using <code>--bedgraph</code> for track visualization uses.</td>
</tr>
<tr>
<td class="org-left"><code>out_min_200_peaks/cluster_peaks/union.bdg</code></td>
<td class="org-left">Merged peaks across all requested nodes in bedgraph format.</td>
</tr>
<tr>
<td class="org-left"><code>out_min_200_peaks/cluster_peaks/union_fragments.tsv.gz</code></td>
<td class="org-left">Merged peaks across all requested nodes in <code>fragments.tsv.gz</code> format.</td>
</tr>
<tr>
<td class="org-left"><code>out_min_200_peaks/cluster_peaks/</code></td>
<td class="org-left">Folder containing merged peaks across nodes and peaks for each individual node in each folder.</td>
</tr>
</tbody>
</table>
<p>
From here, all of the normal <code>too-many-cells</code> processes work on the tree with
the <code>union_fragments.tsv.gz</code> file. For instance, to see <code>chr2:87011729-87035519</code>
accessibility on the tree, we can do:
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells make-tree <span style="color: #afaf00;">\</span>
--prior out_min_200 <span style="color: #afaf00;">\</span>
-m ./out_min_200_peaks/cluster_peaks/union_fragments.tsv.gz <span style="color: #afaf00;">\</span>
--draw-leaf <span style="color: #afaf00;">"DrawItem (DrawContinuous [\"chr2:87011729-87035519\"])"</span> <span style="color: #afaf00;">\</span>
--normalization <span style="color: #afaf00;">"LogCPMNorm 2"</span> <span style="color: #afaf00;">\</span>
--custom-region <span style="color: #afaf00;">"chr2:87011729-87035519"</span> <span style="color: #afaf00;">\</span>
--draw-mark <span style="color: #afaf00;">"MarkModularity"</span> <span style="color: #afaf00;">\</span>
--output out_min_200 <span style="color: #afaf00;">\</span>
> clusters_min_200.csv
</pre>
</div>
<p>
For a faster process, you may first want to create a smaller matrix with the
regions of interest, then plot those regions in different ways by using the
output matrix rather than all of the fragments:
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells matrix-output <span style="color: #afaf00;">\</span>
-m ./out_min_200_peaks/cluster_peaks/union_fragments.tsv.gz <span style="color: #afaf00;">\</span>
--normalization NoneNorm <span style="color: #afaf00;">\</span>
--custom-region <span style="color: #afaf00;">"chr2:87011729-87035519"</span> <span style="color: #afaf00;">\</span>
--mat-output mini_mat
</pre>
</div>
<p>
For more information about the capabilities of visualization and differential
expression, check out <a href="https://gregoryschwartz.github.io/too-many-cells/">https://gregoryschwartz.github.io/too-many-cells/</a>!
</p>
</div>
</div>
</div>
<div id="outline-container-orgc471568" class="outline-2">
<h2 id="orgc471568">Identify NK cells</h2>
<div class="outline-text-2" id="text-orgc471568">
<p>
Now that we have a base tree with higher resolution peaks, we can now try
searching for known cell populations such as NK cells. While we can use the
<code>classify</code> entry point of <code>too-many-cells</code> to link bulk reference data with
single-cell data, we will use basic known markers to exemplify the visualization
features of the tree. Here, we will only focus on the <code>NKG7</code> region for NK
cells. So, let's look at what that accessibility looks like on the tree at that
region, making sure to overlay node numbers for easy reference! For maximum
resolution, we'll use the full tree rather than the pruned tree.
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells make-tree <span style="color: #afaf00;">\</span>
--prior out <span style="color: #afaf00;">\</span>
-m ./out_min_200_peaks/cluster_peaks/union_fragments.tsv.gz <span style="color: #afaf00;">\</span>
--draw-leaf <span style="color: #afaf00;">"DrawItem (DrawContinuous [\"chr19:51874860-51875969\"])"</span> <span style="color: #afaf00;">\</span>
--custom-region <span style="color: #afaf00;">"chr19:51874860-51875969"</span> <span style="color: #afaf00;">\</span>
--draw-mark <span style="color: #afaf00;">"MarkModularity"</span> <span style="color: #afaf00;">\</span>
--dendrogram-output <span style="color: #afaf00;">"NKG7.svg"</span> <span style="color: #afaf00;">\</span>
--draw-node-number <span style="color: #afaf00;">\</span>
--draw-scale-saturation <span style="color: #d787af;">10</span> <span style="color: #afaf00;">\</span>
--output out <span style="color: #afaf00;">\</span>
> clusters.csv
<span style="color: #ff8700;">printf</span> <span style="color: #afaf00;">"./out/NKG7.svg"</span>
</pre>
</div>
<div id="orgf93d5ef" class="figure">
<p><object type="image/svg+xml" data="./out/NKG7.svg" class="org-svg">
Sorry, your browser does not support SVG.</object>
</p>
</div>
<p>
Here, <code>--custom-region</code> tells <code>too-many-peaks</code> to create a new feature within
that specific region. We can also use the original fragments to see the
accessibility on the tree before peak finding and filtering.
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells make-tree <span style="color: #afaf00;">\</span>
--prior out <span style="color: #afaf00;">\</span>
-m ./data/pbmc/atac_v1_pbmc_5k_fragments.tsv.gz <span style="color: #afaf00;">\</span>
--draw-leaf <span style="color: #afaf00;">"DrawItem (DrawContinuous [\"chr19:51874860-51875969\"])"</span> <span style="color: #afaf00;">\</span>
--custom-region <span style="color: #afaf00;">"chr19:51874860-51875969"</span> <span style="color: #afaf00;">\</span>
--draw-mark <span style="color: #afaf00;">"MarkModularity"</span> <span style="color: #afaf00;">\</span>
--dendrogram-output <span style="color: #afaf00;">"NKG7_raw.svg"</span> <span style="color: #afaf00;">\</span>
--draw-node-number <span style="color: #afaf00;">\</span>
--draw-scale-saturation <span style="color: #d787af;">10</span> <span style="color: #afaf00;">\</span>
--output out <span style="color: #afaf00;">\</span>
> clusters.csv
<span style="color: #ff8700;">printf</span> <span style="color: #afaf00;">"./out/NKG7_raw.svg"</span>
</pre>
</div>
<div id="org9193078" class="figure">
<p><object type="image/svg+xml" data="./out/NKG7_raw.svg" class="org-svg">
Sorry, your browser does not support SVG.</object>
</p>
</div>
<p>
Based on the coloring and the node number overlay,
there seems to be a high level of accessibility within node 85.
To further investigate, let's see what the differential accessibility is between
node 85 and the rest of the tree (seeing more than the top 100 features and without
using <code>edgeR</code> for scATAC-seq):
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells differential <span style="color: #afaf00;">\</span>
-m ./out_min_200_peaks/cluster_peaks/union_fragments.tsv.gz <span style="color: #afaf00;">\</span>
--prior out <span style="color: #afaf00;">\</span>
--nodes <span style="color: #afaf00;">"([118,1], [85])"</span> <span style="color: #afaf00;">\</span>
--normalization <span style="color: #afaf00;">"TotalNorm"</span> <span style="color: #afaf00;">\</span>
--top-n <span style="color: #d787af;">1000000000</span> <span style="color: #afaf00;">\</span>
> ./out/NK_vs_other.csv
<span style="color: #ff8700;">printf</span> <span style="color: #afaf00;">"./out/NK_vs_other.csv"</span>
</pre>
</div>
<p>
<a href="./out/NK_vs_other.csv">./out/NK_vs_other.csv</a>
</p>
<p>
These results are liable to change with the inclusion of
<code>--blacklist-regions-file</code>, which should filter out unwanted regions (as noted
above). We can also see just our specific region:
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells differential <span style="color: #afaf00;">\</span>
-m ./out_min_200_peaks/cluster_peaks/union_fragments.tsv.gz <span style="color: #afaf00;">\</span>
--prior out <span style="color: #afaf00;">\</span>
--nodes <span style="color: #afaf00;">"([118,1], [85])"</span> <span style="color: #afaf00;">\</span>
--normalization <span style="color: #afaf00;">"TotalNorm"</span> <span style="color: #afaf00;">\</span>
--custom-region <span style="color: #afaf00;">"chr19:51874860-51875969"</span> <span style="color: #afaf00;">\</span>
> ./out/NK_vs_other_NKG7.csv
<span style="color: #ff8700;">printf</span> <span style="color: #afaf00;">"./out/NK_vs_other_NKG7.csv"</span>
</pre>
</div>
<p>
<a href="./out/NK_vs_other_NKG7.csv">./out/NK_vs_other_NKG7.csv</a>
</p>
<p>
As expected, there's some difference at the <code>NKG7</code> locus. Now we can see what
motifs may be enriched in this differential.
</p>
</div>
</div>
<div id="outline-container-org3fa3d40" class="outline-2">
<h2 id="org3fa3d40">Motifs</h2>
<div class="outline-text-2" id="text-org3fa3d40">
<p>
<code>too-many-peaks</code> can also identify motifs from differential expression analyses
using tools such as MEME and HOMER. For instance, with HOMER's
<code>findMotifsGenome.pl</code> in your path, you can use the input from
<code>too-many-peaks</code>'s differential accessibility output from
<code>too-many-cells differential</code> that we just calculated to find enriched motifs
(getting rid of infinity fold changes, or "divide by zero"):
</p>
<div class="org-src-container">
<pre class="src src-shell">cat ./out/NK_vs_other.csv | csvsql --query <span style="color: #afaf00;">"SELECT * FROM stdin WHERE qVal < 0.05 AND log2FC > 0"</span> | grep -v inf | grep -v Infinity > tmp.csv
too-many-cells motifs <span style="color: #afaf00;">\</span>
--diff-file tmp.csv <span style="color: #afaf00;">\</span>
--motif-genome hg19 <span style="color: #afaf00;">\</span>
--top-n <span style="color: #d787af;">100000000</span> <span style="color: #afaf00;">\</span>
-o homer_out <span style="color: #afaf00;">\</span>
--motif-genome-command <span style="color: #afaf00;">"findMotifsGenome.pl %s %s %s"</span>
</pre>
</div>
<p>
This command outputs motifs in the <code>homer_out</code> directory found using
<code>findMotifsGenome.pl</code> on the significant and positive differentially accessible
sites from <code>./out/BLANK_vs_BLANK.csv</code> which was output from our <code>too-many-cells
differential</code> run, (so we set <code>--top-n</code> to a high number to include all sites
instead of just the top sites).
</p>
<p>
These kinds of analyses and more are all available using <code>too-many-peaks</code>, which
makes full use of the <code>too-many-cells</code> suite of tools so be sure to <a href="https://gregoryschwartz.github.io/too-many-cells/">check it
out!</a>
</p>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: Gregory W. Schwartz</p>
<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
</html>