Skip to contents

This document describes how the SVG and related information used in the examples of the ‘bscui’ package were prepared.

Requirements

The following packages were used:


Built on 2024-03-31

## R version 4.3.3 (2024-02-29)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.4 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=fr_BE.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=fr_BE.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=fr_BE.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: Europe/Brussels
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] stringr_1.5.1 readr_2.1.5   dplyr_1.1.4   xml2_1.3.6    bscui_0.1.5  
## [6] here_1.0.1    knitr_1.45   
## 
## loaded via a namespace (and not attached):
##  [1] jsonlite_1.8.8    compiler_4.3.3    tidyselect_1.2.1  jquerylib_0.1.4  
##  [5] systemfonts_1.0.6 textshaping_0.3.7 yaml_2.3.8        fastmap_1.1.1    
##  [9] R6_2.5.1          generics_0.1.3    htmlwidgets_1.6.4 tibble_3.2.1     
## [13] desc_1.4.3        rprojroot_2.0.4   tzdb_0.4.0        bslib_0.7.0      
## [17] pillar_1.9.0      rlang_1.1.3       utf8_1.2.4        stringi_1.8.3    
## [21] cachem_1.0.8      xfun_0.43         fs_1.6.3          sass_0.4.9       
## [25] memoise_2.0.1     cli_3.6.2         pkgdown_2.0.7     magrittr_2.0.3   
## [29] digest_0.6.35     rstudioapi_0.16.0 hms_1.1.3         lifecycle_1.0.4  
## [33] vctrs_0.6.5       evaluate_0.23     glue_1.7.0        ragg_1.3.0       
## [37] fansi_1.0.6       rmarkdown_2.26    purrr_1.0.2       tools_4.3.3      
## [41] pkgconfig_2.0.3   htmltools_0.5.8


Reading EBI anatomograms

Original SVG

Anatomical diagrams are taken from the EBI gene expression group.

file_name <- "homo_sapiens.female.svg"
svg <- read_xml(file.path(
   "https://raw.githubusercontent.com",
   "ebi-gene-expression-group/anatomogram",
   "master/src/svg",
   file_name
))

Extract element titles from the SVG

Organ identifiers and names were extracted directly from the SVG.

get_element_titles <- function(x){
   id <- xml_attr(x, "id")
   children <- xml_children(x)
   children_titles <- tibble(id=character(), label=character())
   label <- character()
   if(length(children) > 0) for(i in 1:length(children)){
      child <- children[[i]]
      if(xml_name(child) == "title"){
         label <- xml_attr(child, "id")
      }else{
         children_titles <- children_titles |>
            bind_rows(get_element_titles(child))
      }
   }
   toRet <- tibble(id = id, label = label)  |>
      bind_rows(children_titles) |>
      filter(!is.na(id))
   return(toRet)
}
element_titles <- get_element_titles(svg)
head(element_titles)
## # A tibble: 6 × 2
##   id             label         
##   <chr>          <chr>         
## 1 UBERON_0001831 parotid gland 
## 2 UBERON_0001013 adipose_tissue
## 3 UBERON_0000948 heart         
## 4 UBERON_0001135 smooth_muscle 
## 5 UBERON_0000955 brain         
## 6 UBERON_0000310 breast

Remove title elements from SVG

In order to avoid double title display, ‘<title>’ elements were removed from the original SVG.

namespace_element_nodes <- xml_find_all(
   svg, "//namespace::*[name()='']/parent::*"
)
xml_attr(namespace_element_nodes, "xmlns") <- NULL
titles <- xml_find_all(svg, "//title")
for(to_remove in titles){
   xml_remove(to_remove)
}
xml_attr(namespace_element_nodes[1], "xmlns") <- "http://www.w3.org/2000/svg"

Move organs in front

Finally, by choice, the organs were put in front of the body outline.

children <- xml_children(svg)
xml_attr(namespace_element_nodes, "xmlns") <- NULL
to_move <- children[[which(xml_attr(children, "id") == "LAYER_EFO")]]
xml_remove(to_move)
xml_add_child(svg, to_move)

Here is the pre-processed SVG in a bscui figure:

bscui(svg)
image/svg+xml

Reading swissbiopics

Read original SVG

The figure of animal cells was taken from SwissBioPics.

file_name <- "Animal_cells.svg"
svg <- read_xml(file.path(
   "https://www.swissbiopics.org/",
   "api/image",
   file_name
))

Remove text elements from SVG

Hidden text elements in the original SVG have consequence on the size and on the scalling of the bscui figure. Therefore, they were removed from the SVG.

namespace_element_nodes <- xml_find_all(
   svg, "//namespace::*[name()='']/parent::*"
)
xml_attr(namespace_element_nodes, "xmlns") <- NULL
titles <- xml_find_all(svg, "//text")
for(to_remove in titles){
   xml_remove(to_remove)
}
xml_attr(namespace_element_nodes[1], "xmlns") <- "http://www.w3.org/2000/svg"

Here is the pre-processed SVG in a bscui figure:

bscui(svg)
http://purl.uniprot.org/locations/111 http://purl.uniprot.org/locations/112 http://purl.uniprot.org/locations/466 http://purl.uniprot.org/locations/243 http://purl.uniprot.org/locations/91 http://purl.uniprot.org/locations/86 http://purl.uniprot.org/locations/138 http://purl.uniprot.org/locations/198 http://purl.uniprot.org/locations/501 http://purl.uniprot.org/locations/46 http://purl.uniprot.org/locations/485 http://purl.uniprot.org/locations/48 http://purl.uniprot.org/locations/484 http://purl.uniprot.org/locations/90 http://purl.uniprot.org/locations/39 http://purl.uniprot.org/locations/310 http://purl.uniprot.org/locations/190 http://purl.uniprot.org/locations/182 http://purl.uniprot.org/locations/188 http://purl.uniprot.org/locations/31 http://purl.uniprot.org/locations/465 http://purl.uniprot.org/locations/127 http://purl.uniprot.org/locations/186 http://purl.uniprot.org/locations/494 http://purl.uniprot.org/locations/180 http://purl.uniprot.org/locations/191 http://purl.uniprot.org/locations/170 http://purl.uniprot.org/locations/172 http://purl.uniprot.org/locations/168 http://purl.uniprot.org/locations/171 http://purl.uniprot.org/locations/167 http://purl.uniprot.org/locations/173 http://purl.uniprot.org/locations/248 http://purl.uniprot.org/locations/235 http://purl.uniprot.org/locations/95 http://purl.uniprot.org/locations/266 http://purl.uniprot.org/locations/135 http://purl.uniprot.org/locations/67 http://purl.uniprot.org/locations/132 http://purl.uniprot.org/locations/295 http://purl.uniprot.org/locations/286 http://purl.uniprot.org/locations/148 http://purl.uniprot.org/locations/87 http://purl.uniprot.org/locations/304 http://purl.uniprot.org/locations/66 http://purl.uniprot.org/locations/280 http://purl.uniprot.org/locations/145 http://purl.uniprot.org/locations/204 http://purl.uniprot.org/locations/161 http://purl.uniprot.org/locations/351 http://purl.uniprot.org/locations/73 http://purl.uniprot.org/locations/23 http://purl.uniprot.org/locations/75 http://purl.uniprot.org/locations/77 http://purl.uniprot.org/locations/98 http://purl.uniprot.org/locations/152 http://purl.uniprot.org/locations/94 http://purl.uniprot.org/locations/174 http://purl.uniprot.org/locations/70 http://purl.uniprot.org/locations/101 http://purl.uniprot.org/locations/35 http://purl.uniprot.org/locations/69 http://purl.uniprot.org/locations/72 http://purl.uniprot.org/locations/158 http://purl.uniprot.org/locations/473 http://purl.uniprot.org/locations/206 http://purl.uniprot.org/locations/118 http://purl.uniprot.org/locations/154 http://purl.uniprot.org/locations/61 http://purl.uniprot.org/locations/281

Get cellular location information

Information about the different part of a cell were taken from UniProt.

tmp_file <- tempfile(fileext=".txt.gz")
info <- download.file(
   url = "https://rest.uniprot.org/locations/stream?compressed=true&fields=id%2Cname%2Ccategory%2Cdefinition%2Ccontent%2Cgene_ontologies&format=tsv&query=%28*%29",
   destfile = tmp_file
)
info <- readr::read_tsv(
   tmp_file,
   col_types = strrep("c", 6)
)

Read wikipathways

Read original SVG

Biological pathway SVGs were taken from WikiPathways.

pid <- "WP112"
file_name <- paste0(pid, ".svg")
svg <- read_xml(file.path(
   "https://www.wikipathways.org",
   "wikipathways-assets/pathways",
   pid,
   file_name
))

Extract href

In the original SVG, elements come with hyperlinks that impair bscui interactions. That’s why they were removed from the SVG itself and put in a table for further use with bscui functions.

namespace_element_nodes <- xml_find_all(
   svg, "//namespace::*[name()='']/parent::*"
)
xml_attr(namespace_element_nodes, "xmlns") <- NULL
a <- xml_find_all(svg, "//a")
info <- tibble(
   id = xml_attr(a, "id"),
   name = xml_attr(a, "name"),
   href = xml_attr(a, "href"),
   svg_class = xml_attr(a, "class")
) |> 
   mutate(
      category = case_when(
         str_detect(svg_class, "GeneProduct") ~ "GeneProduct",
         str_detect(svg_class, "Metabolite") ~ "Metabolite",
         TRUE ~ as.character(NA)
      ),
      ensembl = strsplit(svg_class, split = " ") |> 
         lapply(function(x){
            grep("^Ensembl_", x, value=TRUE) |> 
               str_remove("Ensembl_") |> 
               paste(collapse=", ")
         }) |> 
         unlist(),
      ChEBI = strsplit(svg_class, split = " ") |> 
         lapply(function(x){
            grep("^ChEBI_", x, value=TRUE) |> 
               str_remove("ChEBI_") |> 
               paste(collapse=", ")
         }) |> 
         unlist()
   )
xml_attr(a, "target") <- NULL
xml_attr(namespace_element_nodes[1], "xmlns") <- "http://www.w3.org/2000/svg"
svg <- as.character(svg) |>
   stringr::str_remove_all('xlink:href="https?://[^"]*"') |>
   read_xml()

Here is the pre-processed SVG in a bscui figure:

bscui(svg)
ArcPathVisio Brace Octagon Ellipse EndoplasmicReticulum HexagonPathVisio GolgiApparatus MimDegradation Mitochondria Octagon PentagonPathVisio Rectangle RoundedRectangle SarcoplasmicReticulum TrianglePathVisio none Mitochondrion Transport between Cytoplasm and Mitochondrion Gluconeogenesis Cytoplasm Glycolysis [NOTE: TKL1, TKL2, Glyceraldehyde-3-phosphate, Fructose-6-phosphate, and Xylulose-5-phosphate are duplicated for clarity, but are part of the same cytoplasmic pool.] Other Pathways of Carbon Metabolism 2-Phosphoglycerate Fructose 1,6-bisphosphate FBP1 Glucose-6-phosphate PFK1 PFK2 Glyceraldehyde-3-phosphate PGI1 PCK1 ACS2 GND1 GND2 D-6-Phospho-glucono-delta-lactone TKL2 TKL1 ADH1 ADH5 ADH2 Acetate GLK1 HXK1 HXK2 PYC1 PYC2 FBA1 Oxaloacetate SOL3 SOL4 Glucose MDH3 MDH2 GPD2 GPD1 CDC19 PYK2 HOR2 RHR2 PDC5 PDC6 PDC1 Phosphoenolpyruvate Acetaldehyde PGK1 Ethanol RKI1 GPM1 Glycerol 3-phosphate Acetyl-CoA Phosphate Dihydroxyacetone ENO2 ENO1 3-Phosphoglycerate D-Ribose-5-Phosphate TDH1 TDH3 TDH2 ALD6 ACS1 (mt) ADH4 (mt) ADH3 (mt) RPE1 Fructose-6-phosphate TKL2 TKL1 ZWF1 6-Phosphogluconate Glycerol GUT1 Erythrose-4-phosphate Ribulose-5-phosphate Malate Ethanol TAL1 ALD4 (mt) GUT2 Glyceraldehyde- 3-phosphate Pyruvate TPI1 Sedoheptulose-7-phosphate 1,3-Bisphosphoglycerate Xylulose-5-phosphate Acetate Fructose-6-phosphate Xylulose-5-phosphate Acetaldehyde CIT3 CIT1 CIT2 SDH4 SDH3 SDH2 SDH1 LPD1 PDX1 LAT1 PDB1 PDA1 Isocitrate Fumarate IDP1 IDH2 IDP2 IDH1 Malate Glyoxylate alpha-ketoglutarate LSC1 LSC2 Succinate Acetyl-CoA MDH1 Succinyl-CoA LPD1 KGD2 KGD1 Citrate FUM1 ACO2 ACO1 MAE1 DAL7 MLS1 ICL1 Pyruvate Oxaloacetate Acetyl-CoA Name: Principal pathways of carbon metabolism Last Modified: 20210520114908 Organism: Saccharomyces cerevisiae