This was working on Friday, it is not working now. So, I don't think this is related to my data, but rather something to GRanges.
I am trying to get the combined peaks from a list of objects in atac data and I am running into the following error.
GRanges objects don't support [[, as.list(), lapply(), or unlist() at the moment
My code is
combined.peaks <- reduce(c(peaks$sample1, peaks$sample2,
peaks$sample3, peaks$sample4
))
This was working a few days ago btw... Is this a new bug?
Thanks!
T
1 answer
Something is probably wrong with your files and one of the entries is not a GRanges object
combined.peaks <- reduce(unlist(GRangesList(c(peaks$sample1, peaks$sample2,peaks$sample3, peaks$sample4))))
You probably need to provide the head() of the peaks$sample1 etc...for us to be certain
Note: You may need to use GenomicRanges::reduce() if you have other packages loaded and get an error about lists
Did you update R?
No, nothing should have been changed.
Something has changed...
what does lapply(peaks,length) give you?
Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or select a chunk of text and use the highlighted button to format it as a code block. If your code has long lines with a single command, break those lines into multiple lines with proper escape sequences so they're easier to read and still run when copy-pasted. I've done it for you this time.

What happens if you do like:
reduce(c(peaks$sample1,peaks$sample2))
and like the same for 1 and 3 and 1 and 4... etc.. Do they all fail with the same error or do some work?
yes, any combo of those fails.
Your peaks object is probably a GRanges instead of a GRangesList.
What about trying to set:
peaks <- GRangesList(peaks)
Does the error change?
I have set this up already.
Hi,
Were you able to resolve this? I had the same error message and a google search landed me here. So, posting what I think was the reason in my case at least -
## example GRanges object
summary(my.sel.peaks.gr)
# [1] "GRanges object with 7536 ranges and 0 metadata columns"
##
library(tidyverse)
## Among other msgs of conflicts
# purrr::reduce() masks GenomicRanges::reduce(), IRanges::reduce()
##
## So -
reduce(my.sel.peaks.gr)
# Error in getListElement(x, i, ...) :
# GRanges objects don't support [[, as.list(), lapply(), or unlist() at
# the moment
##
## But -
GenomicRanges::reduce(my.sel.peaks.gr)
# GRanges object with 7269 ranges and 0 metadata columns:
# seqnames ranges strand
# <Rle> <IRanges> <Rle>
# [1] chr1 629793-630083 *
# [2] chr1 632733-633039 *
# [3] chr1 633868-634183 *
# ... ... ... ...
# [7269] chrY 19567023-19567392 *
# -------
# seqinfo: 24 sequences from an unspecified genome; no seqlengths
##
So, explicitly specifying the package from where I wanted to use reduce from, resolved the issue.
Selected session info -
R version 4.2.0 (2022-04-22)
GenomicRanges_1.50.0
tidyverse_2.0.0
purrr_1.0.1
I had the same issue: your fix worked for me too - thanks!
Log in to answer this question.
Please add a reproducible example via
dput.This is obviously not reproducible for anyone that does not have your
fragments.tsv.gzfiles. Please follow ATPoint's advice and usedputon objects.We still do not know how exactly your GRanges objects look, that is why I asked for dput.
This works:
so if you need help provide data (not code, and not as a screenshot)
I am sorry for that. This is what my object looks like. Is this more useful to you for providing a solution?
Please show the output of
It's incomplete. Without a reproducible this thread is pointless.
This is a long output and it's not accepted by biostars to be posted. Can I send this to you via email?
Use a Gist when content is too large for Biostars
Use
GenomicRanges::reduce()