# Given a Genomic Ranges of SNPs, how to inject these SNPs in genome via BSGenome?

Let's say I have the genome hg19 loaded into R via BSGenome

library("BSgenome")


I then have a list of SNPs loaded as a GRanges object, gr

library(GenomicRanges)

> gr
GRanges object with 212 ranges and 3 metadata columns:
seqnames               ranges strand |     width     REF    ALT
<Rle>          v <IRanges>  <Rle> | <numeric>
[1]        1 [86099032, 86099032]      * |         1     C      T
[2]        1 [86099033, 86099033]      * |         1     C      A
[3]        1 [86099199, 86099199]      * |         1     G      A
....


Is there a straightforward way to inject these SNPs into hg19genome?

• By inject you mean that the hg19genome should have the alternative base instead of the reference base for those positions?
– llrs
Aug 11 '17 at 10:57
• @Llopis Yes, that's what I mean Aug 11 '17 at 16:06

• I noticed those. Question: can you think of another algorithmically efficient way to accomplish this? One way would be to convert the GRanges into a BED, then used this to create a new FASTA with the SNPS, and loaded this into BSGenome and then used getSeq(). That's very complicated though Aug 11 '17 at 16:18