├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── .vimrc ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R ├── buildquery.R ├── dbinfo.R ├── dbversion.R ├── externallinks.R ├── getdata.R ├── listdata.R ├── mirnasummary.R ├── mmquery.R ├── multiMiR_package.R ├── search.R ├── sqlclasses.R ├── sqlclauses.R ├── sqltables.R ├── tabletypes.R ├── utils.R └── zzz.R ├── README.md ├── inst ├── CITATION └── extdata │ ├── counts_table.Rds │ └── strains_factor.Rds ├── man ├── add.multimir.links.Rd ├── all_tables.Rd ├── as.mmquery.Rd ├── as_mmsql_components.Rd ├── build_mmsql.Rd ├── default_cutoff.Rd ├── deprecate_arg.Rd ├── extract_mmquery.Rd ├── get.multimir.cutoffs.Rd ├── get_multimir.Rd ├── list_multimir.Rd ├── mmquery_bioc-class.Rd ├── multiMiR.Rd ├── multimir.summary.Rd ├── multimir_dbInfo.Rd ├── multimir_switchDBVersion.Rd ├── null_to_df.Rd ├── pad.Rd ├── parens_quote.Rd ├── parens_wrap.Rd ├── parse_orgs.Rd ├── parse_response.Rd ├── query_multimir.Rd ├── quote_wrap.Rd ├── remove_empty_strings.Rd ├── remove_table.Rd ├── search_multimir.Rd ├── split_by.Rd ├── sql_org.Rd ├── sql_validated.Rd └── submit_request.Rd ├── tests ├── testthat.R └── testthat │ └── test_dbinfo.R └── vignettes └── multiMiR.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | .git 2 | ..Rcheck 3 | .vimrc 4 | .travis.yml 5 | .gitignore 6 | test/ 7 | ^.*\.Rproj$ 8 | ^\.Rproj\.user$ 9 | README.Rmd 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # System temp files 2 | .DS_Store 3 | 4 | # R system/temp files 5 | .Rhistory 6 | .Rapp_history 7 | ..Rcheck 8 | 9 | # Vim temp files 10 | *.swo 11 | *.swp 12 | 13 | .Rproj.user 14 | tags 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | sudo: false 5 | cache: packages 6 | r: 7 | - bioc-devel 8 | os: 9 | - linux 10 | 11 | warnings_are_errors: true 12 | 13 | r_packages: 14 | - covr 15 | 16 | after_success: 17 | - Rscript -e 'library(covr); codecov()' 18 | 19 | notifications: 20 | email: 21 | on_success: change 22 | on_failure: change 23 | 24 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | 2 | set autoindent " always set autoindenting on 3 | set smartindent 4 | "set cindent 5 | set shiftwidth=4 6 | set tabstop=4 7 | set softtabstop=4 8 | set expandtab 9 | set formatoptions+=t " c for autowrap comments, t for text/code 10 | set wrap " turns on text wrapping 11 | set textwidth=80 " textwidth for wrapping 12 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: multiMiR 2 | Title: 3 | Integration of multiple microRNA-target databases with their disease and 4 | drug associations 5 | Version: 1.11.0 6 | Authors@R: c( 7 | person("Yuanbin", "Ru", email = "ruyuanbin@gmail.com", role = c("aut")), 8 | person("Matt", "Mulvahill", email = "matt.mulvahill@gmail.com", role = c("cre", "aut")), 9 | person("Spencer", "Mahaffey", email = "spencer.mahaffey@ucdenver.edu", role = c("aut")), 10 | person("Katerina", "Kechris", email = "Katerina.Kechris@ucdenver.edu", role = c("aut", "cph", "ths"))) 11 | Description: 12 | A collection of microRNAs/targets from external resources, including 13 | validated microRNA-target databases (miRecords, miRTarBase and TarBase), 14 | predicted microRNA-target databases (DIANA-microT, ElMMo, MicroCosm, 15 | miRanda, miRDB, PicTar, PITA and TargetScan) and microRNA-disease/drug 16 | databases (miR2Disease, Pharmaco-miR VerSe and PhenomiR). 17 | URL: https://github.com/KechrisLab/multiMiR 18 | BugReports: https://github.com/KechrisLab/multiMiR/issues 19 | Depends: 20 | R (>= 3.4) 21 | Imports: 22 | stats, 23 | XML, 24 | RCurl, 25 | purrr (>= 0.2.2), 26 | tibble (>= 1.2), 27 | methods, 28 | BiocGenerics, 29 | AnnotationDbi, 30 | dplyr, 31 | Suggests: 32 | BiocStyle, 33 | edgeR, 34 | knitr, 35 | rmarkdown, 36 | testthat (>= 1.0.2) 37 | VignetteBuilder: knitr 38 | License: MIT + file LICENSE 39 | LazyData: true 40 | NeedsCompilation: no 41 | biocViews: miRNAData, Homo_sapiens_Data, Mus_musculus_Data, 42 | Rattus_norvegicus_Data, OrganismData 43 | RoxygenNote: 6.0.1 44 | Encoding: UTF-8 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | multiMiR is provided "as is" without warranty of any kind. 2 | YEAR: 2017 3 | COPYRIGHT HOLDER: Katerina Kechris 4 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(all_tables) 4 | export(conserved_tables) 5 | export(diseasedrug_tables) 6 | export(get.multimir) 7 | export(get_multimir) 8 | export(list.multimir) 9 | export(list_multimir) 10 | export(multimir_dbCount) 11 | export(multimir_dbInfo) 12 | export(multimir_dbInfoVersions) 13 | export(multimir_dbSchema) 14 | export(multimir_dbTables) 15 | export(multimir_switchDBVersion) 16 | export(predicted_tables) 17 | export(reverse_table_lookup) 18 | export(search.multimir) 19 | export(search_multimir) 20 | export(table_types) 21 | export(tables_wo_target) 22 | export(validated_tables) 23 | exportClasses(mmquery_bioc) 24 | exportMethods(columns) 25 | exportMethods(keys) 26 | exportMethods(keytypes) 27 | exportMethods(select) 28 | exportMethods(show) 29 | importFrom(AnnotationDbi,columns) 30 | importFrom(AnnotationDbi,keys) 31 | importFrom(AnnotationDbi,keytypes) 32 | importFrom(AnnotationDbi,select) 33 | importFrom(AnnotationDbi,show) 34 | importFrom(BiocGenerics,Filter) 35 | importFrom(RCurl,postForm) 36 | importFrom(XML,readHTMLTable) 37 | importFrom(dplyr,full_join) 38 | importFrom(methods,new) 39 | importFrom(methods,slot) 40 | importFrom(purrr,compact) 41 | importFrom(purrr,flatten) 42 | importFrom(purrr,map) 43 | importFrom(purrr,map_chr) 44 | importFrom(purrr,map_lgl) 45 | importFrom(purrr,reduce) 46 | importFrom(purrr,simplify_all) 47 | importFrom(purrr,transpose) 48 | importFrom(stats,setNames) 49 | importFrom(tibble,as_data_frame) 50 | -------------------------------------------------------------------------------- /R/buildquery.R: -------------------------------------------------------------------------------- 1 | #' Constructors for parts of SQL queries 2 | #' Expand_query converts a \code{mmyquery} object to a SQL query string 3 | #' 4 | #' @return A complete SQL statement and related information. 5 | #' @keywords internal 6 | #' @importFrom purrr map 7 | #' @importFrom purrr transpose 8 | #' @importFrom purrr compact 9 | #' @importFrom purrr map_chr 10 | #' @importFrom purrr flatten 11 | build_mmsql <- function(.table, org, 12 | mirna = NULL, 13 | target = NULL, 14 | disease.drug = NULL, 15 | predicted.site = NULL, 16 | predicted.cutoff.type = NULL, 17 | predicted.cutoff = NULL, 18 | limit = NULL) { 19 | 20 | components <- list(mirna = sql_mirna(mirna), 21 | target = sql_target(.table, target), 22 | validated = sql_validated(.table), 23 | predicted = sql_predicted(.table, org, predicted.site, 24 | predicted.cutoff.type, 25 | predicted.cutoff), 26 | diseasedrug = sql_diseasedrug(.table, disease.drug), 27 | org = sql_org(.table, org)) 28 | 29 | sql_parts <- purrr::transpose(components) 30 | sql_parts$.limit <- limit 31 | sql_parts_trim <- purrr::map(sql_parts, purrr::compact) 32 | table_type <- reverse_table_lookup(.table) 33 | 34 | 35 | list(query = expand_query(sql_parts_trim), 36 | #sqlparts = sql_parts_trim, 37 | table = .table, 38 | type = table_type) 39 | 40 | } 41 | 42 | #' @rdname build_mmsql 43 | #' @keywords internal 44 | expand_query <- function(x) { 45 | paste(expand_select(x$.select), 46 | expand_from(x$.from), 47 | expand_on(x$.on), 48 | expand_where_list(x$.where_list), 49 | expand_orderby(x$.orderby), 50 | expand_limit(x$.limit)) 51 | } 52 | 53 | #' @rdname build_mmsql 54 | #' @keywords internal 55 | expand_select <- function(x) { 56 | paste("SELECT", paste(unlist(x), collapse = ", ")) 57 | } 58 | 59 | #' @rdname build_mmsql 60 | #' @keywords internal 61 | expand_from <- function(x) { 62 | x <- merge_order(x) 63 | paste("FROM", paste(unlist(x), collapse = " INNER JOIN ")) 64 | } 65 | 66 | #' @rdname build_mmsql 67 | #' @keywords internal 68 | expand_on <- function(x) { 69 | x <- merge_order(x) 70 | paste0("ON (", paste(unlist(x), collapse = " AND "), ")") 71 | } 72 | 73 | #' @rdname build_mmsql 74 | #' @keywords internal 75 | expand_where_list <- function(x) { 76 | paste("WHERE", paste(unlist(purrr::map(purrr::flatten(x), expand_where)), 77 | collapse = " AND ")) 78 | 79 | } 80 | 81 | #' @rdname build_mmsql 82 | #' @keywords internal 83 | expand_where <- function(x) { 84 | sep <- pad(x$.connect) 85 | value <- switch(x$.operator, 86 | IN = parens_quote(x$.value), 87 | x$.value) 88 | x <- purrr::map_chr(x$.vars, paste, x$.operator, value) 89 | parens_wrap(paste(x, collapse = sep)) 90 | } 91 | 92 | #' @rdname build_mmsql 93 | #' @keywords internal 94 | expand_orderby <- function(x) { 95 | if (!is.null(x) & length(x) > 0) { 96 | x <- purrr::compact(x) 97 | stopifnot(length(x) == 1, inherits(x[[1]], "orderby")) 98 | x <- purrr::flatten(x) 99 | paste("ORDER BY", x$.vars, x$.order) 100 | } 101 | } 102 | 103 | #' @rdname build_mmsql 104 | #' @keywords internal 105 | expand_limit <- function(x) { 106 | if (!is.null(x)) paste("LIMIT", x) 107 | } 108 | 109 | #' @rdname build_mmsql 110 | #' @keywords internal 111 | merge_order <- function(.list) { 112 | # Reorder list to match the table merging order 113 | c(.list["mirna"], 114 | .list[c("validated", "predicted", "diseasedrug")], 115 | .list["target"]) 116 | } 117 | 118 | -------------------------------------------------------------------------------- /R/dbinfo.R: -------------------------------------------------------------------------------- 1 | 2 | #' Collect Information About the Web Server And Database of the multiMiR 3 | #' Package 4 | #' 5 | #' Functions for collecting and displaying information about the web server and 6 | #' database of the multiMiR package. 7 | #' 8 | #' \code{multimir.url} is a global option containing the URL of the multiMiR web 9 | #' server. Set using \code{options("multimir.url" = ...)} 10 | #' 11 | #' \code{multimir_dbCount} returns counts of records in the tables in the 12 | #' multiMiR database. Each table contains data from an external miRNA/target 13 | #' database. 14 | #' 15 | #' \code{multimir_dbInfo} returns other information about the multiMiR 16 | #' database. This includes information of external miRNA/target databases in 17 | #' multiMiR. 18 | #' 19 | #' \code{multimir_dbInfoVersions} returns other information about the multiMiR 20 | #' database versions available. This provides a list of available options if 21 | #' switching to previous version is desired. 22 | #' 23 | #' \code{multimir_dbSchema} prints the schema definition of the multiMiR 24 | #' database. 25 | #' 26 | #' \code{multimir_dbTables} returns the vector of tables in the multiMiR 27 | #' database and saves it to the global option \code{multimir.tables.list}. This 28 | #' function is automatically run when get_multimir is called if the 29 | #' \code{multimir.tables.list} is NULL. 30 | #' 31 | #' @aliases multimir_dbCount multimir_dbInfo multimir_dbInfoVersions 32 | #' multimir_dbSchema multimir_dbTables 33 | #' @param url Deprecated. Use global option \code{multimir.url} instead. 34 | #' @param schema.file Deprecated. Option exists as \code{multimir.schema}, 35 | #' but it should not need to be set directly. 36 | #' @return 37 | #' \code{multimir_dbCount}: a data frame with the count of records in 38 | #' each of the tables in the multiMiR database. 39 | #' 40 | #' \code{multimir_dbInfo}: a data frame with information about the multiMiR 41 | #' database. 42 | #' 43 | #' \code{multimir_dbInfoVersions}: a data frame with information about the 44 | #' multiMiR database versions. 45 | #' 46 | #' \code{multimir_dbSchema}: none (invisible \code{NULL}). 47 | #' 48 | #' \code{multimir_dbTables}: a data frame with table names in the multiMiR 49 | #' database. 50 | #' @keywords utilities database 51 | #' @examples 52 | #' 53 | #' this_url <- getOption("multimir.url") 54 | #' this_url 55 | #' options(multimir.url = this_url) 56 | #' 57 | #' db_ver <- multimir_dbInfoVersions() 58 | #' 59 | #' db_count <- multimir_dbCount() 60 | #' 61 | #' db_info <- multimir_dbInfo() 62 | #' 63 | #' multimir_dbSchema() 64 | #' 65 | #' db_tables <- multimir_dbTables() 66 | #' 67 | #' @export 68 | multimir_dbInfo <- function(url = NULL) { 69 | 70 | if (!is.null(url)) deprecate_arg("url") 71 | qry <- "SELECT * FROM map_metadata" 72 | search_multimir(query = qry) 73 | 74 | } 75 | 76 | 77 | #' @rdname multimir_dbInfo 78 | #' @export 79 | multimir_dbInfoVersions <- function(url = NULL) { 80 | 81 | if (!is.null(url)) deprecate_arg("url") 82 | qry <- paste("SELECT * FROM multimir_versions.version", 83 | "WHERE public=1 ORDER BY version DESC") 84 | submit_request(query = qry, .cgifields = "query") 85 | } 86 | 87 | #' @rdname multimir_dbInfo 88 | #' @export 89 | multimir_dbSchema <- function(schema.file = NULL) { 90 | 91 | if (!is.null(schema.file)) deprecate_arg("schema.file") 92 | schema <- readLines(full_url("multimir.schema")) 93 | cat(schema, sep = "\n") 94 | 95 | } 96 | 97 | #' @rdname multimir_dbInfo 98 | #' @export 99 | multimir_dbTables <- function(url = NULL) { 100 | 101 | if (!is.null(url)) deprecate_arg("db.tables") 102 | tbls <- as.character(readLines(full_url("multimir.db.tables"))) 103 | options("multimir.tables.list" = tbls) 104 | return(tbls) 105 | 106 | } 107 | 108 | #' @rdname multimir_dbInfo 109 | #' @export 110 | multimir_dbCount <- function(url = NULL) { 111 | 112 | if (!is.null(url)) deprecate_arg("url") 113 | 114 | qry <- "SELECT * FROM map_counts" 115 | res <- search_multimir(query = qry) 116 | 117 | for (i in 2:ncol(res)) { 118 | res[, i] <- as.numeric(as.character(res[, i])) 119 | } 120 | 121 | return(res) 122 | 123 | } 124 | 125 | -------------------------------------------------------------------------------- /R/dbversion.R: -------------------------------------------------------------------------------- 1 | 2 | #' Manage Database Version to use 3 | #' 4 | #' Functions for managing the database version used to complete requests on the 5 | #' web server. 6 | #' 7 | #' \code{url} is a character string containing the URL of the multiMiR web 8 | #' server. Optional as it is set when the package is loaded. 9 | #' 10 | #' \code{multimir_dbInfoVersions} returns other information about the multiMiR 11 | #' database versions available. This provides a list of available options if 12 | #' switching to previous version is desired. 13 | #' 14 | #' \code{multimir_switchDBVersion} returns other information about the multiMiR 15 | #' database versions available. This provides a list of available options if 16 | #' switching to previous version is desired. 17 | #' 18 | #' @param url Deprecated. Use global option \code{multimir.url} instead. 19 | #' @param db_version A character string containing the full version number for 20 | #' the database version to use for for all package functions. The default will 21 | #' be the most recent version. 22 | #' @return 23 | #' 24 | #' \code{multimir_dbInfoVersions}: a data frame with information about the 25 | #' multiMiR database versions. 26 | #' 27 | #' \code{multimir_switchDBVersion}: none (invisible \code{NULL}). 28 | #' @keywords utilities database 29 | #' @examples 30 | #' 31 | #' multimir_dbInfoVersions() 32 | #' multimir_switchDBVersion(db_version="2.0.0") 33 | #' 34 | #' @export multimir_switchDBVersion 35 | multimir_switchDBVersion <- function(db_version, url = NULL) { 36 | 37 | if (!is.null(url)) deprecate_arg("url") 38 | 39 | old_vers <- getOption("multimir.db.version") 40 | vers_table <- multimir_dbInfoVersions() 41 | new_vers <- subset(vers_table, vers_table$VERSION == db_version) 42 | 43 | if (nrow(new_vers) == 0) stop("DB version ", db_version, " not found. ", 44 | "Please use the full version as displayed ", 45 | "in multimir_dbInfoVersions().") 46 | if (nrow(new_vers) > 1) stop("Multiple matching DB versions. Consider ", 47 | "submitting an issue on Github repository.") 48 | 49 | set_dbversion(dbversion_row = new_vers, overwrite = TRUE) 50 | message(paste0("Now using database version: ", 51 | getOption("multimir.db.version"))) 52 | 53 | } 54 | 55 | 56 | 57 | # Internal function 58 | # @param overwrite Overwite existing options (TRUE/FALSE). 59 | # @param dbversion_row A single row data frame from \code{queryDBVersions()} 60 | set_dbversion <- function(dbversion_row, overwrite = FALSE) { 61 | 62 | # Get current global options 63 | op <- options() 64 | 65 | # Convert all cols to character (using [] is a trick via SO and Hadley that 66 | # allows the dataframe to keep its 'data.frame' class) 67 | dbversion_row[] <- lapply(dbversion_row, as.character) 68 | 69 | op.multimir.vers <- 70 | list(multimir.db.version = dbversion_row$VERSION, 71 | multimir.db.updated = dbversion_row$UPDATED, 72 | multimir.db.name = dbversion_row$DBNAME, 73 | multimir.db.tables = dbversion_row$TABLES, 74 | multimir.schema = dbversion_row$SCHEMA, 75 | multimir.cutoffs = dbversion_row$RDA) 76 | 77 | # Set option values 78 | toset <- ifelse(overwrite, 79 | rep(TRUE, length(op.multimir.vers)), 80 | !(names(op.multimir.vers) %in% names(op))) 81 | if (any(toset)) options(op.multimir.vers[toset]) 82 | 83 | } 84 | 85 | 86 | # Internal function for combining base url (multimir.url) with the url paths for 87 | # various requests. 88 | # @param pkg_option One of the package options corresponding to a url path 89 | # needing appending to the base url 90 | # @return the full url to the object path passed to the function 91 | full_url <- function(pkg_option = c("multimir.queries", 92 | "multimir.db.tables", 93 | "multimir.schema", 94 | "multimir.cutoffs")) { 95 | 96 | pkg_option <- match.arg(pkg_option) 97 | paste0(getOption("multimir.url"), getOption(pkg_option)) 98 | 99 | } 100 | 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /R/externallinks.R: -------------------------------------------------------------------------------- 1 | 2 | #' Add External Database Link for Each of the multiMiR Result Entry 3 | #' 4 | #' This is an internal multiMiR function that is not intended to be used 5 | #' directly. Please use \code{get_multimir}. 6 | #' 7 | #' @param x table/dataset returned by multimir db 8 | #' @param org Organism (see \code{get_multimir}) 9 | #' @return The input data frame \code{x} with a column added for the external 10 | #' database links. 11 | #' @keywords internal 12 | add.multimir.links <- function(x, org) { 13 | # To add external database link for each of the multiMiR result entry 14 | if (nrow(x) == 0) return(x) 15 | 16 | links <- rep(NA, nrow(x)) 17 | db <- as.character(unique(x$database)) 18 | for (d in db) { 19 | m <- which(x$database == d) 20 | mir <- as.character(x$mature_mirna_id[m]) 21 | 22 | if (d == "mirecords") { 23 | # NOTE: need to resolve miRNA IDs with '*' in mirecords 24 | mir <- sub("-5p", "", mir) 25 | mir <- sub("-3p", "", mir) 26 | symbol <- as.character(x$target_symbol[m]) 27 | if (org == "hsa") { 28 | s <- "species=Homo+sapiens" 29 | } else if (org == "mmu") { 30 | s <- "species=Mus+musculus" 31 | } else if (org == "rno") { 32 | s <- "species=Rattus+norvegicus" 33 | } 34 | links[m] <- paste0("http://mirecords.biolead.org/interactions.php?", 35 | s, "&mirna_acc=", mir, 36 | "&targetgene_type=symbol&targetgene_info=", 37 | symbol, "&v=yes&search_int=Search") 38 | } else if (d == "mirtarbase") { 39 | symbol <- as.character(x$target_symbol[m]) 40 | links[m] <- 41 | paste0("http://mirtarbase.mbc.nctu.edu.tw/php/search.php?org=", 42 | org, "&mirnas=", mir, "&targets=", symbol, "&opt=adv") 43 | } else if (d == "tarbase") { 44 | symbol <- as.character(x$target_symbol[m]) 45 | links[m] <- 46 | paste0("http://diana.imis.athena-innovation.gr/DianaTools/", 47 | "index.php?r=tarbase/index&mirnas=", 48 | mir, "&genes=", symbol) 49 | } else if (d == "mir2disease") { 50 | # NOTE: Can only search by miRNA, gene or disease alone - here use 51 | # gene 52 | symbol <- as.character(x$target_symbol[m]) 53 | links[m] <- 54 | paste0("http://watson.compbio.iupui.edu:8080/miR2Disease/", 55 | "searchTarget.jsp?SearchUnit=target&SearchText=", 56 | symbol, "&checkbox2=Causal&checkbox2=Unspecified") 57 | } else if (d == "pharmaco_mir") { 58 | # NOTE: Links don't work 59 | 60 | } else if (d == "phenomir") { 61 | # NOTE: search by gene 62 | symbol <- as.character(x$target_symbol[m]) 63 | links[m] <- 64 | paste0("http://mips.helmholtz-muenchen.de/phenomir/main/list/", 65 | "searchform2?query=", symbol, 66 | "&selectedview=mirs&searchtype=fuzzy") 67 | } else if (d == "diana_microt") { 68 | ensembl <- as.character(x$target_ensembl[m]) 69 | links[m] <- 70 | paste0("http://diana.imis.athena-innovation.gr/DianaTools/", 71 | "index.php?r=microT_CDS/results&genes=", ensembl, 72 | "&mirnas=", mir, "&threshold=0") 73 | } else if (d == "elmmo") { 74 | # NOTE: Need RefSeq accession for the gene - use miRNA only 75 | mir <- sub("-5p", "", mir) 76 | mir <- sub("-3p", "", mir) 77 | if (org == "hsa") { 78 | s <- "organism=hg" 79 | } else if (org == "mmu") { 80 | s <- "organism=mm" 81 | } else if (org == "rno") { 82 | s <- "organism=rn" 83 | } 84 | links[m] <- paste0("http://www.mirz.unibas.ch/ElMMo3/?", s, 85 | "&cellType=all&miRNAs[]=", mir, 86 | "&predict=Predict+miRNAs+targets+!") 87 | } else if (d == "microcosm") { 88 | mir <- sub("-5p", "", mir) 89 | mir <- sub("-3p", "", mir) 90 | if (org == "hsa") { 91 | s <- "genome_id=2964" 92 | } else if (org == "mmu") { 93 | s <- "genome_id=3876" 94 | } else if (org == "rno") { 95 | s <- "genome_id=5171" 96 | } 97 | symbol <- as.character(x$target_symbol[m]) 98 | links[m] <- 99 | paste0("http://www.ebi.ac.uk/enright-srv/microcosm/cgi-bin/", 100 | "targets/v5/hit_list.pl?", 101 | s, "&mirna_id=", mir, "&external_name=", symbol) 102 | } else if (d == "miranda") { 103 | # NOTE: Could only search by gene or miRNA - use gene here 104 | if (org == "hsa") { 105 | s <- "organism=9606" 106 | } else if (org == "mmu") { 107 | s <- "organism=10090" 108 | } else if (org == "rno") { 109 | s <- "organism=10116" 110 | } 111 | symbol <- as.character(x$target_symbol[m]) 112 | links[m] <- 113 | paste0("http://www.microrna.org/microrna/searchGenes.do?gene=", 114 | symbol, "&", s) 115 | } else if (d == "mirdb") { 116 | # NOTE: Could only search by gene or miRNA - use gene here 117 | if (org == "hsa") { 118 | s <- "species=Human" 119 | } else if (org == "mmu") { 120 | s <- "species=Mouse" 121 | } else if (org == "rno") { 122 | s <- "species=Rat" 123 | } 124 | symbol <- as.character(x$target_symbol[m]) 125 | links[m] <- paste0("http://mirdb.org/cgi-bin/search.cgi?", s, 126 | "&searchType=gene&geneChoice=symbol&searchBox=", 127 | symbol) 128 | } else if (d == "pictar") { 129 | # NOTE: Links don't work 130 | 131 | } else if (d == "pita") { 132 | mir <- sub("-5p", "", mir) 133 | mir <- sub("-3p", "", mir) 134 | if (org == "hsa") { 135 | s <- "Organism=Human" 136 | } else if (org == "mmu") { 137 | s <- "Organism=Mouse" 138 | } 139 | symbol <- as.character(x$target_symbol[m]) 140 | links[m] <- 141 | paste0("http://genie.weizmann.ac.il/cgi-bin/", 142 | "search_mir07_prediction.pl?", s, "µRNAs=", mir, 143 | "&Genes=", symbol, 144 | "&MinimumSeed=7&AllowSingleGU=1&AllowSingleMismatch=1", 145 | "&MinConservation=0&FlankOption=0_0") 146 | } else if (d == "targetscan") { 147 | mir <- sub("-5p", "", mir) 148 | mir <- sub("-3p", "", mir) 149 | symbol <- as.character(x$target_symbol[m]) 150 | if (org == "hsa") { 151 | links[m] <- 152 | paste0("http://www.targetscan.org/cgi-bin/targetscan/", 153 | "vert_61/targetscan.cgi?species=Human&gid=", symbol, 154 | "&mirg=", mir) 155 | } else if (org == "mmu") { 156 | links[m] <- 157 | paste0("http://www.targetscan.org/cgi-bin/targetscan/", 158 | "mmu_61/targetscan.cgi?species=Mouse&gid=", symbol, 159 | "&mirg=", mir) 160 | } 161 | } 162 | } 163 | 164 | x = data.frame(x, DB.link = links) 165 | return(x) 166 | } 167 | 168 | -------------------------------------------------------------------------------- /R/getdata.R: -------------------------------------------------------------------------------- 1 | 2 | #' Get microRNA-target Interactions from the multiMiR Package 3 | #' 4 | #' The main function to retrieve predicted and validated miRNA-target 5 | #' interactions and their disease and drug associations from the multiMiR 6 | #' package. 7 | #' 8 | #' get.multimir() has been deprecated and replaced with the get_multimir() 9 | #' version. 10 | #' 11 | #' \code{get_multimir} is the main and recommended function to retrieve 12 | #' information from the multiMiR package. Input to the function must contain at 13 | #' least one of the followings: miRNA(s), target gene(s), and disease and drug 14 | #' term(s). 15 | #' 16 | #' The setting of \code{predicted.site} is applicable to three ("miranda", 17 | #' "pita", and "targetscan") of the eight predicted tables. If 18 | #' \code{predicted.site} is \code{"conserved"}, the function will search 19 | #' conserved target sites annotated by TargetScan, target sites with 20 | #' conservation scores greater than or equal to 0.57 (in human and rat; or 21 | #' 0.566 in mouse) in miRanda, and/or sites with conservation scores greater 22 | #' than or equal to 0.9 in PITA. 23 | #' 24 | #' Although the summary (if \code{summary=TRUE}) can be used to find results 25 | #' that are recorded by combinations of different databases, please note that 26 | #' for predicted interactions a combination approach may not be as effective as 27 | #' a single algorithm because of age or quality of the tool. 28 | #' 29 | #' Note: The length of the list supported has been increased from version1.0.1. 30 | #' The size is now limited to 20MB which should accommodate most requests. 31 | #' There is a possibility for technical reasons that the query could fail even 32 | #' if the list is under this limit. If this occurs it is recommended that you 33 | #' break up the list into smaller batches and submit them sequentially. 34 | #' 35 | #' @param url Deprecated. The URL for queries is now defined by the package 36 | #' options \code{multimir.url} and \code{multimir.queries}. 37 | #' @param org a character string for the organism. Three organisms are 38 | #' supported so far: human ("hsa" (default), "human", or "Homo Sapiens"), mouse 39 | #' ("mmu", "mouse", or "Mus musculus"), and rat ("rno", "rat", or "Rattus 40 | #' norvegicus"). The organism is case insensitive. 41 | #' @param mirna 'NULL' (default) or a character string or character vector for 42 | #' the mature miRNA(s). It can be the mature miRNA accession number (i.e. 43 | #' "MIMAT0000072"), mature miRNA ID (i.e. "hsa-miR-199a-3p"), or a combination 44 | #' of both (i.e. c("MIMAT0000065", "hsa-miR-30a-5p")). The character is case 45 | #' insensitive. *See note about the length of list supported. 46 | #' @param target 'NULL' (default) or a character string or character vector for 47 | #' the target gene(s). It can be the gene symbol (i.e. c("TP53", "KRAS")), 48 | #' Entrez gene ID (i.e. c(578, 3845)), Ensembl gene ID (i.e. 49 | #' "ENSG00000171791"), or a combination of any of these identifiers (i.e. 50 | #' c("TP53", 3845, "ENSG00000171791")). The character is case insensitive. *See 51 | #' note about the length of list supported. 52 | #' @param disease.drug 'NULL' (default) or a character string or character 53 | #' vector for the disease(s) and/or drug(s) (i.e. c("bladder cancer", 54 | #' "cisplatin")). The character is case insensitive. 55 | #' @param table a character string indicating which table(s) in multiMiR to 56 | #' search. Each table contains data from an external database. Options include 57 | #' "validated" (default, to search all validated tables "mirecords", 58 | #' "mirtarbase", and "tarbase"), "predicted" (to search all predicted tables 59 | #' "diana_microt", "elmmo", "microcosm", "miranda", "mirdb", "pictar", "pita", 60 | #' and "targetscan"), "disease.drug" (to search all disease/drug tables 61 | #' "mir2disease", "pharmaco_mir", and "phenomir"), "all" (to search all of the 62 | #' tables above), or an individual table from above. 63 | #' @param predicted.cutoff.type a character indicating the type of prediction 64 | #' score cutoff. This must be either "p" (default, percentage cutoff) or "n" 65 | #' (number cutoff). 66 | #' @param predicted.cutoff 'NULL' (default) or an integer giving a prediction 67 | #' score cutoff. By default ('NULL'), the cutoff is '20' (search the top 20\% 68 | #' if \code{predicted.cutoff.type="p"}) or '300000' (search the top 300000 (or 69 | #' all records if total < 300000) if \code{predicted.cutoff.type="n"}). 70 | #' @param predicted.site a character string indicating the type of predicted 71 | #' target sites to search. This can be one of the strings "conserved", 72 | #' "nonconserved", or "all", and can be abbreviated. This only applies to three 73 | #' of the predicted tables ("miranda", "pita", and "targetscan") that have 74 | #' conservation information of the target sites. 75 | #' @param summary logical. Whether to summarize the result (default = FALSE). 76 | #' @param add.link logical. Whether to add link to external database for each 77 | #' result entry. 78 | #' @param use.tibble logical. Whether to use the data_frame class from the 79 | #' tibble package for returned dataframes. The key benefit for large datasets 80 | #' is more restrictive printing to the console (first 10 rows and only the 81 | #' number of columns that will fit \code{getOption('width')}). See 82 | #' \code{?tible::data_frame} for more information. 83 | #' @param limit a positive integer. Limits the number of records returned from 84 | #' each table. Useful in testing potentially large queries. 85 | #' @param legacy.out logical. Whether to return the Bioconductor compatible S4 86 | #' object or the legacy S3 object (default=FALSE). 87 | #' 88 | #' @return \code{get_multimir} returns an S4 object (see 89 | #' \code{?mmquery_bioc-class} containing the queried data and associated 90 | #' metadata. With \code{legacy.out=FALSE} (default), the data is a single 91 | #' dataset with association/interaction type defined by the \code{type} 92 | #' variable. With \code{legacy.out=TRUE} the original S3 object with 3 separate 93 | #' data frames ('predicted', 'validated', and 'disease_drug') is returned. 94 | #' @keywords utilities database 95 | #' @examples 96 | #' 97 | #' ## search 'hsa-miR-18a-3p' in validated interactions in human 98 | #' example1 <- get_multimir(mirna='hsa-miR-18a-3p', summary=TRUE) 99 | #' columns(example1) 100 | #' ## target genes that are validated by Luciferase assay 101 | #' lucif <- select(example1, keytype = "type", keys = "validated", 102 | #' columns = columns(example1)) 103 | #' lucif[grep("Luciferase", lucif$experiment), ] 104 | #' example1@summary[example1@summary[,"target_symbol"] == "KRAS",] 105 | #' 106 | #' ## search 'cisplatin' in disease and drug tables in human 107 | #' example2 <- get_multimir(disease.drug='cisplatin', table='disease.drug') 108 | #' nrow(example2@data) 109 | #' head(example2@data) 110 | #' 111 | #' @importFrom purrr map 112 | #' @importFrom tibble as_data_frame 113 | #' @importFrom stats setNames 114 | #' @export get_multimir 115 | get_multimir <- function(url = NULL, 116 | org = "hsa", 117 | mirna = NULL, 118 | target = NULL, 119 | disease.drug = NULL, 120 | table = "validated", 121 | predicted.cutoff = NULL, 122 | predicted.cutoff.type = "p", 123 | predicted.site = "conserved", 124 | summary = FALSE, 125 | add.link = FALSE, 126 | use.tibble = FALSE, 127 | limit = NULL, 128 | legacy.out = FALSE) { 129 | 130 | if (!is.null(url)) deprecate_arg("url") 131 | if (is.null(mirna) & is.null(target) & is.null(disease.drug)) return(NULL) 132 | 133 | # Argument checking 134 | if (!table %in% c(all_tables(), "predicted", "validated", "disease.drug", 135 | "all")) { 136 | stop("Invalid table value. See help for options.") 137 | } 138 | if (is.null(mirna) & is.null(target) & table == "all") { 139 | message("Predicted and validated tables require either mirna or ", 140 | "target arguments. Only disease/drug tables will be returned.") 141 | table <- "disease.drug" 142 | } 143 | 144 | # Grab argument for storing in return object 145 | my_args <- mget(names(formals()), sys.frame(sys.nframe())) 146 | argmatch <- match(c("table", "org", "mirna", "target", "disease.drug", 147 | "predicted.cutoff", "predicted.cutoff.type", 148 | "predicted.site"), names(my_args), 0L) 149 | sqlargs <- as.list(my_args[c(argmatch)]) 150 | 151 | # Parse arguments 152 | org <- parse_orgs(org) 153 | mirna <- remove_empty_strings(mirna) 154 | target <- remove_empty_strings(target) 155 | predicted.cutoff <- default_cutoff(predicted.cutoff.type, predicted.cutoff) 156 | .table <- switch(table, 157 | all = all_tables(), 158 | validated = validated_tables(), 159 | predicted = predicted_tables(), 160 | disease.drug = diseasedrug_tables(), 161 | table) 162 | 163 | # Don't build queries for tables that don't apply to provided arguments 164 | if (org == "rno") { 165 | .table <- remove_table(.table, c("diana_microt", "pictar", "pita", 166 | "targetscan")) 167 | } 168 | if (is.null(mirna) & is.null(disease.drug)) { 169 | .table <- remove_table(.table, c("mir2disease", "phenomir")) 170 | } 171 | 172 | # Build queries and request from server 173 | queries <- map(.table, build_mmsql, 174 | org = org, 175 | mirna = mirna, 176 | target = target, 177 | disease.drug = disease.drug, 178 | predicted.site = predicted.site, 179 | predicted.cutoff.type = predicted.cutoff.type, 180 | predicted.cutoff = predicted.cutoff, 181 | limit = limit) 182 | queries <- setNames(queries, .table) 183 | # Request data 184 | .data <- map(queries, query_multimir, org = org, 185 | add.link = add.link, use.tibble = use.tibble) 186 | # Restructure data and related info for returning 187 | rtnobject <- extract_mmquery(outlist = .data, org = org, summary = summary, 188 | use.tibble = use.tibble, .args = sqlargs) 189 | 190 | if (add.link) { 191 | message(paste("Some of the links to external databases may be broken", 192 | "due to outdated identifiers in these databases. Please", 193 | "refer to Supplementary Table 2 in the multiMiR paper", 194 | "for details of the issue.\n")) 195 | } 196 | 197 | # Choose between S4 and legacy S3 output 198 | rtnobject <- if (legacy.out) as.mmquery(rtnobject) else as.mmquery_bioc(rtnobject) 199 | 200 | return(rtnobject) 201 | 202 | } 203 | 204 | #' @rdname get_multimir 205 | #' @export 206 | get.multimir <- function(url = NULL, 207 | org = "hsa", 208 | mirna = NULL, 209 | target = NULL, 210 | disease.drug = NULL, 211 | table = "validated", 212 | predicted.cutoff = NULL, 213 | predicted.cutoff.type = "p", 214 | predicted.site = "conserved", 215 | summary = FALSE, 216 | add.link = FALSE, 217 | use.tibble = FALSE, 218 | limit = NULL) { 219 | 220 | .Deprecated("get_multimir") 221 | get_multimir(url = url, 222 | org = org, 223 | mirna = mirna, 224 | target = target, 225 | disease.drug = disease.drug, 226 | table = table, 227 | predicted.cutoff = predicted.cutoff, 228 | predicted.cutoff.type = predicted.cutoff.type, 229 | predicted.site = predicted.site, 230 | summary = summary, 231 | add.link = add.link, 232 | use.tibble = use.tibble, 233 | limit = limit) 234 | 235 | } 236 | 237 | 238 | 239 | #' Each org can be specified in one of 3 ways -- this standardizes the argument 240 | #' into the 3 char abbreviation. 241 | #' 242 | #' @return A standardized, abbreviated form of the input org. 243 | #' @keywords internal 244 | parse_orgs <- function(org) { 245 | 246 | # only allows single string (TODO: same as old version?). 247 | if (!is.null(org)) { 248 | org <- gsub("hsa|human|homo sapiens", "hsa", org, ignore.case = TRUE) 249 | org <- gsub("mmu|mouse|mus musculus", "mmu", org, ignore.case = TRUE) 250 | org <- gsub("rno|rat|rattus norvegicus", "rno", org, ignore.case = TRUE) 251 | 252 | if (!(org %in% c("hsa", "mmu", "rno"))) { 253 | stop("Organism ", org, " is not in multiMiR. Current options ", 254 | "are 'hsa' (human), 'mmu' (mouse) and 'rno' (rat).\n") 255 | } 256 | } 257 | 258 | return(org) 259 | } 260 | 261 | 262 | #' If null, set default predicted.cutoff 263 | #' 264 | #' @return The default cutoff value. 265 | #' @keywords internal 266 | default_cutoff <- function(predicted.cutoff.type, predicted.cutoff) { 267 | 268 | if (!is.null(predicted.cutoff.type) & is.null(predicted.cutoff)) { 269 | predicted.cutoff <- switch(predicted.cutoff.type, 270 | p = 20, 271 | n = 300000) 272 | } 273 | 274 | if (predicted.cutoff.type == "p" & 275 | (predicted.cutoff < 1 | predicted.cutoff > 100)) { 276 | stop(paste("Percent predicted cutoff (predicted.cutoff) should be", 277 | "between 1 and 100.\n")) 278 | } 279 | 280 | return(predicted.cutoff) 281 | 282 | } 283 | 284 | 285 | #' Wrapper for search_multimir for adding feature (printing notification to 286 | #' console) 287 | #' 288 | #' @return The queried multimir data with the addition of a requested feature. 289 | #' @keywords internal 290 | #' @importFrom tibble as_data_frame 291 | query_multimir <- function(x, org, add.link, use.tibble) { 292 | 293 | cat("Searching", x$table, "...\n") 294 | x$data <- search_multimir(x$query) 295 | 296 | if (!is.null(x$data)) { 297 | x$data <- cbind('database' = x$table, x$data, stringsAsFactors = FALSE) 298 | if (add.link) { 299 | x$data <- add.multimir.links(x$data, org) 300 | } 301 | } else { 302 | x$data <- data.frame() 303 | } 304 | 305 | if (use.tibble) x$data <- as_data_frame(x$data) 306 | if (x$table %in% diseasedrug_tables()) x$data <- unique(x$data) 307 | 308 | return(x) 309 | 310 | } 311 | 312 | 313 | #' Remove tables x from a vector of table names. 314 | #' 315 | #' Typically used when a set of arguments don't apply to a table or would return 316 | #' an error/empty response 317 | #' 318 | #' @param tables A character vector. 319 | #' @param x A second character vector to remove from the first (\code{tables}). 320 | #' @return Character vector \code{tables} excluding the strings matching those 321 | #' in \code{x}. 322 | #' @keywords internal 323 | remove_table <- function(tables, x) tables[!tables %in% x] 324 | 325 | 326 | #' Remove empty strings from character vector. 327 | #' 328 | #' The WHERE clauses for target and mirna use allow for multiple arguments 329 | #' always separated by 'OR' and several columns are checked for each value 330 | #' (mirna id, acc; target symbol, entrez, ensemble). If empty strings "" are 331 | #' present in the get_multimir arguments, Targets and miRNA with empty values in 332 | #' one of these columns will be incorrectly returned. -- thus purge empty 333 | #' strings first. 334 | #' 335 | #' @param x A character vector 336 | #' @return A character vector with empty strings removed 337 | #' @keywords internal 338 | remove_empty_strings <- function(x) x[x != ""] 339 | 340 | 341 | 342 | -------------------------------------------------------------------------------- /R/listdata.R: -------------------------------------------------------------------------------- 1 | 2 | #' List microRNAs, Genes, Drugs Or Diseases in the multiMiR Package 3 | #' 4 | #' \code{list_multimir} lists all the unique microRNAs, target genes, drugs, or 5 | #' diseases in the web server of the multiMiR package. 6 | #' 7 | #' list.multimir() has been deprecated and replaced with the list_multimir() 8 | #' version. 9 | #' 10 | #' @param x a character string indicating what to list. This must be one of the 11 | #' strings \code{"mirna"} (default), \code{"gene"}, \code{"drug"}, or 12 | #' \code{"disease"}. This can be abbreviated and is case insensitive. 13 | #' @param limit a positive integer. Limits the number of records returned from 14 | #' each table. Useful in testing potentially large queries. 15 | #' @param url Deprecated. Use global option \code{multimir.url} instead. 16 | #' @return \code{list_multimir} returns a data frame with information of 17 | #' microRNAs (microRNA unique ID, organism, mature microRNA accession number, 18 | #' and mature microRNA ID), target genes (gene unique ID, organism, gene 19 | #' symbol, Entrez gene ID, and Ensembl gene ID), drugs (drug names), and 20 | #' diseases (disease name). 21 | #' @author Yuanbin Ru \email{ruyuanbin@@gmail.com} 22 | #' @keywords utilities database 23 | #' @examples 24 | #' miRNAs <- list_multimir("mirna", limit = 10) 25 | #' genes <- list_multimir("gene", limit = 10) 26 | #' drugs <- list_multimir("drug", limit = 10) 27 | #' diseases <- list_multimir("disease", limit = 10) 28 | #' @importFrom purrr map 29 | #' @export list_multimir 30 | list_multimir <- function(x = c("mirna", "gene", "drug", "disease"), 31 | limit = NULL, 32 | url = NULL) { 33 | 34 | if (!is.null(url)) deprecate_arg("url") 35 | x <- match.arg(x) 36 | 37 | # Set chosen query and submit/request from server 38 | qry <- switch(x, 39 | mirna = list("SELECT * FROM mirna"), 40 | gene = list("SELECT * FROM target"), 41 | drug = list("SELECT DISTINCT(drug) FROM pharmaco_mir"), 42 | disease = list("SELECT DISTINCT(disease) FROM mir2disease", 43 | "SELECT DISTINCT(disease) FROM phenomir")) 44 | if (!is.null(limit)) qry <- purrr::map(qry, ~ paste(.x, "LIMIT", limit)) 45 | result <- lapply(qry, search_multimir) 46 | 47 | stopifnot(length(result) %in% 1:2) 48 | 49 | # Clean up result and return 50 | if (length(result) == 2) { 51 | stopifnot(names(result[[1]]) == names(result[[2]])) 52 | nm <- names(result[[1]]) 53 | result <- sort(union(toupper(result[[1]][, 1]), 54 | toupper(result[[2]][, 1]))) 55 | result <- data.frame(result) 56 | colnames(result) <- nm 57 | } else { 58 | result <- result[[1]] 59 | } 60 | 61 | return(result) 62 | 63 | } 64 | 65 | 66 | #' @export list.multimir 67 | #' @rdname list_multimir 68 | list.multimir <- function(x = c("mirna", "gene", "drug", "disease"), 69 | limit = NULL, 70 | url = NULL) { 71 | .Deprecated("list_multimir") 72 | list_multimir(x = x, 73 | limit = limit, 74 | url = url) 75 | } 76 | 77 | 78 | -------------------------------------------------------------------------------- /R/mirnasummary.R: -------------------------------------------------------------------------------- 1 | 2 | #' Summarize microRNA/target Information from the multiMiR Package 3 | #' 4 | #' This is an internal multiMiR function that is not intended to be used 5 | #' directly. Please use \code{get_multimir}. 6 | #' 7 | #' @param result PLACEHOLDER 8 | #' @param pair.index PLACEHOLDER 9 | #' @param order.by PLACEHOLDER 10 | #' @return Summary of objects queries from databse 11 | #' @keywords internal 12 | multimir.summary <- function(result, 13 | pair.index = 2:6, 14 | order.by = "all.sum") { 15 | # To summarize the result from functions get_multimir* 16 | len <- length(pair.index) 17 | r <- NULL 18 | for (n in names(result)) { 19 | r <- rbind(r, cbind(result[[n]][, pair.index], 20 | matrix(result[[n]]$database, ncol = 1))) 21 | } 22 | 23 | if (is.null(r)) return(NULL) 24 | 25 | info <- table(apply(r[, 1:len], 1, function(x) { 26 | paste(x, collapse = "|") 27 | }), r[, len + 1]) 28 | info.ncol <- ncol(info) 29 | if (info.ncol > 1) { 30 | all.sum <- apply(info, 1, function(x) { 31 | sum(x > 0) 32 | }) 33 | cols <- colnames(info) 34 | d.m <- match(cols, c("mir2disease", "pharmaco_mir", "phenomir")) 35 | if (sum(!is.na(d.m)) > 1) { 36 | d.sum <- apply(matrix(info[, !is.na(d.m)], ncol = sum(!is.na(d.m))), 37 | 1, function(x) { 38 | sum(x > 0) 39 | }) 40 | info <- cbind(info, disease.sum = d.sum) 41 | } else if (sum(!is.na(d.m)) == 1) { 42 | d.sum <- as.integer(info[, !is.na(d.m)] > 0) 43 | info <- cbind(info, disease.sum = d.sum) 44 | } 45 | p.m <- match(cols, c("diana_microt", "elmmo", "microcosm", "miranda", 46 | "mirdb", "pictar", "pita", "targetscan")) 47 | if (sum(!is.na(p.m)) > 1) { 48 | p.sum <- apply(matrix(info[, !is.na(p.m)], ncol = sum(!is.na(p.m))), 49 | 1, function(x) { 50 | sum(x > 0) 51 | }) 52 | info <- cbind(info, predicted.sum = p.sum) 53 | } else if (sum(!is.na(p.m)) == 1) { 54 | p.sum <- as.integer(info[, !is.na(p.m)] > 0) 55 | info <- cbind(info, predicted.sum = p.sum) 56 | } 57 | v.m <- match(cols, c("mirecords", "mirtarbase", "tarbase")) 58 | if (sum(!is.na(v.m)) > 1) { 59 | v.sum <- apply(matrix(info[, !is.na(v.m)], ncol = sum(!is.na(v.m))), 60 | 1, function(x) { 61 | sum(x > 0) 62 | }) 63 | info <- cbind(info, validated.sum = v.sum) 64 | } else if (sum(!is.na(v.m)) == 1) { 65 | v.sum <- as.integer(info[, !is.na(v.m)] > 0) 66 | info <- cbind(info, validated.sum = v.sum) 67 | } 68 | info <- cbind(info, all.sum = all.sum) 69 | } 70 | 71 | s <- NULL 72 | for (i in 1:nrow(info)) { 73 | row.name = rownames(info)[i] 74 | row.name = sub("\\|$", "\\|\\|", row.name) 75 | pair <- strsplit(row.name, "\\|")[[1]] 76 | pair <- c(pair, info[i, ]) 77 | s <- rbind(s, pair) 78 | } 79 | colnames(s) <- c(colnames(result[[1]])[pair.index], colnames(info)) 80 | s <- data.frame(s, row.names = NULL) 81 | 82 | m <- match(order.by, colnames(s)) 83 | if (is.na(m)) { 84 | s <- s[order(as.numeric(as.character(s[, ncol(s)])), decreasing = TRUE), ] 85 | } else { 86 | s <- s[order(as.numeric(as.character(s[, m])), decreasing = TRUE), ] 87 | } 88 | s <- data.frame(s, row.names = NULL) 89 | 90 | n.s <- ncol(s) 91 | n.i <- ncol(info) 92 | for (n in (n.s - n.i + 1):n.s) { 93 | s[, n] <- as.numeric(as.character(s[, n])) 94 | } 95 | 96 | return(s) 97 | } 98 | 99 | 100 | -------------------------------------------------------------------------------- /R/mmquery.R: -------------------------------------------------------------------------------- 1 | 2 | #' Creates all objects needed for the legacy S3 return object and the new S4 3 | #' object. 4 | #' 5 | #' @return A list of data queried, summary of results, and related input 6 | #' parameters. 7 | #' @return a list for packaging by \code{as.mmquery} and \code{as.mmquery_bioc} 8 | #' @keywords internal 9 | #' @importFrom tibble as_data_frame 10 | #' @importFrom purrr map 11 | #' @importFrom purrr transpose 12 | #' @importFrom purrr reduce 13 | #' @importFrom purrr compact 14 | extract_mmquery <- function(outlist, org, .args, summary = FALSE, 15 | use.tibble = FALSE) { 16 | 17 | # outlist structured by table (list containing data, query, table name, 18 | # type) restructure so organized by type (predicted/validated/diseasedrug) 19 | outobj <- split_by(outlist, ~ .x$type) 20 | outobj <- map(outobj, ~ transpose(.x)) 21 | outobj <- list(data = map(outobj, ~ reduce(.x$data, rbind)), 22 | queries = map(outobj, ~ reduce(.x$query, c))) 23 | 24 | # Add summary table if requested 25 | data_wo_null <- compact(outobj$data) 26 | 27 | if (summary) { 28 | mmsum <- multimir.summary(data_wo_null) 29 | if (use.tibble) mmsum <- as_data_frame(mmsum) 30 | } else mmsum <- data.frame() 31 | 32 | cutoff <- null_to_num(.args$predicted.cutoff) 33 | cutoff.type <- null_to_char(.args$predicted.cutoff.type) 34 | site <- null_to_char(.args$predicted.site) 35 | 36 | rtn <- list(validated = null_to_df(outobj$data$validated), 37 | predicted = null_to_df(outobj$data$predicted), 38 | disease.drug = null_to_df(outobj$data$disease.drug), 39 | queries = outobj$queries, 40 | summary = mmsum, 41 | tables = .args$table, 42 | org = .args$org, 43 | # not including these, because they could be very large 44 | # mirna = .args$mirna, 45 | # target = .args$target, 46 | # disease.drug = .args$disease.drug, 47 | predicted.cutoff = cutoff, 48 | predicted.cutoff.type = cutoff.type, 49 | predicted.site = site) 50 | 51 | return(rtn) 52 | 53 | } 54 | 55 | 56 | #' S3 constructor and methods for object returned by \code{get_multimir()}. 57 | #' 58 | #' This package's primary user-facing object. Contains the SQL statement and the 59 | #' returned data query, as well as a summary table depending on 60 | #' specified option. 61 | #' 62 | #' @keywords internal 63 | #' @return An \code{mmquery} object. 64 | as.mmquery <- function(a_list) { 65 | 66 | stopifnot(all(c("validated", "predicted", "disease.drug", "queries", 67 | "summary", "tables", "org", "predicted.cutoff", 68 | "predicted.cutoff.type", "predicted.site") %in% 69 | names(a_list))) 70 | 71 | # Create and return s3 object 72 | structure(list(validated = a_list$validated, 73 | predicted = a_list$predicted, 74 | disease.drug = a_list$disease.drug, 75 | queries = a_list$queries, 76 | summary = a_list$summary), 77 | class = c("mmquery"), 78 | tables = a_list$table, 79 | org = a_list$org, 80 | predicted.cutoff = a_list$predicted.cutoff, 81 | predicted.cutoff.type = a_list$predicted.cutoff.type, 82 | predicted.site = a_list$predicted.site) 83 | 84 | } 85 | 86 | 87 | #' @importFrom tibble as_data_frame 88 | #' @rdname as.mmquery 89 | print.mmquery <- function(x) { 90 | 91 | cat("MultiMiR query\n") 92 | cat("Validated interactions:\n") 93 | print(as_data_frame(x$validated), n = 5) 94 | cat("Predicted interactions:\n") 95 | print(as_data_frame(x$predicted), n = 5) 96 | cat("Disease/Drug associations:\n") 97 | print(as_data_frame(x$diseasedrug), n = 5) 98 | cat("Summary:\n") 99 | print(as_data_frame(x$summary), n = 5) 100 | 101 | } 102 | 103 | 104 | 105 | 106 | 107 | #' S4 constructor and methods for object returned by \code{get_multimir()}. 108 | #' 109 | #' This package's primary user-facing object. Contains the SQL statement and the 110 | #' returned data query, as well as a summary table depending on 111 | #' specified option. Note that the returned data is now contained in a single 112 | #' dataframe. To filter to a specific type of association or interaction, 113 | #' \code{select} on the \code{type} variable. 114 | #' 115 | #' @slot data A dataframe containing validated and predicted microRNA-target 116 | #' interactions and disease/drug assocations found. 117 | #' @slot queries A list of queries submitted to the multiMiR SQL server. 118 | #' @slot summary A summary dataframe of the returned microRNA dataframes 119 | #' @slot tables A character vector of the microRNA relationship types returned 120 | #' (validated, predicted, disease.drug, or all). 121 | #' @slot org The selected organism (hsa/human, mmu/mouse, rno/rat). 122 | #' @slot predicted.cutoff An integer giving a prediction score cutoff. 123 | #' @slot predicted.cutoff.type A character indicating the type of prediction 124 | #' score cutoff (p = percentage, n = number, character() = none) 125 | #' @slot predicted.site A character string indicating the type of predicted 126 | #' target sites to searched. 127 | #' @param x,object An mmquery_bioc object. 128 | #' @param keys A result of the keys() function. For the mmquery_bioc class this 129 | #' is a character vector of microRNA's in the returned mmquery_bioc object. 130 | #' @param keytype allows the user to discover which keytypes can be passes in to 131 | #' select or keys and the keytype argument 132 | #' @param columns lists the columns that can be returned for the 133 | #' \code{mmquery_bioc} object. 134 | #' @param .list a list of returned dataframes, summary 135 | #' @param ... additional arguments 136 | #' @return an s4 object of class mmquery_bioc. Contains queried data, a summary 137 | #' dataset, and associated input parameters. 138 | #' 139 | #' @importFrom AnnotationDbi select 140 | #' @importFrom AnnotationDbi columns 141 | #' @importFrom AnnotationDbi keys 142 | #' @importFrom AnnotationDbi keytypes 143 | #' @importFrom AnnotationDbi show 144 | #' @importFrom BiocGenerics Filter 145 | #' @importFrom methods new 146 | #' @importFrom methods slot 147 | #' @importFrom purrr reduce 148 | #' @importFrom dplyr full_join 149 | #' @export 150 | setClass("mmquery_bioc", 151 | representation(data = "data.frame", 152 | queries = "list", 153 | summary = "data.frame", 154 | tables = "character", 155 | org = "character", 156 | predicted.cutoff = "numeric", 157 | predicted.cutoff.type = "character", 158 | predicted.site = "character")) 159 | 160 | #' @rdname mmquery_bioc-class 161 | as.mmquery_bioc <- function(.list) { 162 | 163 | #stopifnot(all(c("validated", "predicted", "disease.drug", "queries", 164 | # "summary", "table", "org", "predicted.cutoff", 165 | # "predicted.cutoff.type", "predicted.site") %in% 166 | # names(a_list))) 167 | tables <- sapply(table_types(), function(y) { 168 | rtn <- .list[[y]] 169 | if (nrow(rtn) > 0) rtn$type <- y 170 | rtn 171 | }) 172 | tables <- Filter(length, tables) 173 | if (length(tables) != 0) { 174 | tables <- reduce(tables, full_join) 175 | } else { 176 | tables <- data.frame() 177 | } 178 | 179 | # Create and return s3 object 180 | new("mmquery_bioc", 181 | data = tables, 182 | queries = .list$queries, 183 | summary = .list$summary, 184 | tables = .list$table, 185 | org = .list$org, 186 | predicted.cutoff = .list$predicted.cutoff, 187 | predicted.cutoff.type = .list$predicted.cutoff.type, 188 | predicted.site = .list$predicted.site 189 | ) 190 | 191 | } 192 | 193 | #' @rdname mmquery_bioc-class 194 | #' @export 195 | setMethod("columns", "mmquery_bioc", function(x) mm_cols(x)) 196 | 197 | #' @rdname mmquery_bioc-class 198 | #' @export 199 | setMethod("keys", "mmquery_bioc", 200 | function(x, keytype, ...) { 201 | 202 | if(missing(keytype)){ 203 | keytype <- mm_centralPkgSymbol() 204 | } 205 | unique(unname(x@data[[keytype]])) 206 | 207 | }) 208 | 209 | #' @rdname mmquery_bioc-class 210 | #' @export 211 | setMethod("keytypes", "mmquery_bioc", function(x) mm_cols(x)) 212 | 213 | #' @rdname mmquery_bioc-class 214 | #' @export 215 | setMethod("select", "mmquery_bioc", 216 | function(x, keys, columns, keytype, ...) { 217 | 218 | if (missing(keytype)) keytype <- mm_centralPkgSymbol() 219 | rtn <- slot(x, "data") 220 | rtn <- rtn[, colnames(rtn) %in% unique(c(columns, keytype))] 221 | if (nrow(rtn) > 0) rtn <- rtn[rtn[[keytype]] %in% keys, ] 222 | rtn 223 | 224 | }) 225 | 226 | #' @rdname mmquery_bioc-class 227 | #' @export 228 | setMethod("show", "mmquery_bioc", 229 | function(object) { 230 | 231 | cat("MultiMiR query\n") 232 | cat("Validated interactions:\n") 233 | print(as_data_frame(select(object, keytype = "type", 234 | keys = "validated", 235 | columns = columns(object), n = 5))) 236 | cat("Predicted interactions:\n") 237 | print(as_data_frame(select(object, keytype = "type", 238 | keys = "predicted", 239 | columns = columns(object), n = 5))) 240 | cat("Disease/Drug associations:\n") 241 | print(as_data_frame(select(object, keytype = "type", 242 | keys = "disease.drug", 243 | columns = columns(object), n = 5))) 244 | cat("Summary:\n") 245 | print(as_data_frame(object@summary), n = 5) 246 | 247 | }) 248 | 249 | 250 | #' @keywords internal 251 | mm_cols <- function(x) { 252 | rtn <- colnames(slot(x, "data")) 253 | rtn <- unique(unname(rtn)) 254 | rtn 255 | } 256 | 257 | #' @keywords internal 258 | mm_centralPkgSymbol <- function() "mature_mirna_id" 259 | 260 | 261 | # # Optional functions 262 | # setMethod("metadata", "AnnotationDb", 263 | # function(x) dbReadTable(dbconn(x), "metadata") 264 | # ) 265 | -------------------------------------------------------------------------------- /R/multiMiR_package.R: -------------------------------------------------------------------------------- 1 | #' MultiMiR: R package for accessing the multiMiR database 2 | #' 3 | #' This package provides an interface to the multiMiR database of 4 | #' microRNA-target interactions, and disease and drug associations. See 5 | #' \url{http://multimir.org} and the vignette ('multiMiR') for more 6 | #' details. 7 | #' 8 | #' @references [Add reference here] 9 | #' 10 | #' @docType package 11 | #' @name multiMiR 12 | #' @aliases multimir multiMiR 13 | #' 14 | NULL 15 | -------------------------------------------------------------------------------- /R/search.R: -------------------------------------------------------------------------------- 1 | 2 | #' Search the multiMiR Database Given a MySQL Query 3 | #' 4 | #' This is a function for directly querying the multiMiR database with MySQL 5 | #' queries. Given a MySQL query, it searches and retrieves result from the 6 | #' multiMiR database on the multiMiR web server. To use \code{search_multimir} 7 | #' directly, users will need to be familiar with MySQL and multiMiR table 8 | #' structures. Users are advised to use \code{get_multimir} instead. 9 | #' 10 | #' search.multimir() has been deprecated and replaced with the search_multimir() 11 | #' version. 12 | #' 13 | #' @param query a character string for the MySQL query. 14 | #' @return \code{search_multimir} returns a data frame containing results from 15 | #' the multiMiR web server. 16 | #' @keywords utilities database 17 | #' @examples 18 | #' 19 | #' ## show all tables in the multiMiR database 20 | #' tables <- search_multimir(query="show tables") 21 | #' 22 | #' ## show the structure of table diana_microt 23 | #' microt <- search_multimir(query="describe diana_microt") 24 | #' 25 | #' ## search for validated target genes of hsa-miR-18a-3p in miRecords 26 | #' qry <- paste("SELECT m.mature_mirna_acc, m.mature_mirna_id,", 27 | #' " t.target_symbol, t.target_entrez, t.target_ensembl,", 28 | #' " i.experiment, i.support_type, i.pubmed_id", 29 | #' "FROM mirna AS m INNER JOIN mirecords AS i INNER JOIN target", 30 | #' "AS t ON (m.mature_mirna_uid=i.mature_mirna_uid AND", 31 | #' " i.target_uid=t.target_uid)", 32 | #' "WHERE m.mature_mirna_id='hsa-miR-18a-3p'") 33 | #' result <- search_multimir(query = qry) 34 | #' 35 | #' @export 36 | search_multimir <- function(query) { 37 | # To search the multiMiR database on the web server given a MySQL query 38 | # NOTE: Can only be used after version is set?? due to dbName arg? 39 | 40 | dbName <- getOption("multimir.db.name") 41 | submit_request(query = query, dbName = dbName, 42 | .cgifields = c("query","dbName")) 43 | } 44 | 45 | #' @rdname search_multimir 46 | #' @export 47 | search.multimir <- function(query) { 48 | .Deprecated("search_multimir") 49 | search_multimir(query = query) 50 | } 51 | 52 | 53 | 54 | 55 | #' General workhorse function for submitting and returning queries 56 | #' 57 | #' This is an internal multiMiR function that is not intended to be used 58 | #' directly. Please use \code{get_multimir}. 59 | #' 60 | #' @importFrom XML readHTMLTable 61 | #' @importFrom RCurl postForm 62 | #' @return Table requested in \code{query}. 63 | #' @keywords internal 64 | submit_request <- function(url = full_url("multimir.queries"), query, ...) { 65 | 66 | request <- RCurl::postForm(url, query = query, ... ) 67 | result <- XML::readHTMLTable(request, stringsAsFactors = FALSE) 68 | parse_response(result) 69 | 70 | } 71 | 72 | 73 | 74 | 75 | #' Parse the Result Returned by the multiMiR Web Server 76 | #' 77 | #' This is an internal multiMiR function that is not intended to be used 78 | #' directly. Please use \code{get_multimir}. 79 | #' 80 | #' @return The queried table portion of the HTML response. 81 | #' @keywords internal 82 | parse_response <- function(HTML.response) { 83 | # To parse the response from the multimir web server. Two tables should 84 | # return. The first table (response[[1]]) is the summary. And the second 85 | # table (response[[2]]) has the response in details. 86 | 87 | response <- NULL 88 | l <- length(HTML.response) 89 | if (l == 2) { 90 | response <- HTML.response[[2]] 91 | } else if (l > 2) { 92 | # This should never happen, but just in case... 93 | stop(paste("Unexpected response from multiMiR web server.", 94 | "Problem originates with web server - Please submit issue", 95 | "on Github repo")) 96 | } else if (l == 0) { 97 | stop("Request to multiMiR web server failed. There could be ", 98 | "incorrect syntax in your query, or you are not connected to ", 99 | "the internet. Alternatively the multiMiR web server at ", 100 | "http://multimir.org is temporarily down. \n") 101 | } # else if l ==1, just return NULL 102 | 103 | return(response) 104 | 105 | } 106 | 107 | -------------------------------------------------------------------------------- /R/sqlclasses.R: -------------------------------------------------------------------------------- 1 | #' S3 Class constructors for objects defining SQL query components 2 | #' and a collection of these parts (\code{mmsql_components}). 3 | #' 4 | #' The collection object has a defined set of components that match the multiMiR 5 | #' database and defined options in \code{get_multimir()}. Conceptually this is 6 | #' split into two parts, the relatively straightforward SELECT, FROM, and ON 7 | #' portion of the query and the more complex filtering and sorting operations: 8 | #' WHERE and ORDER BY. The latter have their own classes, the former are 9 | #' resolved as strings (or character vectors) in the functions defining handling 10 | #' of each sql table (\code{sql_} prefix). 11 | #' 12 | #' @aliases as_mmsql_components, as_where_list, as_where, as_orderby, 13 | #' is_where_list 14 | #' @return 15 | #' \code{as_mmsql_components}: A collection of components that make up a 16 | #' SQL query. 17 | #' \code{as_where_list}, \code{as_where}, \code{as_orderby}: Individual 18 | #' components of a SQL query. 19 | #' @keywords internal 20 | as_mmsql_components <- function(.select = NULL, .from = NULL, .on = NULL, 21 | .where_list = NULL, .orderby = NULL, 22 | typeattr = NULL) { 23 | 24 | if (!is.null(.where_list)) stopifnot(inherits(.where_list, "where_list")) 25 | if (!is.null(.orderby)) stopifnot(inherits(.orderby, "orderby")) 26 | 27 | structure(list(.select = .select, 28 | .from = .from, 29 | .on = .on, 30 | .where_list = .where_list, 31 | .orderby = .orderby), 32 | class = c("mmsql_components")) 33 | 34 | } 35 | 36 | #' @rdname as_mmsql_components 37 | #' @keywords internal 38 | #' @importFrom purrr compact 39 | #' @importFrom purrr map_lgl 40 | as_where_list <- function(...) { 41 | wlist <- purrr::compact(list(...)) 42 | stopifnot(all(purrr::map_lgl(wlist, inherits, "where"))) 43 | structure(wlist, class = "where_list") 44 | } 45 | 46 | #' @rdname as_mmsql_components 47 | #' @keywords internal 48 | as_where <- function(.vars, .connect = NULL, .operator, .value = "%s") { 49 | structure(list(.vars = .vars, 50 | .connect = .connect, 51 | .operator = .operator, 52 | .value = .value), 53 | class = c("where")) 54 | } 55 | 56 | #' @rdname as_mmsql_components 57 | #' @keywords internal 58 | is_where <- function(x) inherits(x, "where") 59 | 60 | #' @rdname as_mmsql_components 61 | #' @keywords internal 62 | as_orderby <- function(.vars, .order) { 63 | stopifnot(.order %in% c("ASC", "DESC")) 64 | structure(list(.vars = .vars, .order = .order), 65 | class = c("orderby")) 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /R/sqlclauses.R: -------------------------------------------------------------------------------- 1 | #' Functions defining the WHERE clauses. 2 | #' 3 | #' Functions defining filtering by organism (org), disease/drug, conserved, and 4 | #' cutoff. Filtering by mirna and target are defined within their \code{sql_...} 5 | #' functions. 6 | #' 7 | #' @aliases sql_org, where_org, where_diseasedrug, where_conserved, 8 | #' where_cutoff create_cutoff_name cutoff_to_score 9 | #' @return The \code{WHERE} portion of a SQL query 10 | #' @keywords tables types predicted validated diseasedrug disease drug 11 | #' 12 | #' @keywords internal 13 | sql_org <- function(.table, org) { 14 | where <- where_org(.table, org) 15 | as_mmsql_components(.where_list = as_where_list(where)) 16 | } 17 | 18 | #' @rdname sql_org 19 | #' @keywords internal 20 | where_org <- function(.table, org) { 21 | no_target <- .table %in% tables_wo_target() 22 | as_where(.vars = if (no_target) "m.org" else c("m.org", "t.org"), 23 | .connect = "AND", 24 | .operator = "=", 25 | .value = quote_wrap(org)) 26 | } 27 | 28 | 29 | #' @rdname sql_org 30 | #' @keywords internal 31 | where_diseasedrug <- function(.table, disease.drug) { 32 | wherevar <- switch(.table, 33 | pharmaco_mir = "i.drug", 34 | mir2disease = "i.disease", 35 | phenomir = c("i.disease", "i.disease_class")) 36 | if (is.null(disease.drug)) { 37 | NULL 38 | } else { 39 | as_where(.vars = wherevar, 40 | .connect = "OR", 41 | .operator = "IN", 42 | .value = disease.drug) 43 | } 44 | 45 | } 46 | 47 | 48 | #' @rdname sql_org 49 | #' @keywords internal 50 | where_conserved <- function(.table, org, predicted.site) { 51 | 52 | miranda_cut <- switch(org, mmu = 0.566, 0.57) 53 | targetscan_cut <- if (predicted.site == "conserved") "'Y'" else "'N'" 54 | pita_cut <- 0.9 55 | 56 | vars <- switch(.table, targetscan = "i.conserved_site", 57 | "i.conservation") 58 | operator <- switch(predicted.site, conserved = ">=", "<") 59 | operator <- switch(.table, targetscan = "=", operator) 60 | cut_value <- switch(.table, 61 | miranda = miranda_cut, 62 | targetscan = targetscan_cut, 63 | pita = pita_cut) 64 | 65 | has_conserved <- (.table %in% conserved_tables() & predicted.site != "all") 66 | 67 | if (!has_conserved) 68 | NULL 69 | else { 70 | as_where(.vars = vars, .operator = operator, .value = cut_value) 71 | } 72 | 73 | } 74 | 75 | 76 | #' @rdname sql_org 77 | #' @keywords internal 78 | where_cutoff <- function(.table, score_var, score_cutoff) { 79 | 80 | # NOTE: Check what the .value should be here. wasn't gettting same value 81 | # from example3 in vignette 82 | operator <- switch(.table, miranda = "<=", pita = "<=", targetscan = "<=", 83 | ">") 84 | as_where(.vars = score_var, .operator = operator, .value = score_cutoff) 85 | 86 | } 87 | 88 | 89 | #' @rdname sql_org 90 | #' @keywords internal 91 | create_cutoff_name <- function(.table, org, predicted.site) { 92 | if (.table %in% conserved_tables()) { 93 | suffix <- switch(predicted.site, conserved = "c1", nonconserved = "c0", 94 | NULL) 95 | } else { 96 | suffix <- NULL 97 | } 98 | paste(c(.table, org, suffix), collapse = ".") 99 | } 100 | 101 | 102 | #' @rdname sql_org 103 | #' @keywords internal 104 | cutoff_to_score <- function(.table, cutoff_name, predicted.cutoff.type, 105 | predicted.cutoff) { 106 | 107 | scipen.orig <- getOption("scipen") 108 | options(scipen = 99) 109 | on.exit(options(scipen = scipen.orig)) 110 | cutoffs <- get.multimir.cutoffs()[[cutoff_name]] 111 | 112 | # get dataset-specific score cutoff 113 | if (predicted.cutoff.type == "p") { 114 | 115 | score_cutoff <- cutoffs[[paste0(predicted.cutoff, "%")]] 116 | 117 | } else if (predicted.cutoff.type == "n") { 118 | 119 | tbl_count <- cutoffs[["count"]] 120 | 121 | count_min <- 10000 122 | too_small <- paste("Number predicted cutoff (predicted.cutoff)", 123 | predicted.cutoff, "may be too small. A cutoff of", 124 | "10000 will be used instead.\n") 125 | too_large <- paste0("Number predicted cutoff (predicted.cutoff) ", 126 | predicted.cutoff, " is larger than the total ", 127 | "number of records in table ", .table, 128 | ". All records will be queried.\n") 129 | if (predicted.cutoff < count_min) message(too_small) 130 | if (predicted.cutoff > tbl_count) message(too_large) 131 | 132 | adj_pred_cutoff <- max(min(tbl_count, predicted.cutoff), count_min) 133 | adj_pred_cutoff <- as.integer(as.integer(adj_pred_cutoff / 10000) * 134 | 10000) 135 | score_cutoff <- cutoffs[[as.character(adj_pred_cutoff)]] 136 | } 137 | 138 | return(score_cutoff) 139 | 140 | } 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /R/sqltables.R: -------------------------------------------------------------------------------- 1 | #' Generate mmsql_components objects for each of the three types of tables, as 2 | #' well as the mirna and target tables. 3 | #' 4 | #' The three types of tables are predicted, validated, and diseasedrug 5 | #' (disease/drug). Additionally, mirna and target portions of the SQL statements 6 | #' are defined, including their filter clauses (\code{WHERE}). 7 | #' 8 | #' @aliases sql_validated sql_predicted sql_diseasedrug sql_mirna 9 | #' sql_target 10 | #' @keywords tables types predicted validated diseasedrug disease drug 11 | #' @return Components of a SQL query specific to each table type. 12 | #' 13 | #' @keywords internal 14 | sql_validated <- function(.table) { 15 | 16 | 17 | if (.table %in% validated_tables()) { 18 | .select <- c("i.experiment, i.support_type, i.pubmed_id") 19 | .from <- sprintf("%s AS i", .table) 20 | } else { 21 | .select <- NULL 22 | .from <- NULL 23 | } 24 | 25 | as_mmsql_components(.select = .select, .from = .from) 26 | 27 | } 28 | 29 | #' @rdname sql_validated 30 | #' @keywords internal 31 | sql_predicted <- function(.table, org, predicted.site, predicted.cutoff.type, 32 | predicted.cutoff) { 33 | 34 | this_type <- .table %in% predicted_tables() 35 | 36 | if (!this_type) { 37 | .where_list <- NULL 38 | .orderby <- NULL 39 | .select <- NULL 40 | .from <- NULL 41 | } else { 42 | score_var <- get_score_var(.table) 43 | cutoff_name <- create_cutoff_name(.table, org, predicted.site) 44 | score_cutoff <- cutoff_to_score(.table, cutoff_name, predicted.cutoff.type, 45 | predicted.cutoff) 46 | conserved <- where_conserved(.table, org, predicted.site) 47 | cutoff <- where_cutoff(.table, score_var, score_cutoff) 48 | .orderby <- as_orderby(.vars = score_var, .order = "DESC") 49 | .where_list <- as_where_list(conserved = conserved, 50 | cutoff = cutoff) 51 | .select <- sprintf("%s AS score", score_var) 52 | .from <- sprintf("%s AS i", .table) 53 | } 54 | as_mmsql_components(.select = .select, 55 | .from = .from, 56 | .where_list = .where_list, 57 | .orderby = .orderby) 58 | 59 | } 60 | 61 | #' @rdname sql_validated 62 | #' @keywords internal 63 | sql_diseasedrug <- function(.table, disease.drug) { 64 | 65 | this_type <- .table %in% diseasedrug_tables() 66 | 67 | # Build select list 68 | assoc <- switch(.table, pharmaco_mir = "i.drug", "i.disease") 69 | pubmed <- switch(.table, 70 | mir2disease = "CONCAT_WS('. ', i.year, i.title)", 71 | "i.pubmed_id") 72 | .select <- sprintf("%s AS disease_drug, %s AS paper_pubmedID", assoc, pubmed) 73 | .where <- where_diseasedrug(.table, disease.drug) 74 | 75 | as_mmsql_components(.select = if (!this_type) NULL else .select, 76 | .from = if (!this_type) NULL else sprintf("%s AS i", .table), 77 | .where_list = if (!this_type) NULL else as_where_list(.where)) 78 | 79 | } 80 | 81 | #' @rdname sql_validated 82 | #' @keywords internal 83 | sql_mirna <- function(mirna) { 84 | 85 | if (is.null(mirna)) { 86 | .where_list <- NULL 87 | } else { 88 | .where <- as_where(.vars = c("m.mature_mirna_acc", 89 | "m.mature_mirna_id"), 90 | .connect = "OR", 91 | .operator = "IN", 92 | .value = mirna) 93 | .where_list <- as_where_list(.where) 94 | } 95 | as_mmsql_components(.select = c("m.mature_mirna_acc", 96 | "m.mature_mirna_id"), 97 | .from = "mirna AS m", 98 | .on = "m.mature_mirna_uid = i.mature_mirna_uid", 99 | .where_list = .where_list) 100 | 101 | } 102 | 103 | #' @rdname sql_validated 104 | #' @importFrom purrr map_chr 105 | #' @keywords internal 106 | sql_target <- function(.table, target) { 107 | 108 | no_target <- .table %in% tables_wo_target() 109 | prefix <- if (no_target) "" else "t." 110 | na_txt <- if (no_target) "'NA' AS " else "" 111 | vars <- purrr::map_chr(c("%1$starget_symbol", "%1$starget_entrez", 112 | "%1$starget_ensembl"), sprintf, prefix) 113 | .select <- paste(paste0("%1$s", vars), collapse = ", ") 114 | if (is.null(target) | no_target) { 115 | .where_list <- NULL 116 | } else { 117 | .where <- as_where(.vars = if (no_target) NULL else vars, 118 | .connect = "OR", 119 | .operator = "IN", 120 | .value = target) 121 | .where_list <- as_where_list(.where) 122 | } 123 | 124 | as_mmsql_components(.select = sprintf(.select, na_txt), #else sprintf(.select, "", ), 125 | .from = if (no_target) NULL else "target AS t", 126 | .on = if (no_target) NULL else "i.target_uid = t.target_uid", 127 | .where_list = .where_list) 128 | 129 | } 130 | 131 | -------------------------------------------------------------------------------- /R/tabletypes.R: -------------------------------------------------------------------------------- 1 | #' Functions defining the category each table belongs to. 2 | #' 3 | #' One of three types: predicted, validated, or diseasedrug. 4 | #' Additionally two functions define characteristics of tables: those without a 5 | #' target column \code{tables_wo_target} and those with conserved target sites 6 | #' \code{conserved_tables}. 7 | #' 8 | #' @param .table a table name 9 | #' @return Returns dataset that names that belong to the category of the 10 | #' function name (e.g. \code{validated_tables()} returns tables with validated 11 | #' miRNA-target interactions). \code{reverse_table_lookup()} does the opposite; 12 | #' it returns the category a given \code{.table} belongs to. 13 | #' 14 | #' @examples 15 | #' all_tables() 16 | #' validated_tables() 17 | #' predicted_tables() 18 | #' diseasedrug_tables() 19 | #' predicted_tables() %in% all_tables() # TRUE 20 | #' table_types() 21 | #' 22 | #' @aliases all_tables, validated_tables, predicted_tables, diseasedrug_tables, 23 | #' tables_wo_target, reverse_table_lookup 24 | #' @keywords tables 25 | #' @export 26 | all_tables <- function() { 27 | c(validated_tables(), predicted_tables(), diseasedrug_tables()) 28 | } 29 | 30 | #' @rdname all_tables 31 | #' @export 32 | validated_tables <- function() c("mirecords", "mirtarbase", "tarbase") 33 | 34 | #' @rdname all_tables 35 | #' @export 36 | predicted_tables <- function() c("diana_microt", "elmmo", "microcosm", 37 | "miranda", "mirdb", "pictar", "pita", 38 | "targetscan") 39 | 40 | #' @rdname all_tables 41 | #' @export 42 | diseasedrug_tables <- function() c("mir2disease", "pharmaco_mir", "phenomir") 43 | 44 | #' @rdname all_tables 45 | #' @export 46 | tables_wo_target <- function() c("mir2disease", "phenomir") 47 | 48 | #' @rdname all_tables 49 | #' @export 50 | conserved_tables <- function() c("miranda", "pita", "targetscan") 51 | 52 | #' @rdname all_tables 53 | #' @export 54 | reverse_table_lookup <- function(.table) { 55 | if (.table %in% validated_tables()) { 56 | "validated" 57 | } else if (.table %in% predicted_tables()) { 58 | "predicted" 59 | } else if (.table %in% diseasedrug_tables()) { 60 | "disease.drug" 61 | } 62 | } 63 | 64 | #' @rdname all_tables 65 | #' @export 66 | table_types <- function() c("validated", "predicted", "disease.drug") 67 | 68 | #' @keywords internal 69 | get_score_var <- function(.table) { 70 | switch(.table, 71 | diana_microt = "i.miTG_score", 72 | elmmo = "i.p", 73 | microcosm = "i.score", 74 | mirdb = "i.score", 75 | pictar = "i.score", 76 | miranda = "i.mirsvr_score", 77 | pita = "i.ddG", 78 | targetscan = "i.context_plus_score", 79 | NULL) 80 | } 81 | 82 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | 2 | #' Load Pre-calculated Prediction Score Cutoffs in the multiMiR Package 3 | #' 4 | #' This is an internal multiMiR function that is not intended to be used 5 | #' directly. Please set prediction score cutoff in \code{get_multimir}. 6 | #' 7 | #' @param cutoff.file Deprecated. Set path to cutoffs file with the global 8 | #' option \code{multimir.cutoffs}. 9 | #' @return Cutoff values object from remote database. 10 | #' @keywords internal 11 | get.multimir.cutoffs <- function(name = NULL, cutoff.file = NULL) { 12 | # To load pre-calculated score cutoffs 13 | # NOTE: should this fn be exported? (NO) 14 | 15 | if (!is.null(cutoff.file)) deprecate_arg("cutoff.file") 16 | 17 | multimir_cutoffs <- NULL 18 | url.file <- url(full_url("multimir.cutoffs")) 19 | on.exit(close(url.file)) 20 | load(url.file) 21 | 22 | if (is.null(name)) { 23 | return(multimir_cutoffs) 24 | } else { 25 | return(multimir_cutoffs[[name]]) 26 | } 27 | 28 | } 29 | 30 | 31 | #' Internal function for sending deprecation messages 32 | #' 33 | #' @param name Name of a deprecated function argument. 34 | #' @return A message indicating deprecated arg and new version. 35 | #' @keywords internal 36 | deprecate_arg <- function(name = c("url", "schema.file", "db.tables", 37 | "cutoff.file")) { 38 | 39 | name <- match.arg(name) 40 | ops <- switch(name, 41 | url = "multimir.url", 42 | schema.file = "multimir.schema", 43 | db.tables = "multimir.db.tables", 44 | cutoff.file = "multimir.cutoffs") 45 | 46 | # the function using the schema option had an arg name of url, so switch for 47 | # an accurate message 48 | if (name == "db.tables") name <- "url" 49 | 50 | message("The ", name, " argument is deprecated. Please set using the ", 51 | "package option ", ops, " via options()") 52 | 53 | } 54 | 55 | 56 | #' Internal function for adding single quotes around a string 57 | #' 58 | #' @param x a string to be wrapped in single quotes. 59 | #' @return The input wrapped in single quotes. 60 | #' @keywords internal 61 | quote_wrap <- function(x) paste0("'", x, "'") 62 | 63 | 64 | 65 | #' Prep certain names for use in SQL query by adding parens 66 | #' 67 | #' @return The input value wrapped in quotes and then parentheses. 68 | #' @keywords internal 69 | parens_quote <- function(x) { 70 | if (!is.null(x)) parens_wrap(quote_wrap(x)) 71 | } 72 | 73 | #' Collapse a vector to a single comma-separated string and wrap in parentheses 74 | #' 75 | #' @return The input vector converted to a comma-separated string wrapped in 76 | #' parentheses. 77 | #' @keywords internal 78 | parens_wrap <- function(x) { 79 | paste0("(", paste(x, collapse = ", "), ")") 80 | } 81 | 82 | #' Pad single space on each side of an input 83 | #' 84 | #' @return Input value wrapped in single spaces. 85 | #' @keywords internal 86 | pad <- function(x) paste0(" ", x, " ") 87 | 88 | 89 | #' Split, order and sort lists by their components. 90 | #' 91 | #' Copied from purrr:v0.2.2 92 | #' 93 | #' @param .x A list or atomic vector. 94 | #' @param .f A function, formula, or atomic vector. 95 | #' @param ... Additional arguments passed on to \code{.f}. 96 | #' @return A list split by \code{.f} 97 | #' @importFrom purrr map 98 | #' @importFrom purrr simplify_all 99 | #' @importFrom purrr transpose 100 | #' @keywords internal 101 | split_by <- function(.x, .f, ...) { 102 | vals <- purrr::map(.x, .f, ...) 103 | split(.x, purrr::simplify_all(purrr::transpose(vals))) 104 | } 105 | 106 | #' Replace nulls with an empty object of each type 107 | #' 108 | #' @return an empty \code{data.frame}, \code{numeric}, or \code{character} 109 | #' vector. 110 | #' @param x input object 111 | #' @keywords internal 112 | null_to_df <- function(x) if (is.null(x)) data.frame() else x 113 | 114 | #' @rdname null_to_df 115 | null_to_num <- function(x) if (is.null(x)) numeric() else x 116 | 117 | #' @rdname null_to_df 118 | null_to_char <- function(x) if (is.null(x)) character() else x 119 | 120 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | 2 | # when loading packages, load runs first, then attach 3 | 4 | # Startup messages, reports default url 5 | .onAttach <- function(libname, pkgname) { 6 | 7 | msg <- paste0("Welcome to multiMiR.\n\n", 8 | "multiMiR database URL has been set to the \n", 9 | "default value: ", getOption("multimir.url"),"\n") 10 | msg <- paste0(msg,"\nDatabase Version: ", getOption("multimir.db.version"), 11 | " Updated: ",getOption("multimir.db.updated"),"\n") 12 | 13 | packageStartupMessage(msg) 14 | 15 | } 16 | 17 | # Set default url options on load 18 | .onLoad <- function(libname, pkgname) { 19 | 20 | op <- options() 21 | 22 | op.multimir <- list(multimir.url = "http://multimir.org/", 23 | multimir.queries = "cgi-bin/multimir_univ.pl") 24 | 25 | # Only set options multimir if name doesn't exist in current global options 26 | toset <- !(names(op.multimir) %in% names(op)) 27 | if (any(toset)) options(op.multimir[toset]) 28 | 29 | # Set database version options 30 | vers_table <- multimir_dbInfoVersions() 31 | curr_vers <- vers_table[1, ] # only choose top row (sorted in queryDBVersions) 32 | set_dbversion(dbversion_row = curr_vers) 33 | 34 | # No warning catches necessary, parse_response() takes care of failed con 35 | # messages 36 | invisible() 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # multiMiR 2 | 3 | [![Build Status](https://travis-ci.org/KechrisLab/multiMiR.svg?branch=master)](https://travis-ci.org/KechrisLab/multiMiR) 4 | [![codecov](https://codecov.io/gh/KechrisLab/multiMiR/branch/master/graph/badge.svg)](https://codecov.io/gh/KechrisLab/multiMiR) 5 | [![biocdownloads](https://bioconductor.org/shields/downloads/release/multiMiR.svg)](https://bioconductor.org/shields/downloads/release/multiMiR.svg) 6 | [![inBioc](https://bioconductor.org/shields/years-in-bioc/multiMiR.svg)](https://bioconductor.org/packages/release/bioc/html/multiMiR.html) 7 | --- 8 | ## DB update is available 8/28/24 (Thank you for your patience) 9 | 10 | The [*multiMiR* web server](http://multimir.org) hosts a 11 | database containing miRNA-target interactions from external databases. The 12 | package *multiMiR* provides functions to communicate with the *multiMiR* web 13 | server and its database. 14 | 15 | Note this repository is where active development occurs (think 'nightly' 16 | builds). The recommended release and devel versions are available via 17 | Bioconductor (as of Bioconductor 3.6). 18 | 19 | ```{r} 20 | # To install multiMiR, use BiocManager::install() 21 | if (!requireNamespace("BiocManager", quietly=TRUE)) 22 | install.packages("BiocManager") 23 | BiocManager::install() 24 | BiocManager::install("multiMiR") 25 | ``` 26 | 27 | Terminology used in package: 28 | - *sql components*: SELECT or FROM or ON or WHERE... etc. (mmsql\_components class) 29 | - *sql features*: specific to this DB and the options used to generate meaningful 30 | queries (i.e. mirna; conserved; table type: validated, predicted; etc.) 31 | - *sql*: a complete sql statement (mmsql class) 32 | - *query*: table result of sql statement (mmquery class), class includes sql 33 | statement and parts. 34 | 35 | ### * Warning * There are issues with merging target IDs from older unmaintained databases. Databases that have been updated more recently (1-2 years) use current versions of annotated IDs. In each update these old target IDs are carried over due to a lack of a reliable method to disambiguate the original ID with current IDs. Please keep this in mind with results from older databases that have not been updated. We continue to look at methods to resolve these ambiguities and improve target agreement between databases. You can use the unique() R function to identify and then remove multiple target genes if needed. 36 | 37 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citEntry(entry = "Article", 2 | title = "The multiMiR R package and database: integration of 3 | microRNA–target interactions along with their disease and drug 4 | associations", 5 | author = personList(as.person("Yuanbin Ru"), 6 | as.person("Katerina J. Kechris"), 7 | as.person("Boris Tabakoff"), 8 | as.person("Paula Hoffman"), 9 | as.person("Richard A. Radcliffe"), 10 | as.person("Russell Bowler"), 11 | as.person("Spencer Mahaffey"), 12 | as.person("Simona Rossi"), 13 | as.person("George A. Calin"), 14 | as.person("Lynne Bemis"), 15 | as.person("Dan Theodorescu")), 16 | journal = "Nucleic Acids Research", 17 | volume = "42", 18 | number = "17", 19 | pages = "e133", 20 | year = "2014", 21 | doi = "10.1093/nar/gku631", 22 | URL = "http://dx.doi.org/10.1093/nar/gku631", 23 | textVersion = 24 | paste("Yuanbin Ru, Katerina J. Kechris, Boris Tabakoff, Paula Hoffman,", 25 | "Richard A. Radcliffe, Russell Bowler, Spencer Mahaffey, Simona", 26 | "Rossi, George A. Calin, Lynne Bemis, Dan Theodorescu; The", 27 | "multiMiR R package and database: integration of microRNA–target", 28 | "interactions along with their disease and drug associations.", 29 | "Nucleic Acids Res 2014; 42 (17): e133. doi: 10.1093/nar/gku631") 30 | ) 31 | 32 | citEntry(entry = "Manual", 33 | title = "multiMiR: Integration of multiple microRNA-target databases with 34 | their disease and drug associations", 35 | author = personList(as.person("Yuanbin Ru"), 36 | as.person("Matt Mulvahill"), 37 | as.person("Spencer Mahaffey"), 38 | as.person("Katerina Kechris")), 39 | url = "https://github.com/KechrisLab/multiMiR", 40 | textVersion = 41 | paste("Yuanbin Ru, Matt Mulvahill, Spencer Mahaffey and Katerina Kechris", 42 | "(2017). multiMiR: Integration of multiple microRNA-target databases", 43 | "with their disease and drug associations. R package version 0.98.0.2.", 44 | "https://github.com/KechrisLab/multiMiR") 45 | ) 46 | 47 | 48 | -------------------------------------------------------------------------------- /inst/extdata/counts_table.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KechrisLab/multiMiR/7e34ddbddbeb7194666496edef7f4a7f57ae4581/inst/extdata/counts_table.Rds -------------------------------------------------------------------------------- /inst/extdata/strains_factor.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KechrisLab/multiMiR/7e34ddbddbeb7194666496edef7f4a7f57ae4581/inst/extdata/strains_factor.Rds -------------------------------------------------------------------------------- /man/add.multimir.links.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/externallinks.R 3 | \name{add.multimir.links} 4 | \alias{add.multimir.links} 5 | \title{Add External Database Link for Each of the multiMiR Result Entry} 6 | \usage{ 7 | add.multimir.links(x, org) 8 | } 9 | \arguments{ 10 | \item{x}{table/dataset returned by multimir db} 11 | 12 | \item{org}{Organism (see \code{get_multimir})} 13 | } 14 | \value{ 15 | The input data frame \code{x} with a column added for the external 16 | database links. 17 | } 18 | \description{ 19 | This is an internal multiMiR function that is not intended to be used 20 | directly. Please use \code{get_multimir}. 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/all_tables.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tabletypes.R 3 | \name{all_tables} 4 | \alias{all_tables} 5 | \alias{all_tables,} 6 | \alias{validated_tables,} 7 | \alias{predicted_tables,} 8 | \alias{diseasedrug_tables,} 9 | \alias{tables_wo_target,} 10 | \alias{reverse_table_lookup} 11 | \alias{validated_tables} 12 | \alias{predicted_tables} 13 | \alias{diseasedrug_tables} 14 | \alias{tables_wo_target} 15 | \alias{conserved_tables} 16 | \alias{reverse_table_lookup} 17 | \alias{table_types} 18 | \title{Functions defining the category each table belongs to.} 19 | \usage{ 20 | all_tables() 21 | 22 | validated_tables() 23 | 24 | predicted_tables() 25 | 26 | diseasedrug_tables() 27 | 28 | tables_wo_target() 29 | 30 | conserved_tables() 31 | 32 | reverse_table_lookup(.table) 33 | 34 | table_types() 35 | } 36 | \arguments{ 37 | \item{.table}{a table name} 38 | } 39 | \value{ 40 | Returns dataset that names that belong to the category of the 41 | function name (e.g. \code{validated_tables()} returns tables with validated 42 | miRNA-target interactions). \code{reverse_table_lookup()} does the opposite; 43 | it returns the category a given \code{.table} belongs to. 44 | } 45 | \description{ 46 | One of three types: predicted, validated, or diseasedrug. 47 | Additionally two functions define characteristics of tables: those without a 48 | target column \code{tables_wo_target} and those with conserved target sites 49 | \code{conserved_tables}. 50 | } 51 | \examples{ 52 | all_tables() 53 | validated_tables() 54 | predicted_tables() 55 | diseasedrug_tables() 56 | predicted_tables() \%in\% all_tables() # TRUE 57 | table_types() 58 | 59 | } 60 | \keyword{tables} 61 | -------------------------------------------------------------------------------- /man/as.mmquery.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mmquery.R 3 | \name{as.mmquery} 4 | \alias{as.mmquery} 5 | \alias{print.mmquery} 6 | \title{S3 constructor and methods for object returned by \code{get_multimir()}.} 7 | \usage{ 8 | as.mmquery(a_list) 9 | 10 | \method{print}{mmquery}(x) 11 | } 12 | \value{ 13 | An \code{mmquery} object. 14 | } 15 | \description{ 16 | This package's primary user-facing object. Contains the SQL statement and the 17 | returned data query, as well as a summary table depending on 18 | specified option. 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/as_mmsql_components.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sqlclasses.R 3 | \name{as_mmsql_components} 4 | \alias{as_mmsql_components} 5 | \alias{as_mmsql_components,} 6 | \alias{as_where_list,} 7 | \alias{as_where,} 8 | \alias{as_orderby,} 9 | \alias{is_where_list} 10 | \alias{as_where_list} 11 | \alias{as_where} 12 | \alias{is_where} 13 | \alias{as_orderby} 14 | \title{S3 Class constructors for objects defining SQL query components 15 | and a collection of these parts (\code{mmsql_components}).} 16 | \usage{ 17 | as_mmsql_components(.select = NULL, .from = NULL, .on = NULL, 18 | .where_list = NULL, .orderby = NULL, typeattr = NULL) 19 | 20 | as_where_list(...) 21 | 22 | as_where(.vars, .connect = NULL, .operator, .value = "\%s") 23 | 24 | is_where(x) 25 | 26 | as_orderby(.vars, .order) 27 | } 28 | \value{ 29 | \code{as_mmsql_components}: A collection of components that make up a 30 | SQL query. 31 | \code{as_where_list}, \code{as_where}, \code{as_orderby}: Individual 32 | components of a SQL query. 33 | } 34 | \description{ 35 | The collection object has a defined set of components that match the multiMiR 36 | database and defined options in \code{get_multimir()}. Conceptually this is 37 | split into two parts, the relatively straightforward SELECT, FROM, and ON 38 | portion of the query and the more complex filtering and sorting operations: 39 | WHERE and ORDER BY. The latter have their own classes, the former are 40 | resolved as strings (or character vectors) in the functions defining handling 41 | of each sql table (\code{sql_} prefix). 42 | } 43 | \keyword{internal} 44 | -------------------------------------------------------------------------------- /man/build_mmsql.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/buildquery.R 3 | \name{build_mmsql} 4 | \alias{build_mmsql} 5 | \alias{expand_query} 6 | \alias{expand_select} 7 | \alias{expand_from} 8 | \alias{expand_on} 9 | \alias{expand_where_list} 10 | \alias{expand_where} 11 | \alias{expand_orderby} 12 | \alias{expand_limit} 13 | \alias{merge_order} 14 | \title{Constructors for parts of SQL queries 15 | Expand_query converts a \code{mmyquery} object to a SQL query string} 16 | \usage{ 17 | build_mmsql(.table, org, mirna = NULL, target = NULL, disease.drug = NULL, 18 | predicted.site = NULL, predicted.cutoff.type = NULL, 19 | predicted.cutoff = NULL, limit = NULL) 20 | 21 | expand_query(x) 22 | 23 | expand_select(x) 24 | 25 | expand_from(x) 26 | 27 | expand_on(x) 28 | 29 | expand_where_list(x) 30 | 31 | expand_where(x) 32 | 33 | expand_orderby(x) 34 | 35 | expand_limit(x) 36 | 37 | merge_order(.list) 38 | } 39 | \value{ 40 | A complete SQL statement and related information. 41 | } 42 | \description{ 43 | Constructors for parts of SQL queries 44 | Expand_query converts a \code{mmyquery} object to a SQL query string 45 | } 46 | \keyword{internal} 47 | -------------------------------------------------------------------------------- /man/default_cutoff.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getdata.R 3 | \name{default_cutoff} 4 | \alias{default_cutoff} 5 | \title{If null, set default predicted.cutoff} 6 | \usage{ 7 | default_cutoff(predicted.cutoff.type, predicted.cutoff) 8 | } 9 | \value{ 10 | The default cutoff value. 11 | } 12 | \description{ 13 | If null, set default predicted.cutoff 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/deprecate_arg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{deprecate_arg} 4 | \alias{deprecate_arg} 5 | \title{Internal function for sending deprecation messages} 6 | \usage{ 7 | deprecate_arg(name = c("url", "schema.file", "db.tables", "cutoff.file")) 8 | } 9 | \arguments{ 10 | \item{name}{Name of a deprecated function argument.} 11 | } 12 | \value{ 13 | A message indicating deprecated arg and new version. 14 | } 15 | \description{ 16 | Internal function for sending deprecation messages 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/extract_mmquery.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mmquery.R 3 | \name{extract_mmquery} 4 | \alias{extract_mmquery} 5 | \title{Creates all objects needed for the legacy S3 return object and the new S4 6 | object.} 7 | \usage{ 8 | extract_mmquery(outlist, org, .args, summary = FALSE, use.tibble = FALSE) 9 | } 10 | \value{ 11 | A list of data queried, summary of results, and related input 12 | parameters. 13 | 14 | a list for packaging by \code{as.mmquery} and \code{as.mmquery_bioc} 15 | } 16 | \description{ 17 | Creates all objects needed for the legacy S3 return object and the new S4 18 | object. 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/get.multimir.cutoffs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{get.multimir.cutoffs} 4 | \alias{get.multimir.cutoffs} 5 | \title{Load Pre-calculated Prediction Score Cutoffs in the multiMiR Package} 6 | \usage{ 7 | get.multimir.cutoffs(name = NULL, cutoff.file = NULL) 8 | } 9 | \arguments{ 10 | \item{cutoff.file}{Deprecated. Set path to cutoffs file with the global 11 | option \code{multimir.cutoffs}.} 12 | } 13 | \value{ 14 | Cutoff values object from remote database. 15 | } 16 | \description{ 17 | This is an internal multiMiR function that is not intended to be used 18 | directly. Please set prediction score cutoff in \code{get_multimir}. 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/get_multimir.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getdata.R 3 | \name{get_multimir} 4 | \alias{get_multimir} 5 | \alias{get.multimir} 6 | \title{Get microRNA-target Interactions from the multiMiR Package} 7 | \usage{ 8 | get_multimir(url = NULL, org = "hsa", mirna = NULL, target = NULL, 9 | disease.drug = NULL, table = "validated", predicted.cutoff = NULL, 10 | predicted.cutoff.type = "p", predicted.site = "conserved", 11 | summary = FALSE, add.link = FALSE, use.tibble = FALSE, limit = NULL, 12 | legacy.out = FALSE) 13 | 14 | get.multimir(url = NULL, org = "hsa", mirna = NULL, target = NULL, 15 | disease.drug = NULL, table = "validated", predicted.cutoff = NULL, 16 | predicted.cutoff.type = "p", predicted.site = "conserved", 17 | summary = FALSE, add.link = FALSE, use.tibble = FALSE, limit = NULL) 18 | } 19 | \arguments{ 20 | \item{url}{Deprecated. The URL for queries is now defined by the package 21 | options \code{multimir.url} and \code{multimir.queries}.} 22 | 23 | \item{org}{a character string for the organism. Three organisms are 24 | supported so far: human ("hsa" (default), "human", or "Homo Sapiens"), mouse 25 | ("mmu", "mouse", or "Mus musculus"), and rat ("rno", "rat", or "Rattus 26 | norvegicus"). The organism is case insensitive.} 27 | 28 | \item{mirna}{'NULL' (default) or a character string or character vector for 29 | the mature miRNA(s). It can be the mature miRNA accession number (i.e. 30 | "MIMAT0000072"), mature miRNA ID (i.e. "hsa-miR-199a-3p"), or a combination 31 | of both (i.e. c("MIMAT0000065", "hsa-miR-30a-5p")). The character is case 32 | insensitive. *See note about the length of list supported.} 33 | 34 | \item{target}{'NULL' (default) or a character string or character vector for 35 | the target gene(s). It can be the gene symbol (i.e. c("TP53", "KRAS")), 36 | Entrez gene ID (i.e. c(578, 3845)), Ensembl gene ID (i.e. 37 | "ENSG00000171791"), or a combination of any of these identifiers (i.e. 38 | c("TP53", 3845, "ENSG00000171791")). The character is case insensitive. *See 39 | note about the length of list supported.} 40 | 41 | \item{disease.drug}{'NULL' (default) or a character string or character 42 | vector for the disease(s) and/or drug(s) (i.e. c("bladder cancer", 43 | "cisplatin")). The character is case insensitive.} 44 | 45 | \item{table}{a character string indicating which table(s) in multiMiR to 46 | search. Each table contains data from an external database. Options include 47 | "validated" (default, to search all validated tables "mirecords", 48 | "mirtarbase", and "tarbase"), "predicted" (to search all predicted tables 49 | "diana_microt", "elmmo", "microcosm", "miranda", "mirdb", "pictar", "pita", 50 | and "targetscan"), "disease.drug" (to search all disease/drug tables 51 | "mir2disease", "pharmaco_mir", and "phenomir"), "all" (to search all of the 52 | tables above), or an individual table from above.} 53 | 54 | \item{predicted.cutoff}{'NULL' (default) or an integer giving a prediction 55 | score cutoff. By default ('NULL'), the cutoff is '20' (search the top 20\% 56 | if \code{predicted.cutoff.type="p"}) or '300000' (search the top 300000 (or 57 | all records if total < 300000) if \code{predicted.cutoff.type="n"}).} 58 | 59 | \item{predicted.cutoff.type}{a character indicating the type of prediction 60 | score cutoff. This must be either "p" (default, percentage cutoff) or "n" 61 | (number cutoff).} 62 | 63 | \item{predicted.site}{a character string indicating the type of predicted 64 | target sites to search. This can be one of the strings "conserved", 65 | "nonconserved", or "all", and can be abbreviated. This only applies to three 66 | of the predicted tables ("miranda", "pita", and "targetscan") that have 67 | conservation information of the target sites.} 68 | 69 | \item{summary}{logical. Whether to summarize the result (default = FALSE).} 70 | 71 | \item{add.link}{logical. Whether to add link to external database for each 72 | result entry.} 73 | 74 | \item{use.tibble}{logical. Whether to use the data_frame class from the 75 | tibble package for returned dataframes. The key benefit for large datasets 76 | is more restrictive printing to the console (first 10 rows and only the 77 | number of columns that will fit \code{getOption('width')}). See 78 | \code{?tible::data_frame} for more information.} 79 | 80 | \item{limit}{a positive integer. Limits the number of records returned from 81 | each table. Useful in testing potentially large queries.} 82 | 83 | \item{legacy.out}{logical. Whether to return the Bioconductor compatible S4 84 | object or the legacy S3 object (default=FALSE).} 85 | } 86 | \value{ 87 | \code{get_multimir} returns an S4 object (see 88 | \code{?mmquery_bioc-class} containing the queried data and associated 89 | metadata. With \code{legacy.out=FALSE} (default), the data is a single 90 | dataset with association/interaction type defined by the \code{type} 91 | variable. With \code{legacy.out=TRUE} the original S3 object with 3 separate 92 | data frames ('predicted', 'validated', and 'disease_drug') is returned. 93 | } 94 | \description{ 95 | The main function to retrieve predicted and validated miRNA-target 96 | interactions and their disease and drug associations from the multiMiR 97 | package. 98 | } 99 | \details{ 100 | get.multimir() has been deprecated and replaced with the get_multimir() 101 | version. 102 | 103 | \code{get_multimir} is the main and recommended function to retrieve 104 | information from the multiMiR package. Input to the function must contain at 105 | least one of the followings: miRNA(s), target gene(s), and disease and drug 106 | term(s). 107 | 108 | The setting of \code{predicted.site} is applicable to three ("miranda", 109 | "pita", and "targetscan") of the eight predicted tables. If 110 | \code{predicted.site} is \code{"conserved"}, the function will search 111 | conserved target sites annotated by TargetScan, target sites with 112 | conservation scores greater than or equal to 0.57 (in human and rat; or 113 | 0.566 in mouse) in miRanda, and/or sites with conservation scores greater 114 | than or equal to 0.9 in PITA. 115 | 116 | Although the summary (if \code{summary=TRUE}) can be used to find results 117 | that are recorded by combinations of different databases, please note that 118 | for predicted interactions a combination approach may not be as effective as 119 | a single algorithm because of age or quality of the tool. 120 | 121 | Note: The length of the list supported has been increased from version1.0.1. 122 | The size is now limited to 20MB which should accommodate most requests. 123 | There is a possibility for technical reasons that the query could fail even 124 | if the list is under this limit. If this occurs it is recommended that you 125 | break up the list into smaller batches and submit them sequentially. 126 | } 127 | \examples{ 128 | 129 | ## search 'hsa-miR-18a-3p' in validated interactions in human 130 | example1 <- get_multimir(mirna='hsa-miR-18a-3p', summary=TRUE) 131 | columns(example1) 132 | ## target genes that are validated by Luciferase assay 133 | lucif <- select(example1, keytype = "type", keys = "validated", 134 | columns = columns(example1)) 135 | lucif[grep("Luciferase", lucif$experiment), ] 136 | example1@summary[example1@summary[,"target_symbol"] == "KRAS",] 137 | 138 | ## search 'cisplatin' in disease and drug tables in human 139 | example2 <- get_multimir(disease.drug='cisplatin', table='disease.drug') 140 | nrow(example2@data) 141 | head(example2@data) 142 | 143 | } 144 | \keyword{database} 145 | \keyword{utilities} 146 | -------------------------------------------------------------------------------- /man/list_multimir.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/listdata.R 3 | \name{list_multimir} 4 | \alias{list_multimir} 5 | \alias{list.multimir} 6 | \title{List microRNAs, Genes, Drugs Or Diseases in the multiMiR Package} 7 | \usage{ 8 | list_multimir(x = c("mirna", "gene", "drug", "disease"), limit = NULL, 9 | url = NULL) 10 | 11 | list.multimir(x = c("mirna", "gene", "drug", "disease"), limit = NULL, 12 | url = NULL) 13 | } 14 | \arguments{ 15 | \item{x}{a character string indicating what to list. This must be one of the 16 | strings \code{"mirna"} (default), \code{"gene"}, \code{"drug"}, or 17 | \code{"disease"}. This can be abbreviated and is case insensitive.} 18 | 19 | \item{limit}{a positive integer. Limits the number of records returned from 20 | each table. Useful in testing potentially large queries.} 21 | 22 | \item{url}{Deprecated. Use global option \code{multimir.url} instead.} 23 | } 24 | \value{ 25 | \code{list_multimir} returns a data frame with information of 26 | microRNAs (microRNA unique ID, organism, mature microRNA accession number, 27 | and mature microRNA ID), target genes (gene unique ID, organism, gene 28 | symbol, Entrez gene ID, and Ensembl gene ID), drugs (drug names), and 29 | diseases (disease name). 30 | } 31 | \description{ 32 | \code{list_multimir} lists all the unique microRNAs, target genes, drugs, or 33 | diseases in the web server of the multiMiR package. 34 | } 35 | \details{ 36 | list.multimir() has been deprecated and replaced with the list_multimir() 37 | version. 38 | } 39 | \examples{ 40 | miRNAs <- list_multimir("mirna", limit = 10) 41 | genes <- list_multimir("gene", limit = 10) 42 | drugs <- list_multimir("drug", limit = 10) 43 | diseases <- list_multimir("disease", limit = 10) 44 | } 45 | \author{ 46 | Yuanbin Ru \email{ruyuanbin@gmail.com} 47 | } 48 | \keyword{database} 49 | \keyword{utilities} 50 | -------------------------------------------------------------------------------- /man/mmquery_bioc-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mmquery.R 3 | \docType{class} 4 | \name{mmquery_bioc-class} 5 | \alias{mmquery_bioc-class} 6 | \alias{as.mmquery_bioc} 7 | \alias{columns,mmquery_bioc-method} 8 | \alias{keys,mmquery_bioc-method} 9 | \alias{keytypes,mmquery_bioc-method} 10 | \alias{select,mmquery_bioc-method} 11 | \alias{show,mmquery_bioc-method} 12 | \title{S4 constructor and methods for object returned by \code{get_multimir()}.} 13 | \usage{ 14 | as.mmquery_bioc(.list) 15 | 16 | \S4method{columns}{mmquery_bioc}(x) 17 | 18 | \S4method{keys}{mmquery_bioc}(x, keytype, ...) 19 | 20 | \S4method{keytypes}{mmquery_bioc}(x) 21 | 22 | \S4method{select}{mmquery_bioc}(x, keys, columns, keytype, ...) 23 | 24 | \S4method{show}{mmquery_bioc}(object) 25 | } 26 | \arguments{ 27 | \item{.list}{a list of returned dataframes, summary} 28 | 29 | \item{x, object}{An mmquery_bioc object.} 30 | 31 | \item{keytype}{allows the user to discover which keytypes can be passes in to 32 | select or keys and the keytype argument} 33 | 34 | \item{...}{additional arguments} 35 | 36 | \item{keys}{A result of the keys() function. For the mmquery_bioc class this 37 | is a character vector of microRNA's in the returned mmquery_bioc object.} 38 | 39 | \item{columns}{lists the columns that can be returned for the 40 | \code{mmquery_bioc} object.} 41 | } 42 | \value{ 43 | an s4 object of class mmquery_bioc. Contains queried data, a summary 44 | dataset, and associated input parameters. 45 | } 46 | \description{ 47 | This package's primary user-facing object. Contains the SQL statement and the 48 | returned data query, as well as a summary table depending on 49 | specified option. Note that the returned data is now contained in a single 50 | dataframe. To filter to a specific type of association or interaction, 51 | \code{select} on the \code{type} variable. 52 | } 53 | \section{Slots}{ 54 | 55 | \describe{ 56 | \item{\code{data}}{A dataframe containing validated and predicted microRNA-target 57 | interactions and disease/drug assocations found.} 58 | 59 | \item{\code{queries}}{A list of queries submitted to the multiMiR SQL server.} 60 | 61 | \item{\code{summary}}{A summary dataframe of the returned microRNA dataframes} 62 | 63 | \item{\code{tables}}{A character vector of the microRNA relationship types returned 64 | (validated, predicted, disease.drug, or all).} 65 | 66 | \item{\code{org}}{The selected organism (hsa/human, mmu/mouse, rno/rat).} 67 | 68 | \item{\code{predicted.cutoff}}{An integer giving a prediction score cutoff.} 69 | 70 | \item{\code{predicted.cutoff.type}}{A character indicating the type of prediction 71 | score cutoff (p = percentage, n = number, character() = none)} 72 | 73 | \item{\code{predicted.site}}{A character string indicating the type of predicted 74 | target sites to searched.} 75 | }} 76 | 77 | -------------------------------------------------------------------------------- /man/multiMiR.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/multiMiR_package.R 3 | \docType{package} 4 | \name{multiMiR} 5 | \alias{multiMiR} 6 | \alias{multimir} 7 | \alias{multiMiR-package} 8 | \title{MultiMiR: R package for accessing the multiMiR database} 9 | \description{ 10 | This package provides an interface to the multiMiR database of 11 | microRNA-target interactions, and disease and drug associations. See 12 | \url{http://multimir.org} and the vignette ('multiMiR') for more 13 | details. 14 | } 15 | \references{ 16 | [Add reference here] 17 | } 18 | -------------------------------------------------------------------------------- /man/multimir.summary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mirnasummary.R 3 | \name{multimir.summary} 4 | \alias{multimir.summary} 5 | \title{Summarize microRNA/target Information from the multiMiR Package} 6 | \usage{ 7 | multimir.summary(result, pair.index = 2:6, order.by = "all.sum") 8 | } 9 | \arguments{ 10 | \item{result}{PLACEHOLDER} 11 | 12 | \item{pair.index}{PLACEHOLDER} 13 | 14 | \item{order.by}{PLACEHOLDER} 15 | } 16 | \value{ 17 | Summary of objects queries from databse 18 | } 19 | \description{ 20 | This is an internal multiMiR function that is not intended to be used 21 | directly. Please use \code{get_multimir}. 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/multimir_dbInfo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/dbinfo.R 3 | \name{multimir_dbInfo} 4 | \alias{multimir_dbInfo} 5 | \alias{multimir_dbCount} 6 | \alias{multimir_dbInfoVersions} 7 | \alias{multimir_dbSchema} 8 | \alias{multimir_dbTables} 9 | \alias{multimir_dbInfoVersions} 10 | \alias{multimir_dbSchema} 11 | \alias{multimir_dbTables} 12 | \alias{multimir_dbCount} 13 | \title{Collect Information About the Web Server And Database of the multiMiR 14 | Package} 15 | \usage{ 16 | multimir_dbInfo(url = NULL) 17 | 18 | multimir_dbInfoVersions(url = NULL) 19 | 20 | multimir_dbSchema(schema.file = NULL) 21 | 22 | multimir_dbTables(url = NULL) 23 | 24 | multimir_dbCount(url = NULL) 25 | } 26 | \arguments{ 27 | \item{url}{Deprecated. Use global option \code{multimir.url} instead.} 28 | 29 | \item{schema.file}{Deprecated. Option exists as \code{multimir.schema}, 30 | but it should not need to be set directly.} 31 | } 32 | \value{ 33 | \code{multimir_dbCount}: a data frame with the count of records in 34 | each of the tables in the multiMiR database. 35 | 36 | \code{multimir_dbInfo}: a data frame with information about the multiMiR 37 | database. 38 | 39 | \code{multimir_dbInfoVersions}: a data frame with information about the 40 | multiMiR database versions. 41 | 42 | \code{multimir_dbSchema}: none (invisible \code{NULL}). 43 | 44 | \code{multimir_dbTables}: a data frame with table names in the multiMiR 45 | database. 46 | } 47 | \description{ 48 | Functions for collecting and displaying information about the web server and 49 | database of the multiMiR package. 50 | } 51 | \details{ 52 | \code{multimir.url} is a global option containing the URL of the multiMiR web 53 | server. Set using \code{options("multimir.url" = ...)} 54 | 55 | \code{multimir_dbCount} returns counts of records in the tables in the 56 | multiMiR database. Each table contains data from an external miRNA/target 57 | database. 58 | 59 | \code{multimir_dbInfo} returns other information about the multiMiR 60 | database. This includes information of external miRNA/target databases in 61 | multiMiR. 62 | 63 | \code{multimir_dbInfoVersions} returns other information about the multiMiR 64 | database versions available. This provides a list of available options if 65 | switching to previous version is desired. 66 | 67 | \code{multimir_dbSchema} prints the schema definition of the multiMiR 68 | database. 69 | 70 | \code{multimir_dbTables} returns the vector of tables in the multiMiR 71 | database and saves it to the global option \code{multimir.tables.list}. This 72 | function is automatically run when get_multimir is called if the 73 | \code{multimir.tables.list} is NULL. 74 | } 75 | \examples{ 76 | 77 | this_url <- getOption("multimir.url") 78 | this_url 79 | options(multimir.url = this_url) 80 | 81 | db_ver <- multimir_dbInfoVersions() 82 | 83 | db_count <- multimir_dbCount() 84 | 85 | db_info <- multimir_dbInfo() 86 | 87 | multimir_dbSchema() 88 | 89 | db_tables <- multimir_dbTables() 90 | 91 | } 92 | \keyword{database} 93 | \keyword{utilities} 94 | -------------------------------------------------------------------------------- /man/multimir_switchDBVersion.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/dbversion.R 3 | \name{multimir_switchDBVersion} 4 | \alias{multimir_switchDBVersion} 5 | \title{Manage Database Version to use} 6 | \usage{ 7 | multimir_switchDBVersion(db_version, url = NULL) 8 | } 9 | \arguments{ 10 | \item{db_version}{A character string containing the full version number for 11 | the database version to use for for all package functions. The default will 12 | be the most recent version.} 13 | 14 | \item{url}{Deprecated. Use global option \code{multimir.url} instead.} 15 | } 16 | \value{ 17 | \code{multimir_dbInfoVersions}: a data frame with information about the 18 | multiMiR database versions. 19 | 20 | \code{multimir_switchDBVersion}: none (invisible \code{NULL}). 21 | } 22 | \description{ 23 | Functions for managing the database version used to complete requests on the 24 | web server. 25 | } 26 | \details{ 27 | \code{url} is a character string containing the URL of the multiMiR web 28 | server. Optional as it is set when the package is loaded. 29 | 30 | \code{multimir_dbInfoVersions} returns other information about the multiMiR 31 | database versions available. This provides a list of available options if 32 | switching to previous version is desired. 33 | 34 | \code{multimir_switchDBVersion} returns other information about the multiMiR 35 | database versions available. This provides a list of available options if 36 | switching to previous version is desired. 37 | } 38 | \examples{ 39 | 40 | multimir_dbInfoVersions() 41 | multimir_switchDBVersion(db_version="2.0.0") 42 | 43 | } 44 | \keyword{database} 45 | \keyword{utilities} 46 | -------------------------------------------------------------------------------- /man/null_to_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{null_to_df} 4 | \alias{null_to_df} 5 | \alias{null_to_num} 6 | \alias{null_to_char} 7 | \title{Replace nulls with an empty object of each type} 8 | \usage{ 9 | null_to_df(x) 10 | 11 | null_to_num(x) 12 | 13 | null_to_char(x) 14 | } 15 | \arguments{ 16 | \item{x}{input object} 17 | } 18 | \value{ 19 | an empty \code{data.frame}, \code{numeric}, or \code{character} 20 | vector. 21 | } 22 | \description{ 23 | Replace nulls with an empty object of each type 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/pad.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{pad} 4 | \alias{pad} 5 | \title{Pad single space on each side of an input} 6 | \usage{ 7 | pad(x) 8 | } 9 | \value{ 10 | Input value wrapped in single spaces. 11 | } 12 | \description{ 13 | Pad single space on each side of an input 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/parens_quote.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{parens_quote} 4 | \alias{parens_quote} 5 | \title{Prep certain names for use in SQL query by adding parens} 6 | \usage{ 7 | parens_quote(x) 8 | } 9 | \value{ 10 | The input value wrapped in quotes and then parentheses. 11 | } 12 | \description{ 13 | Prep certain names for use in SQL query by adding parens 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/parens_wrap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{parens_wrap} 4 | \alias{parens_wrap} 5 | \title{Collapse a vector to a single comma-separated string and wrap in parentheses} 6 | \usage{ 7 | parens_wrap(x) 8 | } 9 | \value{ 10 | The input vector converted to a comma-separated string wrapped in 11 | parentheses. 12 | } 13 | \description{ 14 | Collapse a vector to a single comma-separated string and wrap in parentheses 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/parse_orgs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getdata.R 3 | \name{parse_orgs} 4 | \alias{parse_orgs} 5 | \title{Each org can be specified in one of 3 ways -- this standardizes the argument 6 | into the 3 char abbreviation.} 7 | \usage{ 8 | parse_orgs(org) 9 | } 10 | \value{ 11 | A standardized, abbreviated form of the input org. 12 | } 13 | \description{ 14 | Each org can be specified in one of 3 ways -- this standardizes the argument 15 | into the 3 char abbreviation. 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/parse_response.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/search.R 3 | \name{parse_response} 4 | \alias{parse_response} 5 | \title{Parse the Result Returned by the multiMiR Web Server} 6 | \usage{ 7 | parse_response(HTML.response) 8 | } 9 | \value{ 10 | The queried table portion of the HTML response. 11 | } 12 | \description{ 13 | This is an internal multiMiR function that is not intended to be used 14 | directly. Please use \code{get_multimir}. 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/query_multimir.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getdata.R 3 | \name{query_multimir} 4 | \alias{query_multimir} 5 | \title{Wrapper for search_multimir for adding feature (printing notification to 6 | console)} 7 | \usage{ 8 | query_multimir(x, org, add.link, use.tibble) 9 | } 10 | \value{ 11 | The queried multimir data with the addition of a requested feature. 12 | } 13 | \description{ 14 | Wrapper for search_multimir for adding feature (printing notification to 15 | console) 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/quote_wrap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{quote_wrap} 4 | \alias{quote_wrap} 5 | \title{Internal function for adding single quotes around a string} 6 | \usage{ 7 | quote_wrap(x) 8 | } 9 | \arguments{ 10 | \item{x}{a string to be wrapped in single quotes.} 11 | } 12 | \value{ 13 | The input wrapped in single quotes. 14 | } 15 | \description{ 16 | Internal function for adding single quotes around a string 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/remove_empty_strings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getdata.R 3 | \name{remove_empty_strings} 4 | \alias{remove_empty_strings} 5 | \title{Remove empty strings from character vector.} 6 | \usage{ 7 | remove_empty_strings(x) 8 | } 9 | \arguments{ 10 | \item{x}{A character vector} 11 | } 12 | \value{ 13 | A character vector with empty strings removed 14 | } 15 | \description{ 16 | The WHERE clauses for target and mirna use allow for multiple arguments 17 | always separated by 'OR' and several columns are checked for each value 18 | (mirna id, acc; target symbol, entrez, ensemble). If empty strings "" are 19 | present in the get_multimir arguments, Targets and miRNA with empty values in 20 | one of these columns will be incorrectly returned. -- thus purge empty 21 | strings first. 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/remove_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getdata.R 3 | \name{remove_table} 4 | \alias{remove_table} 5 | \title{Remove tables x from a vector of table names.} 6 | \usage{ 7 | remove_table(tables, x) 8 | } 9 | \arguments{ 10 | \item{tables}{A character vector.} 11 | 12 | \item{x}{A second character vector to remove from the first (\code{tables}).} 13 | } 14 | \value{ 15 | Character vector \code{tables} excluding the strings matching those 16 | in \code{x}. 17 | } 18 | \description{ 19 | Typically used when a set of arguments don't apply to a table or would return 20 | an error/empty response 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/search_multimir.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/search.R 3 | \name{search_multimir} 4 | \alias{search_multimir} 5 | \alias{search.multimir} 6 | \title{Search the multiMiR Database Given a MySQL Query} 7 | \usage{ 8 | search_multimir(query) 9 | 10 | search.multimir(query) 11 | } 12 | \arguments{ 13 | \item{query}{a character string for the MySQL query.} 14 | } 15 | \value{ 16 | \code{search_multimir} returns a data frame containing results from 17 | the multiMiR web server. 18 | } 19 | \description{ 20 | This is a function for directly querying the multiMiR database with MySQL 21 | queries. Given a MySQL query, it searches and retrieves result from the 22 | multiMiR database on the multiMiR web server. To use \code{search_multimir} 23 | directly, users will need to be familiar with MySQL and multiMiR table 24 | structures. Users are advised to use \code{get_multimir} instead. 25 | } 26 | \details{ 27 | search.multimir() has been deprecated and replaced with the search_multimir() 28 | version. 29 | } 30 | \examples{ 31 | 32 | ## show all tables in the multiMiR database 33 | tables <- search_multimir(query="show tables") 34 | 35 | ## show the structure of table diana_microt 36 | microt <- search_multimir(query="describe diana_microt") 37 | 38 | ## search for validated target genes of hsa-miR-18a-3p in miRecords 39 | qry <- paste("SELECT m.mature_mirna_acc, m.mature_mirna_id,", 40 | " t.target_symbol, t.target_entrez, t.target_ensembl,", 41 | " i.experiment, i.support_type, i.pubmed_id", 42 | "FROM mirna AS m INNER JOIN mirecords AS i INNER JOIN target", 43 | "AS t ON (m.mature_mirna_uid=i.mature_mirna_uid AND", 44 | " i.target_uid=t.target_uid)", 45 | "WHERE m.mature_mirna_id='hsa-miR-18a-3p'") 46 | result <- search_multimir(query = qry) 47 | 48 | } 49 | \keyword{database} 50 | \keyword{utilities} 51 | -------------------------------------------------------------------------------- /man/split_by.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{split_by} 4 | \alias{split_by} 5 | \title{Split, order and sort lists by their components.} 6 | \usage{ 7 | split_by(.x, .f, ...) 8 | } 9 | \arguments{ 10 | \item{.x}{A list or atomic vector.} 11 | 12 | \item{.f}{A function, formula, or atomic vector.} 13 | 14 | \item{...}{Additional arguments passed on to \code{.f}.} 15 | } 16 | \value{ 17 | A list split by \code{.f} 18 | } 19 | \description{ 20 | Copied from purrr:v0.2.2 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/sql_org.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sqlclauses.R 3 | \name{sql_org} 4 | \alias{sql_org} 5 | \alias{sql_org,} 6 | \alias{where_org,} 7 | \alias{where_diseasedrug,} 8 | \alias{where_conserved,} 9 | \alias{where_cutoff} 10 | \alias{create_cutoff_name} 11 | \alias{cutoff_to_score} 12 | \alias{where_org} 13 | \alias{where_diseasedrug} 14 | \alias{where_conserved} 15 | \alias{where_cutoff} 16 | \alias{create_cutoff_name} 17 | \alias{cutoff_to_score} 18 | \title{Functions defining the WHERE clauses.} 19 | \usage{ 20 | sql_org(.table, org) 21 | 22 | where_org(.table, org) 23 | 24 | where_diseasedrug(.table, disease.drug) 25 | 26 | where_conserved(.table, org, predicted.site) 27 | 28 | where_cutoff(.table, score_var, score_cutoff) 29 | 30 | create_cutoff_name(.table, org, predicted.site) 31 | 32 | cutoff_to_score(.table, cutoff_name, predicted.cutoff.type, predicted.cutoff) 33 | } 34 | \value{ 35 | The \code{WHERE} portion of a SQL query 36 | } 37 | \description{ 38 | Functions defining filtering by organism (org), disease/drug, conserved, and 39 | cutoff. Filtering by mirna and target are defined within their \code{sql_...} 40 | functions. 41 | } 42 | \keyword{disease} 43 | \keyword{diseasedrug} 44 | \keyword{drug} 45 | \keyword{internal} 46 | \keyword{predicted} 47 | \keyword{tables} 48 | \keyword{types} 49 | \keyword{validated} 50 | -------------------------------------------------------------------------------- /man/sql_validated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sqltables.R 3 | \name{sql_validated} 4 | \alias{sql_validated} 5 | \alias{sql_predicted} 6 | \alias{sql_diseasedrug} 7 | \alias{sql_mirna} 8 | \alias{sql_target} 9 | \alias{sql_predicted} 10 | \alias{sql_diseasedrug} 11 | \alias{sql_mirna} 12 | \alias{sql_target} 13 | \title{Generate mmsql_components objects for each of the three types of tables, as 14 | well as the mirna and target tables.} 15 | \usage{ 16 | sql_validated(.table) 17 | 18 | sql_predicted(.table, org, predicted.site, predicted.cutoff.type, 19 | predicted.cutoff) 20 | 21 | sql_diseasedrug(.table, disease.drug) 22 | 23 | sql_mirna(mirna) 24 | 25 | sql_target(.table, target) 26 | } 27 | \value{ 28 | Components of a SQL query specific to each table type. 29 | } 30 | \description{ 31 | The three types of tables are predicted, validated, and diseasedrug 32 | (disease/drug). Additionally, mirna and target portions of the SQL statements 33 | are defined, including their filter clauses (\code{WHERE}). 34 | } 35 | \keyword{disease} 36 | \keyword{diseasedrug} 37 | \keyword{drug} 38 | \keyword{internal} 39 | \keyword{predicted} 40 | \keyword{tables} 41 | \keyword{types} 42 | \keyword{validated} 43 | -------------------------------------------------------------------------------- /man/submit_request.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/search.R 3 | \name{submit_request} 4 | \alias{submit_request} 5 | \title{General workhorse function for submitting and returning queries} 6 | \usage{ 7 | submit_request(url = full_url("multimir.queries"), query, ...) 8 | } 9 | \value{ 10 | Table requested in \code{query}. 11 | } 12 | \description{ 13 | This is an internal multiMiR function that is not intended to be used 14 | directly. Please use \code{get_multimir}. 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(multiMiR) 3 | 4 | test_check("multiMiR") 5 | -------------------------------------------------------------------------------- /tests/testthat/test_dbinfo.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | context("Database information functions") 4 | 5 | test_that("multimir_dbInfo returns table source metadata", { 6 | dbInfo_rtn <- multimir_dbInfo() 7 | 8 | expect_message(multimir_dbInfo(url = "test.com")) 9 | expect_is(dbInfo_rtn, "data.frame") 10 | expect_output(str(dbInfo_rtn), "14 obs.") 11 | expect_output(str(dbInfo_rtn), "5 variables") 12 | expect_output(str(dbInfo_rtn), "map_name") 13 | expect_output(str(dbInfo_rtn), "source_name") 14 | expect_output(str(dbInfo_rtn), "source_version") 15 | expect_output(str(dbInfo_rtn), "source_date") 16 | expect_output(str(dbInfo_rtn), "source_url") 17 | }) 18 | 19 | test_that("multimir_dbInfoVersions returns database version metadata", { 20 | dbInfoVers_rtn <- multimir_dbInfoVersions() 21 | 22 | expect_message(multimir_dbInfoVersions(url = "test.com")) 23 | expect_is(dbInfoVers_rtn, "data.frame") 24 | expect_output(str(dbInfoVers_rtn), "7 variables") 25 | expect_output(str(dbInfoVers_rtn), "VERSION") 26 | expect_output(str(dbInfoVers_rtn), "UPDATED") 27 | expect_output(str(dbInfoVers_rtn), "RDA") 28 | expect_output(str(dbInfoVers_rtn), "DBNAME") 29 | expect_output(str(dbInfoVers_rtn), "SCHEMA") 30 | expect_output(str(dbInfoVers_rtn), "PUBLIC") 31 | expect_output(str(dbInfoVers_rtn), "TABLES") 32 | }) 33 | 34 | test_that("multimir_dbSchema prints sql code defining mm database to console.", { 35 | expect_message(multimir_dbSchema(schema.file = "test.com")) 36 | expect_null(multimir_dbSchema()) 37 | expect_output(multimir_dbSchema(), "CREATE TABLE") 38 | }) 39 | 40 | 41 | -------------------------------------------------------------------------------- /vignettes/multiMiR.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "The multiMiR user's guide" 3 | author: 4 | - name: Yuanbin Ru 5 | email: ruyuanbin@gmail.com 6 | affiliation: BioMarin Pharmaceutical Inc. 7 | - name: Matt Mulvahill 8 | email: matthew.mulvahill@ucdenver.edu 9 | affiliation: CU Anschutz 10 | - name: Spencer Mahaffey 11 | affiliation: CU Anschutz 12 | - name: Katerina Kechris 13 | affiliation: CU Anschutz 14 | package: multiMiR 15 | output: 16 | BiocStyle::html_document: 17 | highlight: "tango" 18 | code_folding: show 19 | toc: true 20 | toc_float: 21 | collapsed: false 22 | vignette: | 23 | %\VignetteIndexEntry{The multiMiR user's guide} 24 | %\VignetteEngine{knitr::rmarkdown} 25 | %\VignetteEncoding{UTF-8} 26 | --- 27 | 28 | ```{r, include=FALSE, echo=FALSE} 29 | # date: "`r doc_date()`" 30 | # "`r pkg_ver('BiocStyle')`" 31 | # 38 | ``` 39 | 40 | # Introduction 41 | 42 | microRNAs (miRNAs) regulate expression by promoting degradation or repressing 43 | translation of target transcripts. miRNA target sites have been cataloged in 44 | databases based on experimental validation and computational prediction using a 45 | variety of algorithms. Several online resources provide collections of multiple 46 | databases but need to be imported into other software, such as R, for 47 | processing, tabulation, graphing and computation. Currently available miRNA 48 | target site packages in R are limited in the number of databases, types of 49 | databases and flexibility. 50 | 51 | The R package *multiMiR*, with web server at 52 | [http://multimir.org](http://multimir.org), is a comprehensive 53 | collection of predicted and validated miRNA-target interactions and their 54 | associations with diseases and drugs. *multiMiR* includes several novel features 55 | not available in existing R packages: 56 | 57 | 1. Compilation of 14 different databases, more than any other collection 58 | 2. Expansion of databases to those based on disease annotation and drug 59 | response, in addition to many experimental and computational databases 60 | 3. User-defined cutoffs for predicted binding strength to provide the most 61 | confident selection. 62 | 63 | The *multiMiR* package enables retrieval of miRNA-target interactions from 14 64 | external databases in R without the need to visit all these databases. 65 | Advanced users can also submit SQL queries to the web server to retrieve 66 | results. See the [publication on 67 | PubMed](https://www.ncbi.nlm.nih.gov/pubmed/25063298) for additional detail on 68 | the database and its creation. The database is now versioned so it is possible 69 | to use previous versions of databases from the current R package, however the 70 | package defaults to the most recent version. 71 | 72 | *Warning* There are issues with merging target IDs from older unmaintained databases. Databases that have been updated more recently (1-2 years) use current versions of annotated IDs. In each update these old target IDs are carried over due to a lack of a reliable method to disambiguate the original ID with current IDs. Please keep this in mind with results from older databases that have not been updated. We continue to look at methods to resolve these ambiguities and improve target agreement between databases. You can use the unique() R function to identify and then remove multiple target genes if needed. 73 | 74 | # Getting to know the multiMiR database 75 | 76 | ```{r annotate, echo=FALSE} 77 | library(knitr) 78 | options(width=100) 79 | opts_chunk$set(echo = TRUE, 80 | message = TRUE, 81 | warning = TRUE, 82 | eval = TRUE) 83 | ``` 84 | 85 | The *multiMiR* web server 86 | [http://multimir.org](http://multimir.org) hosts a database 87 | containing miRNA-target interactions from external databases. The package 88 | *multiMiR* provides functions to communicate with the *multiMiR* web server and 89 | its database. The *multiMiR* database is now versioned. By default *multiMiR* 90 | will use the most recent version each time *multiMiR* is loaded. However it is 91 | now possible to switch between database versions and get information about the 92 | *multiMiR* database versions. `multimir_dbInfoVersions()` returns a dataframe with 93 | the available versions. 94 | 95 | ```{r multimir_dbInfoVersions} 96 | library(multiMiR) 97 | db.ver = multimir_dbInfoVersions() 98 | db.ver 99 | ``` 100 | 101 | To switch between versions we can use `multimir_switchDBVersion()`. 102 | 103 | ```{r multimir_switchDBVersion, echo=TRUE} 104 | vers_table <- multimir_dbInfoVersions() 105 | vers_table 106 | 107 | multimir_switchDBVersion(db_version = "2.0.0") 108 | 109 | curr_vers <- vers_table[1, "VERSION"] # current version 110 | multimir_switchDBVersion(db_version = curr_vers) 111 | ``` 112 | 113 | The remaining functions will query the selected version until the package is reloaded 114 | or until we switch to another version. 115 | 116 | Information from each external database is stored in a table in the *multiMiR* database. 117 | To see a list of the tables, we can use the `multimir_dbTables()` function. 118 | 119 | ```{r multimir_dbTables} 120 | db.tables = multimir_dbTables() 121 | db.tables 122 | ``` 123 | 124 | To display the database schema, we can use the `multimir_dbSchema()` 125 | function. Following is only a portion of the full output. 126 | 127 | ```{sql, eval=FALSE} 128 | ## -- 129 | ## -- Table structure for table `mirna` 130 | ## -- 131 | ## 132 | ## DROP TABLE IF EXISTS `mirna`; 133 | ## CREATE TABLE `mirna` ( 134 | ## mature_mirna_uid INTEGER UNSIGNED AUTO_INCREMENT, -- mature miRNA unique ID 135 | ## org VARCHAR(4) NOT NULL, -- organism abbreviation 136 | ## mature_mirna_acc VARCHAR(20) default NULL, -- mature miRNA accession 137 | ## mature_mirna_id VARCHAR(20) default NULL, -- mature miRNA ID/name 138 | ## PRIMARY KEY (mature_mirna_uid), 139 | ## KEY org (org), 140 | ## KEY mature_mirna_acc (mature_mirna_acc), 141 | ## KEY mature_mirna_id (mature_mirna_id) 142 | ## ); 143 | ## 144 | ## -- 145 | ## -- Table structure for table `target` 146 | ## -- 147 | ## 148 | ## DROP TABLE IF EXISTS `target`; 149 | ## CREATE TABLE `target` ( 150 | ## target_uid INTEGER UNSIGNED AUTO_INCREMENT, -- target gene unique ID 151 | ## org VARCHAR(4) NOT NULL, -- organism abbreviation 152 | ## target_symbol VARCHAR(80) default NULL, -- target gene symbol 153 | ## target_entrez VARCHAR(10) default NULL, -- target gene Entrez gene ID 154 | ## target_ensembl VARCHAR(20) default NULL, -- target gene Ensembl gene ID 155 | ## PRIMARY KEY (target_uid), 156 | ## KEY org (org), 157 | ## KEY target_symbol (target_symbol), 158 | ## KEY target_entrez (target_entrez), 159 | ## KEY target_ensembl (target_ensembl) 160 | ## ); 161 | ## 162 | ## -- 163 | ## -- Table structure for table `mirecords` 164 | ## -- 165 | ## 166 | ## DROP TABLE IF EXISTS `mirecords`; 167 | ## CREATE TABLE `mirecords` ( 168 | ## mature_mirna_uid INTEGER UNSIGNED NOT NULL, -- mature miRNA unique ID 169 | ## target_uid INTEGER UNSIGNED NOT NULL, -- target gene unique ID 170 | ## target_site_number INT(10) default NULL, -- target site number 171 | ## target_site_position INT(10) default NULL, -- target site position 172 | ## experiment VARCHAR(160) default NULL, -- supporting experiment 173 | ## support_type VARCHAR(40) default NULL, -- type of supporting experiment 174 | ## pubmed_id VARCHAR(10) default NULL, -- PubMed ID 175 | ## FOREIGN KEY (mature_mirna_uid) 176 | ## REFERENCES mirna(mature_mirna_uid) 177 | ## ON UPDATE CASCADE ON DELETE RESTRICT, 178 | ## FOREIGN KEY (target_uid) 179 | ## REFERENCES target(target_uid) 180 | ## ON UPDATE CASCADE ON DELETE RESTRICT 181 | ## ); 182 | ## 183 | ## ...... 184 | ## 185 | ## (Please note that only three of the 19 tables are shown here for demonstration 186 | ## purpose.) 187 | 188 | ``` 189 | 190 | The function `multimir_dbInfo()` will display information about the external 191 | miRNA and miRNA-target databases in *multiMiR*, including version, release date, 192 | link to download the data, and the corresponding table in *multiMiR*. 193 | 194 | ```{r multimir_dbInfo} 195 | db.info = multimir_dbInfo() 196 | db.info 197 | ``` 198 | 199 | Among the 14 external databases, eight contain predicted miRNA-target 200 | interactions (DIANA-microT-CDS, ElMMo, MicroCosm, miRanda, miRDB, PicTar, PITA, 201 | and TargetScan), three have experimentally validated miRNA-target interactions 202 | (miRecords, miRTarBase, and TarBase) and the remaining three contain 203 | miRNA-drug/disease associations (miR2Disease, Pharmaco-miR, and PhenomiR). To 204 | check these categories and databases from within R, we have a set of four 205 | helper functions: 206 | 207 | ```{r multimir-tabletype} 208 | predicted_tables() 209 | validated_tables() 210 | diseasedrug_tables() 211 | reverse_table_lookup("targetscan") 212 | ``` 213 | 214 | To see how many records are in these 14 external databases we refer to the 215 | `multimir_dbCount` function. 216 | 217 | ```{r multimir_dbCount} 218 | db.count = multimir_dbCount() 219 | db.count 220 | apply(db.count[,-1], 2, sum) 221 | ``` 222 | 223 | The current version of *multiMiR* contains nearly 50 million records. 224 | 225 | 226 | # Changes to `package:multiMiR` - S3 and S4 classes 227 | 228 | With the addition of multiMiR to Bioconductor, the return object has changed 229 | from an S3 (`mmquery`) to an S4 class (`mmquery_bioc`). The new S4 object has a 230 | similar structure to the prior version, except all returned datasets (validated, 231 | predicted, disease.drug) are now combined into a single dataset. To get only 232 | one type, filter on the `type` variable using the AnnotationDbi method discussed 233 | later or the base R approach `subset(myqry@data, myqry@data$type == "validated")`). 234 | For backwards compatibility, `get_multimir()` will return the old S3 object if 235 | the argument `legacy.out = TRUE`. 236 | 237 | Features are now accessible using the S4 accessor operator `@`. Additionally, 238 | the `AnnotationDbi` accessor methods `column`, `keys`, `keytypes`, and `select` 239 | all work for `mmquery_bioc` objects. See Section \@ref(annodbi). 240 | 241 | 242 | # List miRNAs, genes, drugs and diseases in the multiMiR database 243 | 244 | In addition to functions displaying database and table information, the 245 | *multiMiR* package also provides the `list_multimir()` function to list all the 246 | unique miRNAs, target genes, drugs, and diseases in the *multiMiR* database. An 247 | option for limiting the number of returned records has been added to help with 248 | testing and exploration. 249 | 250 | ```{r list_multimir} 251 | miRNAs = list_multimir("mirna", limit = 10) 252 | genes = list_multimir("gene", limit = 10) 253 | drugs = list_multimir("drug", limit = 10) 254 | diseases = list_multimir("disease", limit = 10) 255 | # executes 2 separate queries, giving 20 results 256 | head(miRNAs) 257 | head(genes) 258 | head(drugs) 259 | head(diseases) 260 | ``` 261 | 262 | The current version of *multiMiR* has 5830 miRNAs and 97186 target genes from 263 | human, mouse, and rat, as well as 64 drugs and 223 disease terms. Depending on 264 | the speed of your Internet connection, it may take a few minutes to retrieve the 265 | large number of target genes. 266 | 267 | 268 | # Use `get_multimir()` to query the multiMiR database 269 | 270 | `get_multimir()` is the main function in the package to retrieve predicted and 271 | validated miRNA-target interactions and their disease and drug associations from 272 | the *multiMiR* database. 273 | 274 | To get familiar with the parameters in `get_multimir()`, you can type 275 | `?get_multimir` or `help(get_multimir)` in R. In the next section, many examples 276 | illustrate the use of the parameters. 277 | 278 | 279 | # Example of multiMiR in a Bioconductor workflow 280 | 281 | This example shows the use of `multiMiR` alongside the `edgeR` Bioconductor 282 | package. Here we take microRNA data from ISS and ILS mouse strains and conduct 283 | a differential expression analysis. The top differentially expresssed 284 | microRNA's are then used to search the multiMiR database for validated 285 | target genes. 286 | 287 | ```{r, biocworkflow, eval=TRUE} 288 | library(edgeR) 289 | library(multiMiR) 290 | 291 | # Load data 292 | counts_file <- system.file("extdata", "counts_table.Rds", package = "multiMiR") 293 | strains_file <- system.file("extdata", "strains_factor.Rds", package = "multiMiR") 294 | counts_table <- readRDS(counts_file) 295 | strains_factor <- readRDS(strains_file) 296 | 297 | # Standard edgeR differential expression analysis 298 | design <- model.matrix(~ strains_factor) 299 | 300 | # Using trended dispersions 301 | dge <- DGEList(counts = counts_table) 302 | dge <- calcNormFactors(dge) 303 | dge$samples$strains <- strains_factor 304 | dge <- estimateGLMCommonDisp(dge, design) 305 | dge <- estimateGLMTrendedDisp(dge, design) 306 | dge <- estimateGLMTagwiseDisp(dge, design) 307 | 308 | # Fit GLM model for strain effect 309 | fit <- glmFit(dge, design) 310 | lrt <- glmLRT(fit) 311 | 312 | # Table of unadjusted p-values (PValue) and FDR values 313 | p_val_DE_edgeR <- topTags(lrt, adjust.method = 'BH', n = Inf) 314 | 315 | # Getting top differentially expressed miRNA's 316 | top_miRNAs <- rownames(p_val_DE_edgeR$table)[1:10] 317 | 318 | # Plug miRNA's into multiMiR and getting validated targets 319 | multimir_results <- get_multimir(org = 'mmu', 320 | mirna = top_miRNAs, 321 | table = 'validated', 322 | summary = TRUE) 323 | head(multimir_results@data) 324 | ``` 325 | 326 | # Examples of multiMiR queries 327 | 328 | In this section a variety of examples are described on how to query the multiMiR 329 | database. 330 | 331 | ## Example 1: Retrieve all validated target genes of a given miRNA 332 | 333 | In the first example, we ask what genes are validated targets of hsa-miR-18a-3p. 334 | 335 | ```{r Example1} 336 | # The default is to search validated interactions in human 337 | example1 <- get_multimir(mirna = 'hsa-miR-18a-3p', summary = TRUE) 338 | names(example1) 339 | # Check which types of associations were returned 340 | table(example1@data$type) 341 | # Detailed information of the validated miRNA-target interaction 342 | head(example1@data) 343 | # Which interactions are supported by Luciferase assay? 344 | example1@data[grep("Luciferase", example1@data[, "experiment"]), ] 345 | example1@summary[example1@summary[,"target_symbol"] == "KRAS",] 346 | ``` 347 | 348 | It turns out that *KRAS* is the only target validated by Luciferase assay. The 349 | interaction was recorded in miRecords and miRTarBase and supported by the same 350 | literature, whose PubMed ID is in column `pubmed_id`. The summary (by setting 351 | `summary = TRUE` when calling `get_multimir()`) shows the number of records in 352 | each of the external databases and the total number of databases supporting the 353 | interaction. 354 | 355 | ## Example 2: Retrieve miRNA-target interactions associated with a given drug or disease 356 | 357 | In this example we would like to know which miRNAs and their target genes are 358 | associated with Cisplatin, a chemotherapy drug used in several cancers. 359 | 360 | ```{r Example2} 361 | example2 <- get_multimir(disease.drug = 'cisplatin', table = 'disease.drug') 362 | names(example2) 363 | nrow(example2@data) 364 | table(example2@data$type) 365 | head(example2@data) 366 | ``` 367 | 368 | `get_multimir()` returns 53 miRNA-target pairs. For more information, we can 369 | always refer to the published papers with PubMed IDs in column `paper_pubmedID`. 370 | 371 | ## Example 3: Select miRNAs predicted to target a gene 372 | 373 | `get_multimir()` also takes target gene(s) as input. In this example we retrieve 374 | miRNAs predicted to target *Gnb1* in mouse. For predicted interactions, the 375 | default is to query the top 20\% predictions within each external database, 376 | which is equivalent to setting parameters `predicted.cutoff = 20` and 377 | `predicted.cutoff.type = 'p'` (for percentage cutoff). Here we search the top 378 | 35% among all conserved and nonconserved target sites. 379 | 380 | ```{r Example3_part1} 381 | example3 <- get_multimir(org = "mmu", 382 | target = "Gnb1", 383 | table = "predicted", 384 | summary = TRUE, 385 | predicted.cutoff = 35, 386 | predicted.cutoff.type = "p", 387 | predicted.site = "all") 388 | names(example3) 389 | table(example3@data$type) 390 | head(example3@data) 391 | head(example3@summary) 392 | ``` 393 | 394 | The records in `example3@predicted` are ordered by scores from best to 395 | worst within each external database. Once again, the summary option allows us to 396 | examine the number of target sites predicted by each external database and the 397 | total number of databases predicting the interaction. 398 | 399 | Finally we examine how many predictions each of the databases has. 400 | 401 | ```{r Example3_part2} 402 | apply(example3@summary[, 6:13], 2, function(x) sum(x > 0)) 403 | ``` 404 | 405 | ## Example 4: Select miRNA(s) predicted to target most, if not all, of the genes of interest 406 | 407 | You may have a list of genes involved in a common biological process. It is 408 | interesting to check whether some, or all, of these genes are targeted by the 409 | same miRNA(s). Here we have four genes involved in chronic obstructive pulmonary 410 | disease (COPD) in human and want to know what miRNAs target these genes by 411 | searching the top 500,000 predictions in each external database. 412 | 413 | ```{r Example4_part1} 414 | example4 <- get_multimir(org = 'hsa', 415 | target = c('AKT2', 'CERS6', 'S1PR3', 'SULF2'), 416 | table = 'predicted', 417 | summary = TRUE, 418 | predicted.cutoff.type = 'n', 419 | predicted.cutoff = 500000) 420 | ``` 421 | 422 | Then we count the number of target genes for each miRNA. 423 | 424 | ```{r Example4_part2} 425 | example4.counts <- addmargins(table(example4@summary[, 2:3])) 426 | example4.counts <- example4.counts[-nrow(example4.counts), ] 427 | example4.counts <- example4.counts[order(example4.counts[, 5], decreasing = TRUE), ] 428 | head(example4.counts) 429 | ``` 430 | 431 | ## Example 5: Retrieve interactions between a set of miRNAs and a set of genes 432 | 433 | In this example, we profiled miRNA and mRNA expression in poorly metastatic 434 | bladder cancer cell lines T24 and Luc, and their metastatic derivatives FL4 and 435 | Lul2, respectively. We identified differentially expressed miRNAs and genes 436 | between the metastatic and poorly metastatic cells. Let's load the data. 437 | 438 | ```{r Example5, echo=TRUE} 439 | load(url("http://multimir.org/bladder.rda")) 440 | ``` 441 | 442 | Variable `DE.miRNA.up` contains 9 up-regulated miRNAs and variable 443 | `DE.entrez.dn` has 47 down-regulated genes in the two metastatic cell 444 | lines. The hypothesis is that interactions between these miRNAs and genes whose 445 | expression changed at opposite directions may play a role in cancer metastasis. 446 | So we use `multiMiR` to check whether any of the nine miRNAs could 447 | target any of the 47 genes. 448 | 449 | ```{r Example5_part2, eval=TRUE, echo=TRUE} 450 | # search all tables & top 10% predictions 451 | example5 <- get_multimir(org = "hsa", 452 | mirna = DE.miRNA.up, 453 | target = DE.entrez.dn, 454 | table = "all", 455 | summary = TRUE, 456 | predicted.cutoff.type = "p", 457 | predicted.cutoff = 10, 458 | use.tibble = TRUE) 459 | ``` 460 | ```{r eval = FALSE, include=FALSE} 461 | ## Searching diana_microt ... 462 | ## Searching elmmo ... 463 | ## Searching microcosm ... 464 | ## Searching miranda ... 465 | ## Searching mirdb ... 466 | ## Searching pictar ... 467 | ## Searching pita ... 468 | ## Searching targetscan ... 469 | ## Searching mirecords ... 470 | ## Searching mirtarbase ... 471 | ## Searching tarbase ... 472 | ## Searching mir2disease ... 473 | ## Searching pharmaco_mir ... 474 | ## Searching phenomir ... 475 | ``` 476 | 477 | 478 | ```{r Example5_part3, eval=TRUE, echo=TRUE} 479 | table(example5@data$type) 480 | result <- select(example5, keytype = "type", keys = "validated", columns = columns(example5)) 481 | unique_pairs <- 482 | result[!duplicated(result[, c("mature_mirna_id", "target_entrez")]), ] 483 | 484 | result 485 | ``` 486 | 487 | In the result, there are `r nrow(unique_pairs)` unique miRNA-gene pairs that have been validated. 488 | 489 | ```{r eval=FALSE, include=FALSE} 490 | ## database mature_mirna_acc mature_mirna_id target_symbol target_entrez 491 | ## 1 mirtarbase MIMAT0000087 hsa-miR-30a-5p FDX1 2230 492 | ## 2 mirtarbase MIMAT0000087 hsa-miR-30a-5p LIMCH1 22998 493 | ## 3 tarbase MIMAT0000087 hsa-miR-30a-5p FDX1 2230 494 | ## 4 tarbase MIMAT0000424 hsa-miR-128 NEK2 4751 495 | ## 5 tarbase MIMAT0000087 hsa-miR-30a-5p LIMCH1 22998 496 | ## target_ensembl experiment support_type pubmed_id 497 | ## 1 ENSG00000137714 Proteomics Functional MTI (Weak) 18668040 498 | ## 2 ENSG00000064042 pSILAC//Proteomics;Other Functional MTI (Weak) 18668040 499 | ## 3 ENSG00000137714 Proteomics positive 500 | ## 4 ENSG00000117650 Microarray positive 501 | ## 5 ENSG00000064042 Proteomics positive 502 | ``` 503 | 504 | 505 | ```{r Example5_part4, eval=TRUE, echo=TRUE} 506 | mykeytype <- "disease_drug" 507 | 508 | mykeys <- keys(example5, keytype = mykeytype) 509 | mykeys <- mykeys[grep("bladder", mykeys, ignore.case = TRUE)] 510 | 511 | result <- select(example5, keytype = "disease_drug", keys = mykeys, 512 | columns = columns(example5)) 513 | result 514 | ``` 515 | 516 | ```{r Example5_part4_fortext, echo=FALSE, include=FALSE, eval=TRUE} 517 | unique_pairs <- 518 | result[!duplicated(apply(result[, c("mature_mirna_id", "disease_drug")], 2, 519 | tolower)), ] 520 | ``` 521 | 522 | `r nrow(unique_pairs)` miRNAs are associated with bladder cancer in miR2Disease and PhenomiR. 523 | 524 | ```{r eval=FALSE, include=FALSE} 525 | ## database mature_mirna_acc mature_mirna_id target_symbol target_entrez 526 | ## 18 mir2disease MIMAT0000418 hsa-miR-23b-3p NA NA 527 | ## 711 phenomir MIMAT0000418 hsa-miR-23b-3p NA NA 528 | ## 311 phenomir MIMAT0000449 hsa-miR-146a-5p NA NA 529 | ## target_ensembl disease_drug 530 | ## 18 NA bladder cancer 531 | ## 711 NA Bladder cancer 532 | ## 311 NA Bladder cancer 533 | ## paper_pubmedID 534 | ## 18 2007. Micro-RNA profiling in kidney and bladder cancers. 535 | ## 711 17826655 536 | ## 311 19127597 537 | ``` 538 | 539 | The predicted databases predict 65 miRNA-gene pairs between the 9 miRNAs and 28 540 | of the 47 genes. 541 | 542 | ```{r Example5_part5, eval=TRUE, echo=TRUE} 543 | predicted <- select(example5, keytype = "type", keys = "predicted", 544 | columns = columns(example5)) 545 | length(unique(predicted$mature_mirna_id)) 546 | length(unique(predicted$target_entrez)) 547 | unique.pairs <- 548 | unique(data.frame(miRNA.ID = as.character(predicted$mature_mirna_id), 549 | target.Entrez = as.character(predicted$target_entrez))) 550 | nrow(unique.pairs) 551 | ``` 552 | 553 | 554 | ```{r Example5_part8, eval=TRUE, echo=TRUE} 555 | head(unique.pairs) 556 | ``` 557 | 558 | Results from each of the predicted databases are already ordered by their scores 559 | from best to worst. 560 | 561 | 562 | ```{r Example5_part9, eval=TRUE, echo=TRUE} 563 | example5.split <- split(predicted, predicted$database) 564 | ``` 565 | 566 | 567 | ## Use of AnnotationDbi accessor methods {#annodbi} 568 | 569 | AnnotationDbi accessor methods can be used to select and filter the data 570 | returned by `get_multimir()`. 571 | 572 | ```{r annodbi} 573 | # On example4's result 574 | columns(example4) 575 | head(keys(example4)) 576 | keytypes(example4) 577 | mykeys <- keys(example4)[1:4] 578 | head(select(example4, keys = mykeys, 579 | columns = c("database", "target_entrez"))) 580 | 581 | # On example3's result 582 | columns(example3) 583 | head(keys(example3)) 584 | keytypes(example3) 585 | mykeys <- keys(example3)[1:4] 586 | head(select(example3, keys = mykeys, 587 | columns = c("database", "target_entrez", "score"))) 588 | 589 | # Search by gene on example4's result 590 | columns(example4) 591 | keytypes(example4) 592 | head(keys(example4, keytype = "target_entrez")) 593 | mykeys <- keys(example4, keytype = "target_entrez")[1] 594 | head(select(example4, keys = mykeys, keytype = "target_entrez", 595 | columns = c("database", "target_entrez", "score"))) 596 | ``` 597 | 598 | 599 | # Direct query to the database on the multiMiR web server 600 | 601 | As shown previously, *get_multimir* is the main function to retrieve 602 | information from the *multiMiR* database, which is hosted at 603 | http://multimir.org. The function builds one SQL query for every 604 | external database that the user is going to search, submits the query to the web 605 | server, and parses, combines, and summarizes results from the web server. For 606 | advanced users, there are a couple ways to query the *multiMiR* 607 | database without using the *multiMiR* package; but they have to be 608 | familiar with SQL queries. In general, users are still advised to use the 609 | `get_multimir()` function when querying multiple external databases in 610 | *multiMiR*. 611 | 612 | ## Direct query on the web server 613 | 614 | The *multiMiR* package communicates with the *multiMiR* database via the script 615 | [http://multimir.org/cgi-bin/multimir\_univ.pl](http://multimir.org/cgi-bin/multimir_univ.pl) 616 | on the web server. Once again, data from each of the external databases is 617 | stored in a table in *multiMiR*. There are also tables for miRNAs (table 618 | *mirna*) and target genes (table *target*). 619 | 620 | NOTE: While it is possible to complete short queries from a browser, the limits of 621 | submitting a query through typing in the address bar of a browser are quickly reached 622 | (8192 characters total). If you are a developer you should use your preferred method 623 | to submit a HTTP POST which will allow for longer queries. The fields to include are 624 | `query` and `dbName`. `query` is the SQL query to submit. `dbName` is the 625 | DBNAME column from a call to `multimir_dbInfoVersions()`, however if this is 626 | excluded the current version is the default. 627 | 628 | To learn about the structure of a table (e.g. DIANA-microT data in table 629 | *diana\_microt*), users can use URL 630 | 631 | [http://multimir.org/cgi-bin/multimir\_univ.pl?query=describe diana\_microt](http://multimir.org/cgi-bin/multimir_univ.pl?query=describe diana_microt) 632 | 633 | Similar with Example 1, the following URL searches for validated target genes of 634 | hsa-miR-18a-3p in miRecords. 635 | 636 | [http://multimir.org/cgi-bin/multimir.pl?query=SELECT m.mature\_mirna\_acc, m.mature\_mirna\_id, t.target\_symbol, t.target\_entrez, t.target\_ensembl, i.experiment, i.support\_type, i.pubmed\_id FROM mirna AS m INNER JOIN mirecords AS i INNER JOIN target AS t ON (m.mature\_mirna\_uid=i.mature\_mirna\_uid and i.target\_uid=t.target\_uid) WHERE m.mature\_mirna\_id='hsa-miR-18a-3p'](http://multimir.org/cgi-bin/multimir.pl?query=SELECT m.mature_mirna_acc, m.mature_mirna_id, t.target_symbol, t.target_entrez, t.target_ensembl, i.experiment, i.support_type, i.pubmed_id FROM mirna AS m INNER JOIN mirecords AS i INNER JOIN target AS t ON (m.mature_mirna_uid=i.mature_mirna_uid and i.target_uid=t.target_uid) WHERE m.mature_mirna_id='hsa-miR-18a-3p') 637 | 638 | As you can see, the query is long and searches just one of the three validated 639 | tables in *multiMiR*. While in Example 1, one line of R command using the 640 | `get_multimir()` function searches, combines and summarizes results from all 641 | three validated external databases (miRecords, miRTarBase and TarBase). 642 | 643 | ## Direct query in R 644 | 645 | The same direct queries we did above on the web server can be done in R as well. 646 | This is the preferred method if you are unfamiliar with HTTP POST. Be sure to 647 | set the correct database version, if you wish to change versions, before calling 648 | `search_multimir()` it uses the currently set version. 649 | 650 | To show the structure of table *diana\_microt*: 651 | 652 | ```{r Direct_query1} 653 | direct2 <- search_multimir(query = "describe diana_microt") 654 | direct2 655 | ``` 656 | 657 | To search for validated target genes of hsa-miR-18a-3p in miRecords: 658 | 659 | ```{r Direct_query2} 660 | qry <- "SELECT m.mature_mirna_acc, m.mature_mirna_id, t.target_symbol, 661 | t.target_entrez, t.target_ensembl, i.experiment, i.support_type, 662 | i.pubmed_id 663 | FROM mirna AS m INNER JOIN mirecords AS i INNER JOIN target AS t 664 | ON (m.mature_mirna_uid=i.mature_mirna_uid and 665 | i.target_uid=t.target_uid) 666 | WHERE m.mature_mirna_id='hsa-miR-18a-3p'" 667 | direct3 <- search_multimir(query = qry) 668 | direct3 669 | ``` 670 | 671 | 672 | # Session Info 673 | 674 | ```{r sessionInfo} 675 | sessionInfo() 676 | warnings() 677 | ``` 678 | 679 | 680 | 681 | 682 | --------------------------------------------------------------------------------