git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/crlmm@43144 bc3139a8-67e5-0310-9ffc-ced21a209358
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,79 +0,0 @@ |
1 |
-setValidity("CopyNumberSet", function(object) { |
|
2 |
- msg <- validMsg(NULL, assayDataValidMembers(assayData(object), c("CA", "CB"))) |
|
3 |
- if (is.null(msg)) TRUE else msg |
|
4 |
-}) |
|
5 |
-##may want to allow thresholding here (... arg) |
|
6 |
-setMethod("CA", "CopyNumberSet", function(object) assayData(object)[["CA"]]/100) |
|
7 |
-setMethod("CB", "CopyNumberSet", function(object) assayData(object)[["CB"]]/100) |
|
8 |
- |
|
9 |
-setReplaceMethod("CA", signature(object="CopyNumberSet", value="matrix"), |
|
10 |
- function(object, value){ |
|
11 |
- assayDataElementReplace(object, "CA", value) |
|
12 |
- }) |
|
13 |
- |
|
14 |
-setReplaceMethod("CB", signature(object="CopyNumberSet", value="matrix"), |
|
15 |
- function(object, value){ |
|
16 |
- assayDataElementReplace(object, "CB", value) |
|
17 |
- }) |
|
18 |
- |
|
19 |
-setMethod("copyNumber", "CopyNumberSet", function(object){ |
|
20 |
- I <- isSnp(object) |
|
21 |
- CA <- CA(object) |
|
22 |
- CB <- CB(object) |
|
23 |
- CN <- CA + CB |
|
24 |
- ##For nonpolymorphic probes, CA is the total copy number |
|
25 |
- CN[!I, ] <- CA(object)[!I, ] |
|
26 |
- CN |
|
27 |
-}) |
|
28 |
- |
|
29 |
- |
|
30 |
- |
|
31 |
-##setMethod("ellipse", "CopyNumberSet", function(x, copynumber, ...){ |
|
32 |
-ellipse.CopyNumberSet <- function(x, copynumber, ...){ |
|
33 |
-##setMethod("ellipse", "CopyNumberSet", function(x, copynumber, ...){ |
|
34 |
- ##fittedOrder <- unique(sapply(basename(celFiles), function(x) strsplit(x, "_")[[1]][2])) |
|
35 |
- ##index <- match(plates, fittedOrder) |
|
36 |
- if(nrow(x) > 1) stop("only 1 snp at a time") |
|
37 |
- ##batch <- unique(x$batch) |
|
38 |
- args <- list(...) |
|
39 |
- if(!"batch" %in% names(args)){ |
|
40 |
- jj <- match("batch", varLabels(x)) |
|
41 |
- if(length(jj) < 1) stop("batch not in varLabels") |
|
42 |
- batch <- unique(pData(x)[, jj]) |
|
43 |
- } else{ |
|
44 |
- batch <- unique(args$batch) |
|
45 |
- } |
|
46 |
- if(length(batch) > 1) stop("batch variable not unique") |
|
47 |
- nuA <- as.numeric(fData(x)[, match(paste("nuA", batch, sep="_"), fvarLabels(x))]) |
|
48 |
- nuB <- as.numeric(fData(x)[, match(paste("nuB", batch, sep="_"), fvarLabels(x))]) |
|
49 |
- phiA <- as.numeric(fData(x)[, match(paste("phiA", batch, sep="_"), fvarLabels(x))]) |
|
50 |
- phiB <- as.numeric(fData(x)[, match(paste("phiB", batch, sep="_"), fvarLabels(x))]) |
|
51 |
- tau2A <- as.numeric(fData(x)[, match(paste("tau2A", batch, sep="_"), fvarLabels(x))]) |
|
52 |
- tau2B <- as.numeric(fData(x)[, match(paste("tau2B", batch, sep="_"), fvarLabels(x))]) |
|
53 |
- sig2A <- as.numeric(fData(x)[, match(paste("sig2A", batch, sep="_"), fvarLabels(x))]) |
|
54 |
- sig2B <- as.numeric(fData(x)[, match(paste("sig2B", batch, sep="_"), fvarLabels(x))]) |
|
55 |
- corrA.BB <- as.numeric(fData(x)[, match(paste("corrA.BB", batch, sep="_"), fvarLabels(x))]) |
|
56 |
- corrB.AA <- as.numeric(fData(x)[, match(paste("corrB.AA", batch, sep="_"), fvarLabels(x))]) |
|
57 |
- corr <- as.numeric(fData(x)[, match(paste("corr", batch, sep="_"), fvarLabels(x))]) |
|
58 |
- for(CN in copynumber){ |
|
59 |
- for(CA in 0:CN){ |
|
60 |
- CB <- CN-CA |
|
61 |
- A.scale <- sqrt(tau2A*(CA==0) + sig2A*(CA > 0)) |
|
62 |
- B.scale <- sqrt(tau2B*(CB==0) + sig2B*(CB > 0)) |
|
63 |
- scale <- c(A.scale, B.scale) |
|
64 |
- if(CA == 0 & CB > 0) rho <- corrA.BB |
|
65 |
- if(CA > 0 & CB == 0) rho <- corrB.AA |
|
66 |
- if(CA > 0 & CB > 0) rho <- corr |
|
67 |
- if(CA == 0 & CB == 0) rho <- 0 |
|
68 |
- lines(ellipse(x=rho, centre=c(log2(nuA+CA*phiA), |
|
69 |
- log2(nuB+CB*phiB)), |
|
70 |
- scale=scale), ...) |
|
71 |
- } |
|
72 |
- } |
|
73 |
-} |
|
74 |
- |
|
75 |
- |
|
76 |
- |
|
77 |
- |
|
78 |
- |
|
79 |
- |
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/crlmm@43010 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -3,49 +3,26 @@ setValidity("CopyNumberSet", function(object) { |
3 | 3 |
if (is.null(msg)) TRUE else msg |
4 | 4 |
}) |
5 | 5 |
##may want to allow thresholding here (... arg) |
6 |
-setMethod("CA", "CopyNumberSet", function(object, ...) assayData(object)[["CA"]]/100) |
|
7 |
-setMethod("CB", "CopyNumberSet", function(object, ...) assayData(object)[["CB"]]/100) |
|
8 |
- |
|
9 |
-setReplaceMethod("CA", signature(object="CopyNumberSet", value="matrix"), function(object, value){ |
|
10 |
- dns <- dimnames(value) |
|
11 |
- value <- matrix(as.integer(value*100), nrow(value), ncol(value)) |
|
12 |
- dimnames(value) <- dns |
|
13 |
- assayDataElementReplace(object, "CA", value) |
|
14 |
-}) |
|
15 |
- |
|
16 |
-setReplaceMethod("CB", signature(object="CopyNumberSet", value="matrix"), function(object, value){ |
|
17 |
- dns <- dimnames(value) |
|
18 |
- value <- matrix(as.integer(value*100), nrow(value), ncol(value)) |
|
19 |
- dimnames(value) <- dns |
|
20 |
- assayDataElementReplace(object, "CB", value) |
|
21 |
-}) |
|
22 |
- |
|
6 |
+setMethod("CA", "CopyNumberSet", function(object) assayData(object)[["CA"]]/100) |
|
7 |
+setMethod("CB", "CopyNumberSet", function(object) assayData(object)[["CB"]]/100) |
|
23 | 8 |
|
9 |
+setReplaceMethod("CA", signature(object="CopyNumberSet", value="matrix"), |
|
10 |
+ function(object, value){ |
|
11 |
+ assayDataElementReplace(object, "CA", value) |
|
12 |
+ }) |
|
24 | 13 |
|
25 |
- |
|
26 |
-setMethod("batch", "CopyNumberSet", function(object){ |
|
27 |
- if("batch" %in% varLabels(object)){ |
|
28 |
- result <- object$batch |
|
29 |
- } else { |
|
30 |
- stop("batch not in varLabels of CopyNumberSet") |
|
31 |
- } |
|
32 |
- return(result) |
|
33 |
-}) |
|
14 |
+setReplaceMethod("CB", signature(object="CopyNumberSet", value="matrix"), |
|
15 |
+ function(object, value){ |
|
16 |
+ assayDataElementReplace(object, "CB", value) |
|
17 |
+ }) |
|
34 | 18 |
|
35 | 19 |
setMethod("copyNumber", "CopyNumberSet", function(object){ |
36 |
- require(paste(annotation(object), "Crlmm", sep=""), character.only=TRUE) || stop(paste("Annotation package ", annotation(object), "Crlmm not available", sep="")) |
|
37 |
- ##ensure that 2 + NA = 2 by replacing NA's with zero |
|
38 |
- ##the above results in copy number 0, 1, or 2 depending on the genotype....safer just to drop |
|
20 |
+ I <- isSnp(object) |
|
39 | 21 |
CA <- CA(object) |
40 | 22 |
CB <- CB(object) |
41 |
- ##nas <- is.na(CA) & is.na(CB) |
|
42 |
- ##CA[is.na(CA)] <- 0 |
|
43 |
- ##CB[is.na(CB)] <- 0 |
|
44 | 23 |
CN <- CA + CB |
45 | 24 |
##For nonpolymorphic probes, CA is the total copy number |
46 |
- CN[cnIndex(object, annotation(object)), ] <- CA(object)[cnIndex(object, annotation(object)), ] |
|
47 |
- ##if both CA and CB are NA, report NA |
|
48 |
- ##CN[nas] <- NA |
|
25 |
+ CN[!I, ] <- CA(object)[!I, ] |
|
49 | 26 |
CN |
50 | 27 |
}) |
51 | 28 |
|
... | ... |
@@ -98,3 +75,5 @@ ellipse.CopyNumberSet <- function(x, copynumber, ...){ |
98 | 75 |
|
99 | 76 |
|
100 | 77 |
|
78 |
+ |
|
79 |
+ |
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/crlmm@42431 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -6,10 +6,19 @@ setValidity("CopyNumberSet", function(object) { |
6 | 6 |
setMethod("CA", "CopyNumberSet", function(object, ...) assayData(object)[["CA"]]/100) |
7 | 7 |
setMethod("CB", "CopyNumberSet", function(object, ...) assayData(object)[["CB"]]/100) |
8 | 8 |
|
9 |
-setReplaceMethod("CA", signature(object="CopyNumberSet", value="matrix"), |
|
10 |
- function(object, value) assayDataElementReplace(object, "CA", value*100)) |
|
11 |
-setReplaceMethod("CB", signature(object="CopyNumberSet", value="matrix"), |
|
12 |
- function(object, value) assayDataElementReplace(object, "CB", value*100)) |
|
9 |
+setReplaceMethod("CA", signature(object="CopyNumberSet", value="matrix"), function(object, value){ |
|
10 |
+ dns <- dimnames(value) |
|
11 |
+ value <- matrix(as.integer(value*100), nrow(value), ncol(value)) |
|
12 |
+ dimnames(value) <- dns |
|
13 |
+ assayDataElementReplace(object, "CA", value) |
|
14 |
+}) |
|
15 |
+ |
|
16 |
+setReplaceMethod("CB", signature(object="CopyNumberSet", value="matrix"), function(object, value){ |
|
17 |
+ dns <- dimnames(value) |
|
18 |
+ value <- matrix(as.integer(value*100), nrow(value), ncol(value)) |
|
19 |
+ dimnames(value) <- dns |
|
20 |
+ assayDataElementReplace(object, "CB", value) |
|
21 |
+}) |
|
13 | 22 |
|
14 | 23 |
|
15 | 24 |
|
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/crlmm@42271 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/crlmm@42144 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -6,12 +6,14 @@ setValidity("CopyNumberSet", function(object) { |
6 | 6 |
##may want to allow thresholding here (... arg) |
7 | 7 |
setMethod("CA", "CopyNumberSet", function(object, ...) assayData(object)[["CA"]]/100) |
8 | 8 |
setMethod("CB", "CopyNumberSet", function(object, ...) assayData(object)[["CB"]]/100) |
9 |
-setReplaceMethod("CB", signature(object="CopyNumberSet", value="matrix"), |
|
10 |
- function(object, value) assayDataElementReplace(object, "CB", value)) |
|
9 |
+ |
|
11 | 10 |
setReplaceMethod("CA", signature(object="CopyNumberSet", value="matrix"), |
12 |
- function(object, value) assayDataElementReplace(object, "CA", value)) |
|
11 |
+ function(object, value) assayDataElementReplace(object, "CA", value*100)) |
|
12 |
+setReplaceMethod("CB", signature(object="CopyNumberSet", value="matrix"), |
|
13 |
+ function(object, value) assayDataElementReplace(object, "CB", value*100)) |
|
14 |
+ |
|
15 |
+ |
|
13 | 16 |
|
14 |
-setMethod("chromosome", "CopyNumberSet", function(object) fData(object)$chromosome) |
|
15 | 17 |
|
16 | 18 |
setMethod("batch", "CopyNumberSet", function(object){ |
17 | 19 |
if("batch" %in% varLabels(object)){ |
... | ... |
@@ -23,19 +25,23 @@ setMethod("batch", "CopyNumberSet", function(object){ |
23 | 25 |
}) |
24 | 26 |
|
25 | 27 |
setMethod("copyNumber", "CopyNumberSet", function(object){ |
28 |
+ require(paste(annotation(object), "Crlmm", sep=""), character.only=TRUE) || stop(paste("Annotation package ", annotation(object), "Crlmm not available", sep="")) |
|
26 | 29 |
##ensure that 2 + NA = 2 by replacing NA's with zero |
30 |
+ ##the above results in copy number 0, 1, or 2 depending on the genotype....safer just to drop |
|
27 | 31 |
CA <- CA(object) |
28 | 32 |
CB <- CB(object) |
29 |
- nas <- is.na(CA) & is.na(CB) |
|
30 |
- CA[is.na(CA)] <- 0 |
|
31 |
- CB[is.na(CB)] <- 0 |
|
33 |
+ ##nas <- is.na(CA) & is.na(CB) |
|
34 |
+ ##CA[is.na(CA)] <- 0 |
|
35 |
+ ##CB[is.na(CB)] <- 0 |
|
32 | 36 |
CN <- CA + CB |
37 |
+ ##For nonpolymorphic probes, CA is the total copy number |
|
38 |
+ CN[cnIndex(object, annotation(object)), ] <- CA(object)[cnIndex(object, annotation(object)), ] |
|
33 | 39 |
##if both CA and CB are NA, report NA |
34 |
- CN[nas] <- NA |
|
40 |
+ ##CN[nas] <- NA |
|
35 | 41 |
CN |
36 | 42 |
}) |
37 | 43 |
|
38 |
-setMethod("position", "CopyNumberSet", function(object) fData(object)$position) |
|
44 |
+ |
|
39 | 45 |
|
40 | 46 |
##setMethod("ellipse", "CopyNumberSet", function(x, copynumber, ...){ |
41 | 47 |
ellipse.CopyNumberSet <- function(x, copynumber, ...){ |
... | ... |
@@ -43,7 +49,15 @@ ellipse.CopyNumberSet <- function(x, copynumber, ...){ |
43 | 49 |
##fittedOrder <- unique(sapply(basename(celFiles), function(x) strsplit(x, "_")[[1]][2])) |
44 | 50 |
##index <- match(plates, fittedOrder) |
45 | 51 |
if(nrow(x) > 1) stop("only 1 snp at a time") |
46 |
- batch <- unique(x$batch) |
|
52 |
+ ##batch <- unique(x$batch) |
|
53 |
+ args <- list(...) |
|
54 |
+ if(!"batch" %in% names(args)){ |
|
55 |
+ jj <- match("batch", varLabels(x)) |
|
56 |
+ if(length(jj) < 1) stop("batch not in varLabels") |
|
57 |
+ batch <- unique(pData(x)[, jj]) |
|
58 |
+ } else{ |
|
59 |
+ batch <- unique(args$batch) |
|
60 |
+ } |
|
47 | 61 |
if(length(batch) > 1) stop("batch variable not unique") |
48 | 62 |
nuA <- as.numeric(fData(x)[, match(paste("nuA", batch, sep="_"), fvarLabels(x))]) |
49 | 63 |
nuB <- as.numeric(fData(x)[, match(paste("nuB", batch, sep="_"), fvarLabels(x))]) |
... | ... |
@@ -65,6 +79,7 @@ ellipse.CopyNumberSet <- function(x, copynumber, ...){ |
65 | 79 |
if(CA == 0 & CB > 0) rho <- corrA.BB |
66 | 80 |
if(CA > 0 & CB == 0) rho <- corrB.AA |
67 | 81 |
if(CA > 0 & CB > 0) rho <- corr |
82 |
+ if(CA == 0 & CB == 0) rho <- 0 |
|
68 | 83 |
lines(ellipse(x=rho, centre=c(log2(nuA+CA*phiA), |
69 | 84 |
log2(nuB+CB*phiB)), |
70 | 85 |
scale=scale), ...) |
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/crlmm@40618 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -3,8 +3,9 @@ setValidity("CopyNumberSet", function(object) { |
3 | 3 |
msg <- validMsg(NULL, assayDataValidMembers(assayData(object), c("CA", "CB"))) |
4 | 4 |
if (is.null(msg)) TRUE else msg |
5 | 5 |
}) |
6 |
-setMethod("CA", "CopyNumberSet", function(object) assayData(object)[["CA"]]/100) |
|
7 |
-setMethod("CB", "CopyNumberSet", function(object) assayData(object)[["CB"]]/100) |
|
6 |
+##may want to allow thresholding here (... arg) |
|
7 |
+setMethod("CA", "CopyNumberSet", function(object, ...) assayData(object)[["CA"]]/100) |
|
8 |
+setMethod("CB", "CopyNumberSet", function(object, ...) assayData(object)[["CB"]]/100) |
|
8 | 9 |
setReplaceMethod("CB", signature(object="CopyNumberSet", value="matrix"), |
9 | 10 |
function(object, value) assayDataElementReplace(object, "CB", value)) |
10 | 11 |
setReplaceMethod("CA", signature(object="CopyNumberSet", value="matrix"), |
... | ... |
@@ -12,6 +13,14 @@ setReplaceMethod("CA", signature(object="CopyNumberSet", value="matrix"), |
12 | 13 |
|
13 | 14 |
setMethod("chromosome", "CopyNumberSet", function(object) fData(object)$chromosome) |
14 | 15 |
|
16 |
+setMethod("batch", "CopyNumberSet", function(object){ |
|
17 |
+ if("batch" %in% varLabels(object)){ |
|
18 |
+ result <- object$batch |
|
19 |
+ } else { |
|
20 |
+ stop("batch not in varLabels of CopyNumberSet") |
|
21 |
+ } |
|
22 |
+ return(result) |
|
23 |
+}) |
|
15 | 24 |
|
16 | 25 |
setMethod("copyNumber", "CopyNumberSet", function(object){ |
17 | 26 |
##ensure that 2 + NA = 2 by replacing NA's with zero |
... | ... |
@@ -29,8 +38,8 @@ setMethod("copyNumber", "CopyNumberSet", function(object){ |
29 | 38 |
setMethod("position", "CopyNumberSet", function(object) fData(object)$position) |
30 | 39 |
|
31 | 40 |
##setMethod("ellipse", "CopyNumberSet", function(x, copynumber, ...){ |
32 |
-##ellipse.CopyNumberSet <- function(x, copynumber, ...){ |
|
33 |
-setMethod("ellipse", "CopyNumberSet", function(x, copynumber, ...){ |
|
41 |
+ellipse.CopyNumberSet <- function(x, copynumber, ...){ |
|
42 |
+##setMethod("ellipse", "CopyNumberSet", function(x, copynumber, ...){ |
|
34 | 43 |
##fittedOrder <- unique(sapply(basename(celFiles), function(x) strsplit(x, "_")[[1]][2])) |
35 | 44 |
##index <- match(plates, fittedOrder) |
36 | 45 |
if(nrow(x) > 1) stop("only 1 snp at a time") |
... | ... |
@@ -61,7 +70,7 @@ setMethod("ellipse", "CopyNumberSet", function(x, copynumber, ...){ |
61 | 70 |
scale=scale), ...) |
62 | 71 |
} |
63 | 72 |
} |
64 |
-}) |
|
73 |
+} |
|
65 | 74 |
|
66 | 75 |
|
67 | 76 |
|
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/crlmm@40527 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -3,15 +3,15 @@ setValidity("CopyNumberSet", function(object) { |
3 | 3 |
msg <- validMsg(NULL, assayDataValidMembers(assayData(object), c("CA", "CB"))) |
4 | 4 |
if (is.null(msg)) TRUE else msg |
5 | 5 |
}) |
6 |
-setMethod("CA", "CopyNumberSet", function(object) assayData(object)[["CA"]]) |
|
7 |
-setMethod("CB", "CopyNumberSet", function(object) assayData(object)[["CB"]]) |
|
6 |
+setMethod("CA", "CopyNumberSet", function(object) assayData(object)[["CA"]]/100) |
|
7 |
+setMethod("CB", "CopyNumberSet", function(object) assayData(object)[["CB"]]/100) |
|
8 | 8 |
setReplaceMethod("CB", signature(object="CopyNumberSet", value="matrix"), |
9 | 9 |
function(object, value) assayDataElementReplace(object, "CB", value)) |
10 | 10 |
setReplaceMethod("CA", signature(object="CopyNumberSet", value="matrix"), |
11 | 11 |
function(object, value) assayDataElementReplace(object, "CA", value)) |
12 | 12 |
|
13 | 13 |
setMethod("chromosome", "CopyNumberSet", function(object) fData(object)$chromosome) |
14 |
-setMethod("position", "CopyNumberSet", function(object) fData(object)$position) |
|
14 |
+ |
|
15 | 15 |
|
16 | 16 |
setMethod("copyNumber", "CopyNumberSet", function(object){ |
17 | 17 |
##ensure that 2 + NA = 2 by replacing NA's with zero |
... | ... |
@@ -20,14 +20,17 @@ setMethod("copyNumber", "CopyNumberSet", function(object){ |
20 | 20 |
nas <- is.na(CA) & is.na(CB) |
21 | 21 |
CA[is.na(CA)] <- 0 |
22 | 22 |
CB[is.na(CB)] <- 0 |
23 |
- CN <- CA/100 + CB/100 |
|
23 |
+ CN <- CA + CB |
|
24 | 24 |
##if both CA and CB are NA, report NA |
25 | 25 |
CN[nas] <- NA |
26 | 26 |
CN |
27 | 27 |
}) |
28 | 28 |
|
29 |
+setMethod("position", "CopyNumberSet", function(object) fData(object)$position) |
|
30 |
+ |
|
29 | 31 |
##setMethod("ellipse", "CopyNumberSet", function(x, copynumber, ...){ |
30 |
-ellipse.CopyNumberSet <- function(x, copynumber, ...){ |
|
32 |
+##ellipse.CopyNumberSet <- function(x, copynumber, ...){ |
|
33 |
+setMethod("ellipse", "CopyNumberSet", function(x, copynumber, ...){ |
|
31 | 34 |
##fittedOrder <- unique(sapply(basename(celFiles), function(x) strsplit(x, "_")[[1]][2])) |
32 | 35 |
##index <- match(plates, fittedOrder) |
33 | 36 |
if(nrow(x) > 1) stop("only 1 snp at a time") |
... | ... |
@@ -58,7 +61,7 @@ ellipse.CopyNumberSet <- function(x, copynumber, ...){ |
58 | 61 |
scale=scale), ...) |
59 | 62 |
} |
60 | 63 |
} |
61 |
-} |
|
64 |
+}) |
|
62 | 65 |
|
63 | 66 |
|
64 | 67 |
|
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/crlmm@40371 bc3139a8-67e5-0310-9ffc-ced21a209358
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,65 @@ |
1 |
+setValidity("CopyNumberSet", function(object) { |
|
2 |
+ ##msg <- validMsg(NULL, Biobase:::isValidVersion(object, "CopyNumberSet")) |
|
3 |
+ msg <- validMsg(NULL, assayDataValidMembers(assayData(object), c("CA", "CB"))) |
|
4 |
+ if (is.null(msg)) TRUE else msg |
|
5 |
+}) |
|
6 |
+setMethod("CA", "CopyNumberSet", function(object) assayData(object)[["CA"]]) |
|
7 |
+setMethod("CB", "CopyNumberSet", function(object) assayData(object)[["CB"]]) |
|
8 |
+setReplaceMethod("CB", signature(object="CopyNumberSet", value="matrix"), |
|
9 |
+ function(object, value) assayDataElementReplace(object, "CB", value)) |
|
10 |
+setReplaceMethod("CA", signature(object="CopyNumberSet", value="matrix"), |
|
11 |
+ function(object, value) assayDataElementReplace(object, "CA", value)) |
|
12 |
+ |
|
13 |
+setMethod("chromosome", "CopyNumberSet", function(object) fData(object)$chromosome) |
|
14 |
+setMethod("position", "CopyNumberSet", function(object) fData(object)$position) |
|
15 |
+ |
|
16 |
+setMethod("copyNumber", "CopyNumberSet", function(object){ |
|
17 |
+ ##ensure that 2 + NA = 2 by replacing NA's with zero |
|
18 |
+ CA <- CA(object) |
|
19 |
+ CB <- CB(object) |
|
20 |
+ nas <- is.na(CA) & is.na(CB) |
|
21 |
+ CA[is.na(CA)] <- 0 |
|
22 |
+ CB[is.na(CB)] <- 0 |
|
23 |
+ CN <- CA/100 + CB/100 |
|
24 |
+ ##if both CA and CB are NA, report NA |
|
25 |
+ CN[nas] <- NA |
|
26 |
+ CN |
|
27 |
+}) |
|
28 |
+ |
|
29 |
+##setMethod("ellipse", "CopyNumberSet", function(x, copynumber, ...){ |
|
30 |
+ellipse.CopyNumberSet <- function(x, copynumber, ...){ |
|
31 |
+ ##fittedOrder <- unique(sapply(basename(celFiles), function(x) strsplit(x, "_")[[1]][2])) |
|
32 |
+ ##index <- match(plates, fittedOrder) |
|
33 |
+ if(nrow(x) > 1) stop("only 1 snp at a time") |
|
34 |
+ batch <- unique(x$batch) |
|
35 |
+ if(length(batch) > 1) stop("batch variable not unique") |
|
36 |
+ nuA <- as.numeric(fData(x)[, match(paste("nuA", batch, sep="_"), fvarLabels(x))]) |
|
37 |
+ nuB <- as.numeric(fData(x)[, match(paste("nuB", batch, sep="_"), fvarLabels(x))]) |
|
38 |
+ phiA <- as.numeric(fData(x)[, match(paste("phiA", batch, sep="_"), fvarLabels(x))]) |
|
39 |
+ phiB <- as.numeric(fData(x)[, match(paste("phiB", batch, sep="_"), fvarLabels(x))]) |
|
40 |
+ tau2A <- as.numeric(fData(x)[, match(paste("tau2A", batch, sep="_"), fvarLabels(x))]) |
|
41 |
+ tau2B <- as.numeric(fData(x)[, match(paste("tau2B", batch, sep="_"), fvarLabels(x))]) |
|
42 |
+ sig2A <- as.numeric(fData(x)[, match(paste("sig2A", batch, sep="_"), fvarLabels(x))]) |
|
43 |
+ sig2B <- as.numeric(fData(x)[, match(paste("sig2B", batch, sep="_"), fvarLabels(x))]) |
|
44 |
+ corrA.BB <- as.numeric(fData(x)[, match(paste("corrA.BB", batch, sep="_"), fvarLabels(x))]) |
|
45 |
+ corrB.AA <- as.numeric(fData(x)[, match(paste("corrB.AA", batch, sep="_"), fvarLabels(x))]) |
|
46 |
+ corr <- as.numeric(fData(x)[, match(paste("corr", batch, sep="_"), fvarLabels(x))]) |
|
47 |
+ for(CN in copynumber){ |
|
48 |
+ for(CA in 0:CN){ |
|
49 |
+ CB <- CN-CA |
|
50 |
+ A.scale <- sqrt(tau2A*(CA==0) + sig2A*(CA > 0)) |
|
51 |
+ B.scale <- sqrt(tau2B*(CB==0) + sig2B*(CB > 0)) |
|
52 |
+ scale <- c(A.scale, B.scale) |
|
53 |
+ if(CA == 0 & CB > 0) rho <- corrA.BB |
|
54 |
+ if(CA > 0 & CB == 0) rho <- corrB.AA |
|
55 |
+ if(CA > 0 & CB > 0) rho <- corr |
|
56 |
+ lines(ellipse(x=rho, centre=c(log2(nuA+CA*phiA), |
|
57 |
+ log2(nuB+CB*phiB)), |
|
58 |
+ scale=scale), ...) |
|
59 |
+ } |
|
60 |
+ } |
|
61 |
+} |
|
62 |
+ |
|
63 |
+ |
|
64 |
+ |
|
65 |
+ |