Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 7a7752866743aa5a893aab2b3cdf2dcb066c99c3 authored by Alexey Sergushichev on 11 May 2018, 11:53:02 UTC, committed by Alexey Sergushichev on 11 May 2018, 11:53:02 UTC
Depending on svglite
1 parent ef3db4f
  • Files
  • Changes
  • 929497b
  • /
  • R
  • /
  • loadPreloaded.R
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:7a7752866743aa5a893aab2b3cdf2dcb066c99c3
directory badge Iframe embedding
swh:1:dir:3cd611c735364a9e5d207ba5cf459094cbcb8f26
content badge Iframe embedding
swh:1:cnt:a83878c046661ca1c6b45128b0a256f063ba76b5
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
loadPreloaded.R
#' Load GEO Dataset.
#'
#' \code{loadPreloaded} returns the file with serialized ExpressionSets using
#'     ProtoBuf, that were preloaded on server.
#'
#' @param name String, containing filename. Assuming
#'     that in the directory with preloaded files \code{preloadedDir}
#'     exists file \code{filename.rda} with list of ExpressionSets \code{ess}.
#'
#' @param exactName If you know, that inside file is object with name
#'   \code{exactName}, you can specify it to load only this object.
#'   Otherwise, whole file will be loaded.
#'
#' @return File with ProtoBuf-serialized ExpressionSet-s
#'     that were loaded from specified file.
#'
#' @import Biobase
loadPreloaded <- function(name, exactName = NULL) {
  preloadedDir <- getOption("phantasusPreloadedDir")
  if (is.null(preloadedDir)) {
    stop("Specify the directory with presaved files")
  } else if (!dir.exists(preloadedDir)) {
    stop("No such directory")
  }

  fileToLoad <- file.path(preloadedDir, paste0(name, '.rda'))

  if (file.exists(fileToLoad)) {
    x <- load(fileToLoad) # must return the object ess
    loaded <- get(x)

    wrongFormat <- paste("Wrong format.",
                            "File must contain either ExpressionSet",
                            "or list of ExpressionSets")

    ess <- NULL

    if (class(loaded) == "ExpressionSet") {
      ess <- list()
      ess[[x]] <- loaded
    } else if (class(loaded) != "list") {
      stop(wrongFormat)
    } else {
      ess <- loaded
    }



    files <- list()

    seriesNames <- names(ess)
    if (is.null(seriesNames)) {
      seriesNames <- paste0(name, "_", 1:length(ess))
    }

    if (!is.null(exactName) && exactName == name) {
      exactName <- NULL
    }
    if (!is.null(exactName) && !(exactName %in% seriesNames)) {
      stop("There is not such object in this file")
    }

    if (!is.null(exactName)) {
      ess <- list(ess[[exactName]])
    }
    for (i in 1:length(ess)) {
      if (class(ess[[i]]) != "ExpressionSet") {
        stop(wrongFormat)
      }
      assign(paste0("es_", i), ess[[i]], envir = parent.frame())

      files[[seriesNames[[i]]]] <- writeToList(ess[[i]])
    }
    f <- tempfile(pattern = "gse", tmpdir = getwd(), fileext = ".bin")
    writeBin(protolite::serialize_pb(files), f)
    jsonlite::toJSON(f)
  } else {
    stop("No such file")
  }
}

#' Check existence of phantasusPreloadedDir
#'
#' \code{preloadedDirExists} checks if there is specified
#'   directory with preloaded files.
#'
#' @return Boolean value.
preloadedDirExists <- function() {
  preloadedDir <- getOption("phantasusPreloadedDir")
  jsonlite::toJSON(!is.null(preloadedDir) && dir.exists(preloadedDir))
}

#' Check names inside preloaded file
#'
#' \code{checkPreloadedNames} checks names of ExpressionSets that
#'   are included in file \code{name}
#'
#' @param name String, containing filename. Assuming
#'     that in the directory with preloaded files \code{preloadedDir}
#'     exists file \code{filename.rda} with list of ExpressionSets \code{ess}.
#'
#' @return Vector of names serialized in JSON format.
#'
checkPreloadedNames <- function(name) {
    if (!jsonlite::fromJSON(preloadedDirExists())) {
        stop("No such directory")
    }

    preloadedDir <- getOption("phantasusPreloadedDir")
    fileToLoad <- file.path(preloadedDir, paste0(name, '.rda'))

    if (!file.exists(fileToLoad)) {
        fileToLoadGct <- file.path(preloadedDir, paste0(name, '.gct'))

        if (!file.exists(fileToLoadGct)) {
            stop("No such file")
        }

        es <- read.gct(fileToLoadGct)
        ess <- list(es=es)
        names(ess) <- name
        save(ess, file=fileToLoad, compress = TRUE)
    }

    x <- load(fileToLoad) # must return the object ess
    loaded <- get(x)

    answer <- c()

    if (class(loaded) == "ExpressionSet") {
        answer <- c(x)
    } else if (class(loaded) == "list") {
        if (!is.null(names(loaded))) {
            answer <- names(loaded)
        }
        else {
            if (length(loaded) > 1) {
                answer <- paste0(name, "_", 1:length(loaded))
            } else {
                answer <- c(name)
            }
        }
    } else {
        wrongFormat <- paste("Wrong format.",
                             "File must contain either ExpressionSet",
                             "or list of ExpressionSets")
        stop(wrongFormat)
    }

    jsonlite::toJSON(answer)
}

The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top