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

  • a78cb8f
  • /
  • function
  • /
  • highchartconverter.R
Raw File Download

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
content badge
swh:1:cnt:6b4761e59cbcea3bc10fecb1a53d036420190f90
directory badge
swh:1:dir:de48f4b3b44890b63710117d534c1001e76424e9

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
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
highchartconverter.R
### Author: Franck Soubès
### Bioinformatics Master Degree - University of Bordeaux, France
### Link: https://github.com/GeT-TRiX/MA_Trix_App/
### Where: GET-TRiX's facility
### Application: MATRiX is a shiny application for Mining and functional Analysis of TRanscriptomics data
### Licence: GPL-3.0


#' DftoHighjson is a function which aims is to reshape a DAVID restable dataframe to a json format
#'
#' @param data A Functional Annotation Summary dataframe (DAVID output)
#' @param method A character to specify if users want to display top term based on the pvalue or the fold Enrichment
#'
#' @return Json object to be pass to highchart library
#'
#' @export
#'


DftoHighjson <- function(data, method) {

  tempData <- (data[grep("Fold.Enrichment",colnames(data))])
  colnames(tempData) <- paste0("y",1)
  tempData$id <- data$Category
  tempData$Term <- data$Term
  tempData$pvalue <- data$PValue
  tempData$FE <- data$Fold.Enrichment



  if(method == "FoldE")
    tempData$xval <- data$Fold.Enrichment
  else
    tempData$xval <- data$PValue


  tempData$Topgenes <-  data$Top
  tempData$percent <- data$percent


  unifiedData <- reshape(tempData, varying=paste0("y",1),
                      direction="long", idvar="Top",sep="",timevar="x")


  unifiedData <- unifiedData[order(unifiedData$id),]
  unifiedData$x <- as.double(as.character(unifiedData$xval))
  unifiedData$y <- as.numeric(unifiedData$Topgenes)
  unifiedData$z <-  as.numeric(as.character(unifiedData$percent))


  unifiedData$GO  = sapply(unifiedData$Term, FUN= function(x) if(grepl("^mmu|^rno|^hsa|^ssc|^ptr|^gga|^cel|^ecb", x)) return(strsplit(as.character(x), ":")%>% unlist() %>% .[1])
                        else return(strsplit(as.character(x), "~")%>% unlist() %>% .[1]))

  unifiedData$Term  = sapply(unifiedData$Term, FUN= function(x) if(grepl("^mmu|^rno|^hsa|^ssc|^ptr|^gga|^cel|^ecb", x)) return(strsplit(as.character(x), ":")%>% unlist() %>% .[2])
                        else return(strsplit(as.character(x), "~")%>% unlist() %>% .[2]))

  unifiedData$Pvalue =  format(tempData$pvalue, digits = 3)

  unifiedData$FE = as.integer(as.character(unifiedData$FE))

  return(highchartsConvert(unifiedData))
}


#' formatPoint is a function which aims is to reutnr a list of information for each category (top 10)
#'
#' @param index A dataframe to be processed
#'
#' @return A list of usefull information from the david restable
#'
#' @export
#'


formatPoint <- function(index) {

  return( list( x=index$x, y=index$y,z=index$z, GO=index$GO, term=index$Term, pvalue = index$Pvalue, FE = index$FE))
}


#' formatCategory is a function which aims is to return a json structure
#'
#' @param dframeCategory A dataframe to be processed
#'
#' @return Json structure
#'
#' @export
#'

formatCategory <- function(dframeCategory) {

  categoryTemplate <- list(name="",data={})
  categoryTemplate$name <- dframeCategory$id[[1]]
  categoryTemplate$visible <- F
  dataPoints <- dlply(dframeCategory,.(1:nrow(dframeCategory)),formatPoint)
  names(dataPoints) <- NULL
  categoryTemplate$data <- dataPoints

  return(categoryTemplate)
}



#' highchartsConvert is a function which aims is to convert a dataframe object to the json format
#' by spliting the dataframe by categories to be passed to the highchart library
#'
#' @param DftoHighjson A dataframe to be processed
#'
#' @return A json object example:[{"GOTERM_BP_ALL" : [{ "x" : 0.005 , "y" : 2 , "Term" : "inactivation of MAPK activity" , "Go" : "GO:0000188"}], ..., "GOTERM_CC_ALL : [{ ...}}]]
#'
#' @export
#'


highchartsConvert <- function(DftoHighjson) {

  json <- dlply (DftoHighjson, .(id), formatCategory)
  names(json) <- NULL
  return(json)

}

back to top

Software Heritage — Copyright (C) 2015–2026, 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— Content policy— Contact— JavaScript license information— Web API