This is a test version of Biostars. For the public version, visit https://www.biostars.org.
extract count data for a gene ID list in R

Hello,

I am using below R code to extract count data for multiple samples from a file but not able to write as a matrix could you please help with it?

data = read.table("DESeq2-Norm-Count-Table.txt",header=T,sep='\t',check.names=F)
> otu.list = read.table("Aman_root_gene.list.txt",header=F,sep='\t',check.names=F)
> i <- row.names(data) %in% otu.list[[1]]
> dim(data[i, ])
[1] 25 72
> write.table(i,"Aman_root_25.gene.txt",sep="\t")

Many thanks

r

Please show content of that file.

1 answer

thanks, it is sorted by using below code.

> df = as.data.frame(data[i, ])
> write.table(df,"Aman_root_25.gene.txt",sep="\t")

Thanks

Do you not have to use:

write.table(df, 'Aman_root_25.gene.txt', sep = '\t', quote = FALSE)

?

Many thanks, I have updated the correct code, why we need to use quote= FALSE?

Yes, does changing it to df solve the problem?

quote = FALSE just prevents R adding quotations ( " ) to any text in the output file.

By mistake I post wrong code ....so I changed it. Yes above code work for me.

Log in to answer this question.