i need a tab-delimited format
1
0
Entering edit mode
8.8 years ago
zizigolu ★ 4.3k

Hello,

I need a tab-delimited text format in which the first column is probesets, the header are array name and in between there are amounts, for example with 12 array, there are 13 columns that the first is prob sets but when I did like below, a messy file was produced that can't be used as tab-delimited and nothing is arranged alike I described

(affy)

> data <- ReadAffy()
> exp <- rma(data)

Background correcting
Normalizing
Calculating Expression
> control <- grep("AFFX",rownames(exp))
> exp <- exp[-control,]
> e <- exprs(exp)
> e <- apply(e,1,function(x) x-median(x))
> e.scaled <- t(scale(t(e),center=FALSE))
write.table(e.scaled,file="scaled.output.txt",sep="\t")

What happened please?

R • 2.7k views
ADD COMMENT
1
Entering edit mode

show here output of

head(e.scaled)
ADD REPLY
1
Entering edit mode

thank Deepak, a long R console that I copied a bit of

here instead of probes, arrays are in column one and no thing is like a tab-delimited format

ADD REPLY
1
Entering edit mode

Perform these 3 commands and show the output:

head(e.scaled)
dim(e.scaled)
str(e.scaled)
ADD REPLY
1
Entering edit mode

thank you,

[1]    12 30302
> str(e.scaled)
 num [1:12, 1:30302] -0.0315 -0.0786 -0.0576 0.1015 0.0796 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:12] "GSM839728_GF_28mm_EC-1.CEL" "GSM839729_GF_28mm_EC-2.CEL" "GSM839730_GF_28mm_EC-3.CEL" "GSM839731_GF_28mm_PC-1.CEL" ...
  ..$ : chr [1:30302] "AF506028_F_at" "AF506028_R_at" "Cit.100.1.S1_x_at" "Cit.1000.1.S1_s_at" ...
 - attr(*, "scaled:scale")= Named num [1:12] 0.576 0.596 0.579 0.644 0.642 ...
  ..- attr(*, "names")= chr [1:12] "GSM839728_GF_28mm_EC-1.CEL" "GSM839729_GF_28mm_EC-2.CEL" "GSM839730_GF_28mm_EC-3.CEL" "GSM839731_GF_28mm_PC-1.CEL" ...
>

and the output of head(e.scaled) was which I copied and pasted in previous comment

ADD REPLY
3
Entering edit mode
8.8 years ago
Deepak Tanwar ★ 4.2k

Perform these commands:

write.table(e.scaled, file = "scaled_output.txt", sep = "\t", quote = F)

Now, try to read the table you have created in R

scaled_table <- read.table("scaled_output.txt", sep = "\t", header = T, stringAsFactors = F, check.names = F, comment.char = "")

View the table by:

View(scaled_table)

If you are able to see a proper table, that is a tab-deli. file. If you open and see a text file, it would be weird for you because of the no. of columns. I will not suggest to open a file in excel. If you use linux, you could open in terminal by:

cat scaled_output.txt | cut -f 1,2

This will display only first and second column.

ADD COMMENT
1
Entering edit mode

thank you Deepak for paying attention

I did so:

data <- ReadAffy()
> 
> exp <- rma(data)

Background correcting
Normalizing
Calculating Expression
>  control <- grep("AFFX",rownames(exp))
>  exp <- exp[-control,]
>  e <- exprs(exp)
>  e <- apply(e,1,function(x) x-median(x))
>  e.scaled <- t(scale(t(e),center=FALSE))
>  write.table(e.scaled, file = "scaled_output.txt", sep = "\t", quote = F)
> scaled_table <- read.table("scaled_output.txt", sep = "\t", header = T, stringAsFactors = F, check.names = F, comment.char = "")
Error in read.table("scaled_output.txt", sep = "\t", header = T, stringAsFactors = F,  :
  unused argument (stringAsFactors = F)
> View(scaled_table)
Error in as.data.frame(x) : object 'scaled_table' not found
>
ADD REPLY
2
Entering edit mode

my bad, its

stringsAsFactors = F
ADD REPLY
1
Entering edit mode

when I corrected the last code like this

scaled_table <- read.table("scaled_output.txt", sep = "\t", header = T, stringsAsFactors = F, check.names = F, comment.char = "")

R started to process for long time and still continuing....thank you Deepak

ADD REPLY
2
Entering edit mode

It might take some time, depending on the size of data. In actual, this was just your confusion regarding the the tab-del. data file. Whenever the data is very big, like this, you should save it as a R object.

saveRDS(scaled_output.txt, file="myDataFile.rds")

Load the data frame

x <- readRDS(file="myDataFile.rds")

This would be very quick

ADD REPLY
0
Entering edit mode
> data <- ReadAffy()
>  exp <- rma(data)

Background correcting
Normalizing
Calculating Expression
> control <- grep("AFFX",rownames(exp))
>  exp <- exp[-control,]
>  e <- exprs(exp)
>  e <- apply(e,1,function(x) x-median(x))
>  e.scaled <- t(scale(t(e),center=FALSE))
>  write.table(e.scaled, file = "scaled_output.txt", sep = "\t", quote = F)
>  > scaled_table <- read.table("scaled_output.txt", sep = "\t", header = T, stringsAsFactors = F, check.names = F, comment.char= "")
Error: unexpected '>' in " >"
> write.table(e.scaled, file = "scaled_output.txt", sep = "\t", quote = F)
> write.table(e.scaled, file = "scaled_output.txt", sep = "\t", quote = F)
> write.table(e.scaled, file = "scaled_output.txt", sep = "\t", quote = F)
> >  > scaled_table <- read.table("scaled_output.txt", sep = "\t", header = T, stringsAsFactors = F, check.names = F, comment.char
Error: unexpected '>' in ">"
> scaled_table <- read.table("scaled_output.txt", sep = "\t", header = T, stringsAsFactors = F, check.names = F, comment.char= "")
>  saveRDS(scaled_output.txt, file="myDataFile.rds")
Error in saveRDS(scaled_output.txt, file = "myDataFile.rds") :
  object 'scaled_output.txt' not found
> 
> x <- readRDS(file="myDataFile.rds")
Error in readRDS(file = "myDataFile.rds") : error reading from connection

sorry Deepak for disturbance

ADD REPLY
0
Entering edit mode

What are you trying to do here?

You loaded data into scaled_table (scaled_table <- read.table()) and try to save object scaled_output.txt.

You should read error messages, everything is written there (object 'scaled_output.txt' not found).

ADD REPLY
0
Entering edit mode

in this post I was trying to have a tab-delimited format that can be read by my workbench...I followed codes but by these codes problem is the same

ADD REPLY
1
Entering edit mode

Sarah, you have to save the object scaled table

saveRDS(scaled_table, file="myDataFile.rds")
ADD REPLY
0
Entering edit mode

thank you Deepak

ADD REPLY

Login before adding your answer.

Traffic: 2546 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