...
|
...
|
@@ -380,14 +380,6 @@ setMethod("[", signature(x = "DataTrack"), function(x, i, j, ..., drop = FALSE)
|
380
|
380
|
}
|
381
|
381
|
return(x)
|
382
|
382
|
})
|
383
|
|
-setMethod("[", signature(x = "AlignedReadTrack"), function(x, i, j, ..., drop = TRUE) {
|
384
|
|
- if (x@coverageOnly) {
|
385
|
|
- stop("This AlignedReadTrack object contains coverage information only and can not be subset")
|
386
|
|
- }
|
387
|
|
- x@range <- x@range[i, , drop = drop]
|
388
|
|
- x <- setCoverage(x)
|
389
|
|
- return(x)
|
390
|
|
-})
|
391
|
383
|
|
392
|
384
|
## Split a RangeTrack or DataTrack by a factor or character
|
393
|
385
|
setMethod("split", signature("RangeTrack"),
|
...
|
...
|
@@ -399,19 +391,7 @@ setMethod("split", signature("RangeTrack"),
|
399
|
391
|
})
|
400
|
392
|
}
|
401
|
393
|
)
|
402
|
|
-setMethod("split", signature("AlignedReadTrack"),
|
403
|
|
- definition = function(x, f, ...) {
|
404
|
|
- if (x@coverageOnly) {
|
405
|
|
- stop("This AlignedReadTrack object contains coverage information only and can not be split")
|
406
|
|
- }
|
407
|
|
- rs <- split(ranges(x), factor(f))
|
408
|
|
- lapply(rs, function(y) {
|
409
|
|
- x@range <- y
|
410
|
|
- x <- setCoverage(x)
|
411
|
|
- return(x)
|
412
|
|
- })
|
413
|
|
- }
|
414
|
|
-)
|
|
394
|
+
|
415
|
395
|
setMethod("split", signature("DataTrack"),
|
416
|
396
|
definition = function(x, f, ...) {
|
417
|
397
|
f <- factor(f)
|
...
|
...
|
@@ -427,14 +407,6 @@ setMethod("split", signature("DataTrack"),
|
427
|
407
|
}
|
428
|
408
|
)
|
429
|
409
|
|
430
|
|
-## Extract the coverage information
|
431
|
|
-setMethod("coverage", signature("AlignedReadTrack"),
|
432
|
|
- definition = function(x, strand = "*") {
|
433
|
|
- str <- c("+", "-", "*")[.strandName(strand, extended = TRUE) + 1]
|
434
|
|
- return(if (!is.null(x@coverage[[str]])) x@coverage[[str]] else Rle())
|
435
|
|
- }
|
436
|
|
-)
|
437
|
|
-
|
438
|
410
|
## Annotation accessors ------------------------------------------------------------------------------------------------------
|
439
|
411
|
##
|
440
|
412
|
## There are several levels of annotation information for most RangeTrack objects: individual features (e.g. exons, biotype),
|
...
|
...
|
@@ -1437,38 +1409,6 @@ setMethod("subset", signature(x = "GenomeAxisTrack"), function(x, from = NULL, t
|
1437
|
1409
|
return(x)
|
1438
|
1410
|
})
|
1439
|
1411
|
|
1440
|
|
-## If the object only stores coverage we subset that, otherwise we can use the RangeTrack method
|
1441
|
|
-setMethod("subset", signature(x = "AlignedReadTrack"), function(x, from = NULL, to = NULL, sort = FALSE, stacks = FALSE, ...) {
|
1442
|
|
- if (x@coverageOnly) {
|
1443
|
|
- if (is.null(from)) {
|
1444
|
|
- from <- min(unlist(lapply(x@coverage, function(y) if (length(y)) min(start(y)))))
|
1445
|
|
- }
|
1446
|
|
- if (is.null(to)) {
|
1447
|
|
- to <- max(unlist(lapply(x@coverage, function(y) if (length(y)) max(start(y)))))
|
1448
|
|
- }
|
1449
|
|
- x@coverage <- lapply(x@coverage, function(y) {
|
1450
|
|
- runValue(y)[end(y) < from | start(y) > to] <- 0
|
1451
|
|
- y
|
1452
|
|
- })
|
1453
|
|
- x@coverage <- lapply(x@coverage, function(y) {
|
1454
|
|
- if (length(y) < to) y <- c(y, Rle(0, to - length(y)))
|
1455
|
|
- y
|
1456
|
|
- })
|
1457
|
|
- ##
|
1458
|
|
- ## from <- min(unlist(lapply(x@coverage, function(y) if (length(y)) head(start(y), 2)[2])))
|
1459
|
|
- if (max(unlist(lapply(x@coverage, function(y) {
|
1460
|
|
- length(runLength(y)[runValue(y) != 0])
|
1461
|
|
- })))) {
|
1462
|
|
- from <- min(unlist(lapply(x@coverage, function(y) if (length(y)) head(start(y)[runValue(y) != 0], 1))))
|
1463
|
|
- to <- max(unlist(lapply(x@coverage, function(y) if (length(y)) tail(end(y), 2)[1])))
|
1464
|
|
- }
|
1465
|
|
- x@range <- GRanges(ranges = IRanges(start = from, end = to), strand = names(x@coverage), seqnames = x@chromosome)
|
1466
|
|
- } else {
|
1467
|
|
- x <- callNextMethod(x = x, from = from, to = to, sort = sort, stacks = stacks)
|
1468
|
|
- }
|
1469
|
|
- return(x)
|
1470
|
|
-})
|
1471
|
|
-
|
1472
|
1412
|
## AlignmentTracks can be subset by using the information in the stackRanges slot, but for the actual reads we need to make sure that
|
1473
|
1413
|
## we keep all the bits that belong to a given group. We still want to record the requested ranges in the internal '.__plottingRange'
|
1474
|
1414
|
## display parameter.
|
...
|
...
|
@@ -1758,45 +1698,6 @@ setMethod("drawAxis", signature(GdObject = "AlignmentsTrack"), function(GdObject
|
1758
|
1698
|
})
|
1759
|
1699
|
|
1760
|
1700
|
|
1761
|
|
-setMethod("drawAxis", signature(GdObject = "AlignedReadTrack"), function(GdObject, from, to, subset = TRUE) {
|
1762
|
|
- detail <- match.arg(.dpOrDefault(GdObject, "detail", "coverage"), c("coverage", "reads"))
|
1763
|
|
- if (detail != "coverage") {
|
1764
|
|
- return(NULL)
|
1765
|
|
- } else {
|
1766
|
|
- if (subset) {
|
1767
|
|
- GdObject <- subset(GdObject, from = from, to = to)
|
1768
|
|
- }
|
1769
|
|
- cov <- coverage(GdObject, strand = "*")
|
1770
|
|
- val <- runValue(coverage(GdObject, strand = "*"))
|
1771
|
|
- ## We have to figure out the data range, taking transformation into account
|
1772
|
|
- ylim <- .dpOrDefault(GdObject, "ylim")
|
1773
|
|
- if (is.null(ylim)) {
|
1774
|
|
- if (!length(val)) {
|
1775
|
|
- ylim <- c(0, 1)
|
1776
|
|
- } else {
|
1777
|
|
- ylim <- c(0, range(val, finite = TRUE, na.rm = TRUE)[2])
|
1778
|
|
- trans <- .dpOrDefault(GdObject, "transformation")[[1]]
|
1779
|
|
- if (!is.null(trans)) {
|
1780
|
|
- ylim <- c(0, trans(ylim[2]))
|
1781
|
|
- }
|
1782
|
|
- }
|
1783
|
|
- }
|
1784
|
|
- for (s in c("+", "-"))
|
1785
|
|
- {
|
1786
|
|
- pushViewport(viewport(height = 0.5, y = ifelse(s == "-", 0, 0.5), just = c("center", "bottom")))
|
1787
|
|
- dummy <- DataTrack(
|
1788
|
|
- start = rep(mean(c(from, to)), 2), end = rep(mean(c(from, to)), 2), data = ylim,
|
1789
|
|
- genome = genome(GdObject), chromosome = chromosome(GdObject)
|
1790
|
|
- )
|
1791
|
|
- oldDp <- displayPars(GdObject, hideInternal = FALSE)
|
1792
|
|
- oldDp[["ylim"]] <- if (s == "+") ylim else rev(ylim)
|
1793
|
|
- displayPars(dummy) <- oldDp
|
1794
|
|
- drawAxis(dummy, from = from, to = to)
|
1795
|
|
- popViewport(1)
|
1796
|
|
- }
|
1797
|
|
- }
|
1798
|
|
-})
|
1799
|
|
-
|
1800
|
1701
|
## drawGrid ------------------------------------------------------------------------------------------------------------
|
1801
|
1702
|
##
|
1802
|
1703
|
## Draw a grid in the background of a GdObject. For some subclasses this is meaningless, and the default function will
|
...
|
...
|
@@ -1831,39 +1732,6 @@ setMethod("drawGrid", signature(GdObject = "AnnotationTrack"), function(GdObject
|
1831
|
1732
|
popViewport(1)
|
1832
|
1733
|
}
|
1833
|
1734
|
})
|
1834
|
|
-setMethod("drawGrid", signature(GdObject = "AlignedReadTrack"), function(GdObject, from, to) {
|
1835
|
|
- detail <- match.arg(.dpOrDefault(GdObject, "detail", "coverage"), c("coverage", "reads"))
|
1836
|
|
- if (detail == "coverage") {
|
1837
|
|
- GdObject <- subset(GdObject, from = from, to = to)
|
1838
|
|
- ## We have to figure out the data range, taking transformation into account
|
1839
|
|
- ylim <- .dpOrDefault(GdObject, "ylim")
|
1840
|
|
- if (is.null(ylim)) {
|
1841
|
|
- maxs <- vapply(c("+", "-"), function(s) {
|
1842
|
|
- cvr <- coverage(GdObject, strand = s)
|
1843
|
|
- if (length(cvr)) max(cvr, na.rm = TRUE, finite = TRUE) else 0L
|
1844
|
|
- }, FUN.VALUE = numeric(1L))
|
1845
|
|
- y.max <- max(maxs, na.rm = TRUE, finite = TRUE)
|
1846
|
|
- ylim <- c(0, if (y.max == 0) 1 else y.max)
|
1847
|
|
- trans <- .dpOrDefault(GdObject, "transformation")[[1]]
|
1848
|
|
- if (!is.null(trans)) {
|
1849
|
|
- ylim <- c(0, trans(ylim[2]))
|
1850
|
|
- }
|
1851
|
|
- }
|
1852
|
|
- for (s in c("+", "-")) {
|
1853
|
|
- pushViewport(viewport(height = 0.5, y = ifelse(s == "-", 0, 0.5), just = c("center", "bottom")))
|
1854
|
|
- dummy <- DataTrack(
|
1855
|
|
- start = rep(mean(c(from, to)), 2), end = rep(mean(c(from, to)), 2), data = ylim,
|
1856
|
|
- genome = genome(GdObject), chromosome = chromosome(GdObject)
|
1857
|
|
- )
|
1858
|
|
- oldDp <- displayPars(GdObject, hideInternal = FALSE)
|
1859
|
|
- oldDp[["ylim"]] <- if (s == "+") ylim else rev(ylim)
|
1860
|
|
- displayPars(dummy) <- oldDp
|
1861
|
|
- drawGrid(dummy, from = from, to = to)
|
1862
|
|
- popViewport(1)
|
1863
|
|
- }
|
1864
|
|
- }
|
1865
|
|
- return(NULL)
|
1866
|
|
-})
|
1867
|
1735
|
|
1868
|
1736
|
setMethod("drawGrid", signature(GdObject = "AlignmentsTrack"), function(GdObject, from, to) {
|
1869
|
1737
|
if (.dpOrDefault(GdObject, "grid", FALSE)) {
|
...
|
...
|
@@ -3819,537 +3687,6 @@ setMethod("drawGD", signature("DataTrack"), function(GdObject, minBase, maxBase,
|
3819
|
3687
|
})
|
3820
|
3688
|
|
3821
|
3689
|
|
3822
|
|
-
|
3823
|
|
-
|
3824
|
|
-## drawGD - AlignedReadTrack -------------------------------------------------------------------------------------------
|
3825
|
|
-##
|
3826
|
|
-## Draw a AlignedRead track
|
3827
|
|
-
|
3828
|
|
-setMethod("drawGD", signature("AlignedReadTrack"), function(GdObject, minBase, maxBase, prepare = FALSE, subset = TRUE, ...) {
|
3829
|
|
- debug <- .dpOrDefault(GdObject, "debug", FALSE)
|
3830
|
|
- if ((is.logical(debug) && debug) || debug == "prepare") {
|
3831
|
|
- browser()
|
3832
|
|
- }
|
3833
|
|
- imageMap(GdObject) <- NULL
|
3834
|
|
- detail <- match.arg(.dpOrDefault(GdObject, "detail", "coverage"), c("reads", "coverage"))
|
3835
|
|
- ## Nothing to do in prepare mode if detail is not 'reads', so we can quit right away, else we need to set the stacking info
|
3836
|
|
- if (prepare) {
|
3837
|
|
- if (detail == "read") {
|
3838
|
|
- if (subset) {
|
3839
|
|
- GdObject <- subset(GdObject, from = minBase, to = maxBase)
|
3840
|
|
- }
|
3841
|
|
- ## GdObject <- setStacks(GdObject)
|
3842
|
|
- }
|
3843
|
|
- return(invisible(GdObject))
|
3844
|
|
- }
|
3845
|
|
- if ((is.logical(debug) && debug) || debug == "draw") {
|
3846
|
|
- browser()
|
3847
|
|
- }
|
3848
|
|
- ## We only proceed if there is something to draw within the ranges, but still may have to add the grid and the legend.
|
3849
|
|
- ## Legend drawing causes another viewport for all the other graphics to be opened and will be called after all other
|
3850
|
|
- ## drawing has finished, hence we call it in on.exit
|
3851
|
|
- if (subset) {
|
3852
|
|
- GdObject <- subset(GdObject, from = minBase, to = maxBase)
|
3853
|
|
- }
|
3854
|
|
- alpha <- .dpOrDefault(GdObject, "alpha", 1)
|
3855
|
|
- ## The optional legend is plotted below the data
|
3856
|
|
- grpLevels <- .dpOrDefault(GdObject, ".__groupLevels")
|
3857
|
|
- if (as.logical(.dpOrDefault(GdObject, "legend", FALSE)) && !is.null(grpLevels)) {
|
3858
|
|
- lSpace <- .dpOrDefault(GdObject, ".__verticalSpace")
|
3859
|
|
- pushViewport(viewport(
|
3860
|
|
- y = 1, height = unit(1, "npc") - unit(lSpace, "inches"),
|
3861
|
|
- just = c(0.5, 1)
|
3862
|
|
- ))
|
3863
|
|
- on.exit({
|
3864
|
|
- popViewport(1)
|
3865
|
|
- cex <- .dpOrDefault(GdObject, "cex.legend", 0.8)
|
3866
|
|
- legFactors <- .dpOrDefault(GdObject, ".__legFactors", character())
|
3867
|
|
- fontsize <- .dpOrDefault(GdObject, "fontsize.legend", 12)
|
3868
|
|
- fontface <- .dpOrDefault(GdObject, "fontface.legend", 1)
|
3869
|
|
- lineheight <- .dpOrDefault(GdObject, "lineheight.legend", 1)
|
3870
|
|
- fontfamily <- .dpOrDefault(GdObject, "fontfamily.legend", 1)
|
3871
|
|
- fontcolor <- .dpOrDefault(GdObject, "fontcolor.legend", .DEFAULT_SHADED_COL)
|
3872
|
|
- pushViewport(viewport(
|
3873
|
|
- y = 0, height = unit(lSpace, "inches"), just = c(0.5, 0),
|
3874
|
|
- gp = gpar(
|
3875
|
|
- cex = cex, fontsize = fontsize, fontface = fontface, fontcolor = fontcolor,
|
3876
|
|
- lineheight = lineheight
|
3877
|
|
- )
|
3878
|
|
- ))
|
3879
|
|
- pushViewport(viewport(width = unit(1, "npc") - unit(0.1, "inches"), height = unit(1, "npc") - unit(0.1, "inches")))
|
3880
|
|
- boxSize <- .dpOrDefault(GdObject, ".__boxSize")
|
3881
|
|
- spacing <- .dpOrDefault(GdObject, ".__spacing")
|
3882
|
|
- dims <- .dpOrDefault(GdObject, ".__layoutDims")
|
3883
|
|
- for (i in seq_along(grpLevels)) {
|
3884
|
|
- row <- (((i) - 1) %/% dims[2]) + 1
|
3885
|
|
- col <- (((i) - 1) %% dims[2]) + 1
|
3886
|
|
- pushViewport(viewport(width = 1 / dims[2], height = 1 / dims[1], x = (1 / dims[2]) * (col - 1), y = 1 - ((1 / dims[1]) * (row - 1)), just = c(0, 1)))
|
3887
|
|
- if (length(setdiff(legFactors, c("col"))) == 0) {
|
3888
|
|
- grid.rect(
|
3889
|
|
- width = unit(boxSize, "inches"), height = unit(boxSize, "inches"), x = 0, just = c(0, 0.5),
|
3890
|
|
- gp = gpar(fill = pcols$col[i], col = .DEFAULT_SHADED_COL)
|
3891
|
|
- )
|
3892
|
|
- } else {
|
3893
|
|
- if (any(c("pch", "col.symbol") %in% legFactors)) {
|
3894
|
|
- panel.points(unit(boxSize / 2, "inches"), 0.5, pch = pcols$pch[i], cex = pcols$cex[i], col = pcols$col.symbol[i])
|
3895
|
|
- }
|
3896
|
|
- if (any(c("lwd", "lty", "col.lines") %in% legFactors)) {
|
3897
|
|
- ## panel.lines(unit(c(0,boxSize), "inches"), c(0.5, 0.5), col=pcols$col.line[i], lwd=pcols$lwd[i], lty=pcols$lty[i])
|
3898
|
|
- grid.lines(unit(c(0, boxSize), "inches"), c(0.5, 0.5), gp = gpar(col = pcols$col.line[i], lwd = pcols$lwd[i], lty = pcols$lty[i]))
|
3899
|
|
- }
|
3900
|
|
- }
|
3901
|
|
- grid.text(x = unit(boxSize + spacing, "inches"), y = 0.5, just = c(0, 0.5), label = grpLevels[i], gp = gpar(col = fontcolor))
|
3902
|
|
- popViewport(1)
|
3903
|
|
- }
|
3904
|
|
- popViewport(2)
|
3905
|
|
- })
|
3906
|
|
- }
|
3907
|
|
- if (!length(GdObject)) {
|
3908
|
|
- if ("g" %in% type) {
|
3909
|
|
- panel.grid(
|
3910
|
|
- h = .dpOrDefault(GdObject, "h", -1), v = .dpOrDefault(GdObject, "v", -1),
|
3911
|
|
- col = .dpOrDefault(GdObject, "col.grid", "#e6e6e6"), lty = .dpOrDefault(GdObject, "lty.grid", 1),
|
3912
|
|
- lwd = .dpOrDefault(GdObject, "lwd.grid", 1), alpha = alpha
|
3913
|
|
- )
|
3914
|
|
- }
|
3915
|
|
- return(invisible(GdObject))
|
3916
|
|
- }
|
3917
|
|
- vals <- values(GdObject)
|
3918
|
|
- ylim <- suppressWarnings(.dpOrDefault(GdObject, "ylim", range(vals, na.rm = TRUE, finite = TRUE)))
|
3919
|
|
- if (diff(ylim) == 0) {
|
3920
|
|
- ylim <- ylim + c(-1, 1)
|
3921
|
|
- }
|
3922
|
|
- if (all(is.infinite(ylim))) {
|
3923
|
|
- ylim <- c(0, 1)
|
3924
|
|
- }
|
3925
|
|
- ylimExt <- extendrange(r = ylim, f = 0.05)
|
3926
|
|
- pushViewport(viewport(xscale = c(minBase, maxBase), yscale = ylimExt, clip = TRUE))
|
3927
|
|
- ## The plotting parameters, some defaults from the lattice package first
|
3928
|
|
- plot.symbol <- trellis.par.get("plot.symbol")
|
3929
|
|
- superpose.symbol <- trellis.par.get("superpose.symbol")
|
3930
|
|
- superpose.line <- trellis.par.get("superpose.line")
|
3931
|
|
- groups <- rep(groups, ncol(vals))
|
3932
|
|
- ## For loess calculation we need some settings
|
3933
|
|
- span <- .dpOrDefault(GdObject, "span", 1 / 5)
|
3934
|
|
- degree <- .dpOrDefault(GdObject, "degree", 1)
|
3935
|
|
- family <- .dpOrDefault(GdObject, "family", c("symmetric", "gaussian"))
|
3936
|
|
- evaluation <- .dpOrDefault(GdObject, "evaluation", 50)
|
3937
|
|
- font <- .dpOrDefault(GdObject, "font", if (is.null(groups)) plot.symbol$font else superpose.symbol$font)
|
3938
|
|
- fontface <- .dpOrDefault(GdObject, "fontface", if (is.null(groups)) plot.symbol$fontface else superpose.symbol$fontface)
|
3939
|
|
- fontsize <- .dpOrDefault(GdObject, "fontsize", if (is.null(groups)) plot.symbol$fontsize else superpose.symbol$fontsize)
|
3940
|
|
- ## An optional baseline to be added
|
3941
|
|
- baseline <- .dpOrDefault(GdObject, "baseline")
|
3942
|
|
- lwd.baseline <- .dpOrDefault(GdObject, "lwd.baseline", pcols$lwd[1])
|
3943
|
|
- lty.baseline <- .dpOrDefault(GdObject, "lty.baseline", pcols$lty[1])
|
3944
|
|
- ## The actual plotting values
|
3945
|
|
- pos <- position(GdObject)
|
3946
|
|
- x <- rep(pos, each = nrow(vals))
|
3947
|
|
- y <- as.numeric(vals)
|
3948
|
|
- ## A grid should always be plotted first, so we need to catch this here
|
3949
|
|
- wg <- match("g", type, nomatch = NA_character_)
|
3950
|
|
- if (!is.na(wg)) {
|
3951
|
|
- panel.grid(
|
3952
|
|
- h = .dpOrDefault(GdObject, "h", -1), v = .dpOrDefault(GdObject, "v", -1),
|
3953
|
|
- col = pcols$col.grid, lty = pcols$lty.grid, lwd = pcols$lwd.grid
|
3954
|
|
- )
|
3955
|
|
- type <- type[-wg]
|
3956
|
|
- }
|
3957
|
|
- ## The special type 'mountain' has to be handled separately
|
3958
|
|
- if ("mountain" %in% type) {
|
3959
|
|
- mbaseline <- if (is.null(baseline)) 0 else baseline[1]
|
3960
|
|
- fill.mountain <- .dpOrDefault(GdObject, "fill.mountain", superpose.symbol$fill)[c(1, 2)]
|
3961
|
|
- col.mountain <- .dpOrDefault(GdObject, "col.mountain", pcols$col)[1]
|
3962
|
|
- col.baseline <- .dpOrDefault(GdObject, "col.baseline", col.mountain)[1]
|
3963
|
|
- lwd.mountain <- .dpOrDefault(GdObject, "lwd.mountain", pcols$lwd)[1]
|
3964
|
|
- lty.mountain <- .dpOrDefault(GdObject, "lty.mountain", pcols$lty)[1]
|
3965
|
|
- .panel.mountain(x, y,
|
3966
|
|
- col = col.mountain, fill = fill.mountain, span = span, degree = degree, family = family,
|
3967
|
|
- evaluation = evaluation, lwd = lwd.mountain, lty = lty.mountain, col.line = col.mountain, alpha = alpha,
|
3968
|
|
- baseline = mbaseline
|
3969
|
|
- )
|
3970
|
|
- if (!is.na(mbaseline)) {
|
3971
|
|
- panel.abline(h = mbaseline, col = col.baseline, lwd = lwd.baseline, lty = lty.baseline, alpha = alpha)
|
3972
|
|
- }
|
3973
|
|
- }
|
3974
|
|
- ## The special type 'polygon' has to be handled separately
|
3975
|
|
- if ("polygon" %in% type) {
|
3976
|
|
- mbaseline <- if (is.null(baseline)) 0 else baseline[1]
|
3977
|
|
- fill.mountain <- .dpOrDefault(GdObject, "fill.mountain", superpose.symbol$fill)[c(1, 2)]
|
3978
|
|
- col.mountain <- .dpOrDefault(GdObject, "col.mountain", pcols$col)[1]
|
3979
|
|
- col.baseline <- .dpOrDefault(GdObject, "col.baseline", col.mountain)[1]
|
3980
|
|
- lwd.mountain <- .dpOrDefault(GdObject, "lwd.mountain", pcols$lwd)[1]
|
3981
|
|
- lty.mountain <- .dpOrDefault(GdObject, "lty.mountain", pcols$lty)[1]
|
3982
|
|
- .panel.polygon(x, y,
|
3983
|
|
- col = col.mountain, fill = fill.mountain, lwd = lwd.mountain,
|
3984
|
|
- lty = lty.mountain, col.line = col.mountain, alpha = alpha,
|
3985
|
|
- baseline = mbaseline
|
3986
|
|
- )
|
3987
|
|
- if (!is.na(mbaseline)) {
|
3988
|
|
- panel.abline(h = mbaseline, col = col.baseline, lwd = lwd.baseline, lty = lty.baseline, alpha = alpha)
|
3989
|
|
- }
|
3990
|
|
- }
|
3991
|
|
- ## Also the type 'boxplot' is handled up front
|
3992
|
|
- if ("boxplot" %in% type) {
|
3993
|
|
- box.ratio <- .dpOrDefault(GdObject, "box.ratio", 1)
|
3994
|
|
- box.width <- .dpOrDefault(GdObject, "box.width", (min(diff(unique(sort(x)))) * 0.5) / box.ratio)
|
3995
|
|
- diff <- .pxResolution(coord = "x")
|
3996
|
|
- if (!is.null(groups)) {
|
3997
|
|
- tw <- min(width(GdObject))
|
3998
|
|
- spacer <- diff
|
3999
|
|
- nb <- nlevels(groups)
|
4000
|
|
- bw <- .dpOrDefault(GdObject, "box.width", (tw - (nb + 2) * spacer) / nb)
|
4001
|
|
- bcex <- min(pcols$cex[1], (bw / diff) / 20)
|
4002
|
|
- by <- lapply(split(vals, groups), matrix, ncol = ncol(vals))
|
4003
|
|
- for (j in seq_along(by))
|
4004
|
|
- {
|
4005
|
|
- xx <- rep(start(GdObject) + (j * spacer) + (j * bw), each = nrow(by[[j]])) - (bw / 2)
|
4006
|
|
- .panel.bwplot(xx, as.numeric(by[[j]]),
|
4007
|
|
- box.ratio = box.ratio, box.width = (bw / 2) / box.ratio, pch = pcols$pch[1],
|
4008
|
|
- lwd = pcols$lwd[1], lty = pcols$lty[1], fontsize = fontsize,
|
4009
|
|
- col = pcols$col.histogram, cex = bcex, font = font, fontfamily = font, fontface = fontface,
|
4010
|
|
- fill = pcols$col[j], varwidth = .dpOrDefault(GdObject, "varwidth", FALSE),
|
4011
|
|
- notch = .dpOrDefault(GdObject, "notch", FALSE), notch.frac = .dpOrDefault(GdObject, "notch.frac", 0.5),
|
4012
|
|
- levels.fos = .dpOrDefault(GdObject, "level.fos", sort(unique(xx))),
|
4013
|
|
- stats = .dpOrDefault(GdObject, "stats", boxplot.stats), coef = .dpOrDefault(GdObject, "coef", 1.5),
|
4014
|
|
- do.out = .dpOrDefault(GdObject, "do.out", TRUE), alpha = alpha
|
4015
|
|
- )
|
4016
|
|
- }
|
4017
|
|
- diffY <- .pxResolution(coord = "y", 2)
|
4018
|
|
- outline <- apply(vals, 2, range)
|
4019
|
|
- grid.rect(start(GdObject), outline[1, ] - diffY,
|
4020
|
|
- width = width(GdObject), height = abs(outline[2, ] - outline[1, ]) + (2 * diffY),
|
4021
|
|
- gp = gpar(col = pcols$col.histogram, fill = "transparent", alpha = alpha, lty = "dotted"),
|
4022
|
|
- default.units = "native", just = c("left", "bottom")
|
4023
|
|
- )
|
4024
|
|
- } else {
|
4025
|
|
- bcex <- min(pcols$cex[1], ((box.width * 2) / diff) / 20)
|
4026
|
|
- .panel.bwplot(x, y,
|
4027
|
|
- box.ratio = box.ratio, box.width = box.width, pch = pcols$pch[1],
|
4028
|
|
- lwd = pcols$lwd[1], lty = pcols$lty[1], fontsize = fontsize,
|
4029
|
|
- col = pcols$col.histogram, cex = bcex, font = font, fontfamily = font, fontface = fontface,
|
4030
|
|
- fill = pcols$fill[1], varwidth = .dpOrDefault(GdObject, "varwidth", FALSE),
|
4031
|
|
- notch = .dpOrDefault(GdObject, "notch", FALSE), notch.frac = .dpOrDefault(GdObject, "notch.frac", 0.5),
|
4032
|
|
- levels.fos = .dpOrDefault(GdObject, "level.fos", sort(unique(x))),
|
4033
|
|
- stats = .dpOrDefault(GdObject, "stats", boxplot.stats), coef = .dpOrDefault(GdObject, "coef", 1.5),
|
4034
|
|
- do.out = .dpOrDefault(GdObject, "do.out", TRUE), alpha = alpha
|
4035
|
|
- )
|
4036
|
|
- }
|
4037
|
|
- }
|
4038
|
|
- ## 'histogram' fills up the full range area if its width is > 1
|
4039
|
|
- if ("histogram" %in% type) {
|
4040
|
|
- ylimSort <- sort(ylimExt)
|
4041
|
|
- yy <- if (ylimSort[1] <= 0 && ylimSort[2] >= 0) 0 else ylimSort[1]
|
4042
|
|
- if (!is.null(groups) && nlevels(groups) > 1) {
|
4043
|
|
- valsS <- .dpOrDefault(GdObject, ".__valsS")
|
4044
|
|
- if (stacked) {
|
4045
|
|
- curMinPos <- curMaxPos <- rep(yy, nrow(valsS))
|
4046
|
|
- for (s in seq_len(ncol(valsS)))
|
4047
|
|
- {
|
4048
|
|
- if (!all(is.na(valsS[, s]))) {
|
4049
|
|
- sel <- !is.na(valsS[, s]) & valsS[, s] >= 0
|
4050
|
|
- yyy <- curMinPos
|
4051
|
|
- yyy[sel] <- curMaxPos[sel]
|
4052
|
|
- offset <- yyy
|
4053
|
|
- offset[offset != yy] <- 0
|
4054
|
|
- grid.rect(start(GdObject), yyy,
|
4055
|
|
- width = width(GdObject), height = valsS[, s] - offset,
|
4056
|
|
- gp = gpar(col = "transparent", fill = pcols$col[s], lwd = pcols$lwd[1], lty = pcols$lty[1], alpha = alpha), default.units = "native",
|
4057
|
|
- just = c("left", "bottom")
|
4058
|
|
- )
|
4059
|
|
- curMaxPos[sel] <- curMaxPos[sel] + (valsS[sel, s] - offset[sel])
|
4060
|
|
- curMinPos[!sel] <- curMinPos[!sel] + (valsS[!sel, s] - offset[!sel])
|
4061
|
|
- }
|
4062
|
|
- }
|
4063
|
|
- diff <- .pxResolution(coord = "x", pcols$lwd[1] + 1)
|
4064
|
|
- tooNarrow <- width(GdObject) < diff
|
4065
|
|
- if (!all(tooNarrow)) {
|
4066
|
|
- grid.rect(start(GdObject)[!tooNarrow], curMinPos[!tooNarrow],
|
4067
|
|
- width = width(GdObject)[!tooNarrow],
|
4068
|
|
- height = (curMaxPos - curMinPos)[!tooNarrow],
|
4069
|
|
- gp = gpar(fill = "transparent", col = pcols$col.histogram, lwd = pcols$lwd[1], lty = pcols$lty[1], alpha = alpha),
|
4070
|
|
- default.units = "native", just = c("left", "bottom")
|
4071
|
|
- )
|
4072
|
|
- }
|
4073
|
|
- } else {
|
4074
|
|
- spacer <- .pxResolution(min.width = 1, coord = "x")
|
4075
|
|
- yOff <- .pxResolution(min.width = 1, coord = "y")
|
4076
|
|
- outline <- apply(valsS, 1, function(x) range(c(yy, x), na.rm = TRUE))
|
4077
|
|
- grid.rect(start(GdObject), outline[1, ] - yOff,
|
4078
|
|
- width = width(GdObject), height = apply(outline, 2, diff) + (yOff * 2),
|
4079
|
|
- gp = gpar(col = pcols$col.histogram, fill = pcols$fill.histogram, lwd = pcols$lwd[1], lty = pcols$lty[1], alpha = alpha), default.units = "native",
|
4080
|
|
- just = c("left", "bottom")
|
4081
|
|
- )
|
4082
|
|
- len <- ncol(valsS)
|
4083
|
|
- subW <- (width(GdObject) - (spacer * (len + 1))) / len
|
4084
|
|
- sel <- subW > spacer
|
4085
|
|
- ## FIXME: how do we treat this if there is not enough space to plot?
|
4086
|
|
- sel <- !logical(length(subW))
|
4087
|
|
- if (any(sel)) {
|
4088
|
|
- subW <- subW[sel]
|
4089
|
|
- valsS <- valsS[sel, ]
|
4090
|
|
- subX <- rep(start(GdObject)[sel], len) + (subW * rep(seq_len(len) - 1, each = sum(sel))) +
|
4091
|
|
- (spacer * rep(seq_len(len), each = sum(sel)))
|
4092
|
|
- grid.rect(subX, yy,
|
4093
|
|
- width = rep(subW, len), height = valsS - yy,
|
4094
|
|
- gp = gpar(
|
4095
|
|
- col = "transparent", fill = rep(pcols$col[seq_len(len)], each = sum(sel)),
|
4096
|
|
- lwd = pcols$lwd[1], lty = pcols$lty[1], alpha = alpha
|
4097
|
|
- ), default.units = "native",
|
4098
|
|
- just = c("left", "bottom")
|
4099
|
|
- )
|
4100
|
|
- }
|
4101
|
|
- }
|
4102
|
|
- } else {
|
4103
|
|
- agFun <- .aggregator(GdObject)
|
4104
|
|
- valsS <- agFun(t(vals))
|
4105
|
|
- grid.rect(start(GdObject), yy,
|
4106
|
|
- width = width(GdObject), height = valsS - yy,
|
4107
|
|
- gp = gpar(col = pcols$col.histogram, fill = pcols$fill.histogram, lwd = pcols$lwd[1], lty = pcols$lty[1], alpha = alpha), default.units = "native",
|
4108
|
|
- just = c("left", "bottom")
|
4109
|
|
- )
|
4110
|
|
- }
|
4111
|
|
- }
|
4112
|
|
- ## gradient summarizes the data as a color gradient
|
4113
|
|
- if ("gradient" %in% type) {
|
4114
|
|
- ncolor <- .dpOrDefault(GdObject, "ncolor", 100)
|
4115
|
|
- gradient <- colorRampPalette(.dpOrDefault(GdObject, "gradient", brewer.pal(9, "Blues")))(ncolor)
|
4116
|
|
- valsScaled <- .z2icol(colMeans(vals, na.rm = TRUE), ncolor, sort(ylim))
|
4117
|
|
- grid.rect(start(GdObject), sort(ylim)[1],
|
4118
|
|
- width = width(GdObject), height = abs(diff(ylim)),
|
4119
|
|
- gp = gpar(col = gradient[valsScaled], fill = gradient[valsScaled], alpha = alpha),
|
4120
|
|
- default.units = "native", just = c("left", "bottom")
|
4121
|
|
- )
|
4122
|
|
- }
|
4123
|
|
- ## heatmap does the same, but for each sample individually
|
4124
|
|
- if ("heatmap" %in% type) {
|
4125
|
|
- ncolor <- .dpOrDefault(GdObject, "ncolor", 100)
|
4126
|
|
- valsScaled <- .z2icol(vals, ncolor, sort(ylim))
|
4127
|
|
- nr <- nrow(vals)
|
4128
|
|
- yy <- seq(min(ylim), max(ylim), len = nr + 1)[-1]
|
4129
|
|
- ydiff <- .pxResolution(coord = "y")
|
4130
|
|
- separator <- .dpOrDefault(GdObject, "separator", 0) * ydiff
|
4131
|
|
- if (!is.null(groups)) {
|
4132
|
|
- valsS <- split(vals, groups)
|
4133
|
|
- freq <- table(factor(.dpOrDefault(GdObject, "groups")))
|
4134
|
|
- cmf <- c(0, cumsum(freq))
|
4135
|
|
- for (s in seq_along(valsS))
|
4136
|
|
- {
|
4137
|
|
- gradient <- colorRampPalette(c("white", pcols$col[s]))(ncolor + 5)[-seq_len(5)]
|
4138
|
|
- valsScaled <- .z2icol(valsS[[s]], ncolor, sort(ylim))
|
4139
|
|
- grid.rect(rep(start(GdObject), each = freq[s]), yy[(cmf[s] + 1):cmf[s + 1]],
|
4140
|
|
- width = rep(width(GdObject), each = freq[s]),
|
4141
|
|
- height = max(ydiff, abs(diff(ylim)) * (1 / nr) - separator),
|
4142
|
|
- gp = gpar(col = gradient[valsScaled], fill = gradient[valsScaled], alpha = alpha),
|
4143
|
|
- default.units = "native", just = c("left", "top")
|
4144
|
|
- )
|
4145
|
|
- }
|
4146
|
|
- } else {
|
4147
|
|
- gradient <- colorRampPalette(.dpOrDefault(GdObject, "gradient", brewer.pal(9, "Blues")))(ncolor)
|
4148
|
|
- grid.rect(rep(start(GdObject), each = nr), yy,
|
4149
|
|
- width = rep(width(GdObject), each = nr),
|
4150
|
|
- height = max(ydiff, abs(diff(ylim)) * (1 / nr) - separator),
|
4151
|
|
- gp = gpar(col = gradient[valsScaled], fill = gradient[valsScaled], alpha = alpha),
|
4152
|
|
- default.units = "native", just = c("left", "top")
|
4153
|
|
- )
|
4154
|
|
- }
|
4155
|
|
- }
|
4156
|
|
- ## The rest uses the lattice panel function
|
4157
|
|
- na.rm <- .dpOrDefault(GdObject, "na.rm", FALSE)
|
4158
|
|
- sel <- is.na(y)
|
4159
|
|
- if (na.rm && any(sel)) {
|
4160
|
|
- x <- x[!sel]
|
4161
|
|
- y <- y[!sel]
|
4162
|
|
- groups <- groups[!sel]
|
4163
|
|
- }
|
4164
|
|
- panel.xyplot(x, y,
|
4165
|
|
- type = type, groups = groups, pch = pcols$pch, col = pcols$col, col.line = pcols$col.line, col.symbol = pcols$col.symbol,
|
4166
|
|
- font = font, fontfamily = font, fontface = fontface, lty = pcols$lty, cex = pcols$cex, fill = pcols$fill, lwd = pcols$lwd, horizontal = FALSE,
|
4167
|
|
- span = span, degree = degree, family = family, evaluation = evaluation,
|
4168
|
|
- jitter.x = .dpOrDefault(GdObject, "jitter.x", FALSE), jitter.y = .dpOrDefault(GdObject, "jitter.y", FALSE),
|
4169
|
|
- factor = .dpOrDefault(GdObject, "factor", 0.5), amount = .dpOrDefault(GdObject, "amount"),
|
4170
|
|
- subscripts = seq_along(x), alpha = alpha
|
4171
|
|
- )
|
4172
|
|
- if (!any(c("mountain", "polygon") %in% type) && !is.null(baseline) && !is.na(baseline)) {
|
4173
|
|
- panel.abline(h = baseline, col = pcols$col.baseline, lwd = lwd.baseline, lty = lty.baseline, alpha = alpha)
|
4174
|
|
- }
|
4175
|
|
- popViewport(1)
|
4176
|
|
- return(invisible(GdObject))
|
4177
|
|
-})
|
4178
|
|
-
|
4179
|
|
-
|
4180
|
|
-
|
4181
|
|
-
|
4182
|
|
-## drawGD AlignedReadTrack 2 ---------------------------------------------------------------------------------------------
|
4183
|
|
-##
|
4184
|
|
-## Draw a AlignedRead track
|
4185
|
|
-
|
4186
|
|
-setMethod("drawGD", signature("AlignedReadTrack"), function(GdObject, minBase, maxBase, prepare = FALSE, subset = TRUE, ...) {
|
4187
|
|
- debug <- .dpOrDefault(GdObject, "debug", FALSE)
|
4188
|
|
- if ((is.logical(debug) && debug) || debug == "prepare") {
|
4189
|
|
- browser()
|
4190
|
|
- }
|
4191
|
|
- imageMap(GdObject) <- NULL
|
4192
|
|
- detail <- match.arg(.dpOrDefault(GdObject, "detail", "coverage"), c("reads", "coverage"))
|
4193
|
|
- ## Nothing to do in prepare mode if detail is not 'reads', so we can quit right away, else we need to set the stacking info
|
4194
|
|
- if (prepare) {
|
4195
|
|
- if (detail == "read") {
|
4196
|
|
- if (subset) {
|
4197
|
|
- GdObject <- subset(GdObject, from = minBase, to = maxBase)
|
4198
|
|
- }
|
4199
|
|
- ## GdObject <- setStacks(GdObject)
|
4200
|
|
- }
|
4201
|
|
- return(invisible(GdObject))
|
4202
|
|
- }
|
4203
|
|
- if ((is.logical(debug) && debug) || debug == "draw") {
|
4204
|
|
- browser()
|
4205
|
|
- }
|
4206
|
|
- ## In plotting mode we either show all the reads (time-consuming), or the coverage only
|
4207
|
|
- rad <- 0.015
|
4208
|
|
- xx <- -0.01
|
4209
|
|
- loc <- vpLocation()$size
|
4210
|
|
- diff <- .pxResolution(coord = "x")
|
4211
|
|
- radv <- rad / if (loc["width"] < loc["height"]) c(1, loc[2] / loc[1]) else c(loc[1] / loc[2], 1)
|
4212
|
|
- if (subset) {
|
4213
|
|
- GdObject <- subset(GdObject, from = minBase, to = maxBase)
|
4214
|
|
- }
|
4215
|
|
- ## If type is 'coverage' all we need to do is compute a coverage vector, create dummy DataTracks and pass everything on
|
4216
|
|
- if (detail == "coverage") {
|
4217
|
|
- if (!any(unlist(lapply(GdObject@coverage, function(y) runValue(y) != 0)))) {
|
4218
|
|
- ## Nothing there, but we still need the strand separator
|
4219
|
|
- panel.abline(h = 0.5, col = "lightgray", lwd = 2)
|
4220
|
|
- grid.circle(xx, c(0.25, 0.75), rad, gp = gpar(fill = "lightgray", col = "lightgray"))
|
4221
|
|
- grid.segments(c(rep(xx - radv[1] + (radv[1] / 2), 2), xx), c(0.25, 0.75, 0.75 - (radv[2] / 2)),
|
4222
|
|
- c(rep(xx + radv[1] - (radv[1] / 2), 2), xx), c(0.25, 0.75, 0.75 + radv[2] / 2),
|
4223
|
|
- gp = gpar(col = "white", lwd = 2, lineend = "square"), default.units = "native"
|
4224
|
|
- )
|
4225
|
|
- return(invisible(GdObject))
|
4226
|
|
- } else {
|
4227
|
|
- ## We want to distinguish between strands, so an extra spitting step is needed for this to work
|
4228
|
|
- val <- c(0, max(unlist(lapply(c("+", "-"), function(x) {
|
4229
|
|
- if (length(coverage(GdObject, strand = x))) {
|
4230
|
|
- max(coverage(GdObject, strand = x))
|
4231
|
|
- } else {
|
4232
|
|
- NULL
|
4233
|
|
- }
|
4234
|
|
- }))))
|
4235
|
|
- trans <- .dpOrDefault(GdObject, "transformation")[[1]]
|
4236
|
|
- if (!is.null(trans)) {
|
4237
|
|
- val[2] <- trans(val[2])
|
4238
|
|
- }
|
4239
|
|
- ylim <- .dpOrDefault(GdObject, "ylim", val)
|
4240
|
|
- for (s in c("+", "-"))
|
4241
|
|
- {
|
4242
|
|
- cov <- coverage(GdObject, strand = s)
|
4243
|
|
- pushViewport(viewport(height = 0.5, y = ifelse(s == "-", 0, 0.5), just = c("center", "bottom")))
|
4244
|
|
- sel <- suppressWarnings(runValue(cov) != 0) # changed from >
|
4245
|
|
- dtr <- if (any(sel)) {
|
4246
|
|
- DataTrack(
|
4247
|
|
- start = start(cov)[sel], end = end(cov)[sel], data = runValue(cov)[sel],
|
4248
|
|
- name = names(GdObject), genome = genome(GdObject), chromosome = chromosome(GdObject)
|
4249
|
|
- )
|
4250
|
|
- } else {
|
4251
|
|
- DataTrack(name = names(GdObject), genome = genome(GdObject), chromosome = chromosome(GdObject))
|
4252
|
|
- }
|
4253
|
|
- displayPars(dtr) <- displayPars(GdObject, hideInternal = FALSE)
|
4254
|
|
- displayPars(dtr) <- list(ylim = if (s == "+") ylim else rev(ylim))
|
4255
|
|
- drawGD(dtr, minBase, maxBase, prepare = prepare, ...)
|
4256
|
|
- popViewport(1)
|
4257
|
|
- }
|
4258
|
|
- panel.abline(h = 0.5, col = "lightgray", lwd = 2)
|
4259
|
|
- grid.circle(xx, c(0.25, 0.75), unit(rad, "native"),
|
4260
|
|
- gp = gpar(fill = "lightgray", col = "lightgray"),
|
4261
|
|
- default.units = "native"
|
4262
|
|
- )
|
4263
|
|
- grid.segments(c(rep(xx - radv[1] + (radv[1] / 2), 2), xx), c(0.25, 0.75, 0.75 - (radv[2] / 2)),
|
4264
|
|
- c(rep(xx + radv[1] - (radv[1] / 2), 2), xx), c(0.25, 0.75, 0.75 + radv[2] / 2),
|
4265
|
|
- gp = gpar(col = "white", lwd = 2, lineend = "square"), default.units = "native"
|
4266
|
|
- )
|
4267
|
|
- return(invisible(GdObject))
|
4268
|
|
- }
|
4269
|
|
- }
|
4270
|
|
- if (detail == "reads") {
|
4271
|
|
- if (!length(GdObject)) {
|
4272
|
|
- ## No reads, but we still need the strand separator
|
4273
|
|
- panel.abline(h = 0.5, col = "lightgray", lwd = 2)
|
4274
|
|
- grid.circle(xx, c(0.25, 0.75), rad, gp = gpar(fill = "lightgray", col = "lightgray"))
|
4275
|
|
- grid.segments(c(rep(xx - radv[1] + (radv[1] / 2), 2), xx), c(0.25, 0.75, 0.75 - (radv[2] / 2)),
|
4276
|
|
- c(rep(xx + radv[1] - (radv[1] / 2), 2), xx), c(0.25, 0.75, 0.75 + radv[2] / 2),
|
4277
|
|
- gp = gpar(col = "white", lwd = 2, lineend = "square"), default.units = "native"
|
4278
|
|
- )
|
4279
|
|
- return(invisible(GdObject))
|
4280
|
|
- } else {
|
4281
|
|
- if (GdObject@coverageOnly) {
|
4282
|
|
- pushViewport(viewport())
|
4283
|
|
- grid.text("Coverage information only for this object.\nUnable to plot read details.",
|
4284
|
|
- gp = gpar(col = "darkgray")
|
4285
|
|
- )
|
4286
|
|
- panel.abline(h = 0.5, col = "lightgray", lwd = 2)
|
4287
|
|
- recMid <- c(0.25, 0.75)
|
4288
|
|
- } else {
|
4289
|
|
- gdSplit <- split(GdObject, factor(strand(GdObject), levels = c("+", "-")))
|
4290
|
|
- st <- lapply(gdSplit, function(x) if (length(x)) stacks(setStacks(x)) - 1 else 0)
|
4291
|
|
- omax <- sum(vapply(st, max, FUN.VALUE = numeric(1L)))
|
4292
|
|
- space <- 0.1
|
4293
|
|
- ratios <- lapply(st[c("-", "+")], function(x) if (omax == 0) 0.5 else max(x) / omax) + (space / (2:1))
|
4294
|
|
- names(ratios) <- c("-", "+")
|
4295
|
|
- y <- if (ratios[["-"]] < ratios[["+"]]) c(0, ratios[["-"]] + space / 2) else c(0, ratios[["-"]] - space / 2)
|
4296
|
|
- h <- if (ratios[["-"]] < ratios[["+"]]) {
|
4297
|
|
- c(
|
4298
|
|
- max(space / 2, ratios["-"] - space / 2),
|
4299
|
|
- max(space / 2, ratios["+"] - ratios["-"] - space / 2)
|
4300
|
|
- )
|
4301
|
|
- } else {
|
4302
|
|
- c(max(space / 2, ratios["-"] - space), max(space / 2, ratios["+"] - ratios["-"] - space / 2))
|
4303
|
|
- }
|
4304
|
|
- names(y) <- names(h) <- names(ratios)
|
4305
|
|
- pushViewport(viewport(height = 0.95, just = "center", yscale = c(0, max(ratios))))
|
4306
|
|
- for (s in c("+", "-"))
|
4307
|
|
- {
|
4308
|
|
- gdSub <- gdSplit[[s]]
|
4309
|
|
- if (length(gdSub)) {
|
4310
|
|
- ylim <- c(0, if (max(st[[s]]) == 0) 1 else max(st[[s]]))
|
4311
|
|
- pushViewport(viewport(
|
4312
|
|
- height = h[s], y = y[s], just = c("center", "bottom"),
|
4313
|
|
- yscale = if (s == "+") ylim else rev(ylim), xscale = c(minBase, maxBase),
|
4314
|
|
- default.units = "native"
|
4315
|
|
- ))
|
4316
|
|
- ## We need to handle the grid here individually
|
4317
|
|
- if (.dpOrDefault(GdObject, "grid", FALSE)) {
|
4318
|
|
- pushViewport(dataViewport(xData = c(minBase, maxBase), extension = c(0, 0), yData = 0:1, clip = TRUE))
|
4319
|
|
- panel.grid(
|
4320
|
|
- h = 0, v = .dpOrDefault(GdObject, "v", -1),
|
4321
|
|
- col = .dpOrDefault(GdObject, "col.grid", "#e6e6e6"), lty = .dpOrDefault(GdObject, "lty.grid", 1),
|
4322
|
|
- lwd = .dpOrDefault(GdObject, "lwd.grid", 1)
|
4323
|
|
- )
|
4324
|
|
- popViewport(1)
|
4325
|
|
- }
|
4326
|
|
- grid.segments(start(gdSub), st[[s]], end(gdSub), st[[s]], default.units = "native")
|
4327
|
|
- popViewport(1)
|
4328
|
|
- }
|
4329
|
|
- }
|
4330
|
|
- al <- h["-"] + space / 4
|
4331
|
|
- panel.abline(h = al, col = "lightgray", lwd = 2)
|
4332
|
|
- recMid <- c(al / 2, al + (max(ratios) - al) / 2)
|
4333
|
|
- }
|
4334
|
|
- grid.circle(xx, recMid, rad, gp = gpar(fill = "lightgray", col = "lightgray"), default.units = "native")
|
4335
|
|
- grid.segments(c(rep(xx - radv[1] + (radv[1] / 2), 2), xx), c(0.25, 0.75, 0.75 - (radv[2] / 2)),
|
4336
|
|
- c(rep(xx + radv[1] - (radv[1] / 2), 2), xx), c(0.25, 0.75, 0.75 + radv[2] / 2),
|
4337
|
|
- gp = gpar(col = "white", lwd = 3, lineend = "square"), default.units = "native"
|
4338
|
|
- )
|
4339
|
|
-
|
4340
|
|
- grid.segments(c(rep(xx - radv[1] + (radv[1] / 2), 2), xx), c(recMid, recMid[2] - radv[2] / 2),
|
4341
|
|
- c(rep(xx + radv[1] - (radv[1] / 2), 2), xx), c(recMid, recMid[2] + radv[2] / 2),
|
4342
|
|
- gp = gpar(col = "white", lwd = 2, lineend = "square"), default.units = "native"
|
4343
|
|
- )
|
4344
|
|
- popViewport(1)
|
4345
|
|
- }
|
4346
|
|
- }
|
4347
|
|
- return(invisible(GdObject))
|
4348
|
|
-})
|
4349
|
|
-
|
4350
|
|
-
|
4351
|
|
-
|
4352
|
|
-
|
4353
|
3690
|
## drawGD - IdeogramTrack ----------------------------------------------------------------------------------------------
|
4354
|
3691
|
##
|
4355
|
3692
|
## Draw an ideogram track
|
...
|
...
|
@@ -5538,24 +4875,6 @@ setMethod(
|
5538
|
4875
|
}
|
5539
|
4876
|
)
|
5540
|
4877
|
|
5541
|
|
-setMethod(
|
5542
|
|
- "show", signature(object = "AlignedReadTrack"),
|
5543
|
|
- function(object) {
|
5544
|
|
- cat(sprintf(
|
5545
|
|
- paste("AlignedReadTrack track '%s' \n",
|
5546
|
|
- "| genome: %s\n",
|
5547
|
|
- "| active chromosome: %s\n",
|
5548
|
|
- "| containing %i read%s\n",
|
5549
|
|
- sep = ""
|
5550
|
|
- ),
|
5551
|
|
- names(object), genome(object),
|
5552
|
|
- gsub("^chr", "", chromosome(object)),
|
5553
|
|
- length(object),
|
5554
|
|
- ifelse(length(object) == 1, "", "s")
|
5555
|
|
- ))
|
5556
|
|
- }
|
5557
|
|
-)
|
5558
|
|
-
|
5559
|
4878
|
setMethod("show", "DisplayPars", function(object) {
|
5560
|
4879
|
cat("Display parameters:\n")
|
5561
|
4880
|
for (i in base::ls(object@pars))
|