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

https://github.com/ctlab/phantasus
21 September 2022, 07:59:32 UTC
  • Code
  • Branches (35)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/RELEASE_3_10
    • refs/heads/RELEASE_3_11
    • refs/heads/RELEASE_3_12
    • refs/heads/RELEASE_3_7
    • refs/heads/RELEASE_3_8
    • refs/heads/RELEASE_3_9
    • refs/heads/appeveyor
    • refs/heads/archs4
    • refs/heads/assaron-patch-1
    • refs/heads/develop
    • refs/heads/export-dataset-history
    • refs/heads/master
    • refs/heads/r-3.4
    • refs/heads/slack-test
    • refs/heads/travis-fix
    • refs/tags/v1.1.2
    • refs/tags/v1.1.3
    • refs/tags/v1.1.5
    • refs/tags/v1.1.6
    • refs/tags/v1.11.0
    • refs/tags/v1.15.2
    • refs/tags/v1.2.0
    • refs/tags/v1.2.1
    • refs/tags/v1.3.0
    • refs/tags/v1.3.1
    • refs/tags/v1.3.2
    • refs/tags/v1.3.3
    • refs/tags/v1.3.4
    • refs/tags/v1.3.5
    • refs/tags/v1.7.2
    • refs/tags/v1.7.3
    • refs/tags/v1.7.4
    • refs/tags/v1.8.0
    • refs/tags/v1.9.0
    • refs/tags/v1.9.2
    No releases to show
  • 065554d
  • /
  • R
  • /
  • loadPreloaded.R
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

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.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:a83878c046661ca1c6b45128b0a256f063ba76b5
origin badgedirectory badge Iframe embedding
swh:1:dir:5a7f4844069990e0b2aea8e476d3bbedb8458837
origin badgerevision badge
swh:1:rev:f40fb807d7e216252ccf42eedf4d41df96db8162
origin badgesnapshot badge
swh:1:snp:81f55656775682937cc054fa1ff232e359617622
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.

  • content
  • directory
  • revision
  • snapshot
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 ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: f40fb807d7e216252ccf42eedf4d41df96db8162 authored by Vladislav Kamenev on 08 October 2018, 14:29:10 UTC
Update JS. Export dataset to R
Tip revision: f40fb80
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)
}

back to top

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