Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request "pull" function #94

Open
eggrandio opened this issue Feb 22, 2022 · 3 comments
Open

Feature request "pull" function #94

eggrandio opened this issue Feb 22, 2022 · 3 comments

Comments

@eggrandio
Copy link

Hello,

I wonder if there is a "tidy" way of retrieving metadata from grange objects. I haven't found an equivalent pull function.

Right now I find it quite cumbersome to filter and retrieve another metadata column as a vector.

I am doing this, but maybe there is a cleaner way (is there another way of converting from S4 to vector?):

gr <- GRanges(seqnames = "chr1", strand = c("+", "-", "+"),
              ranges = IRanges(start = c(1,3,5), width = 3)) %>% 
  mutate(score = c(0.1, 0.5, 0.3),
         peak = c("a", "b", "c"))

output <- gr %>% filter(score > 0.2) %>% select(peak, .drop_ranges = TRUE) %>% as.data.frame() %>% unlist() %>% unname()

Having a pull function would simplify this.

@snystrom
Copy link
Contributor

This works and is probably the easiest solution:

pull.GenomicRanges(x, ...){
   dplyr::pull(data.frame(x), ...)
}

I can't really think of any features that would be unique to GRanges objects since it's really just extracting a vector.

@eggrandio
Copy link
Author

eggrandio commented Feb 23, 2022

This works and is probably the easiest solution:

pull.GenomicRanges(x, ...){
   dplyr::pull(data.frame(x), ...)
}

I can't really think of any features that would be unique to GRanges objects since it's really just extracting a vector.

Thanks! yes, that's probably the easiest way. I am still getting familiar with plyranges, I though some functions were just wrappers to ease the use of genomicRanges.

For example, I was expecting to have a rename function to rename metadata column names. Is there a tidy way of doing it? Currently I use

%>% `mcols<-`(value = list("new_name" = .$old_name))

but that could be simplified, and probably is not very efficient.

@lawremi
Copy link
Collaborator

lawremi commented Feb 23, 2022

A pull() method for DataFrame would solve the original issue.

For renaming, you could use rename() on the DataFrame returned by mcols(). Then you just need a pipeable way to set the mcols, like create a set_mcols() function that just calls mcols<-().

Perhaps @sa-lee could weigh in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants