R/combine_mir_vt.R

Defines functions combine_mir_vt

Documented in combine_mir_vt

#' @include all_classes.R
NULL
#'Combine miRNA validated targets from differents sources (miRecords and miRTarbase)
#'
#'@description A helper function for combining miRNA targets from differents
#'  sources. Duplicated miRNA-target interactions are automatically removed.
#'
#'@param ... a list of MirTarget object to combine. MirTarget object can be
#'  generated by the functions get_mirecords_*() or by get_mirtarbase_*().
#' @return  Returns an
#'   object of class MirTarget which is a data frame containing combined validated
#'   targets for each miRNA.
#'
#'@author Alboukadel Kassambara \email{alboukadel.kassambara@@gmail.com}
#'@references A. Kassambara. Statistical Tools for High-throughput Data
#'  Analysis. http://www.sthda.com
#' @examples
#' \dontrun{
#' # Example of miRNAs
#' miRNAs <- c("hsa-miR-16", "hsa-miR-155")
#'
#' # Validated target from miRecords
#' mirecords_vt <- get_mirecords_vt(miRNAs)
#'
#'# Validated target from miRTarbase
#' mirtarbase_vt <- get_mirtarbase_vt(miRNAs)
#'
#' v_targets <- combine_mir_vt(mirecords_vt, mirtarbase_vt)
#' head(v_targets)
#' }
#'
#'@name combine_mir_vt
#'@rdname combine_mir_vt
#'@export
combine_mir_vt <- function(...){

  objects <- list(...)

  fargs <- as.list(match.call(expand.dots = TRUE))
  objnames <- as.character(fargs)[-1]

  for (i in 1:length(objects)) {
    if(!inherits(objects[[i]], "MirTarget"))
      stop(objnames[[i]], "must be an object of class MirTarget.")
  }
  res <- objects[[1]]

  for (i in 2:length(objects)) {
    res <- rbind(res, objects[[i]])
  }
  # Remove duplicated rows
  row_ids <- paste0(res$mirna_name, res$target.gene_name)
  res <- res[!duplicated(row_ids), ]
  res <- na.omit(res)
  MirTarget(res)
}
kassambara/miRTarget documentation built on May 20, 2019, 7:40 a.m.