Browse code

anno_density(): add xlim argument

Zuguang Gu authored on 08/06/2020 09:53:31
Showing13 changed files

... ...
@@ -278,6 +278,7 @@ importFrom("GetoptLong", qq)
278 278
 importFrom("GetoptLong", qq.options)
279 279
 importFrom("GetoptLong", qqcat)
280 280
 importFrom("GlobalOptions", setGlobalOptions)
281
+importFrom("IRanges", "IntegerList")
281 282
 importFrom("RColorBrewer", brewer.pal)
282 283
 importFrom("S4Vectors", "DataFrame")
283 284
 importFrom("circlize", add_transparency)
... ...
@@ -295,4 +296,4 @@ importFrom("utils", "combn")
295 296
 importFrom("utils", "getFromNamespace")
296 297
 importFrom("utils", "packageDescription")
297 298
 importFrom("utils", "str")
298
-importFrom("IRanges", "IntegerList")
299
+
... ...
@@ -1,31 +1,31 @@
1
+setGeneric('get_legend_param_list', function(object, ...) standardGeneric('get_legend_param_list'))
1 2
 setGeneric('re_size', function(object, ...) standardGeneric('re_size'))
2
-setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
3
-setGeneric('annotation_legend_size', function(object, ...) standardGeneric('annotation_legend_size'))
4
-setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
5
-setGeneric('adjust_heatmap_list', function(object, ...) standardGeneric('adjust_heatmap_list'))
6
-setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
3
+setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
7 4
 setGeneric('draw_heatmap_body', function(object, ...) standardGeneric('draw_heatmap_body'))
8
-setGeneric('get_legend_param_list', function(object, ...) standardGeneric('get_legend_param_list'))
9
-setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
10
-setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
11
-setGeneric('component_width', function(object, ...) standardGeneric('component_width'))
12
-setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
13 5
 setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
14
-setGeneric('draw_title', function(object, ...) standardGeneric('draw_title'))
15
-setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_heatmap_legend'))
16
-setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
17
-setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
18
-setGeneric('make_column_cluster', function(object, ...) standardGeneric('make_column_cluster'))
6
+setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
19 7
 setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
20
-setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
21
-setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
22
-setGeneric('set_component_width', function(object, ...) standardGeneric('set_component_width'))
23
-setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
24
-setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
8
+setGeneric('adjust_heatmap_list', function(object, ...) standardGeneric('adjust_heatmap_list'))
25 9
 setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
26
-setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
10
+setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
27 11
 setGeneric('draw', function(object, ...) standardGeneric('draw'))
28
-setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
29 12
 setGeneric('row_order', function(object, ...) standardGeneric('row_order'))
13
+setGeneric('annotation_legend_size', function(object, ...) standardGeneric('annotation_legend_size'))
14
+setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
15
+setGeneric('make_column_cluster', function(object, ...) standardGeneric('make_column_cluster'))
16
+setGeneric('draw_title', function(object, ...) standardGeneric('draw_title'))
17
+setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
30 18
 setGeneric('set_component_height', function(object, ...) standardGeneric('set_component_height'))
19
+setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
20
+setGeneric('component_width', function(object, ...) standardGeneric('component_width'))
21
+setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
22
+setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
23
+setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
31 24
 setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
25
+setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
26
+setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
27
+setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_heatmap_legend'))
28
+setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
29
+setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
30
+setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
31
+setGeneric('set_component_width', function(object, ...) standardGeneric('set_component_width'))
... ...
@@ -1611,7 +1611,7 @@ anno_histogram = function(x, which = c("column", "row"), n_breaks = 11,
1611 1611
 	histogram_counts = lapply(histogram_stats, function(x) x$counts)
1612 1612
 
1613 1613
 	xscale = range(unlist(histogram_breaks), na.rm = TRUE)
1614
-	xscale = xscale + c(0, 0.05)*(xscale[2] - xscale[1])
1614
+	xscale = xscale + c(-0.025, 0.025)*(xscale[2] - xscale[1])
1615 1615
 	yscale = c(0, max(unlist(histogram_counts)))
1616 1616
 	yscale[2] = yscale[2]*1.05
1617 1617
 
... ...
@@ -1718,6 +1718,7 @@ anno_histogram = function(x, which = c("column", "row"), n_breaks = 11,
1718 1718
 # -which Whether it is a column annotation or a row annotation?
1719 1719
 # -type Type of graphics to represent density distribution. "lines" for normal density plot; "violine" for violin plot
1720 1720
 #       and "heatmap" for heatmap visualization of density distribution.
1721
+# -xlim Range on x-axis.
1721 1722
 # -heatmap_colors A vector of colors for interpolating density values.
1722 1723
 # -joyplot_scale Relative height of density distribution. A value higher than 1 increases the height of the density
1723 1724
 #               distribution and the plot will represented as so-called "joyplot".
... ...
@@ -1746,7 +1747,7 @@ anno_histogram = function(x, which = c("column", "row"), n_breaks = 11,
1746 1747
 #     heatmap_colors = c("white", "orange"))
1747 1748
 # draw(anno, test = "heatmap, colors")
1748 1749
 anno_density = function(x, which = c("column", "row"),
1749
-	type = c("lines", "violin", "heatmap"), 
1750
+	type = c("lines", "violin", "heatmap"), xlim = NULL,
1750 1751
 	heatmap_colors = rev(brewer.pal(name = "RdYlBu", n = 11)), 
1751 1752
 	joyplot_scale = 1, border = TRUE, gp = gpar(fill = "#CCCCCC"),
1752 1753
 	axis = TRUE, axis_param = default_axis_param(which),
... ...
@@ -1788,8 +1789,20 @@ anno_density = function(x, which = c("column", "row"),
1788 1789
 	min_density_x = min(unlist(density_x))
1789 1790
 	max_density_x = max(unlist(density_x))
1790 1791
 	
1791
-	xscale = range(unlist(density_x), na.rm = TRUE)
1792
-	xscale = xscale + c(0, 0.05)*(xscale[2] - xscale[1])
1792
+	if(is.null(xlim)) {
1793
+		xscale = range(unlist(density_x), na.rm = TRUE)
1794
+	} else {
1795
+		xscale = xlim
1796
+		for(i in seq_len(n)) {
1797
+			l = density_x[[i]] >= xscale[1] & density_x[[i]] <= xscale[2]
1798
+			density_x[[i]] = density_x[[i]][l]
1799
+			density_y[[i]] = density_y[[i]][l]
1800
+
1801
+			density_x[[i]] = c(density_x[[i]][ 1 ], density_x[[i]], density_x[[i]][ length(density_x[[i]]) ])
1802
+			density_y[[i]] = c(0, density_y[[i]], 0)
1803
+		}
1804
+	}
1805
+	xscale = xscale + c(-0.025, 0.025)*(xscale[2] - xscale[1])
1793 1806
 	if(type == "lines") {
1794 1807
 		yscale = c(0, max(unlist(density_y)))
1795 1808
 		yscale[2] = yscale[2]*1.05
... ...
@@ -1797,7 +1810,6 @@ anno_density = function(x, which = c("column", "row"),
1797 1810
 		yscale = max(unlist(density_y))
1798 1811
 		yscale = c(-yscale*1.05, yscale*1.05)
1799 1812
 	} else if(type == "heatmap") {
1800
-		xscale = range(unlist(density_x), na.rm = TRUE)
1801 1813
 		yscale = c(0, 1)
1802 1814
 		min_y = min(unlist(density_y))
1803 1815
 		max_y = max(unlist(density_y))
... ...
@@ -2226,7 +2238,7 @@ anno_joyplot = function(x, which = c("column", "row"), gp = gpar(fill = "#000000
2226 2238
 	}
2227 2239
 
2228 2240
 	xscale = range(lapply(value, function(x) x[, 1]), na.rm = TRUE)
2229
-	xscale = xscale + c(-0.05, 0.05)*(xscale[2] - xscale[1])
2241
+	xscale = xscale + c(-0.025, 0.025)*(xscale[2] - xscale[1])
2230 2242
 	yscale = range(lapply(value, function(x) x[, 2]), na.rm = TRUE)
2231 2243
 	yscale[1] = 0
2232 2244
 	yscale[2] = yscale[2]*1.05
... ...
@@ -11,8 +11,8 @@ Method dispatch page for \code{add_heatmap}.
11 11
 
12 12
 \itemize{
13 13
 \item \code{\link{add_heatmap,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14
-\item \code{\link{add_heatmap,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
15 14
 \item \code{\link{add_heatmap,Heatmap-method}}, \code{\link{Heatmap-class}} class method
15
+\item \code{\link{add_heatmap,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
16 16
 }
17 17
 }
18 18
 \examples{
... ...
@@ -8,7 +8,7 @@ Density Annotation
8 8
 }
9 9
 \usage{
10 10
 anno_density(x, which = c("column", "row"),
11
-    type = c("lines", "violin", "heatmap"),
11
+    type = c("lines", "violin", "heatmap"), xlim = NULL,
12 12
     heatmap_colors = rev(brewer.pal(name = "RdYlBu", n = 11)),
13 13
     joyplot_scale = 1, border = TRUE, gp = gpar(fill = "#CCCCCC"),
14 14
     axis = TRUE, axis_param = default_axis_param(which),
... ...
@@ -19,6 +19,7 @@ anno_density(x, which = c("column", "row"),
19 19
   \item{x}{A matrix or a list. If \code{x} is a matrix and if \code{which} is \code{column}, statistics for boxplots are calculated by columns, if \code{which} is \code{row}, the calculation is done by rows.}
20 20
   \item{which}{Whether it is a column annotation or a row annotation?}
21 21
   \item{type}{Type of graphics to represent density distribution. "lines" for normal density plot; "violine" for violin plot and "heatmap" for heatmap visualization of density distribution.}
22
+  \item{xlim}{Range on x-axis.}
22 23
   \item{heatmap_colors}{A vector of colors for interpolating density values.}
23 24
   \item{joyplot_scale}{Relative height of density distribution. A value higher than 1 increases the height of the density distribution and the plot will represented as so-called "joyplot".}
24 25
   \item{border}{Wether draw borders of the annotation region?}
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{column_order}.
10 10
 \code{column_order} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{column_order,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{column_order,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{column_order,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{component_width}.
10 10
 \code{component_width} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{component_width,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{component_width,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{component_width,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{copy_all}.
10 10
 \code{copy_all} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{copy_all,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
14 13
 \item \code{\link{copy_all,SingleAnnotation-method}}, \code{\link{SingleAnnotation-class}} class method
14
+\item \code{\link{copy_all,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,12 +10,12 @@ Method dispatch page for \code{draw}.
10 10
 \code{draw} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
+\item \code{\link{draw,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
14
+\item \code{\link{draw,Heatmap-method}}, \code{\link{Heatmap-class}} class method
15
+\item \code{\link{draw,Legends-method}}, \code{\link{Legends-class}} class method
13 16
 \item \code{\link{draw,SingleAnnotation-method}}, \code{\link{SingleAnnotation-class}} class method
14
-\item \code{\link{draw,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 17
 \item \code{\link{draw,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
16
-\item \code{\link{draw,Legends-method}}, \code{\link{Legends-class}} class method
17
-\item \code{\link{draw,Heatmap-method}}, \code{\link{Heatmap-class}} class method
18
-\item \code{\link{draw,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
18
+\item \code{\link{draw,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
19 19
 }
20 20
 }
21 21
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{make_layout}.
10 10
 \code{make_layout} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{make_layout,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14 13
 \item \code{\link{make_layout,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14
+\item \code{\link{make_layout,Heatmap-method}}, \code{\link{Heatmap-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{row_dend}.
10 10
 \code{row_dend} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{row_dend,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14 13
 \item \code{\link{row_dend,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14
+\item \code{\link{row_dend,Heatmap-method}}, \code{\link{Heatmap-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -22,6 +22,9 @@ selectPosition(ht_list, pos = NULL, mark = TRUE, verbose = TRUE,
22 22
 \value{
23 23
 A \code{\link[S4Vectors:DataFrame-class]{DataFrame}} object with row index and column index corresponding to the selected position.
24 24
 }
25
+\seealso{
26
+The code for this shiny app is at \url{https://github.com/jokergoo/ComplexHeatmap/blob/master/inst/app/app.R}
27
+}
25 28
 \author{
26 29
 Zuguang Gu <z.gu@dkfz.de>
27 30
 }
... ...
@@ -10,12 +10,12 @@ Method dispatch page for \code{show}.
10 10
 \code{show} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
+\item \code{\link{show,ColorMapping-method}}, \code{\link{ColorMapping-class}} class method
13 14
 \item \code{\link{show,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14 15
 \item \code{\link{show,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
15
-\item \code{\link{show,ColorMapping-method}}, \code{\link{ColorMapping-class}} class method
16 16
 \item \code{\link{show,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
17
-\item \code{\link{show,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
18 17
 \item \code{\link{show,SingleAnnotation-method}}, \code{\link{SingleAnnotation-class}} class method
18
+\item \code{\link{show,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
19 19
 }
20 20
 }
21 21
 \examples{