Browse code

Removed helperFunctions.R. Added totalCopyNumber method to methods-CNSet.

Revised generic and function for totalCopyNumber.

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/branches/RELEASE_2_6/madman/Rpacks/crlmm@49109 bc3139a8-67e5-0310-9ffc-ced21a209358

Rob Scharp authored on 30/08/2010 15:45:33
Showing3 changed files

... ...
@@ -8,5 +8,4 @@ setGeneric("snpIndex", function(object) standardGeneric("snpIndex"))
8 8
 setGeneric("snpNames", function(object) standardGeneric("snpNames"))
9 9
 setGeneric("lM", function(object) standardGeneric("lM"))
10 10
 setGeneric("lM<-", function(object, value) standardGeneric("lM<-"))
11
-setGeneric("totalCopyNumber", function(object, i, j, ...) standardGeneric("totalCopyNumber"))
12
-
11
+setGeneric("totalCopyNumber", function(object, ...) standardGeneric("totalCopyNumber"))
... ...
@@ -87,7 +87,7 @@ setMethod("computeCopynumber", "CNSet",
87 87
 	if(bias.adj & all(is.na(CA(object)))){
88 88
 		cnOptions[["bias.adj"]] <- FALSE
89 89
 	}
90
-	object <- computeCopynumber.CNSet(object, cnOptions)				
90
+	object <- computeCopynumber.CNSet(object, cnOptions)
91 91
 	if(bias.adj & !cnOptions[["bias.adj"]]){
92 92
 		## Do a second iteration with bias adjustment
93 93
 		cnOptions[["bias.adj"]] <- TRUE
... ...
@@ -156,3 +156,73 @@ ellipse.CNSet <- function(x, copynumber, batch, ...){
156 156
 }
157 157
 
158 158
 
159
+setMethod("totalCopyNumber",
160
+	  signature=signature(object="CNSet", ...),
161
+	  function(object, ...){
162
+		  is.ff <- is(CA(object), "ff") | is(CA(object), "ffdf")
163
+		  dotArgs <- names(list(...))
164
+		  missing.i <- "i" %in% dotArgs
165
+		  missing.j <- "j" %in% dotArgs
166
+		  if(missing.i & missing.j){
167
+			  if(is.ff) stop("Must specify i and/or j for ff objects")
168
+		  }
169
+		  if(!missing.i) {
170
+			  i <- dotArgs[["i"]]
171
+			  snp.index <- intersect(i, which(isSnp(object)))
172
+			  ##which rows in the return matrix are snps
173
+			  snp.index2 <- which(isSnp(object)[i])
174
+		  } else {
175
+			  i <- 1:nrow(object)
176
+			  snp.index2 <- snp.index <- which(isSnp(object))
177
+		  }
178
+		  if(!missing.j){
179
+			  j <- dotArgs[["j"]]
180
+		  } else j <- 1:ncol(object)
181
+		  cn.total <- as.matrix(CA(object)[i, j])
182
+		  if(length(snp.index) > 0){
183
+			  cb <- as.matrix(CB(object)[snp.index, j])
184
+			  ##				 snps <- (1:nrow(cn.total))[i %in% snp.index]
185
+			  cn.total[snp.index2, ] <- cn.total[snp.index, ] + cb
186
+		  }
187
+		  cn.total <- cn.total/100
188
+		  return(cn.total)
189
+##		  if(missing.i){
190
+####		  if(missing.i & !missing.j){
191
+##			 snp.index <- which(isSnp(object))
192
+##			 cn.total <- as.matrix(CA(object)[, j])
193
+##			 if(length(snp.index) > 0){
194
+##				 cb <- as.matrix(CB(object)[snp.index, j])
195
+####				 snps <- (1:nrow(cn.total))[i %in% snp.index]
196
+##				 cn.total[snp.index, ] <- cn.total[snp.index, ] + cb
197
+##			 }
198
+##		 } else{
199
+##			 snp.index <- intersect(which(isSnp(object)), i)
200
+##			 cn.total <- as.matrix(CA(object)[i, ])
201
+##			 if(length(snp.index) > 0){
202
+##				 cb <- as.matrix(CB(object)[snp.index, ])
203
+##				 snps <- (1:nrow(cn.total))[i %in% snp.index]
204
+##				 cn.total[snps, ] <- cn.total[snps, ] + cb
205
+##			 }
206
+##		 }
207
+##		 if(!missing(i) & missing(j)){
208
+##			 snp.index <- intersect(which(isSnp(object)), i)
209
+##			 cn.total <- as.matrix(CA(object)[i, ])
210
+##			 if(length(snp.index) > 0){
211
+##				 cb <- as.matrix(CB(object)[snp.index, ])
212
+##				 snps <- (1:nrow(cn.total))[i %in% snp.index]
213
+##				 cn.total[snps, ] <- cn.total[snps, ] + cb
214
+##			 }
215
+##		 }
216
+##		 if(!missing(i) & !missing(j)){
217
+##			 snp.index <- intersect(which(isSnp(object)), i)
218
+##			 cn.total <- as.matrix(CA(object)[i, j])
219
+##			 if(length(snp.index) > 0){
220
+##				 cb <- as.matrix(CB(object)[snp.index, j])
221
+##				 snps <- (1:nrow(cn.total))[i %in% snp.index]
222
+##				 cn.total[snps, ] <- cn.total[snps, ] + cb
223
+##			 }
224
+##		 }
225
+##		 cn.total <- cn.total/100
226
+##		 dimnames(cn.total) <- NULL
227
+##		 return(cn.total)
228
+	 })
159 229
deleted file mode 100644
... ...
@@ -1,42 +0,0 @@
1
-setClassUnion("integerOrMissing", c("integer", "missing", "numeric"))
2
-setGeneric("totalCopyNumber", function(object, i, j, ...) standardGeneric("totalCopyNumber"))
3
-setMethod("totalCopyNumber",
4
-	  signature=signature(object="CNSet", i="integerOrMissing", j="integerOrMissing"),
5
-	  function(object, i, j, ...){
6
-	if(missing(i) & missing(j)){
7
-		if(inherits(CA(object), "ff") | inherits(CA(object), "ffdf")) stop("Must specify i and/or j for ff objects")
8
-	}
9
-	if(missing(i) & !missing(j)){
10
-		snp.index <- which(isSnp(object))	
11
-		cn.total <- as.matrix(CA(object)[, j])
12
-		if(length(snp.index) > 0){
13
-			cb <- as.matrix(CB(object)[snp.index, j])
14
-			snps <- (1:nrow(cn.total))[i %in% snp.index]
15
-			cn.total[snps, ] <- cn.total[snps, j] + cb				
16
-		}
17
-	}
18
-	if(!missing(i) & missing(j)){
19
-		snp.index <- intersect(which(isSnp(object)), i)
20
-		cn.total <- as.matrix(CA(object)[i, ])
21
-		if(length(snp.index) > 0){
22
-			cb <- as.matrix(CB(object)[snp.index, ])
23
-			snps <- (1:nrow(cn.total))[i %in% snp.index]
24
-			cn.total[snps, ] <- cn.total[snps, ] + cb				
25
-		}
26
-	}
27
-	if(!missing(i) & !missing(j)){
28
-		snp.index <- intersect(which(isSnp(object)), i)		
29
-		cn.total <- as.matrix(CA(object)[i, j])
30
-		if(length(snp.index) > 0){
31
-			cb <- as.matrix(CB(object)[snp.index, j])
32
-			snps <- (1:nrow(cn.total))[i %in% snp.index]
33
-			cn.total[snps, ] <- cn.total[snps, ] + cb
34
-		}
35
-	}
36
-	cn.total <- cn.total/100
37
-	dimnames(cn.total) <- NULL
38
-	return(cn.total)
39
-})
40
-
41
-
42
-