Hi guys,
On 02/20/2015 04:17 PM, Michael Lawrence wrote:
On Thu, Feb 19, 2015 at 12:46 PM, Thomas Sandmann <sandmann.tho...@gene.com>
wrote:
Hi Valerie, hi Michael,
I find myself frequently moving back and forth between data.frames,
GRanges and VRanges objects.
The makeGRangesFromDataFrame function from the GenomicRanges makes the
coercion between the former straightforward, but I couldn't find anything
similar for the second step, coercsion from GRanges to VRanges.
There is a coercion method defined in the GenomicRanges package:
getMethod(coerce, c("GRanges", "VRanges"))
Method Definition:
function (from, to = "VRanges", strict = TRUE)
{
obj <- new("VRanges")
as(obj, "GRanges") <- from
obj
}
<environment: namespace:GenomicRanges>
Signatures:
from to
target "GRanges" "VRanges"
defined "GRanges" "VRanges"
but I haven't been able to get it to work (or find where it is
documented). The source code shown above doesn't indicate how the coercion
method would check for the presence of required / optional VRanges columns,
e.g. 'ref', 'alt', 'altDepth', etc.
This is just the default coercion method added by the methods package for a
conversion of a class to its parent class. It obviously will not do the
right thing, in general.
Just to clarify, the automatic coercion methods for converting a class
to its parent (e.g. from VRanges to GRanges) just remove the extra
stuff and that almost always does the right thing. So it makes a lot of
sense to have them.
Going in the opposite direction (i.e. from parent to child) is the hard
part and, not too surprisingly, the automatic coercion methods are
almost never able to do the right thing. How could they possibly guess
what stuff needs to be added to the original object to make it a valid
instance of the child class? It has always been a mystery to me why the
methods package defines automatic coercion methods to go in that
direction...
Cheers,
H.
Would it be useful to add an explicit makeVRangesFromGRanges function to
the VariantAnnotation package ( and / or the corresponding coercion method)
?
Then it would be easy to go from a data.frame to a VRanges object, e.g.
as in this pseudocode:
makeVRangesFromGRanges(
makeGRangesFromDataFrame( data.frame )
)
You can find a first attempt at implementing the makeVRangesFromGRanges function
here <https://gist.github.com/tomsing1/bf917b1b48afb952e1c5>, which you
are welcome to use / modify if you find it useful.
If this functionality should already be available, I'd be happy to learn
about that, too !
Val, do you think you could review and incorporate Thomas's code? It seems
like a good addition to me.
Thanks,
Michael
Thank you,
Thomas
SessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats4 parallel stats graphics grDevices utils datasets
methods base
other attached packages:
[1] VariantAnnotation_1.12.9 Rsamtools_1.18.2 Biostrings_2.34.1
XVector_0.6.0 GenomicRanges_1.18.4
[6] GenomeInfoDb_1.2.4 IRanges_2.0.1 S4Vectors_0.4.0
BiocGenerics_0.12.1 BiocInstaller_1.16.1
[11] roxygen2_4.1.0 devtools_1.7.0
loaded via a namespace (and not attached):
[1] AnnotationDbi_1.28.1 base64enc_0.1-2 BatchJobs_1.5
BBmisc_1.9 Biobase_2.26.0
[6] BiocParallel_1.0.3 biomaRt_2.22.0 bitops_1.0-6
brew_1.0-6 BSgenome_1.34.1
[11] checkmate_1.5.1 codetools_0.2-10 DBI_0.3.1
digest_0.6.8 fail_1.2
[16] foreach_1.4.2 GenomicAlignments_1.2.1
GenomicFeatures_1.18.3 iterators_1.0.7 Rcpp_0.11.4
[21] RCurl_1.95-4.5 RSQLite_1.0.0 rtracklayer_1.26.2
sendmailR_1.2-1 stringr_0.6.2
[26] tools_3.1.2 XML_3.98-1.1 zlibbioc_1.12.0
[[alternative HTML version deleted]]
_______________________________________________
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel
--
Hervé Pagès
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024
E-mail: hpa...@fredhutch.org
Phone: (206) 667-5791
Fax: (206) 667-1319
_______________________________________________
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel