bnprks / BPCells

Scaling Single Cell Analysis to Millions of Cells
https://bnprks.github.io/BPCells
Other
166 stars 17 forks source link

[r] add peak track plotting #113

Closed immanuelazn closed 4 months ago

immanuelazn commented 4 months ago

Description

Added function for peak track plotting using trackplot_genome_annotations() Modularize code for determining vertical position for segments (trackplot_calculate_segment_height()), and creating continuous arrow segments (trackplot_create_arrow_segs()) in trackplot_gene().

Tests

Only added test case for function created for creating arrow segments creating continuous trackplot arrows works I think it would be hard to make a test for trackplot_calculate_segment_height() because it is intrinsically random. Certainly we set a seed but I'm not sure if future refactoring of the function would case a false positive on a regression.

Thoughts

The direction_by arrows don't necessarily follow the length of the segment as I would expect. I thought I could just do annotation_size/(2*sin(angle)) but it looks like it is bigger than expected when playing around with plot size. I think it could be due to the different coordinate systems of the x axis and the y axis, but I'm not 100%.

immanuelazn commented 4 months ago

Some example usages:


gr_ranges <- GRanges(
  seqnames = Rle(c("chr15")),
  ranges = IRanges(52771198:52806108)
)
start_example_1 = 52771100
end_example_1 = 52810000
test_peak_example <- GRanges(
  seqnames <- rep("chr15", 32),
  ranges = IRanges(c(seq.int(from = start_example, to=end_example, length.out=12),
                     seq.int(from=start_example, to=end_example, length.out=11),
                     seq.int(from=start_example, to=end_example, length.out=9)),
                   c(seq.int(from = as.integer(start_example+(end_example-start_example)/20),
                           to = as.integer(end_example + (end_example-start_example)/12),
                           length.out=12),
                     seq.int(from = as.integer(start_example+(end_example-start_example)/19),
                             to = as.integer(end_example + (end_example-start_example)/11),
                             length.out=11),
                     seq.int(from = as.integer(start_example+(end_example-start_example)/17),
                             to = as.integer(end_example + (end_example-start_example)/9),
                             length.out=9))),
  strand = strand(c(rep("+", 16), rep("-", 16))),
  score = seq.int(from = 10, to = 800, length.out=32),
  labels = c(LETTERS[1:16], LETTERS[1:16])
)
trackplot_genome_annotations(test_peak_example, gr_ranges)
trackplot_genome_annotations(test_peak_example, gr_ranges, annotation_size=10)
trackplot_genome_annotations(test_peak_example, gr_ranges, label_by = "labels")
trackplot_genome_annotations(test_peak_example, gr_ranges, label_by = "labels", 
                             color_by ="score")
trackplot_genome_annotations(test_peak_example, gr_ranges,label_by = "labels",
                             color_by ="score", direction_by = "strand")