Image may be NSFW.
Clik here to view.My typical approach for getting a particular DNA sequence is to use the UCSC genome browser. Recently I needed to screen over 40 SNPs for restriction enzyme cut sites and didn’t want to go through all the clicks on the UCSC browser to get the flanking sequences. The Galaxy tool could certainly make quick work of this task, but lately I’ve been trying to do all of my work in R. Here is an R solution utilizing the BSgenome package from Bioconductor:
#Install the BSgenome package from Bioconductor
source("http://bioconductor.org/biocLite.R")
biocLite("BSgenome")
#Load the BSgenome package
library(BSgenome)
#Download and install the genome of your choice
available.genomes()
biocLite("BSgenome.Celegans.UCSC.ce6")
#Load the Celegans data package, sequences are put into memory as needed
library(BSgenome.Celegans.UCSC.ce6)
#Create data.frame of SNPs
snps <- data.frame(chrom=c("chrI","chrII","chrIV"), start=c(8534533,7338823,
6938443), end=c(8534534,7338824,6938444))
snps
## chrom start end
## 1 chrI 8534533 8534534
## 2 chrII 7338823 7338824
## 3 chrIV 6938443 6938444
#Get flanking sequence where SNP is in the middle of 20 bp
snp.flanks <- getSeq(Celegans, snps$chrom, start=(snps$end-9),
end=(snps$end+10))
names(snp.flanks) <- paste(snps$chrom, snps$end, sep = "_")
writeXStringSet(snp.flanks, "Celegans.snp.flanks.fasta")
read.table("Celegans.snp.flanks.fasta")
## V1
## 1 >chrI_8534534
## 2 CAAATTTTAGAAATTGTCAA
## 3 >chrII_7338824
## 4 TAAAGTATGTTTCTGTCTCA
## 5 >chrIV_6938444
## 6 TATTTAATGATGGAAATTAG