Entering edit mode
ረ
•
0
@-10147
Last seen 6.4 years ago
PROBLEM
I have the following script where I am using the export
function from BSgenome
package to write only the first seven chromosomes of an object (of class BSgenome
) into separate files.
source("https://bioconductor.org/biocLite.R") biocLite("BSgenome.Scerevisiae.UCSC.sacCer3") library(BSgenome.Scerevisiae.UCSC.sacCer3) library(BSgenome) export(BSgenome.Scerevisiae.UCSC.sacCer3::Scerevisiae$chrI, "Scerevisiae_chr1.fasta", compress=FALSE) export(BSgenome.Scerevisiae.UCSC.sacCer3::Scerevisiae$chrII, "Scerevisiae_chr2.fasta", compress=FALSE) export(BSgenome.Scerevisiae.UCSC.sacCer3::Scerevisiae$chrIII, "Scerevisiae_chr3.fasta", compress=FALSE) export(BSgenome.Scerevisiae.UCSC.sacCer3::Scerevisiae$chrIV, "Scerevisiae_chr4.fasta", compress=FALSE) export(BSgenome.Scerevisiae.UCSC.sacCer3::Scerevisiae$chrV, "Scerevisiae_chr5.fasta", compress=FALSE) export(BSgenome.Scerevisiae.UCSC.sacCer3::Scerevisiae$chrVI, "Scerevisiae_chr6.fasta", compress=FALSE) export(BSgenome.Scerevisiae.UCSC.sacCer3::Scerevisiae$chrVII, "Scerevisiae_chr7.fasta", compress=FALSE)
The problem is that I have many other organisms for which I must do the same.
OBJECTIVE
How can I automate the export process in a way that the filename of the output matches the object and element used?
So as an example, when Scerevisiae$chrVII
is exported, I want to see Scerevisiae_chrVII.fasta for the name of the FASTA file.
WHAT I HAVE TRIED AND HAS NOT WORKED
BiocGenerics::sapply(X = Scerevisiae, MARGIN = c(1:7), function(x) BSgenome::export(con = paste0(substitute(x), ".fasta"))) BiocGenerics::sapply(X = Scerevisiae, FUN = export) bsapply(new("BSParams", X = Scerevisiae, FUN = function(x) BSgenome::export(con = paste0(substitute(x), ".fasta"))))