Search
Question: What is the proper way to modify mcols of a GRanges inside a GRangesList?
0
gravatar for Ryan C. Thompson
6 months ago by
The Scripps Research Institute, La Jolla, CA
Ryan C. Thompson6.1k wrote:

Sometimes I have a GRangeList object and I want to modify the mcols of the underlying GRanges object. The only way I know to do this is to do something like:

grl@unlistData$newColumn <- newValue

But that unfortunately breaks the GRangesList abstraction by directly accessing the slot. Is there any way to do this without resorting to slot access?

(To be clear, I'm aware that the GRangesList also has its own separate set of mcols, and those are not what I'm trying to access.)

ADD COMMENTlink modified 6 months ago by Michael Lawrence9.8k • written 6 months ago by Ryan C. Thompson6.1k
3
gravatar for Michael Lawrence
6 months ago by
United States
Michael Lawrence9.8k wrote:

This should work (as long as the column is not actually "new"):

grl[,"newColumn"] <- newValue

Someone should probably document that (I only found it by reading the code). But maybe it's better to do this:

mcols(grl, level="within")$newColumn <- newValue

Because it's more explicit, can add new columns, and is consistent with extracting a column:

mcols(grl, level="within")$newColumn

I'm wondering whether it would make sense to support this syntax for extraction:

grl[[,"newColumn"]]

It shares the problem with the first example, in that it's not clear whether "newColumn" is coming from the inside or outside. But in interactive code, those concerns are often secondary to convenience... the biggest practical problem is that there is no way to tell it to add an inner column. I guess there could be a heuristic based on the value being a list of the right shape. Opinions?

ADD COMMENTlink written 6 months ago by Michael Lawrence9.8k

The level="within" trick is exactly what I was looking for. I don't know if we really need a shortcut for this pattern, since it doesn't come up that often. As long as there's a way to do it at all without breaking abstraction, I'm satisfied.

ADD REPLYlink written 6 months ago by Ryan C. Thompson6.1k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 236 users visited in the last hour