forked from GregorySchwartz/too-many-cells
-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.html
2017 lines (1768 loc) · 83.4 KB
/
README.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>too-many-cells</title>
<meta name="author" content="Gregory W. Schwartz" />
<meta name="generator" content="Org Mode" />
<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/x-mathjax-config">
MathJax.Hub.Config({
displayAlign: "center",
displayIndent: "0em",
"HTML-CSS": { scale: 100,
linebreaks: { automatic: "false" },
webFont: "TeX"
},
SVG: {scale: 100,
linebreaks: { automatic: "false" },
font: "TeX"},
NativeMML: {scale: 100},
TeX: { equationNumbers: {autoNumber: "AMS"},
MultLineWidth: "85%",
TagSide: "right",
TagIndent: ".8em"
}
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script>
</head>
<body>
<div id="content" class="content">
<h1 class="title">too-many-cells</h1>
<div id="table-of-contents" role="doc-toc">
<h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc">
<ul>
<li><a href="#orgcce20f5">1. Description</a></li>
<li><a href="#org6992a13">2. New features for v3.0.0.0</a></li>
<li><a href="#org43dc2d3">3. New features for v2.2.0.0</a></li>
<li><a href="#org40cd514">4. New features for v2.0.0.0</a></li>
<li><a href="#orgec216f4">5. New features since initial launch</a></li>
<li><a href="#org4d8bb01">6. Installation</a>
<ul>
<li><a href="#org2a4d583">6.1. nix</a></li>
<li><a href="#org76a491e">6.2. Stack (unsupported in <code>too-many-cells >= v2.0.0.0</code>, use nix)</a>
<ul>
<li><a href="#org95b6d2d">6.2.1. Dependencies</a></li>
<li><a href="#orge1f3094">6.2.2. Install <code>stack</code></a></li>
<li><a href="#org7560e2e">6.2.3. Install <code>too-many-cells</code></a></li>
</ul>
</li>
<li><a href="#org29dd1b4">6.3. Docker</a></li>
</ul>
</li>
<li><a href="#org38b35bd">7. Troubleshooting</a>
<ul>
<li><a href="#org31b88a0">7.1. Using nix, I'm getting shared object not found errors.</a></li>
<li><a href="#orgd655944">7.2. I am getting errors like <code>AesonException "Error in $.packages.cassava.constraints.flags...</code> when running <code>stack</code> commands</a></li>
<li><a href="#org74de1e9">7.3. I use conda or custom ld library locations and I cannot install <code>too-many-cells</code> or run into weird R errors</a></li>
<li><a href="#org2478aec">7.4. I am still having issues with installation</a></li>
<li><a href="#orgdf2bfb6">7.5. I am on macOS/Windows with docker and <code>too-many-cells</code> silently crashes.</a></li>
<li><a href="#org2801396">7.6. I am getting the error <code>--draw-leaf</code> cannot be read, but I copied the command!</a></li>
</ul>
</li>
<li><a href="#org4549d0d">8. Included projects</a></li>
<li><a href="#org4f4fa59">9. Usage</a>
<ul>
<li><a href="#makeTreeUsage">9.1. <code>make-tree</code></a>
<ul>
<li><a href="#orgeb67830">9.1.1. Output</a></li>
<li><a href="#orgb2d1b3c">9.1.2. Outline with options</a></li>
<li><a href="#org05486bc">9.1.3. Example</a></li>
</ul>
</li>
<li><a href="#org20b1b06">9.2. <code>interactive</code></a></li>
<li><a href="#orge81a340">9.3. <code>differential</code></a></li>
<li><a href="#orgb2da5a5">9.4. <code>diversity</code></a></li>
<li><a href="#org1e4d537">9.5. <code>paths</code></a></li>
<li><a href="#too-many-peaks">9.6. Working with scATAC-seq data using <code>too-many-peaks</code></a></li>
<li><a href="#orgabc2989">9.7. <code>peaks</code></a></li>
<li><a href="#org9ad7ebb">9.8. <code>motifs</code></a></li>
<li><a href="#orga4ec4f5">9.9. <code>classify</code></a></li>
<li><a href="#spatial">9.10. <code>spatial</code></a></li>
<li><a href="#org34fb3c4">9.11. <code>matrix-output</code></a></li>
</ul>
</li>
<li><a href="#orgbc82a8e">10. Advanced documentation</a></li>
<li><a href="#orgb860e2b">11. Demo</a></li>
</ul>
</div>
</div>
<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. See <a href="#too-many-peaks">
<code>too-many-peaks</code> </a> for more information about scATAC-seq usage. See <a href="#spatial"> <code>spatial</code> </a> for
more information about spatial usage.
</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="orgc3da573" class="figure">
<p><img src="img/pruned_tree.png" alt="pruned_tree.png" />
</p>
</div>
<div id="outline-container-orgcce20f5" class="outline-2">
<h2 id="orgcce20f5"><span class="section-number-2">1.</span> Description</h2>
<div class="outline-text-2" id="text-1">
<p>
<code>too-many-cells</code> is a suite of tools, algorithms, and visualizations focusing on
the relationships between cell clades. This includes new ways of clustering,
plotting, choosing differential expression comparisons, and more! While
<code>too-many-cells</code> was intended for single cell RNA-seq, any abundance data in any
domain can be used. Rather than opt for a unique positioning of each cell using
dimensionality reduction approaches like t-SNE, UMAP, and LSA, <code>too-many-cells</code>
recursively divides cells into clusters and relates clusters rather than
individual cells. In fact, by recursively dividing until further dividing would
be considered noise or random partitioning, we can eliminate noisy relationships
at the fine-grain level. The resulting binary tree serves as a basis for a
different perspective of single cells, using our <a href="http://github.com/GregorySchwartz/birch-beer#readme"> <code>birch-beer</code> </a> visualization
and tree measures to describe simultaneously large and small populations,
without additional parameters or runs. See below for a full list of features.
</p>
</div>
</div>
<div id="outline-container-org6992a13" class="outline-2">
<h2 id="org6992a13"><span class="section-number-2">2.</span> New features for v3.0.0.0</h2>
<div class="outline-text-2" id="text-2">
<ul class="org-ul">
<li>Added new <code>spatial</code> entry point for spatial analysis of cells! Can make
interactive plots of the cells in-situ with their features as well as quantify
spatial relationships between pairs of cells.</li>
<li>Overhauled the command line interface, so expect to find possible instability
with the options. Open an issue at
<a href="https://github.com/GregorySchwartz/too-many-cells/issues">https://github.com/GregorySchwartz/too-many-cells/issues</a> if you encounter any
expected errors or behavior!</li>
<li>Added MinMaxNorm for min-max normalization and TransposeNorm to transpose the
matrix to apply normalizations back and forth between axes, for instance,
<code>--normalization QuantileNorm --normalization TransposeNorm --normalization
MinMaxNorm --normalization TransposeNorm</code> will first apply quantile
normalization to each cell, then min-max normalization to each column (before
returning the cells to the proper axis with another tranpose).</li>
<li>Incompatibility: Projection file format changed "barcode" column to "item".</li>
</ul>
</div>
</div>
<div id="outline-container-org43dc2d3" class="outline-2">
<h2 id="org43dc2d3"><span class="section-number-2">3.</span> New features for v2.2.0.0</h2>
<div class="outline-text-2" id="text-3">
<ul class="org-ul">
<li><code>--no-edger</code> replaced with <code>--edger</code> as the default is now Kruskal-Wallis.</li>
<li>Can now use backgrounds for motifs.</li>
<li>Can specify motif for genome analysis (i.e. <code>findMotifsGenome.pl</code> from HOMER).</li>
<li>Temporary directories are now variables to correctly specify location.</li>
<li>Added q-values for differential.</li>
<li>Updated documentation for <code>too-many-peaks</code>.</li>
</ul>
</div>
</div>
<div id="outline-container-org40cd514" class="outline-2">
<h2 id="org40cd514"><span class="section-number-2">4.</span> New features for v2.0.0.0</h2>
<div class="outline-text-2" id="text-4">
<ul class="org-ul">
<li>Support for scATAC-seq for chromatin state relationships with <a href="#too-many-peaks"> <code>too-many-peaks</code> </a>!</li>
<li>Find enchriched regions as peaks for scATAC-seq with <code>peaks</code>.</li>
<li>Find motifs from differential chromatin state using <code>motifs</code>.</li>
<li>Linear relationships across the tree as pseudotime with <code>paths</code>.</li>
<li>Classify single-cell data from bulk with <code>classify</code>.</li>
<li>New dimensionality reductions with <code>--lsa</code>.</li>
<li>Output transformed matrix with <code>matrix-output</code>.</li>
<li>Bypass <code>labels.csv</code> with <code>-Z</code> quick labels.</li>
<li>MADs-from-median-based thresholds for multi-gene overlay plots</li>
<li>Multiple normalization application</li>
<li>And much more!</li>
</ul>
</div>
</div>
<div id="outline-container-orgec216f4" class="outline-2">
<h2 id="orgec216f4"><span class="section-number-2">5.</span> New features since initial launch</h2>
<div class="outline-text-2" id="text-5">
<ul class="org-ul">
<li>Now packaged for the functional package manager <code>nix</code> (Linux only)! No more dependency
shuffling or root for Docker needed!</li>
<li>A new R wrapper was written to quickly get data to and from <code>too-many-cells</code>
from R. <a href="https://github.com/GregorySchwartz/tooManyCellsR">Check it out here</a>!</li>
<li>Now works with Cellranger 3.0 matrices in addition to Cellranger 2.0</li>
<li>Can prune (make into leaves) specified nodes with <code>--custom-cut</code>.</li>
<li>Can analyze sets of features averaged together (e.g. gene sets). <b>Breaks API</b>,
so update your <code>--draw-leaf "DrawItem (DrawContinuous \"Cd4\")"</code> argument to
<code>--draw-leaf "DrawItem (DrawContinuous [\"Cd4\"])"</code> (notice the list
notation).</li>
<li>Outputs values from differential entry point plots (from <code>--features</code>), and can
aggregate features by average.</li>
</ul>
</div>
</div>
<div id="outline-container-org4d8bb01" class="outline-2">
<h2 id="org4d8bb01"><span class="section-number-2">6.</span> Installation</h2>
<div class="outline-text-2" id="text-6">
<p>
We provide multiple ways to install <code>too-many-cells</code>. We recommend installing
with <a href="#org2a4d583"> <code>nix</code> </a>. <code>nix</code> will provide all dependencies in the build, supports Linux,
and should be reproducible, so try that first. We also have <a href="#org29dd1b4">docker</a> images and a
<code>Dockerfile</code> to use in any system in case you have a custom build (for instance,
a non-standard R installation) or difficulty installing. <b>macOS and Windows
users:</b> <code>too-many-cells</code> was built and tested on Linux, so we highly recommend
using the <a href="#org29dd1b4">docker</a> image (which is a completely isolated environment which
requires no compiling or installation, other than docker itself) as there may be
difficulties in installing the dependencies.
</p>
</div>
<div id="outline-container-org2a4d583" class="outline-3">
<h3 id="org2a4d583"><span class="section-number-3">6.1.</span> nix</h3>
<div class="outline-text-3" id="text-6-1">
<p>
<code>too-many-cells</code> can be installed using the functional package manager <a href="https://nixos.org/nix/"> <code>nix</code> </a>.
While you will need <code>sudo</code> to install, no <code>sudo</code> is required after the correct
setup. First, install <code>nix</code> following the instructions
<a href="https://nixos.org/nix/">on the website</a>. Then, with an unset <code>LD_LIBRARY_PATH</code>,
</p>
<div class="org-src-container">
<pre class="src src-sh">git clone https://github.com/GregorySchwartz/too-many-cells.git
<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-org76a491e" class="outline-3">
<h3 id="org76a491e"><span class="section-number-3">6.2.</span> Stack (unsupported in <code>too-many-cells >= v2.0.0.0</code>, use nix)</h3>
<div class="outline-text-3" id="text-6-2">
</div>
<div id="outline-container-org95b6d2d" class="outline-4">
<h4 id="org95b6d2d"><span class="section-number-4">6.2.1.</span> Dependencies</h4>
<div class="outline-text-4" id="text-6-2-1">
<p>
You may require the following dependencies to build and run (from Ubuntu 14.04,
use the appropriate packages from your distribution of choice):
</p>
<ul class="org-ul">
<li>build-essential</li>
<li>libgmp-dev</li>
<li>libblas-dev</li>
<li>liblapack-dev</li>
<li>libgsl-dev</li>
<li>libgtk2.0-dev</li>
<li>libcairo2-dev</li>
<li>libpango1.0-dev</li>
<li>graphviz</li>
<li>r-base</li>
<li>r-base-dev</li>
</ul>
<p>
To install them, in Ubuntu:
</p>
<div class="org-src-container">
<pre class="src src-shell">sudo apt install build-essential libgmp-dev libblas-dev liblapack-dev libgsl-dev libgtk2.0-dev libcairo2-dev libpango1.0-dev graphviz r-base r-base-dev
</pre>
</div>
<p>
<code>too-many-cells</code> also uses the following packages from R:
</p>
<ul class="org-ul">
<li>cowplot</li>
<li>ggplot2</li>
<li>edgeR</li>
<li>jsonlite</li>
</ul>
<p>
To install them in R,
</p>
<div class="org-src-container">
<pre class="src src-R">install.packages<span style="color: #008787;">(</span>c<span style="color: #d75f87;">(</span><span style="color: #afaf00;">"ggplot2"</span>, <span style="color: #afaf00;">"cowplot"</span>, <span style="color: #afaf00;">"jsonlite"</span><span style="color: #d75f87;">)</span><span style="color: #008787;">)</span>
install.packages<span style="color: #008787;">(</span><span style="color: #afaf00;">"BiocManager"</span><span style="color: #008787;">)</span>
BiocManager::install<span style="color: #008787;">(</span><span style="color: #afaf00;">"edgeR"</span><span style="color: #008787;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orge1f3094" class="outline-4">
<h4 id="orge1f3094"><span class="section-number-4">6.2.2.</span> Install <code>stack</code></h4>
<div class="outline-text-4" id="text-6-2-2">
<p>
See <a href="https://docs.haskellstack.org/en/stable/README/">https://docs.haskellstack.org/en/stable/README/</a> for more details.
</p>
<div class="org-src-container">
<pre class="src src-sh">curl -sSL https://get.haskellstack.org/ | sh
stack setup
</pre>
</div>
</div>
</div>
<div id="outline-container-org7560e2e" class="outline-4">
<h4 id="org7560e2e"><span class="section-number-4">6.2.3.</span> Install <code>too-many-cells</code></h4>
<div class="outline-text-4" id="text-6-2-3">
</div>
<ol class="org-ol">
<li><a id="orgdc58dd1"></a>Source<br />
<div class="outline-text-5" id="text-6-2-3-1">
<p>
Probably the easiest method if you don't want to mess with dependencies (outside
of the ones above).
</p>
<div class="org-src-container">
<pre class="src src-sh">git clone https://github.com/GregorySchwartz/too-many-cells.git
<span style="color: #ff8700;">cd</span> too-many-cells
stack install
</pre>
</div>
</div>
</li>
<li><a id="org9435c45"></a>Online<br />
<div class="outline-text-5" id="text-6-2-3-2">
<p>
We only require <code>stack</code> (or <code>cabal</code>), you do not need to download any source
code (but you might need the stack.yaml.old dependency versions), just run the
following command to place <code>too-many-cells < v2.0.0.0</code> in your <code>~/.local/bin/</code>:
</p>
<div class="org-src-container">
<pre class="src src-sh">mv stack.yaml.preV2 stack.yaml
stack install too-many-cells
</pre>
</div>
<p>
If you run into errors like <code>Error: While constructing the build plan, the
following exceptions were encountered:</code>, then follow the advice. Usually you
just need to follow the suggestion and add the dependencies to the specified
file. For a quick <code>yaml</code> configuration, refer to
<a href="https://github.com/GregorySchwartz/too-many-cells/blob/master/stack.yaml.old">https://github.com/GregorySchwartz/too-many-cells/blob/master/stack.yaml.old</a>.
</p>
</div>
</li>
<li><a id="macOS"></a>macOS<br />
<div class="outline-text-5" id="text-macOS">
<p>
We recommend using <a href="#org29dd1b4">docker</a> on macOS. The following is written for
<code>too-many-cells < v2.0.0.0</code>. If you must compile
<code>too-many-cells</code>, you should get the above dependencies. For some dependencies,
you can use <a href="https://brew.sh/">brewer</a>, then install <code>too-many-cells</code> (in the cloned folder, don't
forget to install the R dependencies above):
</p>
<div class="org-src-container">
<pre class="src src-shell">brew cask install xquartz
brew install glib cairo gtk gettext fontconfig freetype
brew tap brewsci/bio
brew tap brewsci/science
brew install r zeromq graphviz pkg-config gsl libffi gobject-introspection gtk+ gtk+3
<span style="color: #767676;"># </span><span style="color: #767676;">Needed so pkg-config and libraries can be found.</span>
<span style="color: #767676;"># </span><span style="color: #767676;">For the second path, use the ouput of "brew info libffi".</span>
<span style="color: #ff8700;">export</span> <span style="color: #87afaf;">PKG_CONFIG_PATH</span>=/usr/local/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig
<span style="color: #767676;"># </span><span style="color: #767676;">Tell gtk that it's quartz</span>
stack install --flag gtk:have-quartz-gtk
</pre>
</div>
</div>
</li>
</ol>
</div>
</div>
<div id="outline-container-org29dd1b4" class="outline-3">
<h3 id="org29dd1b4"><span class="section-number-3">6.3.</span> Docker</h3>
<div class="outline-text-3" id="text-6-3">
<p>
Different computers have different setups, operating systems, and repositories.
Do put the entire program in a container to bypass difficulties (with the other
methods above), we user <code>docker</code>. So first, <a href="https://docs.docker.com/">install docker</a>.
</p>
<p>
To get <code>too-many-cells</code> (replace 2.0.0.0 with <a href="https://cloud.docker.com/repository/docker/gregoryschwartz/too-many-cells/general">any version needed</a>):
</p>
<div class="org-src-container">
<pre class="src src-sh">docker pull gregoryschwartz/too-many-cells:2.0.0.0
</pre>
</div>
<p>
To run <code>too-many-cells</code> in a docker container:
</p>
<div class="org-src-container">
<pre class="src src-sh">sudo docker run -it --rm -v <span style="color: #afaf00;">"/home/username:/home/username"</span> gregoryschwartz/too-many-cells:2.0.0.0 -h
</pre>
</div>
<p>
Now you can follow the tutorial below with the addition of the docker paths and
commands. If you add yourself to the docker group, <code>sudo</code> is not needed. For instance:
</p>
<div class="org-src-container">
<pre class="src src-sh">docker run -it --rm -v <span style="color: #afaf00;">"/home/username:/home/username"</span> <span style="color: #afaf00;">\</span>
gregoryschwartz/too-many-cells:2.0.0.0 make-tree <span style="color: #afaf00;">\</span>
--matrix-path /home/username/path/to/input <span style="color: #afaf00;">\</span>
--labels-file /home/username/path/to/labels.csv <span style="color: #afaf00;">\</span>
--draw-collection <span style="color: #afaf00;">"PieRing"</span> <span style="color: #afaf00;">\</span>
--output /home/username/path/to/out <span style="color: #afaf00;">\</span>
> clusters.csv
</pre>
</div>
<p>
Make sure to <a href="https://docs.docker.com/config/containers/resource_constraints/">increase the memory</a> that can be used by docker containers if you
use macOS or Windows. Also, docker won't be able to find your files by default.
You need to mount the folders with <code>-v</code> in order to have docker read and write
from and to the filesystem, respectively. Read the <a href="https://docs.docker.com/storage/volumes/">documentation</a> about volumes
for more information. You can simply mount your entire relevant path as in the
above example to handle both input and output, or just mount your entire user
directory as above. Specifically, <code>-v "/home/username:/home/username"</code> for the
whole directory or each individual <code>-v /path/to/matrix/on/host:/input_matrix</code>
with <code>-m /input_matrix</code> is what you want, where before the <code>:</code> is on the host
filesystem while after the <code>:</code> is what the docker program sees. Then you can
write the output in the same way: <code>-v /path/to/output/on/host:/output</code> will
write the output to the folder before the <code>:</code>.
</p>
<p>
To build the <code>too-many-cells</code> image yourself if you want:
</p>
<div class="org-src-container">
<pre class="src src-sh">nix-build docker.nix
docker load < /nix/store/$<span style="color: #008787;">{</span><span style="color: #87afaf;">NAME_OF_OUTPUT_IMAGE</span><span style="color: #008787;">}</span>.tar.gz
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org38b35bd" class="outline-2">
<h2 id="org38b35bd"><span class="section-number-2">7.</span> Troubleshooting</h2>
<div class="outline-text-2" id="text-7">
</div>
<div id="outline-container-org31b88a0" class="outline-3">
<h3 id="org31b88a0"><span class="section-number-3">7.1.</span> Using nix, I'm getting shared object not found errors.</h3>
<div class="outline-text-3" id="text-7-1">
<p>
Be sure to have <code>LD_LIBRARY_PATH</code> unset when running <code>nix-env</code> to make sure the
linked libraries are in <code>/nix/store</code>.
</p>
</div>
</div>
<div id="outline-container-orgd655944" class="outline-3">
<h3 id="orgd655944"><span class="section-number-3">7.2.</span> I am getting errors like <code>AesonException "Error in $.packages.cassava.constraints.flags...</code> when running <code>stack</code> commands</h3>
<div class="outline-text-3" id="text-7-2">
<p>
Try upgrading stack with <code>stack upgrade</code>. The new installation will be in
<code>~/.local/bin</code>, so use that binary.
</p>
</div>
</div>
<div id="outline-container-org74de1e9" class="outline-3">
<h3 id="org74de1e9"><span class="section-number-3">7.3.</span> I use conda or custom ld library locations and I cannot install <code>too-many-cells</code> or run into weird R errors</h3>
<div class="outline-text-3" id="text-7-3">
<p>
<code>stack</code> and <code>too-many-cells</code> assume system libraries and programs. To solve this
issue, first install the dependencies above at the system level, including
system <code>R</code>. Then to every <code>stack</code> and <code>too-many-cells</code> command, prepend
<code>PATH="$HOME/.local/bin:/usr/bin:$PATH"</code> to all commands. For instance:
</p>
<ul class="org-ul">
<li><code>PATH="$HOME/.local/bin:/usr/bin:$PATH" stack install</code></li>
<li><code>PATH="$HOME/.local/bin:/usr/bin:$PATH" too-many-cells make-tree -h</code></li>
</ul>
<p>
If your shared libraries are abnormal and use <code>libR.so</code> from non-system
locations, be sure to also have <code>LD_LIBRARY_PATH=/usr/lib/:$LD_LIBRARY_PATH</code>
when installing (and / or the location of R libraries, such as
<code>/usr/local/lib/R/lib/</code>).
</p>
</div>
</div>
<div id="outline-container-org2478aec" class="outline-3">
<h3 id="org2478aec"><span class="section-number-3">7.4.</span> I am still having issues with installation</h3>
<div class="outline-text-3" id="text-7-4">
<p>
<a href="https://github.com/GregorySchwartz/too-many-cells/issues">Open an issue</a>! While working on the issue, try out the docker for
<code>too-many-cells</code>, it requires no installation at all (other than docker).
</p>
</div>
</div>
<div id="outline-container-orgdf2bfb6" class="outline-3">
<h3 id="orgdf2bfb6"><span class="section-number-3">7.5.</span> I am on macOS/Windows with docker and <code>too-many-cells</code> silently crashes.</h3>
<div class="outline-text-3" id="text-7-5">
<p>
Docker containers may run into this issue if the memory given to the containers
is insufficient. Make sure to <a href="https://docs.docker.com/config/containers/resource_constraints/">increase the memory</a> that can be used by docker
containers.
</p>
</div>
</div>
<div id="outline-container-org2801396" class="outline-3">
<h3 id="org2801396"><span class="section-number-3">7.6.</span> I am getting the error <code>--draw-leaf</code> cannot be read, but I copied the command!</h3>
<div class="outline-text-3" id="text-7-6">
<p>
For some computers, you may need to change the command to single quotations for
the argument: <code>--draw-leaf 'DrawItem (DrawContinuous [\"Cd4\"])'</code>
</p>
</div>
</div>
</div>
<div id="outline-container-org4549d0d" class="outline-2">
<h2 id="org4549d0d"><span class="section-number-2">8.</span> Included projects</h2>
<div class="outline-text-2" id="text-8">
<p>
This project is a collection of libraries and programs written specifically for
<code>too-many-cells</code>:
</p>
<dl class="org-dl">
<dt><a href="https://github.com/GregorySchwartz/birch-beer"> <code>birch-beer</code> </a></dt><dd>Generate a tree for displaying a hierarchy of groups with
colors, scaling, and more.</dd>
<dt><a href="https://github.com/GregorySchwartz/modularity"> <code>modularity</code> </a></dt><dd>Find the modularity of a network.</dd>
<dt><a href="https://github.com/GregorySchwartz/spectral-clustering"> <code>spectral-clustering</code> </a></dt><dd>Library for spectral clustering.</dd>
<dt><a href="https://github.com/GregorySchwartz/hierarchical-spectral-clustering"> <code>hierarchical-spectral-clustering</code> </a></dt><dd>Hierarchical spectral clustering of a
graph.</dd>
<dt><a href="https://github.com/GregorySchwartz/differential"> <code>differential</code> </a></dt><dd>Finds out whether an entity comes from different
distributions (statuses).</dd>
</dl>
</div>
</div>
<div id="outline-container-org4f4fa59" class="outline-2">
<h2 id="org4f4fa59"><span class="section-number-2">9.</span> Usage</h2>
<div class="outline-text-2" id="text-9">
<p>
<code>too-many-cells</code> has several entry points depending on the desired analysis.
</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">Argument</th>
<th scope="col" class="org-left">Analysis</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left"><code>make-tree</code></td>
<td class="org-left">Generate the tree from single cell data with various measurement outputs and visualize tree</td>
</tr>
<tr>
<td class="org-left"><code>interactive</code></td>
<td class="org-left">Interactive visuzalization of the tree, very slow</td>
</tr>
<tr>
<td class="org-left"><code>differential</code></td>
<td class="org-left">Find differentially expressed features between two nodes</td>
</tr>
<tr>
<td class="org-left"><code>diversity</code></td>
<td class="org-left">Conduct diversity analyses of multiple cell populations</td>
</tr>
<tr>
<td class="org-left"><code>paths</code></td>
<td class="org-left">The binary tree equivalent of the so called "pseudotime", or 1D dimensionality reduction</td>
</tr>
</tbody>
</table>
<p>
The main workflow is to first generate and plot the population tree using
<code>too-many-cells make-tree</code>, then use the rest of the entry points as needed.
</p>
<p>
At any point, use <code>-h</code> to see the help of each entry point.
</p>
<p>
Also, check out <a href="https://github.com/GregorySchwartz/tooManyCellsR">tooManyCellsR</a> for an R wrapper!
</p>
</div>
<div id="outline-container-makeTreeUsage" class="outline-3">
<h3 id="makeTreeUsage"><span class="section-number-3">9.1.</span> <code>make-tree</code></h3>
<div class="outline-text-3" id="text-makeTreeUsage">
<p>
<code>too-many-cells make-tree</code> generates a binary tree using hierarchical spectral
clustering. We start with all cells in a single node. Spectral clustering
partitions the cells into two groups. We assess the clustering using
Newman-Girvan modularity: if \(Q > 0\) then we recursively continue with
hierarchical spectral clustering. If not, then there is only a single community
and we do not partition – the resulting node is a leaf and is considered the
finest-grain cluster.
</p>
<p>
<b>The most important argument is the –prior argument.</b> Making the tree may
take some time, so if the tree was already generated and other analysis or
visualizations need to be run on the tree, point the <code>--prior</code> argument to the
output folder from a previous run of <code>too-many-cells</code>. If you do not use
<code>--prior</code>, <b>the entire tree will be recalculated even if you just wanted to
change the visualization!</b>
</p>
<p>
The main input is the <code>--matrix-path</code> argument. When a directory is supplied,
<code>too-many-cells</code> interprets the folder to have <code>matrix.mtx</code>, <code>genes.tsv</code>, and
<code>barcodes.tsv</code> files (<code>cellranger</code> outputs, see <code>cellranger</code> for specifics). If
a file is supplied instead of a directory, we assume a <code>csv</code> file containing
feature row names and cell column names. This argument can be called multiple times
to combine multiple single cell matrices: <code>--matrix-path input1 --matrix-path
input2</code>.
</p>
<p>
The second most important argument is <code>--labels-file</code>. Supply with a <code>csv</code> with
a format and header of "item,label" to provide colorings and statistics of the
relationships between labels. Here the "item" column contains the name of each
cell (barcode) and the label is any property of the cell (the tissue of origin,
hour in a time course, celltype, etc.). You can also now use <code>-Z</code> as a list for
each matching <code>-m</code> in order to manually give the entire matrix that label
(useful for situations like <code>-m ./t-all -Z T-ALL -m ./control -Z Control). To
get the newly generated labels with =-Z</code> into a <code>labels.csv</code> file, specify
<code>--labels-output</code> and the <code>labels.csv</code> will be in the output folder.
</p>
<p>
To see the full list of options, use <code>too-many-cells -h</code> and <code>-h</code> for each entry
point (i.e. <code>too-many-cells make-tree -h</code>).
</p>
</div>
<div id="outline-container-orgeb67830" class="outline-4">
<h4 id="orgeb67830"><span class="section-number-4">9.1.1.</span> Output</h4>
<div class="outline-text-4" id="text-9-1-1">
<p>
<code>too-many-cells make-tree</code> generates several files in the output folder. Below
is a short description of each file.
</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>clumpiness.csv</code></td>
<td class="org-left">When labels are provided, uses the clumpiness measure to determine the level of aggregation between each label within the tree.</td>
</tr>
<tr>
<td class="org-left"><code>clumpiness.pdf</code></td>
<td class="org-left">When labels are provided, a figure of the clumpiness between labels.</td>
</tr>
<tr>
<td class="org-left"><code>cluster_diversity.csv</code></td>
<td class="org-left">When labels are provided, the diversity, or "effective number of labels", of each cluster.</td>
</tr>
<tr>
<td class="org-left"><code>cluster_info.csv</code></td>
<td class="org-left">Various bits of information for each cluster and the path leading up to each cluster, from that cluster to the root. For instance, the <code>size</code> column has <code>cluster_size/parent_size/parent_parent_size/.../root_size</code></td>
</tr>
<tr>
<td class="org-left"><code>cluster_list.json</code></td>
<td class="org-left">The <code>json</code> file containing a list of clusterings.</td>
</tr>
<tr>
<td class="org-left"><code>cluster_tree.json</code></td>
<td class="org-left">The <code>json</code> file containing the output tree in a recursive format.</td>
</tr>
<tr>
<td class="org-left"><code>dendrogram.svg</code></td>
<td class="org-left">The visualization of the tree. There are many possible options for this visualization included. Can rename to choose between PNG, PS, PDF, and SVG using <code>--dendrogram-output</code>.</td>
</tr>
<tr>
<td class="org-left"><code>graph.dot</code></td>
<td class="org-left">A <code>dot</code> file of the tree, with less information than the tree in <code>cluster_results.json</code>.</td>
</tr>
<tr>
<td class="org-left"><code>node_info.csv</code></td>
<td class="org-left">Various information of each node in the tree.</td>
</tr>
<tr>
<td class="org-left"><code>projection.pdf</code></td>
<td class="org-left">When <code>--projection</code> is supplied with a file of the format "barcode,x,y", provides a plot of each cell at the specified x and y coordinates (for instance, when looking at t-SNE plots with the same labelings as the dendrogram here).</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-orgb2d1b3c" class="outline-4">
<h4 id="orgb2d1b3c"><span class="section-number-4">9.1.2.</span> Outline with options</h4>
<div class="outline-text-4" id="text-9-1-2">
<p>
The basic outline of the <b>default</b> matrix pre-processing pipeline with some
relevant options is as follows (there are many additional options including cell
whitelists that can be seen using <code>too-many-cells make-tree -h</code>):
</p>
<ol class="org-ol">
<li>Read matrix.</li>
<li>Optionally remove cells with less than X counts (<code>--filter-thresholds</code>).</li>
<li>Optionally remove features with less than X count (<code>--filter-thresholds</code>).</li>
<li>Term frequency-inverse document frequency normalization (<code>--normalization</code>).</li>
<li>Optionally use dimensionality reduction (<code>--lsa</code>).</li>
<li>Finish.</li>
</ol>
</div>
</div>
<div id="outline-container-org05486bc" class="outline-4">
<h4 id="org05486bc"><span class="section-number-4">9.1.3.</span> Example</h4>
<div class="outline-text-4" id="text-9-1-3">
</div>
<ol class="org-ol">
<li><a id="preprocessedData"></a>Setup<br />
<div class="outline-text-5" id="text-preprocessedData">
<p>
We start with our input matrix. Here,
</p>
<div class="org-src-container">
<pre class="src src-sh">ls ./input
</pre>
</div>
<pre class="example" id="org121b64d">
barcodes.tsv genes.tsv matrix.mtx
</pre>
<p>
Note that the input can be a directory (with the <code>cellranger</code> matrix format
above) or a file (a <code>csv</code> file). You can also point to a <code>cellranger</code> >= 3.0
folder which has <code>matrix.mtx.gz</code>, <code>features.tsv.gz</code>, and <code>barcodes.tsv.gz</code> files
instead. <b>You don't need to use scRNA-seq data!</b> You can use any data that has
observations (cells) and features (genes), as long as you agree that the
observations are related by their feature abundances. If
you do upstream batch effect correction, LSA, normalization, or anything else,
be sure to use <code>--normalization NoneNorm</code> (and <code>--shift-positive</code>
for LSA) to avoid wrong filters and scalings! <b>If using dimensionality reduction
such as PCA and t-SNE</b>, we highly recommend generating your own similarity
matrix for use with our <code>cluster-tree</code> program and plot with <code>birch-beer</code>, as we
emphasize a feature matrix in <code>too-many-cells</code> and dimensionality reduction
algorithms transform counts (our input which works with cosine similarity) into
more nebulous information (which may not work with cosine similarity).
<code>cluster-tree</code>, however, can be used with adjacency and similarity matrices. As
for formats, the matrix market format contains three files like so:
</p>
<p>
The <code>matrix.mtx</code> file is in matrix market format.
</p>
<pre class="example" id="org3bf76ae">
%%MatrixMarket matrix coordinate integer general
%
23433 1981 4255069
4 1 1
5 1 1
11 1 2
23 1 2
25 1 2
40 1 2
48 1 1
...
</pre>
<p>
The <code>genes.tsv</code> file (or <code>features.tsv.gz</code>) contains the features of each cell
and corresponds to the rows of <code>matrix.mtx</code>. Here, both columns were the same
gene symbols, but you can have Ensembl as the first column and gene symbol as
the second, etc. The columns and column orders don't matter, but make sure all
matrices have the same format and specify the symbols you want to use (for
overlaying gene expression, differential expression, etc.) with
<code>--feature-column COLUMN</code>. So to use the second column for gene expression, you
would use <code>--feature-column 2</code>.
</p>
<pre class="example" id="org857ab38">
Xkr4 Xkr4
Rp1 Rp1
Sox17 Sox17
Mrpl15 Mrpl15
Lypla1 Lypla1
Tcea1 Tcea1
Rgs20 Rgs20
Atp6v1h Atp6v1h
Oprk1 Oprk1
Npbwr1 Npbwr1
...
</pre>
<p>
The <code>barcodes.tsv</code> file contains the ids of each cell or observation and
corresponds to the columns of <code>matrix.mtx</code>.
</p>
<pre class="example" id="org7a9ca19">
AAACCTGCAGTAACGG-1
AAACGGGAGAAGAAGC-1
AAACGGGAGACCGGAT-1
AAACGGGAGCGCTCCA-1
AAACGGGAGGACGAAA-1
AAACGGGAGGTACTCT-1
AAACGGGAGGTGCTTT-1
AAACGGGAGTCGAGTG-1
AAACGGGCATGGTCAT-1
AAAGATGAGCTTCGCG-1
...
</pre>
<p>
For a <code>csv</code> file, the format is dense (observation columns (cells), feature rows
(genes)):
</p>
<pre class="example" id="org37c47fd">
"","A22.D042044.3_9_M.1.1","C5.D042044.3_9_M.1.1","D10.D042044.3_9_M.1.1","E13.D042044.3_9_M.1.1","F19.D042044.3_9_M.1.1","H2.D042044.3_9_M.1.1","I9.D042044.3_9_M.1.1",...
"0610005C13Rik",0,0,0,0,0,0,0,...
"0610007C21Rik",0,112,185,54,0,96,42,...
"0610007L01Rik",0,0,0,0,0,153,170,...
"0610007N19Rik",0,0,0,0,0,0,0,...
"0610007P08Rik",0,0,0,0,0,19,0,...
"0610007P14Rik",0,58,0,0,255,60,0,...
"0610007P22Rik",0,0,0,0,0,65,0,...
"0610008F07Rik",0,0,0,0,0,0,0,...
"0610009B14Rik",0,0,0,0,0,0,0,...
...
</pre>
<p>
We also know where each cell came from, so we mark that down as well in a
<code>labels.csv</code> file.
</p>
<pre class="example" id="orgaaa9c94">
item,label
AAACCTGCAGTAACGG-1,Marrow
AAACGGGAGACCGGAT-1,Marrow
AAACGGGAGCGCTCCA-1,Marrow
AAACGGGAGGACGAAA-1,Marrow
AAACGGGAGGTACTCT-1,Marrow
...
</pre>
<p>
This can be easily accomplished with <code>sed</code>:
</p>
<div class="org-src-container">
<pre class="src src-sh">cat barcodes.tsv | sed <span style="color: #afaf00;">"s/-1/-1,Marrow/"</span> | s/-2/etc... > labels.csv
</pre>
</div>
<p>
For <code>cellranger</code>, note that the <code>-1</code>, <code>-2</code>, etc. postfixes denote the first,
second, etc. label in the aggregation <code>csv</code> file used as input for <code>cellranger
aggr</code>.
</p>
</div>
</li>
<li><a id="orga249f36"></a>Default run<br />
<div class="outline-text-5" id="text-9-1-3-2">
<p>
We can now run the <code>too-many-cells</code> algorithm on our data. The resulting cells
with assigned clusters will be printed to <code>stdout</code> (don't forget to use
<code>--normalization NoneNorm</code> on preprocessed data, as stated <a href="#preprocessedData">here</a>). While older
versions had default filter thresholds for (MINCELL, MINFEATURE) counts, since
<code>v2.0.0.0</code> the default is now no filtering to account for multiple assay types.
</p>
<div class="org-src-container">
<pre class="src src-sh">too-many-cells make-tree <span style="color: #afaf00;">\</span>
--matrix-path input <span style="color: #afaf00;">\</span>
--labels-file labels.csv <span style="color: #afaf00;">\</span>
--filter-thresholds <span style="color: #afaf00;">"(250, 1)"</span> <span style="color: #afaf00;">\</span>
--draw-collection <span style="color: #afaf00;">"PieRing"</span> <span style="color: #afaf00;">\</span>
--output out <span style="color: #afaf00;">\</span>
> clusters.csv
</pre>
</div>
<div id="org12e536b" class="figure">
<p><img src="img/complete_default_tree.png" alt="complete_default_tree.png" />
</p>
</div>
</div>
</li>
<li><a id="org12e497f"></a>Pruning tree<br />
<div class="outline-text-5" id="text-9-1-3-3">
<p>
Large cell populations can result in a very large tree. What if we only want to
see larger subpopulations rather than the large (inner nodes) and small
(leaves)? We can use the <code>--min-size 100</code> argument to set the minimum size of a
leaf to 100 in this case. Alternatively, we can specify <code>--smart-cutoff 4</code> in
addition to <code>--min-size 1</code> to set the minimum size of a node to \(4 *
\text{median absolute deviation (MAD)}\) of the nodes in the original tree.
Varying the number of MADs varies the number of leaves in the tree.
<code>--smart-cutoff</code> should be used in addition to <code>--min-size</code>, <code>--max-proportion</code>,
<code>--min-distance</code>, or <code>--min-distance-search</code> to decide which cutoff variable to
use. The value supplied to the cutoff variable is ignored when <code>--smart-cutoff</code>
is specified. We'll prune the tree for better visibility in this document.
</p>
<p>
<b>Note: the pruning arguments change the tree file, not just the plot, so be sure
to output into a different directory.</b>
</p>
<p>
Also, <b>we do not need to recalculate the entire tree!</b> We can just supply the
previous results using <code>--prior</code> (we can also remove <code>--matrix-path</code> with
<code>--prior</code> to speed things up, but miss out on some features if needed):
</p>
<div class="org-src-container">
<pre class="src src-sh">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>
--smart-cutoff <span style="color: #d787af;">4</span> <span style="color: #afaf00;">\</span>
--min-size <span style="color: #d787af;">1</span> <span style="color: #afaf00;">\</span>
--draw-collection <span style="color: #afaf00;">"PieRing"</span> <span style="color: #afaf00;">\</span>
--output out_pruned <span style="color: #afaf00;">\</span>
> clusters_pruned.csv