Augmenting metadata values in GRanges object
1
0
Entering edit mode
Fahim Md ▴ 250
@fahim-md-4018
Last seen 9.6 years ago
Hi Is there a function to augment metadata into an already built GRanges object? For example (ex from vignette) > gr <- GRanges(seqnames = Rle(c("chr1", "chr2", "chr1",+ "chr3"), c(1, 3, 2, 4)), ranges = IRanges(1:10, end = 7:16,+ names = head(letters, 10)), strand = Rle(strand(c("-",+ "+", "*", "+", "-")), c(1, 2, 2, 3, 2)), score = 1:10,+ GC = seq(1, 0, length = 10))> grGRanges with 10 ranges and 2 elementMetadata values: seqnames ranges strand | score GC <rle> <iranges> <rle> | <integer> <numeric> a chr1 [ 1, 7] - | 1 1 b chr2 [ 2, 8] + | 2 0.888888888888889 c chr2 [ 3, 9] + | 3 0.777777777777778 d chr2 [ 4, 10] * | 4 0.666666666666667 e chr1 [ 5, 11] * | 5 0.555555555555556 f chr1 [ 6, 12] + | 6 0.444444444444444 g chr3 [ 7, 13] + | 7 0.333333333333333 h chr3 [ 8, 14] + | 8 0.222222222222222 i chr3 [ 9, 15] - | 9 0.111111111111111 j chr3 [10, 16] - | 10 0 --- seqlengths: chr1 chr2 chr3 NA NA NA> toAdd = c(1:10) > toAdd [1] 1 2 3 4 5 6 7 8 9 10 I want to append this ('toAdd') metadata to already built GRanges object ('gr'). Is there any function to do that? Thanks Thanks Fahim Bioinformatics Lab University of Louisville Louisville, KY USA [[alternative HTML version deleted]]
• 1.2k views
ADD COMMENT
0
Entering edit mode
@martin-morgan-1513
Last seen 20 hours ago
United States
On 11/15/2011 03:50 PM, Fahim Mohammad wrote: > Hi > Is there a function to augment metadata into an already built GRanges > object? > > For example (ex from vignette) > > >> gr<- GRanges(seqnames = Rle(c("chr1", "chr2", "chr1",+ "chr3"), c(1, 3, 2, 4)), ranges = IRanges(1:10, end = 7:16,+ names = head(letters, 10)), strand = Rle(strand(c("-",+ "+", "*", "+", "-")), c(1, 2, 2, 3, 2)), score = 1:10,+ GC = seq(1, 0, length = 10)) > grGRanges with 10 ranges and 2 elementMetadata values: > seqnames ranges strand | score GC > <rle> <iranges> <rle> |<integer> <numeric> > a chr1 [ 1, 7] - | 1 1 > b chr2 [ 2, 8] + | 2 0.888888888888889 > c chr2 [ 3, 9] + | 3 0.777777777777778 > d chr2 [ 4, 10] * | 4 0.666666666666667 > e chr1 [ 5, 11] * | 5 0.555555555555556 > f chr1 [ 6, 12] + | 6 0.444444444444444 > g chr3 [ 7, 13] + | 7 0.333333333333333 > h chr3 [ 8, 14] + | 8 0.222222222222222 > i chr3 [ 9, 15] - | 9 0.111111111111111 > j chr3 [10, 16] - | 10 0 > --- > seqlengths: > chr1 chr2 chr3 > NA NA NA> toAdd = c(1:10)> toAdd [1] 1 2 3 4 5 > 6 7 8 9 10 > > > I want to append this ('toAdd') metadata to already built GRanges object > ('gr'). > Is there any function to do that? Hi Fahim -- Along the lines of > metadata(gr) = list("some thing") > metadata(gr) = c(metadata(gr), list("some other thing")) > metadata(gr) [[1]] [1] "some thing" [[2]] [1] "some other thing" see ?"metadata<-". Martin > Thanks > > Thanks > Fahim > Bioinformatics Lab > University of Louisville > Louisville, KY USA > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- 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
0
Entering edit mode
On 11/15/2011 05:31 PM, Martin Morgan wrote: > On 11/15/2011 03:50 PM, Fahim Mohammad wrote: >> Hi >> Is there a function to augment metadata into an already built GRanges >> object? >> >> For example (ex from vignette) >> >> >>> gr<- GRanges(seqnames = Rle(c("chr1", "chr2", "chr1",+ "chr3"), c(1, >>> 3, 2, 4)), ranges = IRanges(1:10, end = 7:16,+ names = head(letters, >>> 10)), strand = Rle(strand(c("-",+ "+", "*", "+", "-")), c(1, 2, 2, 3, >>> 2)), score = 1:10,+ GC = seq(1, 0, length = 10)) > >> grGRanges with 10 ranges and 2 elementMetadata values: >> seqnames ranges strand | score GC >> <rle> <iranges> <rle> |<integer> <numeric> >> a chr1 [ 1, 7] - | 1 1 >> b chr2 [ 2, 8] + | 2 0.888888888888889 >> c chr2 [ 3, 9] + | 3 0.777777777777778 >> d chr2 [ 4, 10] * | 4 0.666666666666667 >> e chr1 [ 5, 11] * | 5 0.555555555555556 >> f chr1 [ 6, 12] + | 6 0.444444444444444 >> g chr3 [ 7, 13] + | 7 0.333333333333333 >> h chr3 [ 8, 14] + | 8 0.222222222222222 >> i chr3 [ 9, 15] - | 9 0.111111111111111 >> j chr3 [10, 16] - | 10 0 >> --- >> seqlengths: >> chr1 chr2 chr3 >> NA NA NA > toAdd = c(1:10) > toAdd [1] 1 2 3 4 5 >> 6 7 8 9 10 oops, your email came through poorly formatted, I think you want values(gr)[["toAdd"]] = 1:10 or values(gr)[,"toAdd"] = 1:10 (equivalently, elementMetadata(gr)[["toAdd"]] = 1:10). values(gr) is returning a DataFrame, which can be manipulated like a standard R data.frame. Sorry about that, and hope I've got it right this time. Martin >> >> I want to append this ('toAdd') metadata to already built GRanges object >> ('gr'). >> Is there any function to do that? > > Hi Fahim -- Along the lines of > > > metadata(gr) = list("some thing") > > metadata(gr) = c(metadata(gr), list("some other thing")) > > metadata(gr) > [[1]] > [1] "some thing" > > [[2]] > [1] "some other thing" > > see ?"metadata<-". > > Martin > >> Thanks >> >> Thanks >> Fahim >> Bioinformatics Lab >> University of Louisville >> Louisville, KY USA >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at r-project.org >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor > > -- 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 REPLY
0
Entering edit mode
Thanks Peter, elementMetadata(gr)[["toAdd"]] = 1:10 worked for me. Cheers!!! Fahim On Tue, Nov 15, 2011 at 8:46 PM, Martin Morgan <mtmorgan@fhcrc.org> wrote: > On 11/15/2011 05:31 PM, Martin Morgan wrote: > >> On 11/15/2011 03:50 PM, Fahim Mohammad wrote: >> >>> Hi >>> Is there a function to augment metadata into an already built GRanges >>> object? >>> >>> For example (ex from vignette) >>> >>> >>> gr<- GRanges(seqnames = Rle(c("chr1", "chr2", "chr1",+ "chr3"), c(1, >>>> 3, 2, 4)), ranges = IRanges(1:10, end = 7:16,+ names = head(letters, >>>> 10)), strand = Rle(strand(c("-",+ "+", "*", "+", "-")), c(1, 2, 2, 3, >>>> 2)), score = 1:10,+ GC = seq(1, 0, length = 10)) >>>> >>> >> grGRanges with 10 ranges and 2 elementMetadata values: >>> seqnames ranges strand | score GC >>> <rle> <iranges> <rle> |<integer> <numeric> >>> a chr1 [ 1, 7] - | 1 1 >>> b chr2 [ 2, 8] + | 2 0.888888888888889 >>> c chr2 [ 3, 9] + | 3 0.777777777777778 >>> d chr2 [ 4, 10] * | 4 0.666666666666667 >>> e chr1 [ 5, 11] * | 5 0.555555555555556 >>> f chr1 [ 6, 12] + | 6 0.444444444444444 >>> g chr3 [ 7, 13] + | 7 0.333333333333333 >>> h chr3 [ 8, 14] + | 8 0.222222222222222 >>> i chr3 [ 9, 15] - | 9 0.111111111111111 >>> j chr3 [10, 16] - | 10 0 >>> --- >>> seqlengths: >>> chr1 chr2 chr3 >>> NA NA NA >>> >> > > toAdd = c(1:10) >> > > > toAdd [1] 1 2 3 4 5 >> >>> 6 7 8 9 10 >>> >> > > oops, your email came through poorly formatted, I think you want > > values(gr)[["toAdd"]] = 1:10 > > or > > values(gr)[,"toAdd"] = 1:10 > > (equivalently, elementMetadata(gr)[["toAdd"]] = 1:10). values(gr) is > returning a DataFrame, which can be manipulated like a standard R > data.frame. > > Sorry about that, and hope I've got it right this time. Martin > > > >>> I want to append this ('toAdd') metadata to already built GRanges object >>> ('gr'). >>> Is there any function to do that? >>> >> >> Hi Fahim -- Along the lines of >> >> > metadata(gr) = list("some thing") >> > metadata(gr) = c(metadata(gr), list("some other thing")) >> > metadata(gr) >> [[1]] >> [1] "some thing" >> >> [[2]] >> [1] "some other thing" >> >> see ?"metadata<-". >> >> Martin >> >> Thanks >>> >>> Thanks >>> Fahim >>> Bioinformatics Lab >>> University of Louisville >>> Louisville, KY USA >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________**_________________ >>> Bioconductor mailing list >>> Bioconductor@r-project.org >>> https://stat.ethz.ch/mailman/**listinfo/bioconductor<https: stat.="" ethz.ch="" mailman="" listinfo="" bioconductor=""> >>> Search the archives: >>> http://news.gmane.org/gmane.**science.biology.informatics.**conduc tor<http: news.gmane.org="" gmane.science.biology.informatics.conductor=""> >>> >> >> >> > > -- > Computational Biology > Fred Hutchinson Cancer Research Center > 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 > > Location: M1-B861 > Telephone: 206 667-2793 > [[alternative HTML version deleted]]
ADD REPLY

Login before adding your answer.

Traffic: 508 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