Last active
January 21, 2021 23:47
-
-
Save hakyim/da75e79ec016ec01b814ff38bc3324ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## add cytoband to gene | |
addband2gene = function(df,geneid = "ensembl_gene_id") | |
{ | |
if(!exists("anno_gene")) | |
{ | |
ensembl <- biomaRt::useMart(biomart="ENSEMBL_MART_ENSEMBL",dataset="hsapiens_gene_ensembl") | |
anno_gene <<- biomaRt::getBM(attributes = c("ensembl_gene_id","external_gene_name","chromosome_name","start_position","end_position","band", "gene_biotype"),mart=ensembl ) | |
print("defined anno_gene") | |
} | |
if(geneid != "ensembl_gene_id") names(df)[names(df)==geneid] = "ensembl_gene_id" ## this is an ugly workaround - need to find a way to use rename_ for this but don't know how to specify a string instead of name in rename(geneid = "ensembl_gene_id") | |
df = df %>% left_join(anno_gene, by=c( "ensembl_gene_id" )) | |
if(geneid != "ensembl_gene_id") names(df)[names(df)=="ensembl_gene_id"] = geneid | |
df %>% mutate(cytoband = paste0(chromosome_name,band)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment