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
  • /
  • performKmeans.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:2a18c530457414123982ac65853d5cc9d90e238f
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 ...
performKmeans.R
#' K-means clusterisation.
#'
#' \code{performKmeans} returns a vector of corresponding clusters for
#'     each gene from a given ExpressionSet.
#'
#' @param es ExpressionSet object.
#'
#' @param columns List of specified columns' indices (optional), indices start from 0
#'
#' @param rows List of specified rows' indices (optional), indices start from 0
#'
#' @param k Expected number of clusters.
#'
#' @param replacena Method for replacing NA values
#'     in series matrix (mean by default)
#'
#' @return Vector of corresponding clusters, serialized to JSON.
#'
#' @import Biobase
#'
#' @examples
#' \dontrun{
#' data(es)
#' performKmeans(es, k = 2)
#' }
performKmeans <- function(es, columns = c(), rows = c(), k,
                            replacena = "mean") {
    assertthat::assert_that(k > 0)

    es <- subsetES(es, columns=columns, rows=rows)

    scaledExprs <- unname(t(scale(t(exprs(es)))))



    naInd <- which(is.na(scaledExprs), arr.ind = TRUE)
    if (nrow(naInd) > 0) {
        replaceValues <- apply(scaledExprs, 1, replacena, na.rm=TRUE)
        scaledExprs[naInd] <- replaceValues[naInd[,1]]
        rowsToCluster <- is.finite(replaceValues)
    } else {
        rowsToCluster <- seq_len(nrow(scaledExprs))
    }

    km <- stats::kmeans(scaledExprs[rowsToCluster, ], k, iter.max = 100L)
    res <- character(nrow(scaledExprs))
    res[rowsToCluster] <- as.character(km$cluster)
    return(jsonlite::toJSON(res))
}
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