Question: how to save file on local disk after applying predictCoding() function?
0
gravatar for anastasiya-terskih
5.0 years ago by
Russian Federation
anastasiya-terskih10 wrote:

Hello! Could you help me please.

I work with vcf file:

> vcf <- readVcf("test.vcf.gz", "hg19")

Then I use  predictCoding() to get information about nucleotide substitutions and output looks like this:

> coding <- predictCoding(vcf_mod, txdb, Hsapiens)
> coding[5:7]

GRanges with 3 ranges and 17 metadata columns:
  1:865692_C/G     chr1 [865692, 865692]      + |         <NA>              

I'd like to save this file on local disk (I mean coding).How can I do it?

Thank you!

 

ADD COMMENTlink modified 5.0 years ago by Thomas Sandmann70 • written 5.0 years ago by anastasiya-terskih10
Answer: how to save file on local disk after applying predictCoding() function?
3
gravatar for Thomas Sandmann
5.0 years ago by
USA
Thomas Sandmann70 wrote:

For the record, here are a few lines from the predictCoding man page that generate the GRanges object you asked about.

library(VariantAnnotation)
library(BSgenome.Hsapiens.UCSC.hg19)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)

txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
fl <- system.file("extdata", "chr22.vcf.gz", package="VariantAnnotation")
vcf <- readVcf(fl, "hg19")

## Rename seqlevels in the VCF object to match those in the TxDb.
vcf <- renameSeqlevels(vcf, "chr22")
coding <- predictCoding(vcf, txdb, Hsapiens)

You can save the GRanges object either as a binary Rdata file e.g.

save( coding, file="output.RData" )

and reload it with the load function.

Alternatively, you can export your results in a text (e.g. csv) file, e.g. after converting the GRanges object to a data.frame

df <- as.data.frame( coding, "data.frame", row.names = NULL)
write.csv(df, file="output.csv")

 

ADD COMMENTlink modified 5.0 years ago by Martin Morgan ♦♦ 23k • written 5.0 years ago by Thomas Sandmann70
1

With devel rtracklayer, you can:

file <- exportToTabix(coding, "output.txt")

This is stored and indexed in a manner that is efficient for restricted range queries:

coding_chr1 <- import(file, which=GRanges("chr1", IRanges(1e6, 2e6)))

 

ADD REPLYlink modified 5.0 years ago • written 5.0 years ago by Michael Lawrence11k

Thank you very much!)

ADD REPLYlink written 5.0 years ago by anastasiya-terskih10
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: 213 users visited in the last hour