Skip to content

Instantly share code, notes, and snippets.

@sinarueeger
Last active July 27, 2018 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinarueeger/4430492e67639fccaeacf4340f7cb7df to your computer and use it in GitHub Desktop.
Save sinarueeger/4430492e67639fccaeacf4340f7cb7df to your computer and use it in GitHub Desktop.
Code snippets for R-package biomaRt.
Here are some extra (unpolished) code snippets for the R-package `biomaRt` that came up during the writing of the [blogpost](https://sinarueeger.github.io/content/post/2018-07-27-GWAS-annotation).
## Extract all SNPs for a particular genomic region
```{r, get-snp-info-pos-chr, include = TRUE, cache=TRUE, eval=FALSE}
library(biomaRt)
## select mart
snpmart = useMart(biomart = "ENSEMBL_MART_SNP", dataset="hsapiens_snp")
## extract SNPs
getBM(attributes = c('refsnp_id','allele','chrom_start','chrom_strand'),
filters = c('chr_name','start','end'),
values = list(8,148350,148612),
mart = snpmart)
```
## Get info about one gene, and extract all SNPs
```{r, get-gene-info, include = TRUE,cache =TRUE, eval=FALSE}
## first, we need to figure out the gene ID of FTO
## select mart
ensembl = useMart("ensembl", dataset="hsapiens_gene_ensembl")
## list all the filters
listFilters(ensembl)
## list all attributes
listAttributes(ensembl)
## run
gene.name.fto <- getBM(attributes = c('ensembl_gene_id'),
filters = c('external_gene_name'),
values = "FTO",
mart = ensembl)
gene.name.fto
## Now we want to get the range of SNPs for that gene
snps.fto <- getBM(attributes = c( 'refsnp_id',
'chr_name',
'chrom_start',
'chrom_end'),
filters = c('ensembl_gene'),
values = gene.name.fto$ensembl_gene_id,
mart = variation)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment