I have Granges with start and end but I want to count number of gc in stretch of DNA. however, i'm not able to properly subset bsgenome to be able to do that. here's my approach.
> gr_pro
GRanges object with 3 ranges and 2 metadata columns:
seqnames ranges strand | symbol key
<Rle> <IRanges> <Rle> | <character> <character>
[1] chr6 143510692-143512691 - | FUCA2 FUCA2_ENSG0000000103..
[2] chr6 53615972-53617971 - | GCLC GCLC_ENSG00000001084..
[3] chr6 41071944-41073943 + | NFYA NFYA_ENSG00000001167..
-------
seqinfo: 24 sequences from an unspecified genome; no seqlengths
##command used
lapply(gr_pro, function(x) Biostrings::countPattern("CG", BSgenome.Hsapiens.UCSC.hg38::Hsapiens[[x]]))
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'subject' in selecting a method for function 'countPattern': error in evaluating the argument 'i' in selecting a method for function '[[': GRanges objects don't support [[, as.list(), lapply(), or unlist() at
the moment
pls see example data
> dput(head(gene_promoters_encode1kb_chr_subset[,c("symbol", "key")], 3))
new("GRanges", seqnames = new("Rle", values = structure(6L, .Label = c("chr1",
"chr2", "chr3", "chr4", "chr5", "chr6", "chr7", "chr8", "chr9",
"chr10", "chr11", "chr12", "chr13", "chr14", "chr15", "chr16",
"chr17", "chr18", "chr19", "chr20", "chr21", "chr22", "chrX",
"chrY"), class = "factor"), lengths = 3L, elementMetadata = NULL,
metadata = list()), ranges = new("IRanges", start = c(143510692L,
53615972L, 41071944L), width = c(2000L, 2000L, 2000L), NAMES = NULL,
elementType = "ANY", elementMetadata = NULL, metadata = list()),
strand = new("Rle", values = structure(2:1, .Label = c("+",
"-", "*"), class = "factor"), lengths = 2:1, elementMetadata = NULL,
metadata = list()), seqinfo = new("Seqinfo", seqnames = c("chr1",
"chr2", "chr3", "chr4", "chr5", "chr6", "chr7", "chr8", "chr9",
"chr10", "chr11", "chr12", "chr13", "chr14", "chr15", "chr16",
"chr17", "chr18", "chr19", "chr20", "chr21", "chr22", "chrX",
"chrY"), seqlengths = c(NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_), is_circular = c(NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA), genome = c(NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_)), elementMetadata = new("DFrame", rownames = NULL,
nrows = 3L, listData = list(symbol = c("FUCA2", "GCLC",
"NFYA"), key = c("FUCA2_ENSG00000001036.13", "GCLC_ENSG00000001084.12",
"NFYA_ENSG00000001167.14")), elementType = "ANY", elementMetadata = NULL,
metadata = list()), elementType = "ANY", metadata = list())
Indeed, I might have misunderstood the question.