R/get-metadata.R

Defines functions get_measurementsets get_biosamples get_experimentset get_datasets get_individuals get_dataset_permissions_archive

Documented in get_individuals

#
# BEGIN_COPYRIGHT
#
# PARADIGM4 INC.
# This file is part of the Paradigm4 Enterprise SciDB distribution kit
# and may only be used with a valid Paradigm4 contract and in accord
# with the terms and conditions specified by that contract.
#
# Copyright (C) 2011 - 2017 Paradigm4 Inc.
# All Rights Reserved.
#
# END_COPYRIGHT
#

#' @export
get_measurementsets = function(measurementset_id = NULL, dataset_version = NULL, all_versions = FALSE, mandatory_fields_only = FALSE, con = NULL){
  get_versioned_secure_metadata_entity(entity = .ghEnv$meta$arrMeasurementSet,
                                       id = measurementset_id,
                                       dataset_version = dataset_version,
                                       all_versions = all_versions,
                                       mandatory_fields_only = mandatory_fields_only,
                                       con = con)
}

#' @export
get_biosamples = function(biosample_id = NULL, dataset_version = NULL, all_versions = FALSE, mandatory_fields_only = FALSE, con = NULL){
  get_versioned_secure_metadata_entity(entity = .ghEnv$meta$arrBiosample,
                                       id = biosample_id,
                                       dataset_version = dataset_version,
                                       all_versions = all_versions,
                                       mandatory_fields_only = mandatory_fields_only,
                                       con = con)
}

#' @export
get_experimentset = function(experimentset_id = NULL, dataset_version = NULL, all_versions = FALSE, mandatory_fields_only = FALSE, con = NULL){
  get_versioned_secure_metadata_entity(entity = .ghEnv$meta$arrExperimentSet,
                                       id = experimentset_id,
                                       dataset_version, all_versions,
                                       mandatory_fields_only = mandatory_fields_only,
                                       con = con)
}

#' @export
get_datasets = function(dataset_id = NULL, dataset_version = NULL,
                        all_versions = TRUE, mandatory_fields_only = FALSE,
                        merge_project_info = FALSE,
                        con = NULL){
  if (!merge_project_info) {
    get_versioned_secure_metadata_entity(entity = .ghEnv$meta$arrDataset,
                                         id = dataset_id,
                                         dataset_version = dataset_version,
                                         all_versions = all_versions,
                                         mandatory_fields_only = mandatory_fields_only,
                                         con = con)
  } else { # merge project info
    con = use_ghEnv_if_null(con = con)
    if (is.null(dataset_id)) {
      left_arr = paste0(
        custom_scan(), "(", full_arrayname(.ghEnv$meta$arrDataset), ")")
    } else {
      left_arr = form_selector_query_secure_array(arrayname = full_arrayname(.ghEnv$meta$arrDataset),
                                                  selected_ids = dataset_id,
                                                  dataset_version = dataset_version)
    }
    query = formulate_equi_join_query(
      left_array_or_query = left_arr,
      right_array_or_query = full_arrayname(.ghEnv$meta$arrProject),
      left_fields_to_join_by = 'project_id',
      right_fields_to_join_by = 'project_id',
      keep_dimensions = TRUE, 
      con = con
    )
    query = formulate_equi_join_query(
      left_array_or_query = query, 
      right_array_or_query = gsub(.ghEnv$meta$arrDataset,
                                  paste0(.ghEnv$meta$arrDataset, "_INFO"),
                                  left_arr),
      left_fields_to_join_by = c('dataset_id', 'dataset_version'),
      right_fields_to_join_by = c('dataset_id', 'dataset_version'),
      left_outer = TRUE, 
      con = con
    )
    res = iquery(con$db, query, return=T)
    # equi_join introduces columns called '_1' for commonly named columns of second array (PROJECT here)
    colnames(res)[grep("_1$", colnames(res))] =
      gsub("_1", "",
           paste0("project_", colnames(res)[grep("_1$", colnames(res))]))
    drop_equi_join_dims(df1 = res)
  }
}

#' Retrieve individuals
#'
#' get_ENTITY can be used to retrive
#' - one individual (e.g. `individual_id = 33`)
#' - more than one individual (e.g. `individual_id = c(33, 44)`)
#' - all individuals visible to user (e.g. `get_individuals()`)
#' @export
get_individuals = function(individual_id = NULL, dataset_version = NULL, all_versions = FALSE, mandatory_fields_only = FALSE, con = NULL){
  get_versioned_secure_metadata_entity(entity = .ghEnv$meta$arrIndividuals,
                                       id = individual_id,
                                       dataset_version = dataset_version,
                                       all_versions = all_versions,
                                       mandatory_fields_only = mandatory_fields_only,
                                       con = con)
}

####### Permissions ########
get_dataset_permissions_archive = function(con = NULL) {
  con = use_ghEnv_if_null(con = con)
  res1 = iquery(con$db, full_arrayname(.ghEnv$meta$arrDatasetPermissionsArchive), return = T)
  res1[, get_idname(.ghEnv$meta$arrDatasetPermissionsArchive)] = NULL
  res1 = res1[order(res1$project_name, res1$dataset_name), ]
  rownames(res1) = 1:nrow(res1)
  return(res1)
}
Paradigm4/revealgenomics documentation built on April 7, 2020, 2:01 a.m.