-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcallbiomaRt.r
48 lines (44 loc) · 1.73 KB
/
callbiomaRt.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#' LONGO call biomaRt
#'
#' This is a internal function. This function calls the biomaRt database to
#' retrieve the gene symbols and lengths.
#'
#' @param data.df dataframe that contains the probe ids that will be checked
#' @param libraryType the gene identifier of the data based off the
#' biomaRt database
#' @param ensembl BiomaRt mart based on the given species
#' @importFrom biomaRt getBM
#' @return returns the data.df with two new columns, length and symbol
callbiomaRt <- function(data.df, libraryType, ensembl) {
biomaRt.df <-
biomaRt::getBM(
#libraryType.
attributes=c(libraryType, "external_gene_name",
"start_position", "end_position"
),
filters=libraryType,
values=data.df[, 1],
mart=ensembl
)
if(is.na(biomaRt.df[2,2]) | nrow(biomaRt.df)<200){
return(NULL)
}
#make sure the values are numbers
biomaRt.df[, 3] < -as.numeric(as.character(biomaRt.df[, 3]))
biomaRt.df[, 4] <- as.numeric(as.character(biomaRt.df[, 4]))
#copy identifier, gene symbol
completeBiomart.df <- biomaRt.df[, 1:2]
#add lengths
#divide by 1000 to get kb
completeBiomart.df$KBlength <-((biomaRt.df[, 4] - biomaRt.df[, 3] + 1)
/ 1000)
# order by length remove duplicate symbols
# keeping the one that has the largest length
completeBiomart.df <- completeBiomart.df[order(completeBiomart.df$KBlength,
decreasing=TRUE, na.last=NA),]
row.names(completeBiomart.df) <- 1:nrow(completeBiomart.df)
completeBiomart.df <-
(completeBiomart.df[!duplicated(completeBiomart.df[, 1]),])
row.names(completeBiomart.df) <- 1:nrow(completeBiomart.df)
return(completeBiomart.df)
}