 I have a list of genomic ranges mapped to hg19 . my data is in matrix format lets call it  `ranges` which has 600,000 rows and 4 clumns 
here is few row of my data

     head(ranges)
      chr    start    end      strand
    [1,] "chr1" "10025"  "10525"  "."   
    [2,] "chr1" "13252"  "13752"  "."   
    [3,] "chr1" "16019"  "16519"  "."   
    [4,] "chr1" "96376"  "96876"  "."   
    [5,] "chr1" "115440" "115940" "."   
    [6,] "chr1" "235393" "235893" "."   
Is there a function that gets sequences and calculates GC content for each row( each range)
I would prefer that  output be in a vector format
I would really appreciate your help




A solution using GenomicRanges and BSgenome from Bioconductor. You will need to transform your data to a GRanges object for this.

    library(GenomicRanges)
    library(BSgenome.Hsapiens.UCSC.hg19)
    library(BSgenome)
    
    gr <- GenomicRanges::GRanges(seqnames = c("chr1", "chr2"),
                                 ranges = IRanges(start = c(123456,123490), 
                                                  end = c(500020, 600020)))
    
    GetGC <- function(bsgenome, gr){
      
      seqs <- BSgenome::getSeq(bsgenome, gr)
      return(as.numeric(Biostrings::letterFrequency(x = seqs, letters = "GC", as.prob = TRUE)))

  
    }

    > gr
    GRanges object with 2 ranges and 0 metadata columns:
          seqnames        ranges strand
             <Rle>     <IRanges>  <Rle>
      [1]     chr1 123456-500020      *
      [2]     chr2 123490-600020      *
      -------
      seqinfo: 2 sequences from an unspecified genome; no seqlengths
    
    > GetGC(bsgenome = BSgenome.Hsapiens.UCSC.hg19, gr = gr)
    [1] 0.2823072 0.4355687





              
