Skip to content

Instantly share code, notes, and snippets.

@joonan30
Last active April 13, 2018 23:42
Show Gist options
  • Select an option

  • Save joonan30/4f0d50a89d9b2bfa6d053246b2226ab3 to your computer and use it in GitHub Desktop.

Select an option

Save joonan30/4f0d50a89d9b2bfa6d053246b2226ab3 to your computer and use it in GitHub Desktop.
Quick meal prep in R
# Get date
date = sapply(strsplit(as.character(Sys.Date()), '-', fixed = T), paste, collapse = "")
## biomart and AnnotationDbi
# Map a gene id to get an ENTREZ id.
require(AnnotationDbi)
require(org.Mm.eg.db) # mice
entrez = mapIds(org.Mm.eg.db,
keys=ens_gene, # has to be a vector
column=c('SYMBOL'),
keytype='ENTREZID',
multiVals='first')
# Get biomart
bm = useMart("ENSEMBL_MART_ENSEMBL", "mmusculus_gene_ensembl", host="oct2016.archive.ensembl.org")
# list attributes
a = listAttributes(bm)
# list filters
f= listFilters(bm)
# Shop biomart
bm1 = getBM(attributes = c("ensembl_gene_id",
"chromosome_name",
"start_position",
"end_position",
"percentage_gc_content"),
mart=bm)
# change multiple columns into factor
df %>% mutate_if(is.character,as.factor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment