Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Latest commit

 

History

History
152 lines (111 loc) · 5.86 KB

File metadata and controls

152 lines (111 loc) · 5.86 KB

Usage of Python and R API Client

ODM APIs empower you to do large-scale, cross-study, and cross-omics analysis on-the-fly. The ODM OpenAPI Specification can be reviewed at GENESTACK_ENDPOINT_ADDR/swagger/helper/, where GENESTACK_ENDPOINT_ADDR is the URL of the Genestack platform.

In addition to that you can also use Python and R SDKs, so you can write your own script, notebook or application.

Installation of generated Python API Client

Requirements

  • Python 3
  • pip

Instructions

Install

  1. Start a console/terminal:

  2. Install the latest version using pip:

    python3 -m pip install \
        --extra-index-url https://public-nexus.devops.gs.team/repository/pypi-releases/simple \
        odm-api

    To install a specific version of a package, simply append the version number to the package reference in the command. For example: odm-api==1.56.1

To check the existing version, and view all available console commands, type

python3 -m pip show --verbose odm-api

You can always remove the package with a help of this command

python3 -m pip uninstall odm-api

Example of usage

Script to search through samples and display them in table format:

    import os
    import pandas as pd
    import odm_api

    os.environ['PRED_SPOT_HOST'] = 'GENESTACK_ENDPOINT_ADDR'
    os.environ['PRED_SPOT_TOKEN'] = 'GENESTACK_TOKEN'
    os.environ['PRED_SPOT_VERSION'] = 'default-released'

    api = odm_api.SampleSPoTApiAsCurator()
    query = '"Disease"="Healthy" OR "Disease"="Alzheimer Disease"'
    samples = api.search_samples(filter=query, page_offset=0)
    print(pd.DataFrame.from_dict(samples.data[:5]))

The output:

  genestack:accession Sample Source ID Sample Name Organism     Sex  Disease   Age Age Unit Tissue Cell Type  ... Family.ID Donor Treatment/Treatment Name Specimen Type Tissue or Cell Type Sample Source Continental Group Code Sample Type Population Code Sample ID Continental Group
0           GSF136813          HG00096        None     None    Male  Healthy  None     None   None      None  ...   HG00096                    Not treated           LCL               Blood         NHGRI                    EUR         DNA             GBR   HG00096       "European "
1           GSF136814          HG00097        None     None  Female  Healthy  None     None   None      None  ...   HG00097                    Not treated           LCL               Blood         NHGRI                    EUR         DNA             GBR   HG00097       "European "
2           GSF136815          HG00099        None     None  Female  Healthy  None     None   None      None  ...   HG00099                    Not treated           LCL               Blood         NHGRI                    EUR         DNA             GBR   HG00099       "European "
3           GSF136816          HG00100        None     None  Female  Healthy  None     None   None      None  ...   HG00100                    Not treated           LCL               Blood         NHGRI                    EUR         DNA             GBR   HG00100       "European "
4           GSF136817          HG00101        None     None    Male  Healthy  None     None   None      None  ...   HG00101                    Not treated           LCL               Blood         NHGRI                    EUR         DNA             GBR   HG00101       "European "

Installation of generated R API Client

Requirements

  • R

Instructions

Install

# Install the latest version
genestackRepo <- "https://public-nexus.devops.gs.team/repository/r-releases"
install.packages("odm-api", repos = genestackRepo)

# OR: Install a specific version starting from 1.53.12, usually the same as ODM version, e.g. 1.54.0
genestackRepo <- "https://public-nexus.devops.gs.team/repository/r-releases"
options("repos" = c(GENESTACK = genestackRepo))

install_specific_version_from_nexus <- function(pkgs, version = NULL, ...) {
  # Build the package name
  pkg_name <- paste0(pkgs, "_", version, ".tar.gz")
  # build the url knowing it should be in root /src/contrib
  for (repo in getOption("repos")) {
    url <- paste(repo, "src/contrib", pkg_name, sep = "/")
    # try to download
    try <- tryCatch({
      path <- file.path(tempdir(), pkg_name)
      suppressWarnings(download.file(url, path, mode = "wb"))},
      # catch the error
      error = function(e) 1L
    )
  }

  # error result means that specific version is not available
  if (try == 1L) stop("\nError: ", pkgs, " not available in version ", version, call. = FALSE)
  on.exit(unlink(path))

  # if no error, install the package using local path
  install.packages(path, repos=NULL, ...)
}

odmVersion <- "1.53.12"
install_specific_version_from_nexus("odm-api", version = odmVersion)

Example of usage

Script to search through samples and display them in table format:

Sys.setenv(PRED_SPOT_HOST = 'GENESTACK_ENDPOINT_ADDR',
           PRED_SPOT_TOKEN = 'GENESTACK_TOKEN',
           PRED_SPOT_VERSION = 'default-released')

library(odm_api)
query <- '"Disease"="Healthy" OR "Disease"="Alzheimer Disease"'
samplesObject <- odm_api::SampleSPoTApiAsCurator_search_samples(filter=query)
samplesObject$content$data[1:5]

The output (shorten):

  genestack:accession Sample Source ID Sample Name Organism     Sex
1           GSF136813          HG00096        None     None    Male
2           GSF136814          HG00097        None     None  Female
3           GSF136815          HG00099        None     None  Female
4           GSF136816          HG00100        None     None  Female
5           GSF136817          HG00101        None     None    Male

Note: To successfully run the example you might need to install additional packages such as R6 and httr. You can do it with a commands like this:

install.packages('R6', repos = "http://cran.us.r-project.org")
install.packages('httr', repos = "http://cran.us.r-project.org")