Question: Using 'BSgenome::export' to write each chromosome of an organism into separate files
0
gravatar for ረ
19 months ago by
0
0 wrote:

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"))))
ADD COMMENTlink modified 19 months ago by James W. MacDonald51k • written 19 months ago by 0
Answer: Using 'BSgenome::export' to write each chromosome of an organism into separate f
2
gravatar for James W. MacDonald
19 months ago by
United States
James W. MacDonald51k wrote:
> dontprint <- lapply(grep("chr", names(Scerevisiae), value = TRUE), function(x) BSgenome::export(Scerevisiae[[x]], paste0("Scerevisiae_", x, ".fasta")))

> dir(".", ".fasta$")
 [1] "Scerevisiae_chrI.fasta"    "Scerevisiae_chrII.fasta"  
 [3] "Scerevisiae_chrIII.fasta"  "Scerevisiae_chrIV.fasta"  
 [5] "Scerevisiae_chrIX.fasta"   "Scerevisiae_chrM.fasta"   
 [7] "Scerevisiae_chrV.fasta"    "Scerevisiae_chrVI.fasta"  
 [9] "Scerevisiae_chrVII.fasta"  "Scerevisiae_chrVIII.fasta"
[11] "Scerevisiae_chrX.fasta"    "Scerevisiae_chrXI.fasta"  
[13] "Scerevisiae_chrXII.fasta"  "Scerevisiae_chrXIII.fasta"
[15] "Scerevisiae_chrXIV.fasta"  "Scerevisiae_chrXV.fasta"  
[17] "Scerevisiae_chrXVI.fasta"
>
ADD COMMENTlink written 19 months ago by James W. MacDonald51k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 157 users visited in the last hour