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

hg19genome = getBSgenome('BSgenome.Hsapiens.UCSC.hg19', masked=FALSE)   

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


 > 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?

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

This seems relatively complicated given the structure of a BSGenome object.

The creator of the package answered this question previously on the Bioconductor support forums: https://support.bioconductor.org/p/86665/#86757

We don't provide an easy way to inject arbitrary SNPs in an arbitrary BSgenome at the moment. However, it should not be too hard to forge the BSgenome ... package. First you would need to compute the sequences of the mutated chromosomes (you can use replaceLetterAt for this), then write them to a 2bit file (put them in a DNAStringSet object and call rtracklayer::export on it), then use that 2bit file to forge the BSgenome .... package (see the BSgenomeForge vignette in the BSgenome package for how to do this). - Herve Pages

Here is another similar question with more info about replaceLetterAt: https://support.bioconductor.org/p/26199/

  • $\begingroup$ 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 $\endgroup$ Aug 11 '17 at 16:18
  • $\begingroup$ I should mention that this is a section in the official documentation---the creators appears to have "not gotten around" to implementing this. See " Injecting known SNPs in the chromosome sequences" here: bioconductor.org/packages/devel/bioc/vignettes/BSgenome/inst/… $\endgroup$ Aug 15 '17 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.