-
Notifications
You must be signed in to change notification settings - Fork 18
/
workshop.html
1321 lines (1160 loc) · 49.8 KB
/
workshop.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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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-cells</code> Workshop</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;}
/* 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-cells</code> Workshop</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org973f0c8">Install <code>too-many-cells</code></a>
<ul>
<li><a href="#orgab0a054">Install <code>too-many-cells</code></a></li>
<li><a href="#org31ec019">Adding to path (with stack installation)</a></li>
<li><a href="#orgdd6492d">Testing the installation</a></li>
</ul>
</li>
<li><a href="#org1e7db3c">Data download</a>
<ul>
<li><a href="#orgfd6d48b">Download brain data</a></li>
<li><a href="#orgd860963">Download heart data</a></li>
</ul>
</li>
<li><a href="#org9f4c122">Prevent overlapping</a>
<ul>
<li><a href="#orga4a5f32">Backup barcodes</a></li>
<li><a href="#orgb11a97a">Edit barcodes</a></li>
</ul>
</li>
<li><a href="#org0f8cd87">Tree creation with <code>too-many-cells</code></a>
<ul>
<li><a href="#org53a2bcf">Initial tree creation</a></li>
</ul>
</li>
<li><a href="#org35c5e56">Coloring the <code>too-many-cells</code> tree.</a>
<ul>
<li><a href="#org931863f">Prepare labels file</a></li>
<li><a href="#org8e20796">Color tree</a></li>
<li><a href="#org0e7eddc">Custom colors</a></li>
</ul>
</li>
<li><a href="#orgefc28f1">Getting more information from the tree</a>
<ul>
<li><a href="#org7b378e1">Overlay modularity</a></li>
</ul>
</li>
<li><a href="#orga67531e">Pruning the tree</a>
<ul>
<li><a href="#org6db3761">Prune tree by size</a></li>
<li><a href="#org5c3efd0">Prune tree by size distribution</a></li>
</ul>
</li>
<li><a href="#orgbe71bb6">Gene expression</a>
<ul>
<li><a href="#org5557f30">Neuron marker overlay</a></li>
<li><a href="#orgabae537">Increasing visibility</a></li>
<li><a href="#org3a211fc">Gene symbol rather than Ensembl</a></li>
<li><a href="#org54d340d">Heart marker overlay</a></li>
<li><a href="#orga0507ff">Multiple gene expression overlays</a></li>
<li><a href="#org620b908">Custom colors for multiple expression overlays</a></li>
</ul>
</li>
<li><a href="#org9e14968">Differential expression</a>
<ul>
<li><a href="#org0c9a4af">Overlay node numbers</a></li>
<li><a href="#org5756f7d">Differential expression for two nodes</a></li>
<li><a href="#org0372f11">Differential expression for two groups of nodes</a></li>
<li><a href="#orgd23bf2f">Label-filtered differential expression</a></li>
<li><a href="#org44ad1cc">Gene distribution plots</a></li>
<li><a href="#orga57d425">All to all!</a></li>
<li><a href="#orgbac3614">More to discover</a></li>
</ul>
</li>
</ul>
</div>
</div>
<p>
This is an instructional example of using <code>too-many-cells</code> meant to demonstrate
typical usage, originally presented in the IFI Advanced Computational Biology
Club.
</p>
<p>
For more information about <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>
<p>
See <a href="https://doi.org/10.1038/s41592-020-0748-5">the publication</a> (and please cite!) for more information about the algorithm.
</p>
<div id="outline-container-org973f0c8" class="outline-2">
<h2 id="org973f0c8">Install <code>too-many-cells</code></h2>
<div class="outline-text-2" id="text-org973f0c8">
</div>
<div id="outline-container-orgab0a054" class="outline-3">
<h3 id="orgab0a054">Install <code>too-many-cells</code></h3>
<div class="outline-text-3" id="text-orgab0a054">
<p>
Follow instructions on <a href="https://gregoryschwartz.github.io/too-many-cells/">https://gregoryschwartz.github.io/too-many-cells/</a> for
details. 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-org31ec019" class="outline-3">
<h3 id="org31ec019">Adding to path (with stack installation)</h3>
<div class="outline-text-3" id="text-org31ec019">
<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-orgdd6492d" class="outline-3">
<h3 id="orgdd6492d">Testing the installation</h3>
<div class="outline-text-3" id="text-orgdd6492d">
<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="org6814341">
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>
</div>
</div>
</div>
<div id="outline-container-org1e7db3c" class="outline-2">
<h2 id="org1e7db3c">Data download</h2>
<div class="outline-text-2" id="text-org1e7db3c">
</div>
<div id="outline-container-orgfd6d48b" class="outline-3">
<h3 id="orgfd6d48b">Download brain data</h3>
<div class="outline-text-3" id="text-orgfd6d48b">
<p>
We'll need data from 10x. Let's cluster mouse brain and heart cells from
<a href="https://support.10xgenomics.com/single-cell-gene-expression/datasets/3.0.0/neuron_1k_v3">https://support.10xgenomics.com/single-cell-gene-expression/datasets/3.0.0/neuron_1k_v3</a>
and
<a href="https://support.10xgenomics.com/single-cell-gene-expression/datasets/3.0.0/heart_1k_v3">https://support.10xgenomics.com/single-cell-gene-expression/datasets/3.0.0/heart_1k_v3</a>
as a quick, illustrative example here. <b>Note</b>: these are modern formats of
<code>cellranger</code> outputs (<code>v3</code>), but <code>too-many-cells</code> works with both older and
newer formats.
</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/brain
<span style="color: #767676;"># </span><span style="color: #767676;">Enter the directory</span>
<span style="color: #ff8700;">cd</span> ./data/brain
<span style="color: #767676;"># </span><span style="color: #767676;">Download the data</span>
wget http://cf.10xgenomics.com/samples/cell-exp/3.0.0/neuron_1k_v3/neuron_1k_v3_filtered_feature_bc_matrix.tar.gz
<span style="color: #767676;"># </span><span style="color: #767676;">Uncompress data</span>
tar xvf neuron_1k_v3_filtered_feature_bc_matrix.tar.gz
</pre>
</div>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left">filtered_feature_bc_matrix/</td>
</tr>
<tr>
<td class="org-left">filtered_feature_bc_matrix/features.tsv.gz</td>
</tr>
<tr>
<td class="org-left">filtered_feature_bc_matrix/matrix.mtx.gz</td>
</tr>
<tr>
<td class="org-left">filtered_feature_bc_matrix/barcodes.tsv.gz</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-orgd860963" class="outline-3">
<h3 id="orgd860963">Download heart data</h3>
<div class="outline-text-3" id="text-orgd860963">
<p>
Let's do the same for the heart cells:
</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/heart
<span style="color: #767676;"># </span><span style="color: #767676;">Enter the directory</span>
<span style="color: #ff8700;">cd</span> ./data/heart
<span style="color: #767676;"># </span><span style="color: #767676;">Download the data</span>
wget http://cf.10xgenomics.com/samples/cell-exp/3.0.0/heart_1k_v3/heart_1k_v3_filtered_feature_bc_matrix.tar.gz
<span style="color: #767676;"># </span><span style="color: #767676;">Uncompress data</span>
tar xvf heart_1k_v3_filtered_feature_bc_matrix.tar.gz
</pre>
</div>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left">filtered_feature_bc_matrix/</td>
</tr>
<tr>
<td class="org-left">filtered_feature_bc_matrix/features.tsv.gz</td>
</tr>
<tr>
<td class="org-left">filtered_feature_bc_matrix/barcodes.tsv.gz</td>
</tr>
<tr>
<td class="org-left">filtered_feature_bc_matrix/matrix.mtx.gz</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div id="outline-container-org9f4c122" class="outline-2">
<h2 id="org9f4c122">Prevent overlapping</h2>
<div class="outline-text-2" id="text-org9f4c122">
</div>
<div id="outline-container-orga4a5f32" class="outline-3">
<h3 id="orga4a5f32">Backup barcodes</h3>
<div class="outline-text-3" id="text-orga4a5f32">
<p>
These matrices both use <code>BARCODE-1</code> as their cell identifiers. If aggregating
with <code>cellranger</code> this won't be an issue, but because we aren't doing that let's
make sure there are no conflicts. First, let's backup our barcodes as we will be
making changes to ensure no overlapping.
</p>
<div class="org-src-container">
<pre class="src src-shell">cp ./data/brain/filtered_feature_bc_matrix/barcodes.tsv<span style="color: #008787;">{</span>.gz,.gz.bk<span style="color: #008787;">}</span>
cp ./data/heart/filtered_feature_bc_matrix/barcodes.tsv<span style="color: #008787;">{</span>.gz,.gz.bk<span style="color: #008787;">}</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgb11a97a" class="outline-3">
<h3 id="orgb11a97a">Edit barcodes</h3>
<div class="outline-text-3" id="text-orgb11a97a">
<p>
Now let's edit the heart barcodes to have <code>-2</code> instead of <code>-1</code>.
</p>
<div class="org-src-container">
<pre class="src src-shell">cat ./data/heart/filtered_feature_bc_matrix/barcodes.tsv.gz.bk <span style="color: #afaf00;">\</span>
| gzip -d <span style="color: #afaf00;">\</span>
| sed <span style="color: #afaf00;">"s/-1/-2/g"</span> <span style="color: #afaf00;">\</span>
| gzip <span style="color: #afaf00;">\</span>
> ./data/heart/filtered_feature_bc_matrix/barcodes.tsv.gz
cat ./data/heart/filtered_feature_bc_matrix/barcodes.tsv.gz | gzip -d | head
</pre>
</div>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left">AAACCCACACCAGTAT-2</td>
</tr>
<tr>
<td class="org-left">AAACCCAGTCACCTTC-2</td>
</tr>
<tr>
<td class="org-left">AAACCCAGTGGAACAC-2</td>
</tr>
<tr>
<td class="org-left">AAACGAAAGTGCCCGT-2</td>
</tr>
<tr>
<td class="org-left">AAACGAAGTCAGGTGA-2</td>
</tr>
<tr>
<td class="org-left">AAAGGATAGCACCGAA-2</td>
</tr>
<tr>
<td class="org-left">AAAGGATGTAACGGTG-2</td>
</tr>
<tr>
<td class="org-left">AAAGGGCAGGACGGAG-2</td>
</tr>
<tr>
<td class="org-left">AAAGTGACAGAACATA-2</td>
</tr>
<tr>
<td class="org-left">AAAGTGATCAAAGGAT-2</td>
</tr>
</tbody>
</table>
<p>
That's it! This will help when we assign labels to each cell later on.
</p>
</div>
</div>
</div>
<div id="outline-container-org0f8cd87" class="outline-2">
<h2 id="org0f8cd87">Tree creation with <code>too-many-cells</code></h2>
<div class="outline-text-2" id="text-org0f8cd87">
</div>
<div id="outline-container-org53a2bcf" class="outline-3">
<h3 id="org53a2bcf">Initial tree creation</h3>
<div class="outline-text-3" id="text-org53a2bcf">
<p>
We now have everything we need for initial runs with <code>too-many-cells</code>! Let's begin
by building a tree (ignore <code>printf</code> throughout this document, they are just
reporting the resulting file). We can specify multiple matrices to combine
automatically.
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells make-tree <span style="color: #afaf00;">\</span>
--matrix-path ./data/brain/filtered_feature_bc_matrix/ <span style="color: #afaf00;">\</span>
--matrix-path ./data/heart/filtered_feature_bc_matrix/ <span style="color: #afaf00;">\</span>
--filter-thresholds <span style="color: #afaf00;">"(250, 1)"</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/dendrogram.svg"</span>
</pre>
</div>
<div id="orgdaf26b2" 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. Want to actually see which cells are brain and which cells
are heart? Let's give the tree some colors!
</p>
</div>
</div>
</div>
<div id="outline-container-org35c5e56" class="outline-2">
<h2 id="org35c5e56">Coloring the <code>too-many-cells</code> tree.</h2>
<div class="outline-text-2" id="text-org35c5e56">
</div>
<div id="outline-container-org931863f" class="outline-3">
<h3 id="org931863f">Prepare labels file</h3>
<div class="outline-text-3" id="text-org931863f">
<p>
We can color the tree using any label. In this case, we want to give each cell a
label based on it's celltype from the data set. Let's quickly do that.
</p>
<div class="org-src-container">
<pre class="src src-shell">gzip -d -c ./data/brain/filtered_feature_bc_matrix/barcodes.tsv.gz ./data/heart/filtered_feature_bc_matrix/barcodes.tsv.gz <span style="color: #afaf00;">\</span>
| sed <span style="color: #afaf00;">"s/-1/-1,Brain/"</span> <span style="color: #afaf00;">\</span>
| sed <span style="color: #afaf00;">"s/-2/-2,Heart/"</span> <span style="color: #afaf00;">\</span>
| sed <span style="color: #afaf00;">"1i item,label"</span> <span style="color: #afaf00;">\</span>
> labels.csv
head ./labels.csv
</pre>
</div>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left">item</td>
<td class="org-left">label</td>
</tr>
<tr>
<td class="org-left">AAACGAATCAAAGCCT-1</td>
<td class="org-left">Brain</td>
</tr>
<tr>
<td class="org-left">AAACGCTGTAATGTGA-1</td>
<td class="org-left">Brain</td>
</tr>
<tr>
<td class="org-left">AAACGCTGTCCTGGGT-1</td>
<td class="org-left">Brain</td>
</tr>
<tr>
<td class="org-left">AAAGAACCAGGACATG-1</td>
<td class="org-left">Brain</td>
</tr>
<tr>
<td class="org-left">AAAGGTACACACGGTC-1</td>
<td class="org-left">Brain</td>
</tr>
<tr>
<td class="org-left">AAAGTCCAGTCACTAC-1</td>
<td class="org-left">Brain</td>
</tr>
<tr>
<td class="org-left">AAAGTCCGTGACTGTT-1</td>
<td class="org-left">Brain</td>
</tr>
<tr>
<td class="org-left">AAAGTCCTCCAGCCTT-1</td>
<td class="org-left">Brain</td>
</tr>
<tr>
<td class="org-left">AAAGTGAGTTCCTAAG-1</td>
<td class="org-left">Brain</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-org8e20796" class="outline-3">
<h3 id="org8e20796">Color tree</h3>
<div class="outline-text-3" id="text-org8e20796">
<p>
Great! Now we just need to feed it to <code>too-many-cells</code>. <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>
--labels-file ./labels.csv <span style="color: #afaf00;">\</span>
--dendrogram-output <span style="color: #afaf00;">"tree_labeled.svg"</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/tree_labeled.svg"</span>
</pre>
</div>
<div id="org5c04ae2" class="figure">
<p><object type="image/svg+xml" data="./out/tree_labeled.svg" class="org-svg">
Sorry, your browser does not support SVG.</object>
</p>
</div>
</div>
</div>
<div id="outline-container-org0e7eddc" class="outline-3">
<h3 id="org0e7eddc">Custom colors</h3>
<div class="outline-text-3" id="text-org0e7eddc">
<p>
We can also change the colors however we want:
</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>
--labels-file ./labels.csv <span style="color: #afaf00;">\</span>
--draw-colors <span style="color: #afaf00;">"[\"#66c2a5\", \"#fc8d62\"]"</span> <span style="color: #afaf00;">\</span>
--dendrogram-output <span style="color: #afaf00;">"tree_labeled_alternate.svg"</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/tree_labeled_alternate.svg"</span>
</pre>
</div>
<div id="org912f337" class="figure">
<p><object type="image/svg+xml" data="./out/tree_labeled_alternate.svg" class="org-svg">
Sorry, your browser does not support SVG.</object>
</p>
</div>
</div>
</div>
</div>
<div id="outline-container-orgefc28f1" class="outline-2">
<h2 id="orgefc28f1">Getting more information from the tree</h2>
<div class="outline-text-2" id="text-orgefc28f1">
</div>
<div id="outline-container-org7b378e1" class="outline-3">
<h3 id="org7b378e1">Overlay modularity</h3>
<div class="outline-text-3" id="text-org7b378e1">
<p>
Now that we have a basic tree, we can start doing some quick edits. Want
modularity overlays to show the modularity at each node in the 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>
--labels-file ./labels.csv <span style="color: #afaf00;">\</span>
--dendrogram-output <span style="color: #afaf00;">"tree_modularity.svg"</span> <span style="color: #afaf00;">\</span>
--draw-mark <span style="color: #afaf00;">"MarkModularity"</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/tree_modularity.svg"</span>
</pre>
</div>
<div id="orga64229b" class="figure">
<p><object type="image/svg+xml" data="./out/tree_modularity.svg" class="org-svg">
Sorry, your browser does not support SVG.</object>
</p>
</div>
</div>
</div>
</div>
<div id="outline-container-orga67531e" class="outline-2">
<h2 id="orga67531e">Pruning the tree</h2>
<div class="outline-text-2" id="text-orga67531e">
</div>
<div id="outline-container-org6db3761" class="outline-3">
<h3 id="org6db3761">Prune tree by size</h3>
<div class="outline-text-3" id="text-org6db3761">
<p>
For a large number of cells, the tree can grow quite large. To prune the tree,
we can use different cutoffs. However, this will change the tree structure, so
be sure to output the tree in a different folder to avoid overwriting the
original tree (so we can still use <code>--prior</code>)! Let's have no leaf with less than
30 cells:
</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>
--labels-file ./labels.csv <span style="color: #afaf00;">\</span>
--min-size <span style="color: #d787af;">30</span> <span style="color: #afaf00;">\</span>
--output out_pruned <span style="color: #afaf00;">\</span>
> clusters_pruned.csv
<span style="color: #ff8700;">printf</span> <span style="color: #afaf00;">"./out_pruned/dendrogram.svg"</span>
</pre>
</div>
<div id="orge6dc117" class="figure">
<p><object type="image/svg+xml" data="./out_pruned/dendrogram.svg" class="org-svg">
Sorry, your browser does not support SVG.</object>
</p>
</div>
</div>
</div>
<div id="outline-container-org5c3efd0" class="outline-3">
<h3 id="org5c3efd0">Prune tree by size distribution</h3>
<div class="outline-text-3" id="text-org5c3efd0">
<p>
Don't want arbitrary number cutoffs? Let's instead make a cutoff using the
distribution of cluster sizes. We can use <code>--smart-cutoff</code> to look at the
distribution of cluster sizes, split proportions, or distances (modularity here)
and select certain median absolute deviations (MADs) away from the median as a
cutoff. We select which feature to create a distribution by using that feature's
normal cutoff argument, where the cutoff value is ignored (so we can put 1, for
instance, as it will be ignored). Let's revise our previous attempt by cutting 1
MAD away from the median node size:
</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>
--labels-file ./labels.csv <span style="color: #afaf00;">\</span>
--min-size <span style="color: #d787af;">1</span> <span style="color: #afaf00;">\</span>
--smart-cutoff <span style="color: #d787af;">1</span> <span style="color: #afaf00;">\</span>
--dendrogram-output <span style="color: #afaf00;">"tree_smart.svg"</span> <span style="color: #afaf00;">\</span>
--output out_pruned <span style="color: #afaf00;">\</span>
> clusters_pruned.csv
<span style="color: #ff8700;">printf</span> <span style="color: #afaf00;">"./out_pruned/tree_smart.svg"</span>
</pre>
</div>
<div id="orgaa9658d" class="figure">
<p><object type="image/svg+xml" data="./out_pruned/tree_smart.svg" class="org-svg">
Sorry, your browser does not support SVG.</object>
</p>
</div>
</div>
</div>
</div>
<div id="outline-container-orgbe71bb6" class="outline-2">
<h2 id="orgbe71bb6">Gene expression</h2>
<div class="outline-text-2" id="text-orgbe71bb6">
</div>
<div id="outline-container-org5557f30" class="outline-3">
<h3 id="org5557f30">Neuron marker overlay</h3>
<div class="outline-text-3" id="text-org5557f30">
<p>
Want to overlay gene expression? We'll need the matrices again, but still use
<code>--prior</code> to avoid clustering. Also, we use normalization to avoid looking at
only the counts, but rather normalized counts. Let's look neuron cell marker
<i>Rbfox3</i>:
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells make-tree <span style="color: #afaf00;">\</span>
--matrix-path ./data/brain/filtered_feature_bc_matrix/ <span style="color: #afaf00;">\</span>
--matrix-path ./data/heart/filtered_feature_bc_matrix/ <span style="color: #afaf00;">\</span>
--filter-thresholds <span style="color: #afaf00;">"(250, 1)"</span> <span style="color: #afaf00;">\</span>
--prior out <span style="color: #afaf00;">\</span>
--normalization <span style="color: #afaf00;">"UQNorm"</span> <span style="color: #afaf00;">\</span>
--draw-leaf <span style="color: #afaf00;">"DrawItem (DrawContinuous [\"ENSMUSG00000025576\"])"</span> <span style="color: #afaf00;">\</span>
--dendrogram-output <span style="color: #afaf00;">"tree_neuron.svg"</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/tree_neuron.svg"</span>
</pre>
</div>
<div id="org2a578f0" class="figure">
<p><object type="image/svg+xml" data="./out/tree_neuron.svg" class="org-svg">
Sorry, your browser does not support SVG.</object>
</p>
</div>
</div>
</div>
<div id="outline-container-orgabae537" class="outline-3">
<h3 id="orgabae537">Increasing visibility</h3>
<div class="outline-text-3" id="text-orgabae537">
<p>
Can't see too well? Let's up the saturation!
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells make-tree <span style="color: #afaf00;">\</span>
--matrix-path ./data/brain/filtered_feature_bc_matrix/ <span style="color: #afaf00;">\</span>
--matrix-path ./data/heart/filtered_feature_bc_matrix/ <span style="color: #afaf00;">\</span>
--filter-thresholds <span style="color: #afaf00;">"(250, 1)"</span> <span style="color: #afaf00;">\</span>
--prior out <span style="color: #afaf00;">\</span>
--normalization <span style="color: #afaf00;">"UQNorm"</span> <span style="color: #afaf00;">\</span>
--draw-leaf <span style="color: #afaf00;">"DrawItem (DrawContinuous [\"ENSMUSG00000025576\"])"</span> <span style="color: #afaf00;">\</span>
--dendrogram-output <span style="color: #afaf00;">"tree_neuron_saturated.svg"</span> <span style="color: #afaf00;">\</span>
--draw-scale-saturation <span style="color: #d787af;">6</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/tree_neuron_saturated.svg"</span>
</pre>
</div>
<div id="org3af4f41" class="figure">
<p><object type="image/svg+xml" data="./out/tree_neuron_saturated.svg" class="org-svg">
Sorry, your browser does not support SVG.</object>
</p>
</div>
</div>
</div>
<div id="outline-container-org3a211fc" class="outline-3">
<h3 id="org3a211fc">Gene symbol rather than Ensembl</h3>
<div class="outline-text-3" id="text-org3a211fc">
<p>
Want to use the gene symbol? <code>cellranger</code> provides that! Let's use that feature
column:
</p>
<div class="org-src-container">
<pre class="src src-shell">too-many-cells make-tree <span style="color: #afaf00;">\</span>
--matrix-path ./data/brain/filtered_feature_bc_matrix/ <span style="color: #afaf00;">\</span>
--matrix-path ./data/heart/filtered_feature_bc_matrix/ <span style="color: #afaf00;">\</span>
--filter-thresholds <span style="color: #afaf00;">"(250, 1)"</span> <span style="color: #afaf00;">\</span>
--prior out <span style="color: #afaf00;">\</span>
--feature-column <span style="color: #d787af;">2</span> <span style="color: #afaf00;">\</span>
--normalization <span style="color: #afaf00;">"UQNorm"</span> <span style="color: #afaf00;">\</span>
--draw-leaf <span style="color: #afaf00;">"DrawItem (DrawContinuous [\"Rbfox3\"])"</span> <span style="color: #afaf00;">\</span>
--dendrogram-output <span style="color: #afaf00;">"tree_neuron_gene_symbol.svg"</span> <span style="color: #afaf00;">\</span>
--draw-scale-saturation <span style="color: #d787af;">6</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/tree_neuron_gene_symbol.svg"</span>