Skip to content
Snippets Groups Projects
Commit bac47658 authored by Marek Ostaszewski's avatar Marek Ostaszewski
Browse files

Merge branch 'Rcode' into 'master'

converters updated, convert_to_image function added, error corrected for SBGN-ML conversion format

See merge request minerva/minervar!79
parents fefbcaf8 8aea2007
Branches master
Tags v1.0.0
No related merge requests found
Package: minervar
Title: Convenience functions for accessing the MINERVA Platform
Version: 0.8.14
Version: 0.8.15
Authors@R:
person("Marek", "Ostaszewski", , "marek.ostaszewski@uni.lu", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1473-370X"))
......
......@@ -5,6 +5,7 @@ export(compare_map_reactions)
export(compare_maps)
export(convert_format)
export(convert_reactome)
export(convert_to_image)
export(convert_wikipathway)
export(create_bipartite_graph)
export(create_search_url)
......
......@@ -7,8 +7,8 @@
#'
#' @param path_to_zipped_files (`character`) an path to the zip file with diagrams;
#' diagrams should be compressed inside of a 'maps' directory
#' @param source_format (`c('CellDesigner_SBML','SBML','GPML','SBGNML')`) a format of the source file
#' @param target_format (`c('CellDesigner_SBML','SBML','GPML','SBGNML')`) a format a file should be converted to
#' @param source_format (`c('CellDesigner_SBML','SBML','GPML','SBGN-ML')`) a format of the source file
#' @param target_format (`c('CellDesigner_SBML','SBML','GPML','SBGN-ML')`) a format a file should be converted to
#' @param minerva_api (`character`) an API endpoint of MINERVA instance to do the merging
#' @param compact_celldesigner_identifiers (`logical`) only applicable if target_format is CellDesigner_SBML;
#' this parameter controls if CellDesigner identifiers (modified after merging) should be made compact
......@@ -50,8 +50,8 @@ merge_zipped_files <- function(path_to_zipped_files,
#' to a given MINERVA Platform instance and retrieves the merged diagram.
#'
#' @param files (`character` vector) a verctor of filepaths to be zipped and sent for merging
#' @param source_format (`c('CellDesigner_SBML','SBML','GPML','SBGNML')`) a format of the source file
#' @param target_format (`c('CellDesigner_SBML','SBML','GPML','SBGNML')`) a format a file should be converted to
#' @param source_format (`c('CellDesigner_SBML','SBML','GPML','SBGN-ML')`) a format of the source file
#' @param target_format (`c('CellDesigner_SBML','SBML','GPML','SBGN-ML')`) a format a file should be converted to
#' @param work_dir (`character`) a path to the directory where 'maps' will be created/zipped, `tempdir()` by default
#' @param remove_source (`logical`) whether to remove source files
#' @param remove_zip (`logical`) whether to remove the zip files
......@@ -124,8 +124,8 @@ merge_unzipped_files <- function(files,
#' and retrieves a converted version of this diagram.
#'
#' @param source_file_path (`character`) a path to a file to be converted
#' @param source_format (`c('CellDesigner_SBML','SBML','GPML','SBGNML')`) a format of the source file
#' @param target_format (`c('CellDesigner_SBML','SBML','GPML','SBGNML')`) a format a file should be converted to
#' @param source_format (`c('CellDesigner_SBML','SBML','GPML','SBGN-ML')`) a format of the source file
#' @param target_format (`c('CellDesigner_SBML','SBML','GPML','SBGN-ML')`) a format a file should be converted to
#' @param minerva_api (`character`) an API endpoint of MINERVA instance to do the merging
#' @param verbose (`logical`) run in verbose mode
#' @param content_encoding (`character`) encoding of the received content
......@@ -136,19 +136,18 @@ merge_unzipped_files <- function(files,
#' convert_format(source_file_path = system.file("extdata", "core.xml", package = "minervar"),
#' source_format = "CellDesigner_SBML", target_format = "GPML")
#' convert_format(source_file_path = system.file("extdata", "WP313_118735.gpml", package = "minervar"),
#' source_format = "GPML", target_format = "SBGNML")
#' source_format = "GPML", target_format = "SBGN-ML")
#'
#' @export
convert_format <- function(source_file_path, source_format, target_format,
minerva_api = paste0("https://minerva-service.lcsb.uni.lu/minerva/api/",
"convert/",source_format,":",target_format),
minerva_api = "https://minerva-service.lcsb.uni.lu/minerva/api/",
verbose = F, content_encoding = "UTF-8") {
if(!(source_format %in% c("CellDesigner_SBML","SBML","GPML","SBGNML"))) {
warning("minervar:convert_format(): Wrong source format, use one of 'CellDesigner_SBML','SBML','GPML','SBGNML'")
if(!(source_format %in% c("CellDesigner_SBML","SBML","GPML","SBGN-ML"))) {
warning("minervar:convert_format(): Wrong source format, use one of 'CellDesigner_SBML','SBML','GPML','SBGN-ML'")
return(NULL)
}
if(!(target_format %in% c("CellDesigner_SBML","SBML","GPML","SBGNML"))) {
warning("minervar:convert_format(): Wrong target format, use one of 'CellDesigner_SBML','SBML','GPML','SBGNML'")
if(!(target_format %in% c("CellDesigner_SBML","SBML","GPML","SBGN-ML"))) {
warning("minervar:convert_format(): Wrong target format, use one of 'CellDesigner_SBML','SBML','GPML','SBGN-ML'")
return(NULL)
}
if(source_format == target_format) {
......@@ -156,20 +155,66 @@ convert_format <- function(source_file_path, source_format, target_format,
return(NULL)
}
message("minervar:convert_format(): coverting diagram from '", source_format , "' to '", target_format, "'")
res <- httr::POST(url = minerva_api,
minerva_call = paste0(minerva_api,
"convert/",source_format,":",target_format)
res <- httr::POST(url = minerva_call,
body = httr::upload_file(source_file_path, "application/octet-stream"),
httr::add_headers(`Content-Type` = "application/octet-stream"),
httr::config(verbose = verbose))
return(httr::content(res, as = "text", encoding = content_encoding))
}
#' @title Convert a file from one MINERVA supported format to an image
#'
#' @description Function that sends a file to a given MINERVA Platform instance
#' and retrieves an image version of this diagram.
#'
#' @param source_file_path (`character`) a path to a file to be converted
#' @param source_format (`c('CellDesigner_SBML','SBML','GPML','SBGN-ML')`) a format of the source file
#' @param target_format (`c('png', 'svg', 'pdf')`) an image format a file should be converted to
#' @param minerva_api (`character`) an API endpoint of MINERVA instance to do the merging
#' @param verbose (`logical`) run in verbose mode
#' @param content_encoding (`character`) encoding of the received content
#'
#' @return (`character`) a response of the API call, an XML of the converted diagram in a single string
#' @examples
#'
#' convert_to_image(source_file_path = system.file("extdata", "core.xml",
#' package = "minervar"),
#' source_format = "CellDesigner_SBML", target_format = "png")
#' convert_to_image(source_file_path = system.file("extdata", "WP313_118735.gpml",
#' package = "minervar"),
#' source_format = "GPML", target_format = "pdf")
#'
#' @export
convert_to_image <- function(source_file_path, source_format, target_format,
minerva_api = "https://minerva-service.lcsb.uni.lu/minerva/api/",
verbose = F, content_encoding = "UTF-8") {
if(!(source_format %in% c("CellDesigner_SBML","SBML","GPML","SBGN-ML"))) {
warning("minervar:convert_to_image(): Wrong source format, use one of 'CellDesigner_SBML','SBML','GPML','SBGN-ML'")
return(NULL)
}
if(!(target_format %in% c("png","svg","pdf"))) {
warning("minervar:convert_to_image(): Wrong target format, use one of 'png','svg','pdf'")
return(NULL)
}
message("minervar:convert_to_image(): coverting diagram from '", source_format , "' to '", target_format, "'")
minerva_call <- paste0(minerva_api,
"convert/image/",source_format,":",target_format)
res <- httr::POST(url = minerva_call,
body = httr::upload_file(source_file_path, "application/octet-stream"),
httr::add_headers(`Content-Type` = "application/octet-stream"),
httr::config(verbose = verbose))
return(httr::content(res, as = "raw", encoding = content_encoding))
}
#' @title Convert a WikiPathways pathway to a given format by WPID
#'
#' @description Function that retrieves a pathway with a given WikiPathways ID and converts it to a defined format
#' ('CellDesigner_SBML' by default)
#'
#' @param id (`character`) WikiPathways ID
#' @param target_format (`c('CellDesigner_SBML','SBML','GPML','SBGNML')`) a format a file should be converted to
#' @param target_format (`c('CellDesigner_SBML','SBML','GPML','SBGN-ML')`) a format a file should be converted to
#' @param minerva_api (`character`) an API endpoint of MINERVA instance to do the merging
#' @param verbose (`logical`) run in verbose mode
#' @param content_encoding (`character`) encoding of the received content
......@@ -226,7 +271,7 @@ convert_wikipathway <- function(id, target_format = "CellDesigner_SBML",
#' ('CellDesigner_SBML' by default)
#'
#' @param id (`character`) Reactome ID
#' @param target_format (`c('CellDesigner_SBML','SBML','GPML','SBGNML')`) a format a file should be converted to
#' @param target_format (`c('CellDesigner_SBML','SBML','GPML','SBGN-ML')`) a format a file should be converted to
#' @param minerva_api (`character`) an API endpoint of MINERVA instance to do the merging
#' @param verbose (`logical`) run in verbose mode
#' @param content_encoding (`character`) encoding of the received content
......
......@@ -8,8 +8,7 @@ convert_format(
source_file_path,
source_format,
target_format,
minerva_api = paste0("https://minerva-service.lcsb.uni.lu/minerva/api/", "convert/",
source_format, ":", target_format),
minerva_api = "https://minerva-service.lcsb.uni.lu/minerva/api/",
verbose = F,
content_encoding = "UTF-8"
)
......@@ -17,9 +16,9 @@ convert_format(
\arguments{
\item{source_file_path}{(\code{character}) a path to a file to be converted}
\item{source_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGNML')}) a format of the source file}
\item{source_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGN-ML')}) a format of the source file}
\item{target_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGNML')}) a format a file should be converted to}
\item{target_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGN-ML')}) a format a file should be converted to}
\item{minerva_api}{(\code{character}) an API endpoint of MINERVA instance to do the merging}
......@@ -39,6 +38,6 @@ and retrieves a converted version of this diagram.
convert_format(source_file_path = system.file("extdata", "core.xml", package = "minervar"),
source_format = "CellDesigner_SBML", target_format = "GPML")
convert_format(source_file_path = system.file("extdata", "WP313_118735.gpml", package = "minervar"),
source_format = "GPML", target_format = "SBGNML")
source_format = "GPML", target_format = "SBGN-ML")
}
......@@ -16,7 +16,7 @@ convert_reactome(
\arguments{
\item{id}{(\code{character}) Reactome ID}
\item{target_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGNML')}) a format a file should be converted to}
\item{target_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGN-ML')}) a format a file should be converted to}
\item{minerva_api}{(\code{character}) an API endpoint of MINERVA instance to do the merging}
......
......@@ -16,7 +16,7 @@ convert_wikipathway(
\arguments{
\item{id}{(\code{character}) WikiPathways ID}
\item{target_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGNML')}) a format a file should be converted to}
\item{target_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGN-ML')}) a format a file should be converted to}
\item{minerva_api}{(\code{character}) an API endpoint of MINERVA instance to do the merging}
......
......@@ -22,9 +22,9 @@ merge_unzipped_files(
\arguments{
\item{files}{(\code{character} vector) a verctor of filepaths to be zipped and sent for merging}
\item{source_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGNML')}) a format of the source file}
\item{source_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGN-ML')}) a format of the source file}
\item{target_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGNML')}) a format a file should be converted to}
\item{target_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGN-ML')}) a format a file should be converted to}
\item{work_dir}{(\code{character}) a path to the directory where 'maps' will be created/zipped, \code{tempdir()} by default}
......
......@@ -19,9 +19,9 @@ merge_zipped_files(
\item{path_to_zipped_files}{(\code{character}) an path to the zip file with diagrams;
diagrams should be compressed inside of a 'maps' directory}
\item{source_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGNML')}) a format of the source file}
\item{source_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGN-ML')}) a format of the source file}
\item{target_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGNML')}) a format a file should be converted to}
\item{target_format}{(\code{c('CellDesigner_SBML','SBML','GPML','SBGN-ML')}) a format a file should be converted to}
\item{minerva_api}{(\code{character}) an API endpoint of MINERVA instance to do the merging}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment