Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 46 additions & 13 deletions R/combineArrays.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

outType <- match.arg(outType)
.isRGOrStop(rgSet)
stopifnot(.is450k(rgSet) || .isEPIC(rgSet))
# Make EPICv2 compatible | Add type EPICv2
stopifnot(.is450k(rgSet) || .isEPIC(rgSet) || .isEPICv2(rgSet))

array <- annotation(rgSet)["array"]
if (array == outType) stop("'rgSet' already in the 'outType' array type.")
Expand All @@ -54,44 +55,69 @@
commonNames <- intersect(probes1$Name, probes2$Name)
probes1 <- probes1[match(commonNames, probes1$Name), ]
probes2 <- probes2[match(commonNames, probes2$Name), ]
# Make EPICv2 compatible | EPICv2 remove different design probes
if (.isEPICv2(rgSet)){
Diff_Color_Indices <- which(probes1$Color != probes2$Color)
commonNames <- setdiff(commonNames, probes2$Name[Diff_Color_Indices])
Diff_ProbeSeqA_Indices <- which(probes1$ProbeSeqA != probes2$ProbeSeqA)
commonNames <- setdiff(commonNames, probes2$Name[Diff_ProbeSeqA_Indices])
probes1 <- probes1[match(commonNames, probes1$Name), ]
probes2 <- probes2[match(commonNames, probes2$Name), ]
}
stopifnot(all(probes1$Color == probes2$Color))
stopifnot(all(probes1$ProbeSeqA == probes2$ProbeSeqA))
stopifnot(all(probes1$ProbeSeqB == probes2$ProbeSeqB))
# Translating rgSet2 addresses to rgSet1 addresses
translate <- c(probes1$AddressA, probes1$AddressB)
names(translate) <- c(probes2$AddressA, probes2$AddressB)
wh <- which(rownames(rgSet) %in% names(translate))
rownames(rgSet)[wh] <- translate[rownames(rgSet)[wh]]
keepAddresses$I <- unname(translate)
# Fix Bug | Save relation between rgSet2 addresses and rgSet1 addresses. Don't change rownames(rgSet) here
keepAddresses$I <- names(translate)
translate_all <- translate

# Probes of Type II
probes1 <- getProbeInfo(manifest1, type = "II")
probes2 <- getProbeInfo(manifest2, type = "II")
commonNames <- intersect(probes1$Name, probes2$Name)
probes1 <- probes1[match(commonNames, probes1$Name),]
probes2 <- probes2[match(commonNames, probes2$Name),]
# Make EPICv2 compatible | EPICv2 remove different design probes
if (.isEPICv2(rgSet)){
Diff_ProbeSeqA_Indices <- which(probes1$ProbeSeqA != probes2$ProbeSeqA)
commonNames <- setdiff(commonNames, probes2$Name[Diff_ProbeSeqA_Indices])
probes1 <- probes1[match(commonNames, probes1$Name), ]
probes2 <- probes2[match(commonNames, probes2$Name), ]
}
stopifnot(all(probes1$ProbeSeqA == probes2$ProbeSeqA))
# Translating rgSet2 addresses to rgSet1 addresses
translate <- probes1$AddressA
names(translate) <- probes2$AddressA
wh <- which(rownames(rgSet) %in% names(translate))
rownames(rgSet)[wh] <- translate[rownames(rgSet)[wh]]
keepAddresses$II <- unname(translate)
# Fix Bug | Save relation between rgSet2 addresses and rgSet1 addresses. Don't change rownames(rgSet) here
keepAddresses$II <- names(translate)
translate_all <- c(translate_all, translate)

# Probes of Type SnpI
probes1 <- getProbeInfo(manifest1, type = "SnpI")
probes2 <- getProbeInfo(manifest2, type = "SnpI")
commonNames <- intersect(probes1$Name, probes2$Name)
probes1 <- probes1[match(commonNames, probes1$Name),]
probes2 <- probes2[match(commonNames, probes2$Name),]
# Make EPICv2 compatible | EPICv2 remove different design probes
if (.isEPICv2(rgSet)){
Diff_ProbeSeq1A2B_Indices <- which(probes1$ProbeSeqA != probes2$ProbeSeqB)
commonNames <- setdiff(commonNames, probes2$Name[Diff_ProbeSeq1A2B_Indices])
Diff_ProbeSeq1B2A_Indices <- which(probes1$ProbeSeqB != probes2$ProbeSeqA)
commonNames <- setdiff(commonNames, probes2$Name[Diff_ProbeSeq1B2A_Indices])
probes1 <- probes1[match(commonNames, probes1$Name), ]
probes2 <- probes2[match(commonNames, probes2$Name), ]
}
stopifnot(all(probes1$ProbeSeqA == probes2$ProbeSeqB))
stopifnot(all(probes1$ProbeSeqB == probes2$ProbeSeqA))
# Translating rgSet2 addresses to rgSet1 addresses
translate <- c(probes1$AddressA, probes1$AddressB)
names(translate) <- c(probes2$AddressA, probes2$AddressB)
wh <- which(rownames(rgSet) %in% names(translate))
rownames(rgSet)[wh] <- translate[rownames(rgSet)[wh]]
keepAddresses$SnpI <- unname(translate)
# Fix Bug | Save relation between rgSet2 addresses and rgSet1 addresses. Don't change rownames(rgSet) here
keepAddresses$SnpI <- names(translate)
translate_all <- c(translate_all, translate)

# Probes of Type SnpII
probes1 <- getProbeInfo(manifest1, type = "SnpII")
Expand All @@ -103,9 +129,9 @@
# Translating rgSet2 addresses to rgSet1 addresses
translate <- probes1$AddressA
names(translate) <- probes2$AddressA
wh <- which(rownames(rgSet) %in% names(translate))
rownames(rgSet)[wh] <- translate[rownames(rgSet)[wh]]
keepAddresses$SnpII <- unname(translate)
# Fix Bug | Save relation between rgSet2 addresses and rgSet1 addresses. Don't change rownames(rgSet) here
keepAddresses$SnpII <- names(translate)
translate_all <- c(translate_all, translate)

# Probes of Type Control
probes1 <- getProbeInfo(manifest1, type = "Control")
Expand All @@ -119,6 +145,13 @@
keepAddresses <- do.call("c", keepAddresses)
keepAddresses <- keepAddresses[keepAddresses %in% rownames(rgSet)]
rgSet <- rgSet[keepAddresses, ]
# Fix Bug | Change rownames(rgSet) to rgSet1 addresses here
wh <- which(rownames(rgSet) %in% names(translate_all))
rownames(rgSet)[wh] <- translate_all[rownames(rgSet)[wh]]
# Set rownames(Green) and rownames(Red) to rgSet1 addresses
rownames(rgSet@assays@data@listData$Green) <- rownames(rgSet)
rownames(rgSet@assays@data@listData$Red) <- rownames(rgSet)
# Set annotation to outType
annotation(rgSet) <- .getAnnotationFromOutType(outType)
rgSet
}
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ ilogit2 <- function(x) 2^x / (1 + 2^x)
annotation(object)["array"] == "IlluminaHumanMethylationEPIC"
}

.isEPICv2 <- function(object) {
annotation(object)["array"] == "IlluminaHumanMethylationEPICv2"
}

.isAllergy <- function(object) {
annotation(object)["array"] == "IlluminaHumanMethylationAllergy"
}
Expand Down