mirror of
https://github.com/johrpan/geposanui.git
synced 2025-10-26 11:17:24 +01:00
input: Only connect to Ensembl if necessary
This commit is contained in:
parent
d87474e574
commit
48aa46c2c4
1 changed files with 15 additions and 6 deletions
21
input.R
21
input.R
|
|
@ -57,10 +57,17 @@ genes_suggested_tpe_old <- c(
|
|||
"TSPAN9"
|
||||
)
|
||||
|
||||
ensembl <- useEnsembl(
|
||||
biomart = "ensembl",
|
||||
version = 104
|
||||
)
|
||||
#' Shared accessor for the Ensembl API.
|
||||
ensembl <- NULL
|
||||
|
||||
#' Get the ensembl accessor and initialize it if necessary.
|
||||
get_ensembl <- function() {
|
||||
if (is.null(ensembl)) {
|
||||
ensembl <<- useEnsembl("ensembl", version = 104)
|
||||
}
|
||||
|
||||
ensembl
|
||||
}
|
||||
|
||||
#' Retrieve information on species.
|
||||
#'
|
||||
|
|
@ -71,7 +78,7 @@ ensembl <- useEnsembl(
|
|||
#' - `replicative` Whether the species is likely to be aging replicatively.
|
||||
retrieve_species <- function() {
|
||||
# Ensembl datasets correspond to distinct species.
|
||||
ensembl_datasets <- data.table(listDatasets(ensembl))
|
||||
ensembl_datasets <- data.table(listDatasets(get_ensembl()))
|
||||
|
||||
# Filter out species ID and name from the result.
|
||||
species <- ensembl_datasets[, .(
|
||||
|
|
@ -92,7 +99,7 @@ retrieve_species <- function() {
|
|||
retrieve_genes <- function() {
|
||||
genes <- data.table(getBM(
|
||||
attributes = c("ensembl_gene_id", "hgnc_symbol", "chromosome_name"),
|
||||
mart = useDataset("hsapiens_gene_ensembl", mart = ensembl)
|
||||
mart = useDataset("hsapiens_gene_ensembl", mart = get_ensembl())
|
||||
))
|
||||
|
||||
genes[, .(
|
||||
|
|
@ -116,6 +123,8 @@ retrieve_genes <- function() {
|
|||
#' - `gene` Ensembl gene ID.
|
||||
#' - `distance` Distance to nearest telomere in base pairs.
|
||||
retrieve_distances <- function(species_ids, gene_ids) {
|
||||
ensembl <- get_ensembl()
|
||||
|
||||
# Exclude the human from the species, in case it is present there.
|
||||
species_ids <- species_ids[species_ids != "hsapiens"]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue