File: AdditiveUnit-class.R

package info (click to toggle)
r-bioc-complexheatmap 2.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,632 kB
  • sloc: makefile: 5
file content (135 lines) | stat: -rwxr-xr-x 4,015 bytes parent folder | download | duplicates (3)
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

# == title
# Class for Concatenating Heatmaps and Annotations
#
# == detail 
# This class is a super class for `Heatmap-class`, `HeatmapList-class` and
# `HeatmapAnnotation-class` classes. It is only designed for ``+`` generic
# method and the ``\%v\%v`` method so that above three classes can be appended to each other.
#
AdditiveUnit = setClass("AdditiveUnit")

# == title
# Constructor Method for AdditiveUnit Class
#
# == param
# -... Black hole arguments.
#
# == details
# This method is not used in the package.
#
# == value
# No value is returned.
#
# == author
# Zuguang Gu <z.gu@dkfz.de>
#
AdditiveUnit = function(...) {
    new("AdditiveUnit", ...)
}


# == title
# Horizontally Add Heatmaps or Annotations to a Heatmap List
#
# == param
# -x A `Heatmap-class` object, a `HeatmapAnnotation-class` object or a `HeatmapList-class` object.
# -y A `Heatmap-class` object, a `HeatmapAnnotation-class` object or a `HeatmapList-class` object.
#
# == detail
# It is only a helper function. It actually calls
# `add_heatmap,Heatmap-method`, `add_heatmap,HeatmapList-method` or
# `add_heatmap,HeatmapAnnotation-method` depending on the class of the input
# objects.
#
# The `HeatmapAnnotation-class` object to be added should only be row
# annotations. Column annotations should be added to the heatmap list by
# `\%v\%`.
#
# ``x`` and ``y`` can also be ``NULL``.
#
# == value
# A `HeatmapList-class` object.
#
# == seealso
# `\%v\%` operator is used for vertical heatmap list.
#
# == author
# Zuguang Gu <z.gu@dkfz.de>
#
"+.AdditiveUnit" = function(x, y) {
    if(inherits(x, "HeatmapAnnotation")) {
    	if(x@which != "row") {
    		stop_wrap("You should specify `which = row` or use `rowAnnotation()` directly if you want to add row annotations horizontally.")
    	}
    }
    if(inherits(y, "HeatmapAnnotation")) {
    	if(y@which != "row") {
            stop_wrap("You should specify `which = row` or use `rowAnnotation()` directly if you want to add row annotations horizontally.")
    	}
    }
    if(is.null(x)) {
        ht_list = new("HeatmapList")
        ht_list@direction = "horizontal"
        add_heatmap(ht_list, y)
    } else if(is.null(y)) {
        ht_list = new("HeatmapList")
        ht_list@direction = "horizontal"
        add_heatmap(ht_list, x)
    } else {
        add_heatmap(x, y)
    }
}


# == title
# Vertically Add Heatmaps or Annotations to a Heatmap List
#
# == param
# -x A `Heatmap-class` object, a `HeatmapAnnotation-class` object or a `HeatmapList-class` object.
# -y A `Heatmap-class` object, a `HeatmapAnnotation-class` object or a `HeatmapList-class` object.
#
# == detail
# It is only a helper function. It actually calls
# `add_heatmap,Heatmap-method`, `add_heatmap,HeatmapList-method` or
# `add_heatmap,HeatmapAnnotation-method` depending on the class of the input
# objects.
#
# The `HeatmapAnnotation-class` object to be added should only be column
# annotations.
#
# ``x`` and ``y`` can also be ``NULL``.
#
# == value
# A `HeatmapList-class` object.
#
# == seealso
# `+.AdditiveUnit` operator is used for horizontal heatmap list.
#
# == author
# Zuguang Gu <z.gu@dkfz.de>
#
"%v%" = function(x, y) {
    if(inherits(x, "HeatmapAnnotation")) {
        if(x@which != "column") {
            stop_wrap("You should specify `which = column` or use `columnAnnotation()` directly if you want to add column annotations vertically.")
        }
    }
    if(inherits(y, "HeatmapAnnotation")) {
        if(y@which != "column") {
            stop_wrap("You should specify `which = column` or use `columnAnnotation()` directly if you want to add column annotations vertically.")
        }
    }
    if(is.null(x)) {
        ht_list = new("HeatmapList")
        ht_list@direction = "vertical"
        add_heatmap(ht_list, y, direction = "vertical")
    } else if(is.null(y)) {
        ht_list = new("HeatmapList")
        ht_list@direction = "vertical"
        add_heatmap(ht_list, x, direction = "vertical")
    } else {
        add_heatmap(x, y, direction = "vertical")
    }
}