A numericvector of cell (probe) indices specifying
which cells to updated. If NULL, all indices are considered.
intensities
A numericvector of intensity values to be stored.
Alternatively, it can also be a named data.frame or matrix (or list)
where the named columns (elements) are the fields to be updated.
stdvs
A optional numericvector.
pixels
A optional numericvector.
writeMap
An optional write map.
...
Not used.
verbose
An integer specifying how much verbose details are
outputted.
Details
Currently only binary (v4) CEL files are supported.
The current version of the method does not make use of the Fusion SDK,
but its own code to navigate and update the CEL file.
Value
Returns (invisibly) the pathname of the file updated.
Author(s)
Henrik Bengtsson
Examples
##############################################################
if (require("AffymetrixDataTestFiles")) { # START #
##############################################################
# Search for some available Calvin CEL files
path <- system.file("rawData", package="AffymetrixDataTestFiles")
files <- findFiles(pattern="[.](cel|CEL)$", path=path, recursive=TRUE, firstOnly=FALSE)
files <- grep("FusionSDK_HG-U133A", files, value=TRUE)
files <- grep("Calvin", files, value=TRUE)
file <- files[1]
# Convert to an XDA CEL file
filename <- file.path(tempdir(), basename(file))
if (file.exists(filename))
file.remove(filename)
convertCel(file, filename)
fields <- c("intensities", "stdvs", "pixels")
# Cells to be updated
idxs <- 1:2
# Get CEL header
hdr <- readCelHeader(filename)
# Get the original data
cel <- readCel(filename, indices=idxs, readStdvs=TRUE, readPixels=TRUE)
print(cel[fields])
cel0 <- cel
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Square-root the intensities
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
updateCel(filename, indices=idxs, intensities=sqrt(cel$intensities))
cel <- readCel(filename, indices=idxs, readStdvs=TRUE, readPixels=TRUE)
print(cel[fields])
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Update a few cell values by a data frame
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data <- data.frame(
intensities=cel0$intensities,
stdvs=c(201.1, 3086.1)+0.5,
pixels=c(9,9+1)
)
updateCel(filename, indices=idxs, data)
# Assert correctness of update
cel <- readCel(filename, indices=idxs, readStdvs=TRUE, readPixels=TRUE)
print(cel[fields])
for (ff in fields) {
stopifnot(all.equal(cel[[ff]], data[[ff]], .Machine$double.eps^0.25))
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Update a region of the CEL file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Load pre-defined data
side <- 306
pathname <- system.file("extras/easternEgg.gz", package="affxparser")
con <- gzfile(pathname, open="rb")
z <- readBin(con=con, what="integer", size=1, signed=FALSE, n=side^2)
close(con)
z <- matrix(z, nrow=side)
side <- min(hdr$cols - 2*22, side)
z <- as.double(z[1:side,1:side])
x <- matrix(22+0:(side-1), nrow=side, ncol=side, byrow=TRUE)
idxs <- as.vector((1 + x) + hdr$cols*t(x))
# Load current data in the same region
z0 <- readCel(filename, indices=idxs)$intensities
# Mix the two data sets
z <- (0.3*z^2 + 0.7*z0)
# Update the CEL file
updateCel(filename, indices=idxs, intensities=z)
# Make some spatial changes
rotate270 <- function(x, ...) {
x <- t(x)
nc <- ncol(x)
if (nc < 2) return(x)
x[,nc:1,drop=FALSE]
}
# Display a spatial image of the updated CEL file
cel <- readCelRectangle(filename, xrange=c(0,350), yrange=c(0,350))
z <- rotate270(cel$intensities)
sub <- paste("Chip type:", cel$header$chiptype)
image(z, col=gray.colors(256), axes=FALSE, main=basename(filename), sub=sub)
text(x=0, y=1, labels="(0,0)", adj=c(0,-0.7), cex=0.8, xpd=TRUE)
text(x=1, y=0, labels="(350,350)", adj=c(1,1.2), cex=0.8, xpd=TRUE)
# Clean up
file.remove(filename)
rm(files, cel, cel0, idxs, data, ff, fields, rotate270)
##############################################################
} # STOP #
##############################################################
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(affxparser)
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/affxparser/updateCel.Rd_%03d_medium.png", width=480, height=480)
> ### Name: updateCel
> ### Title: Updates a CEL file
> ### Aliases: updateCel
> ### Keywords: file IO
>
> ### ** Examples
>
> ##############################################################
> if (require("AffymetrixDataTestFiles")) { # START #
+ ##############################################################
+
+ # Search for some available Calvin CEL files
+ path <- system.file("rawData", package="AffymetrixDataTestFiles")
+ files <- findFiles(pattern="[.](cel|CEL)$", path=path, recursive=TRUE, firstOnly=FALSE)
+ files <- grep("FusionSDK_HG-U133A", files, value=TRUE)
+ files <- grep("Calvin", files, value=TRUE)
+ file <- files[1]
+
+ # Convert to an XDA CEL file
+ filename <- file.path(tempdir(), basename(file))
+ if (file.exists(filename))
+ file.remove(filename)
+ convertCel(file, filename)
+
+
+ fields <- c("intensities", "stdvs", "pixels")
+
+ # Cells to be updated
+ idxs <- 1:2
+
+ # Get CEL header
+ hdr <- readCelHeader(filename)
+
+ # Get the original data
+ cel <- readCel(filename, indices=idxs, readStdvs=TRUE, readPixels=TRUE)
+ print(cel[fields])
+ cel0 <- cel
+
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ # Square-root the intensities
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ updateCel(filename, indices=idxs, intensities=sqrt(cel$intensities))
+ cel <- readCel(filename, indices=idxs, readStdvs=TRUE, readPixels=TRUE)
+ print(cel[fields])
+
+
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ # Update a few cell values by a data frame
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ data <- data.frame(
+ intensities=cel0$intensities,
+ stdvs=c(201.1, 3086.1)+0.5,
+ pixels=c(9,9+1)
+ )
+ updateCel(filename, indices=idxs, data)
+
+ # Assert correctness of update
+ cel <- readCel(filename, indices=idxs, readStdvs=TRUE, readPixels=TRUE)
+ print(cel[fields])
+ for (ff in fields) {
+ stopifnot(all.equal(cel[[ff]], data[[ff]], .Machine$double.eps^0.25))
+ }
+
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ # Update a region of the CEL file
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ # Load pre-defined data
+ side <- 306
+ pathname <- system.file("extras/easternEgg.gz", package="affxparser")
+ con <- gzfile(pathname, open="rb")
+ z <- readBin(con=con, what="integer", size=1, signed=FALSE, n=side^2)
+ close(con)
+ z <- matrix(z, nrow=side)
+ side <- min(hdr$cols - 2*22, side)
+ z <- as.double(z[1:side,1:side])
+ x <- matrix(22+0:(side-1), nrow=side, ncol=side, byrow=TRUE)
+ idxs <- as.vector((1 + x) + hdr$cols*t(x))
+ # Load current data in the same region
+ z0 <- readCel(filename, indices=idxs)$intensities
+ # Mix the two data sets
+ z <- (0.3*z^2 + 0.7*z0)
+ # Update the CEL file
+ updateCel(filename, indices=idxs, intensities=z)
+
+ # Make some spatial changes
+ rotate270 <- function(x, ...) {
+ x <- t(x)
+ nc <- ncol(x)
+ if (nc < 2) return(x)
+ x[,nc:1,drop=FALSE]
+ }
+
+ # Display a spatial image of the updated CEL file
+ cel <- readCelRectangle(filename, xrange=c(0,350), yrange=c(0,350))
+ z <- rotate270(cel$intensities)
+ sub <- paste("Chip type:", cel$header$chiptype)
+ image(z, col=gray.colors(256), axes=FALSE, main=basename(filename), sub=sub)
+ text(x=0, y=1, labels="(0,0)", adj=c(0,-0.7), cex=0.8, xpd=TRUE)
+ text(x=1, y=0, labels="(350,350)", adj=c(1,1.2), cex=0.8, xpd=TRUE)
+
+
+ # Clean up
+ file.remove(filename)
+ rm(files, cel, cel0, idxs, data, ff, fields, rotate270)
+
+
+ ##############################################################
+ } # STOP #
Loading required package: AffymetrixDataTestFiles
$intensities
[1] 31980 925
$stdvs
[1] 4553.5 106.9
$pixels
[1] 25 25
$intensities
[1] 178.82953 30.41381
$stdvs
[1] 4553.5 106.9
$pixels
[1] 25 25
$intensities
[1] 31980 925
$stdvs
[1] 201.6 3086.6
$pixels
[1] 9 10
> ##############################################################
>
>
>
>
>
>
> dev.off()
null device
1
>