[Bioc-devel] GRanges to VRanges coercion
hpages at fredhutch.org
Sat Feb 21 02:11:57 CET 2015
On 02/20/2015 04:17 PM, Michael Lawrence wrote:
> On Thu, Feb 19, 2015 at 12:46 PM, Thomas Sandmann <sandmann.thomas at gene.com>
>> 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
>> <environment: namespace:GenomicRanges>
>> 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
>> 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:
>> 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.
>> Thank you,
>> R version 3.1.2 (2014-10-31)
>> Platform: x86_64-apple-darwin13.4.0 (64-bit)
>>  en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>> attached base packages:
>>  stats4 parallel stats graphics grDevices utils datasets
>> methods base
>> other attached packages:
>>  VariantAnnotation_1.12.9 Rsamtools_1.18.2 Biostrings_2.34.1
>> XVector_0.6.0 GenomicRanges_1.18.4
>>  GenomeInfoDb_1.2.4 IRanges_2.0.1 S4Vectors_0.4.0
>> BiocGenerics_0.12.1 BiocInstaller_1.16.1
>>  roxygen2_4.1.0 devtools_1.7.0
>> loaded via a namespace (and not attached):
>>  AnnotationDbi_1.28.1 base64enc_0.1-2 BatchJobs_1.5
>> BBmisc_1.9 Biobase_2.26.0
>>  BiocParallel_1.0.3 biomaRt_2.22.0 bitops_1.0-6
>> brew_1.0-6 BSgenome_1.34.1
>>  checkmate_1.5.1 codetools_0.2-10 DBI_0.3.1
>> digest_0.6.8 fail_1.2
>>  foreach_1.4.2 GenomicAlignments_1.2.1
>> GenomicFeatures_1.18.3 iterators_1.0.7 Rcpp_0.11.4
>>  RCurl_1.95-4.5 RSQLite_1.0.0 rtracklayer_1.26.2
>> sendmailR_1.2-1 stringr_0.6.2
>>  tools_3.1.2 XML_3.98-1.1 zlibbioc_1.12.0
> [[alternative HTML version deleted]]
> Bioc-devel at r-project.org mailing list
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: hpages at fredhutch.org
Phone: (206) 667-5791
Fax: (206) 667-1319
More information about the Bioc-devel