matrix transposing in R
6
0
Entering edit mode
Angel ▴ 40
@angel-7981
Last seen 7.7 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 • 3.6k views
ADD COMMENT
2
Entering edit mode
arfranco ▴ 130
@arfranco-8341
Last seen 7 months 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..

ADD COMMENT
2
Entering edit mode
arfranco ▴ 130
@arfranco-8341
Last seen 7 months 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

 

ADD COMMENT
1
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

> head(rawData)
Error in head(rawData) : object 'rawData' not found
>
> str(rawData)
Error in str(rawData) : object 'rawData' not found

did i wrong?
 

ADD REPLY
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

ADD REPLY
0
Entering edit mode

thank you Antonio

ADD REPLY
1
Entering edit mode
Angel ▴ 40
@angel-7981
Last seen 7.7 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))
rawData = ReadAffy(filenames=fileNames)
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...

ADD COMMENT
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.

ADD REPLY
0
Entering edit mode

thank you Martin

ADD REPLY
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")
Loading required package: BiocGenerics
Loading required package: parallel

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’
> dataDirectory <- system.file("extdata", package="Biobase")
> "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")
> exprs <- as.matrix(read.table(exprsFile, header=TRUE, sep="\t",
+ row.names=1,
+ as.is=TRUE))
Error in read.table(exprsFile, header = TRUE, sep = "\t", row.names = 1,  :
  object 'exprsFile' not found
> exprs <- as.matrix(read.table(exprsGSE33964, header=TRUE, sep="\t",
+ row.names=1,
+ as.is=TRUE))
Error in read.table(exprsGSE33964, header = TRUE, sep = "\t", row.names = 1,  :
  object 'exprsGSE33964' not found
>  exprs <- as.matrix(read.table(exprsGSE33964, header=TRUE, sep="\t",
+ + row.names=1,
Error: unexpected '=' in:
" exprs <- as.matrix(read.table(exprsGSE33964, header=TRUE, sep="\t",
+ row.names="
>  exprs <- as.matrix(read.table("E:/New folder" , header=TRUE,  sep="\t",
+ row.names=1,
+ as.is=TRUE))
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : cannot open file 'E:/New folder': Permission denied
>  exprs <- as.matrix(read.table("E:/New folder/GSE33964" , header=TRUE,  sep="\t",
+ row.names=1,
+  as.is=TRUE))
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
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....

ADD REPLY
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.

ADD REPLY
0
Entering edit mode

thank you, you all right

ADD REPLY

Login before adding your answer.

Traffic: 671 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6