matrix transposing in R
6
0
Entering edit mode
Angel ▴ 40
@angel-7981
Last seen 5.8 years ago
Berlin

hello,

i have a file normalized by mas5, i want to transpose that, i typed these codes but no new file was produced or no changed i saw in primary file. then where is transposed matrix please or if i did right?

changedir

> GSE33964_new <- t(GSE33964)
> GSE33964 <- matrix(1:30, 5, 6)
> tGSE33964 <- t(GSE33964) ##-- i.e.,  GSE33964[i, j] == tGSE33964[j, i] for all i,j :
> for(j in seq(ncol(a)))
+      if(! all(GSE33964[, j] == tGSE33964[j, ])) stop("wrong transpose")
> transpose_GSE33964 <- t(GSE33964)

affy mas5 • 2.5k views
2
Entering edit mode
arfranco ▴ 130
@arfranco-8341
Last seen 21 hours ago
European Union

I gave a look to GSE33964, and this is file with RAW data containing 12 different sub-samples, each of them in CEL format

I don't see how you can transpose this data in a usable format. I don't see with the information you give how you could normalize that data

It is sort of confusing..

2
Entering edit mode
arfranco ▴ 130
@arfranco-8341
Last seen 21 hours ago
European Union

Simply run the following into R

>head(rawData)

>str(rawData)

And you will see how your downloaded  data have been read with the readAffy() from the original gz compressed file to become a special file (rawData) that encompasses many different parts (data.frames, vector, factors, matrix) organized into a special class file (type) that includes all of the necessary information for Affy to proceed

If you want to transpose something, it has to be part of this special class file, and you need to learn how to name it or extract it

1
Entering edit mode

And anyway... Why do you want or need to transpose your data for ?

0
Entering edit mode

i want to do pearson coeficient correlation which needs a transposed matrix

0
Entering edit mode

i changed directory towhere  my CEL files are there and typed:

>
> str(rawData)

did i wrong?

1
Entering edit mode

You have writting the following code

rawData = ReadAffy(filenames=fileNames)

So after reading your data or having that file in the global environment is when you have to run the head(rawData), str(rawData) or even summarize(rawData) and class(rawData)

This will allow you to see the internal structure of this file. Then you have to learn how to find and discover where into this file is your data, and how to use it

0
Entering edit mode

thank you Antonio

1
Entering edit mode
Angel ▴ 40
@angel-7981
Last seen 5.8 years ago
Berlin

first i normalized GSE33964, with below commands

library(affy)
library(methods)
inFilePattern = "*CEL.gz"
outFilePath = "GSE33964.matrix"
fileNames = list.files(pattern=glob2rx(inFilePattern))
eset <- mas5(rawData)
write.exprs(eset, file=outFilePath, col.names=NA)

i dont know how to transpose the resulted file now, i file containing NA...

1
Entering edit mode

Rather than working with files, work with the object that you have available. Extract the matrix of expression values from the eset, and transpose that

t(exprs(eset))

See the Biobase vignette for working with ExpressionSet objects.

0
Entering edit mode

thank you Martin

0
Entering edit mode

sorry martin, i named my text file resulted from mas5 normalizing GSE33964 which stored in E:\New folder

i typed:

> library("Biobase")

Attaching package: ‘BiocGenerics’

The following objects are masked from ‘package:parallel’:

clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB

The following object is masked from ‘package:stats’:

xtabs

The following objects are masked from ‘package:base’:

anyDuplicated, append, as.data.frame, as.vector, cbind, colnames,
do.call, duplicated, eval, evalq, Filter, Find, get, intersect,
is.unsorted, lapply, Map, mapply, match, mget, order, paste, pmax,
pmax.int, pmin, pmin.int, Position, rank, rbind, Reduce, rep.int,
rownames, sapply, setdiff, sort, table, tapply, union, unique,
unlist, unsplit

Welcome to Bioconductor

Vignettes contain introductory material; view with
'browseVignettes()'. To cite Bioconductor, see
'citation("Biobase")', and for packages 'citation("pkgname")'.

> library(convert)
Error in library(convert) : there is no package called ‘convert’
> "E:\New folder" <- file.path(dataDirectory, "GSE33964")
Error: '\N' is an unrecognized escape in character string starting ""E:\N"
> "E:/New folder" <- file.path(dataDirectory, "GSE33964")
+ row.names=1,
+ as.is=TRUE))
Error in read.table(exprsFile, header = TRUE, sep = "\t", row.names = 1,  :
+ row.names=1,
+ as.is=TRUE))
Error in read.table(exprsGSE33964, header = TRUE, sep = "\t", row.names = 1,  :
+ + row.names=1,
Error: unexpected '=' in:
+ row.names="
+ row.names=1,
+ as.is=TRUE))
Error in file(file, "rt") : cannot open the connection
In file(file, "rt") : cannot open file 'E:/New folder': Permission denied
+ row.names=1,
+  as.is=TRUE))
Error in file(file, "rt") : cannot open the connection
In file(file, "rt") :
cannot open file 'E:/New folder/GSE33964': No such file or directory

really i got confused to transpose my text file....

0
Entering edit mode

Please edit your code to remove errors that you know you took, e.g., trying to load the 'convert' package when it was not yet installed, and your various typos and so on. I guess you're just trying to read a file in to R, and you have failed to identify the correct location. Try

fname = file.choose()


This should open a dialog box which allows you to choose the file that you would like to input. Verify that you've chosen the correct file by typing fname, and by testing it's existence

fname
file.exists(fname)

Finally, read in the data (maybe the options you give are correct, but maybe not, it depends on your file format)

exprs <- as.matrix(read.table(fname , header=TRUE,  sep="\t",
row.names=1, as.is=TRUE))


Please also take a few minutes to look at the output, and to compare it to the commands you tried to enter, and to read introductory R documentation; it doesn't make sense to try to run before walking. It might help to find a colleague at your local institution with whom you can explore the basics of R together.

0
Entering edit mode

thank you, you all right