IRanges - Find
1
0
Entering edit mode
Fahim Md ▴ 250
@fahim-md-4018
Last seen 9.7 years ago
Hi Is it possible to filter ranges by imposing condition on name field. I am using the IRanges vignette example below: Require(IRanges) ir1 <- IRanges(start = 1:10, width = 10:1) ir2 <- IRanges(start = 1:10, end = 11) ir3 <- IRanges(end = 11, width = 10:1) identical(ir1, ir2) & identical(ir2, ir3) ir <- IRanges(c(1, 8, 14, 15, 19, 34, 40), width = c(12, 6, 6, 15, 6, 2, 7)) values <- rnorm(length(ir)) rd <- RangedData(ir, name = letters[seq_len(length(ir))], values) rd 1> rd RangedData with 7 rows and 2 value columns across 1 space space ranges | name values <character> <iranges> | <character> <numeric> 1 1 [ 1, 12] | a -0.8204717 2 1 [ 8, 13] | b -0.2419617 3 1 [14, 19] | c -0.7747140 4 1 [15, 29] | d -0.1103875 5 1 [19, 24] | e -0.2945884 6 1 [34, 35] | f 1.8082479 7 1 [40, 46] | g -0.1854162 I have another list *toFind*: toFind = c ('a', 'c', 'd', 'f') Is it possible to find the correponding ranges? The output in this case would be 1> output RangedData with 4 rows and 2 value columns across 1 space space ranges | name values <character> <iranges> | <character> <numeric> 1 1 [ 1, 12] | a -0.8204717 2 1 [14, 19] | c -0.7747140 3 1 [15, 29] | d -0.1103875 4 1 [34, 35] | f 1.8082479 Thanks a lot. Fahim -- Fahim Mohammad Bioinforformatics Lab University of Louisville Louisville, KY, USA Ph: +1-502-409-1167 [[alternative HTML version deleted]]
IRanges IRanges • 733 views
ADD COMMENT
0
Entering edit mode
@martin-morgan-1513
Last seen 11 days ago
United States
On 03/12/2011 06:41 AM, Fahim Mohammad wrote: > Hi > Is it possible to filter ranges by imposing condition on name field. I am > using the IRanges vignette example below: > > Require(IRanges) > ir1 <- IRanges(start = 1:10, width = 10:1) > ir2 <- IRanges(start = 1:10, end = 11) > ir3 <- IRanges(end = 11, width = 10:1) > identical(ir1, ir2) & identical(ir2, ir3) > ir <- IRanges(c(1, 8, 14, 15, 19, 34, 40), > width = c(12, 6, 6, 15, 6, 2, 7)) > > values <- rnorm(length(ir)) > rd <- RangedData(ir, name = letters[seq_len(length(ir))], values) > rd > 1> rd > RangedData with 7 rows and 2 value columns across 1 space > space ranges | name values > <character> <iranges> | <character> <numeric> > 1 1 [ 1, 12] | a -0.8204717 > 2 1 [ 8, 13] | b -0.2419617 > 3 1 [14, 19] | c -0.7747140 > 4 1 [15, 29] | d -0.1103875 > 5 1 [19, 24] | e -0.2945884 > 6 1 [34, 35] | f 1.8082479 > 7 1 [40, 46] | g -0.1854162 > > > I have another list *toFind*: > > toFind = c ('a', 'c', 'd', 'f') > > Is it possible to find the correponding ranges? The output in this case > would be Hi Fahim -- access the 'name' field rd[["name"]] and use R's %in% to see which are in toFind; this is a logical vector that can be used to subset rd, as > rd[rd[["name"]] %in% toFind, ] RangedData with 4 rows and 2 value columns across 1 space space ranges | name values <character> <iranges> | <character> <numeric> 1 1 [ 1, 12] | a -0.02434458 2 1 [14, 19] | c 0.43727261 3 1 [15, 29] | d 0.92065069 4 1 [34, 35] | f 0.66271368 > > 1> output > RangedData with 4 rows and 2 value columns across 1 space > space ranges | name values > <character> <iranges> | <character> <numeric> > 1 1 [ 1, 12] | a -0.8204717 > 2 1 [14, 19] | c -0.7747140 > 3 1 [15, 29] | d -0.1103875 > 4 1 [34, 35] | f 1.8082479 > > > Thanks a lot. > Fahim > > > > -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793
ADD COMMENT

Login before adding your answer.

Traffic: 624 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6