[Bioc-devel] GRanges Intersect
Dario Strbenac
D.Strbenac at garvan.org.au
Wed Oct 5 03:00:08 CEST 2011
Thanks, it's good to know to keep in mind those issues.
---- Original message ----
>Date: Tue, 04 Oct 2011 16:40:07 -0700
>From: bioc-devel-bounces at r-project.org (on behalf of Hervé Pagès <hpages at fhcrc.org>)
>Subject: Re: [Bioc-devel] GRanges Intersect
>To: bioc-devel at r-project.org
>
>Hi Dario,
>
>On 11-09-26 09:30 PM, Dario Strbenac wrote:
>> Now I understand how it works.
>>
>> What I needed was identical(gr1, gr2).
>
>Note that, depending on how strict you want this comparison to be,
>you can also do all(gr1 == gr2). It's less strict than
>identical(gr1, gr2) in the sense that it will only compare the
>genomic ranges in gr1 and gr2, and not the "metadata stuff" and
>other attributes attached to the objects (e.g. names, elementMetadata,
>etc...).
>
>Also be aware that identical() is unreliable in case the compared
>objects contain external pointers.
>
>False positive:
>
> > library(Biostrings)
> > gr1 <- gr2 <- GRanges("chr1", IRanges(31:33, width=1))
> > elementMetadata(gr1)$ref <- DNAStringSet(c("A", "C", "T"))
> > elementMetadata(gr2)$ref <- DNAStringSet(c("G", "G", "N"))
>
> > gr1
> GRanges with 3 ranges and 1 elementMetadata value
> seqnames ranges strand | ref
> <Rle> <IRanges> <Rle> | <DNAStringSet>
> [1] chr1 [31, 31] * | A
> [2] chr1 [32, 32] * | C
> [3] chr1 [33, 33] * | T
>
> seqlengths
> chr1
> NA
>
> > gr2
> GRanges with 3 ranges and 1 elementMetadata value
> seqnames ranges strand | ref
> <Rle> <IRanges> <Rle> | <DNAStringSet>
> [1] chr1 [31, 31] * | G
> [2] chr1 [32, 32] * | G
> [3] chr1 [33, 33] * | N
>
> seqlengths
> chr1
> NA
>
> > identical(gr1, gr2)
> [1] TRUE
>
>False negatives:
>
> > elementMetadata(gr2)$ref <- DNAStringSet(c("GG", "A", "C", "T"))[-1]
>
> > gr2
> GRanges with 3 ranges and 1 elementMetadata value
> seqnames ranges strand | ref
> <Rle> <IRanges> <Rle> | <DNAStringSet>
> [1] chr1 [31, 31] * | A
> [2] chr1 [32, 32] * | C
> [3] chr1 [33, 33] * | T
>
> seqlengths
> chr1
> NA
>
> > identical(gr1, gr2)
> [1] FALSE
>
>Cheers,
>H.
>
>>
>> Thanks,
>> Dario.
>>
>> _______________________________________________
>> Bioc-devel at 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: hpages at fhcrc.org
>Phone: (206) 667-5791
>Fax: (206) 667-1319
>
>_______________________________________________
>Bioc-devel at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/bioc-devel
--------------------------------------
Dario Strbenac
Research Assistant
Cancer Epigenetics
Garvan Institute of Medical Research
Darlinghurst NSW 2010
Australia
More information about the Bioc-devel
mailing list