Error in as.vector(x) : no method for coercing this S4 class to a vector
I tried to run the following code in R studio. Everything worked fine, except at the last step [write.table(mdat, "recount_mdat.csv")] when I tried to export the 'mdat', I got the following error:
Error in as.vector(x) : no method for coercing this S4 class to a vector
My code
library('dplyr')
library('recount')
library('magrittr')
library('ffpe')
library('RSkittleBrewer')
library('SummarizedExperiment')
library('devtools')
trop <- RSkittleBrewer::RSkittleBrewer('tropical')
colon_proj <- c('SRP025982', 'SRP42161')
if(any(!file.exists(file.path(colon_proj, 'rse_gene.Rdata')))) {
sapply(colon_proj, download_study)
}
blood_proj <- c('SRP066834', 'SRP041736', 'SRP060416')
if(any(!file.exists(file.path(blood_proj, 'rse_gene.Rdata')))) {
sapply(blood_proj, download_study)
}
proj <- c(colon_proj,blood_proj)
dat <- lapply(proj, function(x) {
load(file.path(x, 'rse_gene.Rdata'))
return(rse_gene)
})
proj
sapply(dat, dim)
metadata <- all_metadata('sra')
write.table(metadata, "recount_metadata.csv")
mdat <- do.call(cbind, dat)
write.table(mdat, "recount_mdat.csv")
• 14,681 views
•
link
1 answer
You can't cbind a bunch of obscure object types.
If you want merged count tables you should do this:
mdat <- do.call(cbind,lapply(dat,assay))
Where row.names are Ensembl gene IDs and col.names are the SRR accessions.
Then run your write.table(mdat, "recount_mdat.csv") command.
-
If you want the coordinates of your genes then do this to make a bed with the genomic locations:
library(rtracklayer)
export.bed(rowRanges(dat[[1]]),'gene_coords.bed')
• 0 views
•
link
Log in to answer this question.
Do you understand the steps that you are doing? Your error should be in "mdat <- do.call(cbind, dat)" rather than the following step of write.table.
Hint: what does class(rse_gene) give you? if it not a vector, you can't run your cbind with do.call because cbind expects a vector (or matrix)
Hello priyankaraina10!
We believe that this post does not fit the main topic of this site.
Not a bioinformatics Q and cross-posted on SE https://bioinformatics.stackexchange.com/questions/7010/error-in-as-vectorx-no-method-for-coercing-this-s4-class-to-a-vector
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!