-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolScheme-class.R
More file actions
142 lines (100 loc) · 4.32 KB
/
colScheme-class.R
File metadata and controls
142 lines (100 loc) · 4.32 KB
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
##############################################################################
#
# Function: colScheme-class.R
# Author: John V Pearson
# Created: 2011-10-27
#
# This class is designed to hold a color scheme for use in plotting NGS
# data from instances of block-class. It must hold tuples of
# { number, color, label } where number is a value that appears in the
# block-class@values data.frame, color is the color of the box to be
# drawn when the number is seen, and label is the string description of
# the number that would be shown in a plot legend.
#
# Copyright 2011 The University of Queensland.
#
# See the LICENSE file in this distribution for more details.
#
# $Id: colScheme-class.R 4390 2011-11-30 23:08:42Z j.pearson $
#
##############################################################################
# "Cry havoc, and let slip the dogs of war ..."
### Define Class #####################################################
setClass("colScheme",
representation(
values = "data.frame",
created_on = "character",
c_version = "character"
),
prototype=list(
values = data.frame(),
colors = c(),
labels = c(),
created_on = date(),
c_version = grep( "^[[:digit:].]+$",
unlist(strsplit("$Revision: 4390 $","\\s")),
value=TRUE )
)
)
### Get Accessor methods #############################################
if (is.null(getGeneric("values")))
setGeneric("values", function(object) standardGeneric("values"))
setMethod("values", "colScheme",
function (object) object@values )
if (is.null(getGeneric("get.values")))
setGeneric("get.values", function(object) standardGeneric("get.values"))
setMethod("get.values", "colScheme",
function (object) row.names(object@values) )
if (is.null(getGeneric("get.labels")))
setGeneric("get.labels", function(object) standardGeneric("get.labels"))
setMethod("get.labels", "colScheme",
function (object) as.vector( object@values[,"labels"] ) )
if (is.null(getGeneric("get.colors")))
setGeneric("get.colors", function(object) standardGeneric("get.colors"))
setMethod("get.colors", "colScheme",
function (object) as.vector( object@values[,"colors"] ) )
if (is.null(getGeneric("values.count")))
setGeneric("values.count", function(object) standardGeneric("values.count"))
setMethod("values.count", "colScheme",
function (object) length(row.names(object@values)) )
if (is.null(getGeneric("created.on")))
setGeneric("created.on", function(object) standardGeneric("created.on"))
setMethod("created.on", "colScheme",
function (object) object@created_on )
if (is.null(getGeneric("code.version")))
setGeneric("code.version", function(object) standardGeneric("code.version"))
setMethod("code.version", "colScheme",
function (object) object@c_version )
### Set Accessor methods #############################################
### Processing methods ###############################################
if (is.null(getGeneric("summary")))
setGeneric("summary", function(object,...) standardGeneric("summary"))
setMethod("summary", "colScheme",
function (object) {
cat( "S4 Object Class: ", class(object), "\n" )
cat( "Creation date: ", created.on(object), "\n" )
cat( "Code version: ", code.version(object), "\n" )
}
)
if (is.null(getGeneric("pick.label")))
setGeneric("pick.label", function(object,...) standardGeneric("pick.label"))
setMethod("pick.label", "colScheme",
function (object,value) {
return( object@values[as.character(value),"labels"] )
}
)
if (is.null(getGeneric("pick.color")))
setGeneric("pick.color", function(object,...) standardGeneric("pick.color"))
setMethod("pick.color", "colScheme",
function (object,value) {
return( object@values[as.character(value),"colors"] )
}
)
### Non-OO Helper Functions ##########################################
newColScheme <- function( values=c(), labels=c(), colors=c() ) {
# Create and return colScheme object
v <- data.frame( values, I(labels), I(colors), row.names=1 )
names(v) <- c("labels","colors")
cs <- new("colScheme", values=v)
return( cs )
}