So a GRangeslist have group and group_name, but when you do this conversion, the info is lost:
Grangeslist -> data.frame -> GRanges ->GrangesList
Is there a way to preserve the information ?
I tried to save the grouping of the original GRangeslist, but since the final GRangeslist only have 1 group, it does not work.
Of course you can do something like:
#df.gr: a global data.frame of all granges GRangesList(lapply(df.gr$names, function(x) getGRLbyName(x)))
getGRLbyName = function(name){ tempEquals = df.gr[df.gr$name == name] #find all in group by name a = GRanges( tempEquals ) names(a) = rep(x,nrow(tempEquals)) # make names return(a) }
But this is just bad..
Another artifact is that now the group will be added as a metacolumn in the final GRangesList.
How do you guys do this ?
Next thing is how GRanges accesses rows:
Usually this is done by name, i.g gr["ENST0009123123"], but what if I want to access by exon_id, which is a meta column ?
It looks like this is not possible ? and I therefor have to transform to data.frame, and I lose the grouping..
I feel like GRanges is not suited if you want to do big changes to specific data in it, because you can not do what you want, unless you transform to data.frame
Yes, that is good, but since I need the grouping I need to do it on a GRangesList:
This does not work:
Output is:
Only way I could get an output is something like this:
But since all exons in each group have same name, it will only return the original list.
Any way around this without making granges or dataframe and preserve the grouping ?
By looking through this post: A: Fast way to access metadata for GRangesList?
I found that this works, but not totaly what I want:
The groups are back, but they are not identical:
This is good enough for me, so I consider the question solved
tweak that so that unlist() has use.names=FALSE, otherwise the names of the unlisted object are those of the elements of the list, e.g.,
If you need the data as a GRangesList, then there is a choice: are you restricting the analysis to a single chromosome? If so, this does what you want:
Or, be explicit: