-
Notifications
You must be signed in to change notification settings - Fork 10
/
utils.R
3367 lines (3129 loc) · 155 KB
/
utils.R
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
#' Mock function used to document all main function.
#'
#' @param sample \strong{\code{\link[SeuratObject]{Seurat}}} | A Seurat object, generated by \link[Seurat]{CreateSeuratObject}.
#' @param font.size \strong{\code{\link[base]{numeric}}} | Overall font size of the plot. All plot elements will have a size relationship with this font size.
#' @param font.type \strong{\code{\link[base]{character}}} | Base font family for the plot. One of:
#' \itemize{
#' \item \emph{\code{mono}}: Mono spaced font.
#' \item \emph{\code{serif}}: Serif font family.
#' \item \emph{\code{sans}}: Default font family.
#' }
#' @param legend.type \strong{\code{\link[base]{character}}} | Type of legend to display. One of:
#' \itemize{
#' \item \emph{\code{normal}}: Default legend displayed by \pkg{ggplot2}.
#' \item \emph{\code{colorbar}}: Redefined colorbar legend, using \link[ggplot2]{guide_colorbar}.
#' }
#' @param legend.position \strong{\code{\link[base]{character}}} | Position of the legend in the plot. One of:
#' \itemize{
#' \item \emph{\code{top}}: Top of the figure.
#' \item \emph{\code{bottom}}: Bottom of the figure.
#' \item \emph{\code{left}}: Left of the figure.
#' \item \emph{\code{right}}: Right of the figure.
#' \item \emph{\code{none}}: No legend is displayed.
#' }
#' @param legend.title \strong{\code{\link[base]{character}}} | Title for the legend.
#' @param legend.title.position \strong{\code{\link[base]{character}}} | Position for the title of the legend. One of:
#' \itemize{
#' \item \emph{\code{top}}: Top of the legend.
#' \item \emph{\code{bottom}}: Bottom of the legend.
#' \item \emph{\code{left}}: Left of the legend.
#' \item \emph{\code{right}}: Right of the legend.
#' }
#' @param legend.framewidth,legend.tickwidth \strong{\code{\link[base]{numeric}}} | Width of the lines of the box in the legend.
#' @param legend.framecolor \strong{\code{\link[base]{character}}} | Color of the lines of the box in the legend.
#' @param legend.tickcolor \strong{\code{\link[base]{character}}} | Color of the ticks of the box in the legend.
#' @param legend.length,legend.width \strong{\code{\link[base]{numeric}}} | Length and width of the legend. Will adjust automatically depending on legend side.
#' @param legend.icon.size \strong{\code{\link[base]{numeric}}} | Size of the icons in legend.
#' @param legend.ncol \strong{\code{\link[base]{numeric}}} | Number of columns in the legend.
#' @param legend.nrow \strong{\code{\link[base]{numeric}}} | Number of rows in the legend.
#' @param legend.byrow \strong{\code{\link[base]{logical}}} | Whether the legend is filled by row or not.
#' @param plot.title,plot.subtitle,plot.caption \strong{\code{\link[base]{character}}} | Title, subtitle or caption to use in the plot.
#' @param individual.titles,individual.subtitles,individual.captions \strong{\code{\link[base]{character}}} | Vector. Title, subtitle or caption to use in the plot when multiple features are passed on. Use NA to keep the original title.
#' @param reduction \strong{\code{\link[base]{character}}} | Reduction to use. Can be the canonical ones such as "umap", "pca", or any custom ones, such as "diffusion". If you are unsure about which reductions you have, use `Seurat::Reductions(sample)`. Defaults to "umap" if present or to the last computed reduction if the argument is not provided.
#' @param assay \strong{\code{\link[base]{character}}} | Assay to use. Defaults to the current assay.
#' @param slot \strong{\code{\link[base]{character}}} | Data slot to use. Only one of: counts, data, scale.data. Defaults to "data".
#' @param viridis.palette \strong{\code{\link[base]{character}}} | A capital letter from A to H or the scale name as in \link[viridis]{scale_fill_viridis}.
#' @param viridis.palette.pvalue,viridis.palette.logfc,viridis.palette.expression \strong{\code{\link[base]{character}}} | Viridis color palettes for the p-value, logfc and expression heatmaps. A capital letter from A to H or the scale name as in \link[viridis]{scale_fill_viridis}.
#' @param raster \strong{\code{\link[base]{logical}}} | Whether to raster the resulting plot. This is recommendable if plotting a lot of cells.
#' @param raster.dpi \strong{\code{\link[base]{numeric}}} | Pixel resolution for rasterized plots. Defaults to 1024. Only activates on Seurat versions higher or equal than 4.1.0.
#' @param plot_cell_borders \strong{\code{\link[base]{logical}}} | Whether to plot border around cells.
#' @param border.size \strong{\code{\link[base]{numeric}}} | Width of the border of the cells.
#' @param border.color \strong{\code{\link[base]{character}}} | Color for the border of the heatmap body.
#' @param na.value \strong{\code{\link[base]{character}}} | Color value for NA.
#' @param axis.text.x.angle \strong{\code{\link[base]{numeric}}} | Degree to rotate the X labels. One of: 0, 45, 90.
#' @param xlab,ylab \strong{\code{\link[base]{character}}} | Titles for the X and Y axis.
#' @param pt.size \strong{\code{\link[base]{numeric}}} | Size of the dots.
#' @param flip \strong{\code{\link[base]{logical}}} | Whether to invert the axis of the displayed plot.
#' @param verbose \strong{\code{\link[base]{logical}}} | Whether to show extra comments, warnings,etc.
#' @param group.by \strong{\code{\link[base]{character}}} | Metadata variable to group the output by. Has to be a character of factor column.
#' @param split.by \strong{\code{\link[base]{character}}} | Secondary metadata variable to further group (split) the output by. Has to be a character of factor column.
#' @param colors.use \strong{\code{\link[SCpubr]{named_vector}}} | Named vector of valid color representations (either name of HEX codes) with as many named colors as unique values of group.by. If group.by is not provided, defaults to the unique values of \link[Seurat]{Idents}. If not provided, a color scale will be set by default.
#' @param plot_marginal_distributions \strong{\code{\link[base]{logical}}} | Whether to plot marginal distributions on the figure or not.
#' @param marginal.type \strong{\code{\link[base]{character}}} | One of:
#' \itemize{
#' \item \emph{\code{density}}: Compute density plots on the margins.
#' \item \emph{\code{histogram}}: Compute histograms on the margins.
#' \item \emph{\code{boxplot}}: Compute boxplot on the margins.
#' \item \emph{\code{violin}}: Compute violin plots on the margins.
#' \item \emph{\code{densigram}}: Compute densigram plots on the margins.
#' }
#' @param marginal.size \strong{\code{\link[base]{numeric}}} | Size ratio between the main and marginal plots. A value of 5 means that the main plot is 5 times bigger than the marginal plots.
#' @param marginal.group \strong{\code{\link[base]{logical}}} | Whether to group the marginal distribution by group.by or current identities.
#' @param enforce_symmetry \strong{\code{\link[base]{logical}}} | Return a symmetrical plot axes-wise or continuous color scale-wise, when applicable.
#' @param column_title \strong{\code{\link[base]{character}}} | Title for the columns of the heatmaps. Only works with single heatmaps.
#' @param row_title \strong{\code{\link[base]{character}}} | Title for the rows of the heatmaps. Only works with single heatmaps.
#' @param cluster_cols \strong{\code{\link[base]{logical}}} | Cluster the columns or rows of the heatmaps.
#' @param cluster_rows \strong{\code{\link[base]{logical}}} | Cluster the rows or rows of the heatmaps.
#' @param column_names_rot \strong{\code{\link[base]{numeric}}} | Degree in which to rotate the column labels.
#' @param row_names_rot \strong{\code{\link[base]{numeric}}} | Degree in which to rotate the row labels.
#' @param cell_size \strong{\code{\link[base]{numeric}}} | Size of each cell in the heatmap.
#' @param input_gene_list \strong{\code{\link[SCpubr]{named_list}}} | Named list of lists of genes to be used as input.
#' @param column_title_rot \strong{\code{\link[base]{numeric}}} | Degree in which to rotate the column titles.
#' @param row_title_rot \strong{\code{\link[base]{numeric}}} | Degree in which to rotate the row titles.
#' @param column_names_side \strong{\code{\link[base]{character}}} | Side to put the column names. Either left or right.
#' @param row_names_side \strong{\code{\link[base]{character}}} | Side to put the row names. Either left or right.
#' @param column_title_side \strong{\code{\link[base]{character}}} | Side to put the column titles Either left or right.
#' @param row_title_side \strong{\code{\link[base]{character}}} | Side to put the row titles Either left or right.
#' @param heatmap.legend.length,heatmap.legend.width \strong{\code{\link[base]{numeric}}} | Width and length of the legend in the heatmap.
#' @param heatmap.legend.framecolor \strong{\code{\link[base]{character}}} | Color of the edges and ticks of the legend in the heatmap.
#' @param scale_direction \strong{\code{\link[base]{numeric}}} | Direction of the viridis scales. Either -1 or 1.
#' @param heatmap_gap \strong{\code{\link[base]{numeric}}} | Gap in cm between heatmaps.
#' @param legend_gap \strong{\code{\link[base]{numeric}}} | Gap in cm between legends.
#' @param cells.highlight,idents.highlight \strong{\code{\link[base]{character}}} | Vector of cells/identities to focus into. The identities have to much those in \code{Seurat::Idents(sample)} The rest of the cells will be grayed out. Both parameters can be used at the same time.
#' @param dims \strong{\code{\link[base]{numeric}}} | Vector of 2 numerics indicating the dimensions to plot out of the selected reduction. Defaults to c(1, 2) if not specified.
#' @param ncol \strong{\code{\link[base]{numeric}}} | Number of columns used in the arrangement of the output plot using "split.by" parameter.
#' @param features \strong{\code{\link[base]{character}}} | Features to represent.
#' @param feature \strong{\code{\link[base]{character}}} | Feature to represent.
#' @param use_viridis \strong{\code{\link[base]{logical}}} | Whether to use viridis color scales.
#' @param viridis.direction \strong{\code{\link[base]{numeric}}} | Either 1 or -1. Controls how the gradient of viridis scale is formed.
#' @param plot.grid \strong{\code{\link[base]{logical}}} | Whether to plot grid lines.
#' @param grid.color \strong{\code{\link[base]{character}}} | Color of the grid in the plot. In heatmaps, color of the border of the cells.
#' @param grid.type \strong{\code{\link[base]{character}}} | One of the possible linetype options:
#' \itemize{
#' \item \emph{\code{blank}}.
#' \item \emph{\code{solid}}.
#' \item \emph{\code{dashed}}.
#' \item \emph{\code{dotted}}.
#' \item \emph{\code{dotdash}}.
#' \item \emph{\code{longdash}}.
#' \item \emph{\code{twodash}}.
#' }
#' @param plot.axes \strong{\code{\link[base]{logical}}} | Whether to plot axes or not.
#' @param nbin \strong{\code{\link[base]{numeric}}} | Number of bins to use in \link[Seurat]{AddModuleScore}.
#' @param ctrl \strong{\code{\link[base]{numeric}}} | Number of genes in the control set to use in \link[Seurat]{AddModuleScore}.
#' @param repel \strong{\code{\link[base]{logical}}} | Whether to repel the text labels.
#' @param plot_density_contour \strong{\code{\link[base]{logical}}} | Whether to plot density contours in the UMAP.
#' @param contour.position \strong{\code{\link[base]{character}}} | Whether to plot density contours on top or at the bottom of the visualization layers, thus overlapping the clusters/cells or not.
#' @param contour.color \strong{\code{\link[base]{character}}} | Color of the density lines.
#' @param contour.lineend \strong{\code{\link[base]{character}}} | Line end style (round, butt, square).
#' @param contour.linejoin \strong{\code{\link[base]{character}}} | Line join style (round, mitre, bevel).
#' @param contour_expand_axes \strong{\code{\link[base]{numeric}}} | To make the contours fit the plot, the limits of the X and Y axis are expanding a given percentage from the min and max values for each axis. This controls such percentage.
#' @param min.cutoff,max.cutoff \strong{\code{\link[base]{numeric}}} | Set the min/max ends of the color scale. Any cell/group with a value lower than min.cutoff will turn into min.cutoff and any cell with a value higher than max.cutoff will turn into max.cutoff. In FeaturePlots, provide as many values as features. Use NAs to skip a feature.
#' @param label \strong{\code{\link[base]{logical}}} | Whether to plot the cluster labels in the UMAP. The cluster labels will have the same color as the cluster colors.
#' @param label.color \strong{\code{\link[base]{character}}} | Color of the labels in the plot.
#' @param label.fill \strong{\code{\link[base]{character}}} | Color to fill the labels. Has to be a single color, that will be used for all labels. If \strong{\code{NULL}}, the colors of the clusters will be used instead.
#' @param label.size \strong{\code{\link[base]{numeric}}} | Size of the labels in the plot.
#' @param label.box \strong{\code{\link[base]{logical}}} | Whether to plot the plot labels as \strong{\code{\link[ggplot2]{geom_text}}} (FALSE) or \strong{\code{\link[ggplot2]{geom_label}}} (TRUE).
#' @param min.overlap \strong{\code{\link[base]{numeric}}} | Filter the output result to the terms which are supported by this many genes.
#' @param GO_ontology \strong{\code{\link[base]{character}}} | GO ontology to use. One of:
#' \itemize{
#' \item \emph{\code{BP}}: For \strong{B}iological \strong{P}rocess.
#' \item \emph{\code{MF}}: For \strong{M}olecular \strong{F}unction.
#' \item \emph{\code{CC}}: For \strong{C}ellular \strong{C}omponent.
#' }
#' @param genes \strong{\code{\link[base]{character}}} | Vector of gene symbols to query for functional annotation.
#' @param org.db \strong{\code{OrgDB}} | Database object to use for the query.
#' @param disable_white_in_viridis \strong{\code{\link[base]{logical}}} | Remove the white in viridis color scale when \strong{\code{viridis.direction}} is set to -1.
#' @param number.breaks \strong{\code{\link[base]{numeric}}} | Controls the number of breaks in continuous color scales of ggplot2-based plots.
#' @param border.density \strong{\code{\link[base]{numeric}}} | Controls the number of cells used when \strong{\code{plot_cell_borders = TRUE}}. Value between 0 and 1. It computes a 2D kernel density and based on this cells that have a density below the specified quantile will be used to generate the cluster contour. The lower this number, the less cells will be selected, thus reducing the overall size of the plot but also potentially preventing all the contours to be properly drawn.
#' @param strip.spacing \strong{\code{\link[base]{numeric}}} | Controls the size between the different facets.
#' @param strip.text.color \strong{\code{\link[base]{character}}} | Color of the strip text.
#' @param strip.text.angle \strong{\code{\link[base]{numeric}}} | Rotation of the strip text (angles).
#' @param diverging.palette \strong{\code{\link[base]{character}}} | Type of symmetrical color palette to use. Out of the diverging palettes defined in \strong{\code{\link[RColorBrewer]{brewer.pal}}}.
#' @param diverging.direction \strong{\code{\link[base]{numeric}}} | Either 1 or -1. Direction of the divering palette. This basically flips the two ends.
#' @param sequential.palette \strong{\code{\link[base]{character}}} | Type of sequential color palette to use. Out of the sequential palettes defined in \strong{\code{\link[RColorBrewer]{brewer.pal}}}.
#' @param sequential.palette.pvalue,sequential.palette.expression,sequential.palette.logfc \strong{\code{\link[base]{character}}} | Sequential palettes for p-value, logfc and expression heatmaps. Type of sequential color palette to use. Out of the sequential palettes defined in \strong{\code{\link[RColorBrewer]{brewer.pal}}}.
#' @param sequential.direction \strong{\code{\link[base]{numeric}}} | Direction of the sequential color scale. Either 1 or -1.
#' @param return_object \strong{\code{\link[base]{logical}}} | Returns the Seurat object with the modifications performed in the function. Nomally, this contains a new assay with the data that can then be used for any other visualization desired.
#' @param statistic \strong{\code{\link[base]{character}}} | DecoupleR statistic to use. One of:
#' \itemize{
#' \item \emph{\code{wmean}}: For weighted mean.
#' \item \emph{\code{norm_wmean}}: For normalized weighted mean.
#' \item \emph{\code{corr_wmean}}: For corrected weighted mean.
#' }
#' @param subsample \strong{\code{\link[base]{numeric}}} | Number of cells to randomly select from the Seurat object to enhance performance. Selecting NA will disable this but might lead to function breaks if the sample size is too large.
#' @param cluster \strong{\code{\link[base]{logical}}} | Whether to perform clustering of rows and columns.
#' @param subsample \strong{\code{\link[base]{numeric}}} | Number of cells to subset for the analysis. NA will use all. Cells are selected at random.
#' @param plot.title.face,plot.subtitle.face,plot.caption.face,axis.title.face,axis.text.face,legend.title.face,legend.text.face \strong{\code{\link[base]{character}}} | Controls the style of the font for the corresponding theme element. One of:
#' \itemize{
#' \item \emph{\code{plain}}: For normal text.
#' \item \emph{\code{italic}}: For text in itallic.
#' \item \emph{\code{bold}}: For text in bold.
#' \item \emph{\code{bold.italic}}: For text both in itallic and bold.
#' }
#' @param strip.text.face \strong{\code{\link[base]{character}}} | Controls the style of the font for the strip text. One of:
#' \itemize{
#' \item \emph{\code{plain}}: For normal text.
#' \item \emph{\code{italic}}: For text in itallic.
#' \item \emph{\code{bold}}: For text in bold.
#' \item \emph{\code{bold.italic}}: For text both in itallic and bold.
#' }
#' @param flavor \strong{\code{\link[base]{character}}} | One of: Seurat, UCell. Compute the enrichment scores using \link[Seurat]{AddModuleScore} or \link[UCell]{AddModuleScore_UCell}.
#' @param features.order \strong{\code{\link[base]{character}}} | Should the gene sets be ordered in a specific way? Provide it as a vector of characters with the same names as the names of the gene sets.
#' @param groups.order \strong{\code{\link[SCpubr]{named_list}}} | Should the groups in theheatmaps be ordered in a specific way? Provide it as a named list (as many lists as values in \strong{\code{group.by}}) with the order for each of the elements in the groups.
#' @param interpolate \strong{\code{\link[base]{logical}}} | Smoothes the output heatmap, saving space on disk when saving the image. However, the image is not as crisp.
#' @param order \strong{\code{\link[base]{logical}}} | Whether to order the boxplots by average values. Can not be used alongside split.by.
#' @param dot.scale \strong{\code{\link[base]{numeric}}} | Scale the size of the dots.
#' @usage NULL
#' @return Nothing. This is a mock function.
#' @keywords internal
#' @examples
#'
#' # This a mock function that stores the documentation for many other functions.
#' # It is not intended for user usage.
doc_function <- function(sample,
font.size,
font.type,
legend.type,
legend.position,
legend.framewidth,
legend.tickwidth,
legend.framecolor,
legend.tickcolor,
legend.length,
legend.width,
plot.title,
plot.subtitle,
plot.caption,
assay,
slot,
reduction,
viridis.palette,
raster,
raster.dpi,
plot_cell_borders,
border.size,
border.color,
na.value,
axis.text.x.angle,
xlab,
ylab,
pt.size,
verbose,
flip,
group.by,
split.by,
colors.use,
legend.title,
legend.icon.size,
legend.byrow,
legend.ncol,
legend.nrow,
plot_marginal_distributions,
marginal.type,
marginal.size,
marginal.group,
enforce_symmetry,
column_title,
row_title,
cluster_cols,
cluster_rows,
column_names_rot,
row_names_rot,
cell_size,
input_gene_list,
column_title_rot,
row_title_rot,
column_names_side,
row_names_side,
column_title_side,
row_title_side,
heatmap.legend.length,
heatmap.legend.width,
heatmap.legend.framecolor,
scale_direction,
heatmap_gap,
legend_gap,
cells.highlight,
idents.highlight,
ncol,
dims,
feature,
features,
use_viridis,
viridis.direction,
plot.grid,
grid.color,
grid.type,
plot.axes,
individual.titles,
individual.subtitles,
individual.captions,
legend.title.position,
repel,
plot_density_contour,
contour.position,
contour.color,
contour.lineend,
contour.linejoin,
contour_expand_axes,
label,
label.color,
label.fill,
label.size,
label.box,
min.overlap,
GO_ontology,
genes,
org.db,
disable_white_in_viridis,
number.breaks,
strip.spacing,
strip.text.color,
strip.text.angle,
diverging.palette,
diverging.direction,
subsample,
plot.title.face,
plot.subtitle.face,
plot.caption.face,
axis.title.face,
axis.text.face,
legend.title.face,
legend.text.face,
flavor,
features.order,
groups.order,
interpolate,
order,
dot.scale){}
#' Named vector.
#'
#' @return Nothing. This is a mock function.
#' @keywords internal
#' @usage NULL
#' @examples
#' # This is a named vector.
#' x <- c("first_element" = 3,
#' "second_element" = TRUE)
#' print(x)
#'
named_vector <- function(){}
#' Named list.
#'
#' @return Nothing. This is a mock function.
#' @keywords internal
#' @usage NULL
#' @examples
#' # This is a named vector.
#' x <- list("first_element" = c("GENE A", "GENE B"),
#' "second_element" = c("GENE C", "GENE D"))
#' print(x)
#'
named_list <- function(){}
# Operators.
# Not in operator.
`%!in%` <- function(x, y) {return(!(x %in% y))}
# nocov start
crayon_body <- function(text){
return(cli::col_none(text))
}
add_star <- function(initial_newline = TRUE){
if (isTRUE(requireNamespace("cli", quietly = TRUE))){
return(paste0(ifelse(isTRUE(initial_newline), "\n\n", ""), cli::col_yellow(cli::style_bold(cli::symbol$star)), " "))
} else {
return("* ")
}
}
add_info <- function(initial_newline = TRUE){
if (isTRUE(requireNamespace("cli", quietly = TRUE))){
return(paste0(ifelse(isTRUE(initial_newline), "\n\n", ""), cli::col_cyan(cli::style_bold(cli::symbol$info)), " "))
} else {
return("i ")
}
}
add_cross <- function(initial_newline = TRUE){
if (isTRUE(requireNamespace("cli", quietly = TRUE))){
return(paste0(ifelse(isTRUE(initial_newline), "\n\n", ""), cli::col_red(cli::style_bold(cli::symbol$cross)), " "))
} else {
return("x ")
}
}
add_warning <- function(initial_newline = TRUE){
if (isTRUE(requireNamespace("cli", quietly = TRUE))){
return(paste0(ifelse(isTRUE(initial_newline), "\n", ""), cli::col_yellow(cli::style_bold("!")), " "))
} else {
return("! ")
}
}
add_tick <- function(initial_newline = TRUE){
if (isTRUE(requireNamespace("cli", quietly = TRUE))){
return(paste0(ifelse(isTRUE(initial_newline), "\n\n", ""), cli::col_green(cli::style_bold(cli::symbol$tick)), " "))
} else {
return("")
}
}
crayon_key <- function(text){
return(cli::col_green(text))
}
# nocov end
#' Return a list of SCpubr dependencies.
#'
#' @noRd
#' @return None
#' @examples
#' \donttest{
#' TBD
#' }
return_dependencies <- function(){
pkg_list <- list("Essentials" = c("Seurat",
"SeuratObject",
"rlang",
"dplyr",
"magrittr",
"dplyr",
"tidyr",
"tibble",
"stringr",
"ggplot2",
"patchwork",
"plyr",
"viridis",
"forcats",
"scales",
"assertthat",
"RColorBrewer",
"labeling",
"withr"),
"do_AffinityAnalysisPlot" = "decoupleR",
"do_AlluvialPlot" = "ggalluvial",
"do_BarPlot" = c("colorspace", "ggrepel"),
"do_BeeSwarmPlot" = c("colorspace", "ggbeeswarm", "ggrastr"),
"do_BoxPlot" = "ggsignif",
"do_CellularStatesPlot" = c("pbapply", "ggExtra", "ggplotify", "scattermore"),
"do_ChordDiagramPlot" = "circlize",
"do_ColorPalette" = NULL,
"do_CopyNumberVariantPlot" = "ggdist",
"do_CorrelationPlot" = NULL,
"do_DimPlot" = c("colorspace", "ggplotify", "scattermore"),
"do_DotPlot" = NULL,
"do_EnrichmentHeatmap" = c("UCell"),
"do_ExpressionHeatmap" = NULL,
"do_FeaturePlot" = c("scattermore", "MASS"),
"do_GeyserPlot" = "ggdist",
"do_GroupwiseDEPlot" = NULL,
"do_MetadataPlot" = "cluster",
"do_LigandReceptorPlot" = "liana",
"do_LoadingsPlot" = NULL,
"do_DiffusionMapPlot" = "Matrix",
"do_NebulosaPlot" = "Nebulosa",
"do_PathwayActivityPlot" = NULL,
"do_RidgePlot" = "ggridges",
"do_SCExpressionHeatmap" = NULL,
"do_SCEnrichmentHeatmap" = c("UCell"),
"do_TermEnrichmentPlot" = c("enrichplot"),
"do_TFActivityPlot" = NULL,
"do_ViolinPlot" = NULL,
"do_VolcanoPlot" = "ggrepel",
"do_WafflePlot" = "waffle",
"save_Plot" = "svglite")
return(pkg_list)
}
#' Checks for Suggests.
#'
#' @noRd
#' @return None
#' @examples
#' \donttest{
#' TBD
#' }
check_suggests <- function(function_name, passive = FALSE){
pkg_list <- return_dependencies()
# The function is not in the current list of possibilities.
if (function_name %!in% names(pkg_list)){
stop(paste0(add_cross(), crayon_key(function_name), crayon_body(" is not an accepted function name.")), call. = FALSE)
}
pkgs <- c(pkg_list[[function_name]], pkg_list[["Essentials"]])
non_seurat_functions <- c("save_Plot",
"do_VolcanoPlot",
"do_LigandReceptorPlot",
"do_ColorPalette")
if (function_name %in% non_seurat_functions){
pkgs <- pkgs[!(pkgs %in% c("Seurat", "SeuratObject"))]
}
pkgs <- vapply(pkgs, requireNamespace, quietly = TRUE, FUN.VALUE = logical(1))
# nocov start
if(sum(!pkgs) > 0){
missing_pkgs <- names(pkgs[vapply(pkgs, function(x){base::isFALSE(x)}, FUN.VALUE = logical(1))])
if (base::isFALSE(passive)){
stop(paste0(add_cross(), crayon_body("Packages "),
paste(vapply(missing_pkgs, crayon_key, FUN.VALUE = character(1)), collapse = crayon_body(", ")),
crayon_body(" must be installed to use "),
crayon_key(function_name),
crayon_body(".")), call. = FALSE)
}
}
value <- if(sum(pkgs) != length(pkgs)){FALSE} else {TRUE}
if (isTRUE(passive)) {return(value)}
# nocov end
}
#' Generate a status report of SCpubr and its dependencies.
#'
#' This function generates a summary report of the installation status of SCpubr, which packages are still missing and which functions can or can not currently be used.
#'
#' @param startup \strong{\code{\link[base]{logical}}} | Whether the message should be displayed at startup, therefore, also containing welcoming messages and tips. If \strong{\code{FALSE}}, only the report itself will be printed.
#' @param extended \strong{\code{\link[base]{logical}}} | Whether the message should also include installed packages, current and available version, and which \strong{\code{SCpubr}} functions can be used with the currently installed packages.
#' @return None
#' @export
#'
#' @examples
#'
#' \donttest{
#' # Print a package report.
#' SCpubr::package_report(startup = FALSE, extended = FALSE)
#' }
package_report <- function(startup = FALSE,
extended = FALSE){
# nocov start
if (base::isFALSE(requireNamespace("cli", quietly = TRUE)) | base::isFALSE(requireNamespace("rlang", quietly = TRUE))){
if (base::isFALSE(startup)){
message(paste(rep("-", 63), collapse = ""))
message('This is a placeholder message. Please install "cli" and "rlang" packages to have an optimal experience using the package.')
message(paste(rep("-", 63), collapse = ""))
} else if(isTRUE(startup)){
packageStartupMessage(paste(rep("-", 63), collapse = ""))
packageStartupMessage('This is a placeholder message. Please install "cli" and "rlang" packages to have an optimal experience using the package.')
packageStartupMessage(paste(rep("-", 63), collapse = ""))
packageStartupMessage("\n\n\nSCpubr")
packageStartupMessage("\nIf you use SCpubr in your research, please cite it accordingly: \nBlanco-Carmona, E. Generating publication ready visualizations for Single Cell transcriptomics using SCpubr. bioRxiv (2022) doi:10.1101/2022.02.28.482303.\n")
packageStartupMessage("If the package is useful to you, consider leaving a Star in the GitHub repo: https://github.com/enblacar/SCpubr/stargazers \n")
packageStartupMessage("Keep track of the package updates on Twitter (@Enblacar) or in https://github.com/enblacar/SCpubr/blob/main/NEWS.md \n")
packageStartupMessage("To suppress this startup message, use: \nsuppressPackageStartupMessages(library('SCpubr'))")
packageStartupMessage(paste(rep("-", 63), collapse = ""))
}
} else {
# nocov end
tip_rule <- cli::rule(left = "General", width = nchar("General") + 6)
tutorials <- paste0(add_info(initial_newline = FALSE),
crayon_body("Have a look at extensive tutorials in "),
crayon_key(cli::style_hyperlink(text = "SCpubr's book",
url = "https://enblacar.github.io/SCpubr-book/")),
crayon_body("."))
cite <- paste0(add_tick(initial_newline = FALSE),
crayon_body("If you use "),
crayon_key("SCpubr"),
crayon_body(" in your research, please "),
crayon_key(cli::style_hyperlink(text = "cite it accordingly",
url = "https://www.biorxiv.org/content/10.1101/2022.02.28.482303v1")),
crayon_body("."))
stars <- paste0(add_star(initial_newline = FALSE),
crayon_body("If the package is useful to you, consider leaving a "),
crayon_key("Star"),
crayon_body(" in the "),
crayon_key(cli::style_hyperlink(text = "GitHub repository",
url = "https://github.com/enblacar/SCpubr")),
crayon_body("."))
updates <- paste0(cli::style_bold(cli::col_blue("!")),
crayon_body(" Keep track of the package "),
crayon_key("updates"),
crayon_body(" on Twitter ("),
crayon_key(cli::style_hyperlink(text = "@Enblacar",
url = "https://twitter.com/Enblacar")),
crayon_body(") or in the "),
crayon_key(cli::style_hyperlink(text = "Official NEWS website",
url = "https://github.com/enblacar/SCpubr/blob/main/NEWS.md")),
crayon_body("."))
plotting <- paste0(cli::style_bold(cli::col_red(cli::symbol$heart)), " ", crayon_body("Happy plotting!"))
header <- cli::rule(left = paste0(crayon_body("SCpubr "),
crayon_key(utils::packageVersion("SCpubr"))), line_col = "cadetblue")
if (isTRUE(extended)){
format_package_name <- function(package,
max_length_packages){
length.use <- max_length_packages - nchar(package)
package.use <- paste0(package, paste(rep(" ", length.use), collapse = ""))
if (isTRUE(requireNamespace(package, quietly = TRUE))){
if ((package == "ggplot2") & (utils::packageVersion(package) < "3.4.0")){
name <- paste0(cli::col_yellow(cli::style_bold("!")),
" ",
cli::col_magenta(package.use))
} else if ((package == "dplyr") & (utils::packageVersion(package) < "1.1.0")){
name <- paste0(cli::col_yellow(cli::style_bold("!")),
" ",
cli::col_magenta(package.use))
} else {
name <- paste0(cli::col_green(cli::symbol$tick),
crayon_body(" "),
crayon_body(package.use))
}
return(name)
} else {
return(paste0(cli::col_red(cli::symbol$cross),
crayon_body(" "),
cli::col_red(package.use)))
}
}
packages <- sort(unique(unlist(return_dependencies())))
max_length_packages <- max(vapply(packages, nchar, FUN.VALUE = numeric(1)))
packages_mod <- vapply(packages, function(x){format_package_name(x,
max_length_packages = max_length_packages)}, FUN.VALUE = character(1))
functions <- sort(unique(names(return_dependencies())))
if (rev(strsplit(as.character( as.character(utils::packageVersion("SCpubr"))), split = "\\.")[[1]])[1] >= 9000){
names.use <- unname(vapply(functions, function(x){if (x %in% c("do_LigandReceptorPlot",
"save_Plot",
"do_MetadataPlot",
"do_SCExpressionHeatmap",
"do_SCEnrichmentHeatmap",
"do_AffinityAnalysisPlot",
"do_DiffusionMapPlot",
"do_LoadingsPlot")){x <- paste0(x, cli::col_cyan(" | DEV"))} else {x}}, FUN.VALUE = character(1)))
functions <- vapply(functions, check_suggests, passive = TRUE, FUN.VALUE = logical(1))
names(functions) <- names.use
# nocov start
} else {
functions <- functions[!(functions %in% c("do_LigandReceptorPlot",
"save_Plot",
"do_MetadataPlot",
"do_SCExpressionHeatmap",
"do_SCEnrichmentHeatmap",
"do_AffinityAnalysisPlot",
"do_DiffusionMapPlot",
"do_LoadingsPlot"))]
functions <- vapply(functions, check_suggests, passive = TRUE, FUN.VALUE = logical(1))
}
# nocov end
functions <- functions[names(functions) != "Essentials"]
max_length_functions <- max(vapply(names(functions), nchar, FUN.VALUE = numeric(1)))
format_functions <- function(name, value, max_length){
func_use <- ifelse(isTRUE(value), cli::col_green(cli::symbol$tick), cli::col_red(cli::symbol$cross))
name_use <- ifelse(isTRUE(value),
cli::ansi_align(crayon_body(name), max_length, align = "left"),
cli::ansi_align(cli::col_red(name), max_length, align = "left"))
paste0(func_use, " ", name_use)
}
functions.use <- NULL
for(item in names(functions)){
functions.use <- append(functions.use, format_functions(name = item, value = functions[[item]], max_length = max_length_functions))
}
counter <- 0
print.list <- list()
print.list.functions <- list()
print.vector <- NULL
print.vector.functions <- NULL
for(item in packages_mod){
counter <- counter + 1
if (counter %% 4 != 0){
print.vector <- append(print.vector, item)
if (counter == length(packages)){
print.list[[item]] <- paste(print.vector, collapse = " ")
print.vector <- NULL
}
} else {
print.vector <- append(print.vector, item)
print.list[[item]] <- paste(print.vector, collapse = " ")
print.vector <- NULL
}
}
counter <- 0
for(item in functions.use){
counter <- counter + 1
if (counter %% 3 != 0){
print.vector.functions <- append(print.vector.functions, item)
if (counter == length(functions.use)){
print.list.functions[[item]] <- paste(print.vector.functions, collapse = " ")
}
} else {
print.vector.functions <- append(print.vector.functions, item)
print.list.functions[[item]] <- paste(print.vector.functions, collapse = " ")
print.vector.functions <- NULL
}
}
packages_check <- cli::rule(left = "Required packages", width = nchar("Required packages") + 6)
packages_tip1 <- paste0(cli::style_bold(cli::col_cyan(cli::symbol$info)),
crayon_body(" Installed packages are denoted by a "),
crayon_key("tick"),
crayon_body(" ("),
cli::style_bold(cli::col_green(cli::symbol$tick)),
crayon_body(") and missing packages by a "),
cli::col_red("cross"),
crayon_body(" ("),
cli::style_bold(cli::col_red(cli::symbol$cross)),
crayon_body(")."))
packages_tip2 <- paste0(cli::style_bold(cli::col_cyan(cli::symbol$info)),
crayon_body(" Installed packages that still require an update to correctly run "),
crayon_key("SCpubr"),
crayon_body(" have an "),
crayon_key("exclamation mark"),
crayon_body(" ("),
cli::style_bold(cli::col_yellow("!")),
crayon_body(")."))
functions_check <- cli::rule(left = "Available functions", width = nchar("Available functions") + 6)
functions_tip1 <- paste0(cli::style_bold(cli::col_cyan(cli::symbol$info)),
crayon_body(" Functions tied to "),
crayon_key("development"),
crayon_body(" builds of "),
crayon_key("SCpubr"),
crayon_body(" are marked by the ("),
cli::style_bold(cli::col_cyan("| DEV")),
crayon_body(") tag."))
functions_tip2 <- paste0(cli::style_bold(cli::col_cyan(cli::symbol$info)),
crayon_body(" You can install development builds of "),
crayon_key("SCpubr"),
crayon_body(" by following the instructions in the "),
crayon_key(cli::style_hyperlink(text = "Releases",
url = "https://github.com/enblacar/SCpubr/releases")),
crayon_body(" page."))
functions_tip3 <- paste0(cli::style_bold(cli::col_cyan(cli::symbol$info)),
crayon_body(" Check the package requirements function-wise with: "),
cli::style_italic(crayon_key('SCpubr:::return_dependencies()')))
}
tip_rule <- cli::rule(left = "Tips!", width = nchar("Tips!") + 6)
tip_message <- paste0(cli::style_bold(cli::col_cyan(cli::symbol$info)),
crayon_body(" To remove the white and black end from continuous palettes, use: "),
cli::style_italic(crayon_key('options("SCpubr.ColorPaletteEnds" = FALSE)')))
disable_message <- paste0(cli::style_bold(cli::col_red(cli::symbol$cross)),
crayon_body(" To suppress this startup message, use: "),
cli::style_italic(crayon_key('suppressPackageStartupMessages(library(SCpubr))\n')),
cli::style_bold(cli::col_red(cli::symbol$cross)),
crayon_body(" Alternatively, you can also set the following option: "),
cli::style_italic(crayon_key('options("SCpubr.verbose" = FALSE)\n')),
crayon_body(" And then load the package normally (and faster) as: "),
cli::style_italic(crayon_key('library(SCpubr)')))
end_rule <- cli::rule(col = "cadetblue")
# Mount all individual messages into a big one that will be then be printed as a packageStartupMessage.
if (isTRUE(startup)){
if (isTRUE(extended)){
msg_wrap <- paste0("\n", "\n",
header, "\n", "\n",
tutorials, "\n", "\n",
cite, "\n", "\n",
stars, "\n", "\n",
updates, "\n", "\n",
plotting, "\n", "\n", "\n", "\n",
packages_check, "\n", "\n",
paste(print.list, collapse = "\n"), "\n", "\n",
packages_tip1, "\n",
packages_tip2, "\n", "\n", "\n", "\n",
functions_check, "\n", "\n",
paste(print.list.functions, collapse = "\n"), "\n", "\n",
functions_tip1, "\n",
functions_tip2, "\n",
functions_tip3, "\n", "\n", "\n", "\n",
tip_rule, "\n", "\n",
tip_message, "\n", "\n",
disable_message, "\n", "\n",
end_rule)
} else {
msg_wrap <- paste0("\n", "\n",
header, "\n", "\n",
tutorials, "\n", "\n",
cite, "\n", "\n",
stars, "\n", "\n",
updates, "\n", "\n",
plotting, "\n", "\n", "\n", "\n",
tip_rule, "\n", "\n",
tip_message, "\n", "\n",
disable_message, "\n", "\n",
end_rule)
}
rlang::inform(msg_wrap, class = "packageStartupMessage")
} else if (base::isFALSE(startup)){
if (isTRUE(extended)){
msg_wrap <- paste0("\n", "\n",
header, "\n", "\n",
packages_check, "\n", "\n",
paste(print.list, collapse = "\n"), "\n", "\n",
packages_tip1, "\n",
packages_tip2, "\n", "\n", "\n", "\n",
functions_check, "\n", "\n",
paste(print.list.functions, collapse = "\n"), "\n", "\n",
functions_tip1, "\n",
functions_tip2, "\n",
functions_tip3, "\n", "\n", "\n", "\n",
tip_rule, "\n", "\n",
tip_message, "\n", "\n",
disable_message, "\n", "\n",
end_rule)
} else {
msg_wrap <- paste0("\n", "\n",
header, "\n", "\n",
tutorials, "\n", "\n",
cite, "\n", "\n",
stars, "\n", "\n",
updates, "\n", "\n",
plotting, "\n", "\n", "\n", "\n",
tip_rule, "\n", "\n",
tip_message, "\n", "\n",
disable_message, "\n", "\n",
end_rule)
}
rlang::inform(msg_wrap)
}
}
}
#' Check for Seurat class.
#'
#' @param sample Seurat object.
#'
#' @noRd
#' @return None
#'
#' @examples
#' \donttest{
#' TBD
#' }
check_Seurat <- function(sample){
assertthat::assert_that("Seurat" %in% class(sample),
msg = paste0(add_cross(), crayon_body("The provided "),
crayon_key("object"),
crayon_body(" is not a "),
crayon_key("Seurat"),
crayon_body(" object.")))
}
#' Internal check for colors.
#'
#' Adapted from: https://stackoverflow.com/a/13290832.
#
#' @param colors Vector of colors.
#' @param parameter_name The name of the parameter for which we are testing the colors.
#' @return None
#' @noRd
#' @examples
#' \donttest{
#' TBD
#' }
check_colors <- function(colors, parameter_name = "") {
check <- vapply(colors, function(color) {
tryCatch(is.matrix(grDevices::col2rgb(colors)),
error = function(e) FALSE)
}, FUN.VALUE = logical(1))
# Check for cols.highlight.
assertthat::assert_that(sum(check) == length(colors),
msg = paste0(add_cross(), crayon_body("The colors provided to "),
crayon_key(parameter_name),
crayon_body(" are not valid color representations.\nCheck whether they are accepted "),
crayon_key("R nammes"),
crayon_body(" or "),
crayon_key("HEX codes"),
crayon_body(".")))
}
#' Internal check for named colors and unique values of the grouping variable.
#'
#' @param sample Seurat object.
#' @param colors Named vector of colors.
#' @param grouping_variable Metadata variable in sample to obtain its unique values.
#' @param idents.keep Identities to keep from the grouping_variable.
#' @return None
#' @noRd
#' @examples
#' \donttest{
#' TBD
#' }
check_consistency_colors_and_names <- function(sample, colors, grouping_variable = NULL, idents.keep = NULL){
# Add lengthy error messages.
withr::local_options(.new = list("warning.length" = 8170))
if (is.null(grouping_variable)){
check_values <- levels(sample)
} else {
if (is.factor(sample@meta.data[, grouping_variable])){
check_values <- levels(sample@meta.data[, grouping_variable])
} else {
check_values <- as.character(unique(sample@meta.data[, grouping_variable]))
}
}
if (!is.null(idents.keep)){
# Remove unwanted idents.
check_values <- check_values[check_values %in% idents.keep]
}
# Remove NAs.
check_values <- check_values[!(is.na(check_values))]
# Remove values that are not in the vector.
if (sum(names(colors) %in% check_values) == length(check_values) & length(names(colors)) > length(check_values)){
colors <- colors[names(colors) %in% check_values]
}
if (base::isFALSE(length(colors) == length(check_values)) | base::isFALSE(sum(names(colors) %in% check_values) == length(check_values))){
format_colors <- function(name, value, colors, max_length){
if (name %in% names(colors)){
name <- paste(c(name, crayon_body(" | "), cli::col_cyan(paste0(colors[[name]]))), collapse = "")
}
func_use <- ifelse(isTRUE(value), cli::col_green(cli::symbol$tick), cli::col_red(cli::symbol$cross))
name_use <- ifelse(isTRUE(value),
cli::ansi_align(crayon_key(name), max_length, align = "left"),
cli::ansi_align(cli::col_red(name), max_length, align = "left"))
paste0(func_use, " ", name_use)
}
color_check <- vapply(check_values, function(x){ifelse(x %in% names(colors), TRUE, FALSE)}, FUN.VALUE = logical(1))
max_length <- max(vapply(check_values, nchar, FUN.VALUE = numeric(1)))
max_length_colors <- max(vapply(unname(colors), nchar, FUN.VALUE = numeric(1)))
length.use <- max_length + 3 + max_length_colors
colors.print <- NULL
for(item in sort(names(color_check))){
colors.print <- append(colors.print, format_colors(name = item, colors = colors, value = color_check[[item]], max_length = length.use))
}
msg <- paste0("\n", "\n",
add_cross(),
crayon_body("The "),
crayon_key("number"),
crayon_body(" or "),
crayon_key("names"),
crayon_body(" of the provided "),
crayon_key("colors"),
crayon_body(" is lower than the "),
crayon_key("number of unique values"),
crayon_body(" in "),
crayon_key("group.by"),
crayon_body(" (which defaults to "),
cli::style_italic(crayon_key("Seurat::Idents(sample)")),
crayon_body(" if "),
crayon_key("NULL"),
crayon_body(")."),
"\n",
add_cross(),
crayon_body("Please check that the "),
crayon_key("colors provided"),
crayon_body(" are a "),
crayon_key("named vector"),
crayon_body(" where the names are the "),
crayon_key("unique values"),
crayon_body(" to which you then assign the "),
crayon_key("colors"),
crayon_body(" to."),
"\n", "\n",
add_warning(),
crayon_body("Example: "),
cli::style_italic(crayon_key('colors.use = c("A" = "red", "B" = "blue")')),
"\n",
"\n", "\n",
crayon_body(cli::rule(left = paste0(crayon_key("Values"), crayon_body(" with an "), cli::col_cyan("assigned color")), width = nchar("Values with an assigned color") + 6)),
"\n", "\n",
paste(colors.print, collapse = "\n"), "\n", "\n")
stop(msg, call. = FALSE)
}
return(colors)
}
#' Generate custom color scale.
#'
#' @param names_use Vector of the names that will go alongside the color scale.
#' @return None
#' @noRd
#' @examples
#' \donttest{
#' TBD
#' }
generate_color_scale <- function(names_use){
# Generate a vector of colors equal to the number of identities in the sample.
colors <- colorspace::qualitative_hcl(length(names_use), palette = "Dark 3")
colors <- grDevices::col2rgb(colors)
colors <- grDevices::rgb2hsv(colors)
colors["v", ] <- colors["v", ] - 0.1
colors["s", ] <- colors["s", ] + 0.2
colors["s", ][colors["s", ] > 1] <- 1
colors <- grDevices::hsv(h = colors["h", ],