[BioC] affy: How to back transform the matrix to a vector? (low-level imaging)
Kasper Daniel Hansen
khansen at stat.Berkeley.EDU
Wed Feb 1 04:16:23 CET 2006
On Jan 31, 2006, at 4:34 PM, Simon Lin wrote:
> I am trying to transform the vector (pm and mm) extracted from
> @exprs to a
> matrix (2-D layout), so an image can be plotted. It works out.
Yes. I assume the code given below has been snapped from
getMethod("image", "AffyBatch")\
(Why do you want to generate that code anyway, when suitable image
functions exists?)
>
>
> Now, when I back-transform the image matrix to the vector, there
> are some
> trouble. See the code below.
>
>
>
> Seems that the matrix has to be transposed somehow. Any ideas?
> Thanks! -Simon
>
>
>
> library (affy)
>
> data (affybatch.example) # has 3 chips
>
> x<- affybatch.example
>
> m.vector <- log2( x at exprs[, 2]) # take the second array
>
>
>
> x.pos <- (1:nrow(x)) - (1 + getOption("BioC")$affy$xy.offset)
>
> y.pos <- (1:ncol(x)) - (1 + getOption("BioC")$affy$xy.offset)
>
> # from vector to matrix
>
> m <- as.matrix(rev(as.data.frame(matrix(m.vector, nrow = length
> (x.pos),
>
> ncol = length(y.pos)))))
If you debug this line, you will understand why a simple as.matrix
does not work. Basically, first a matrix is created. It is then
converted to a data.frame so that rev() works on columns. Look:
> matrix(1:9, nrow = 3)
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> as.data.frame(matrix(1:9, nrow = 3))
V1 V2 V3
1 1 4 7
2 2 5 8
3 3 6 9
> rev(as.data.frame(matrix(1:9, nrow = 3)))
V3 V2 V1
1 7 4 1
2 8 5 2
3 9 6 3
> as.matrix(rev(as.data.frame(matrix(1:9, nrow = 3))))
V3 V2 V1
1 7 4 1
2 8 5 2
3 9 6 3
> as.vector(as.matrix(rev(as.data.frame(matrix(1:9, nrow = 3)))))
[1] 7 8 9 4 5 6 1 2 3
Ok?
/Kasper
>
>
> # ????????????????
>
> # from matrix to vector
>
> m0.vector<- as.vector (m) # this does not work, need some
> massage of m
>
> # see if it works
>
> sum (m.vector!= m0.vector)
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
More information about the Bioconductor
mailing list