---
title: "transomics2cytoscape"
author: "by Kozo Nishida, Katsuyuki Yugi"
date: "30 May 2021"
package: transomics2cytoscape
output: BiocStyle::html_document
bibliography: references.bib
csl: biometrics.csl
vignette: |
    %\VignetteIndexEntry{transomics2cytoscape}
    %\VignetteEncoding{UTF-8}
    %\VignetteEngine{knitr::rmarkdown}
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
    eval=FALSE
)
```

# Version Information

**R version**: 4.1.0

**Bioconductor version**: 3.13

**Cytoscape**: 3.8.2

**Cy3D (Cytoscape app)**: 1.1.3

**KEGGscape (Cytoscape app)**: 0.9.1

# Introduction

Visualization of Trans-omic networks helps biological interpretation by
illustrating pathways where the signals are transmitted
[@gehlenborg_visualization_2010].

To characterize signals that go across multiple omic layers, Yugi and
colleagues have proposed a method for network visualization
[@yugi_reconstruction_2014] by stacking multiple 2D pathways in a 3D space.

The 3D network visualization was realized by VANTED [@rohn_vanted_2012].
However, the visualization relies on time-consuming manual operation.
Here we propose transomics2cytoscape, an R package that automatically creates
3D network visualization in combination with
Cytoscape [@shannon_cytoscape:_2003],
[Cy3D](http://apps.cytoscape.org/apps/cy3d) App, and
Cytoscape Automation [@otasek_cytoscape_2019].


## Installation

This package requires [Cytoscape](https://cytoscape.org/) to be installed and
you need to run Cytoscape before running the following R code.

```{r}
BiocManager::install("transomics2cytoscape")
```

# Workflow

There is 2 functions `create3Dnetwork` and `createTransomicEdges`
in transomics2cytoscape.
Below is a diagram of the transomics2cytoscape workflow.

![Figure 1. The transomics2cytoscape workflow](../man/figures/workflow_diagram.png)

`create3Dnetwork` has 3 arguments.

The 1st one is a directory path where you put the network files
to be layered in 3D space.
The 2nd one is a file path of TSV for the Z-axis layout of the network files
(called "Layer definition file").
The last one is a file path of XML used to style Cytoscape.

For example,
```
suid <- create3Dnetwork(networkDataDir, networkLayers, stylexml)
```

`createTransomicEdges` has 2 arguments.

The 1st one is the SUID of the network created by `create3Dnetwork`.
The 2nd one is a file path of TSV for the transomic interactions
(called "Transomic interaction file").

For example,
```
suid <- createTransomicEdges(suid, layer1to2)
```

## Input files

### (Any number of) network files to be layered in 3D space

Files that Cytoscape can import.
You need to put these files in the directory of the 1st argument of
`create3Dnetwork`.
You don't need to put files for the KEGG pathway.
For KEGG pathway, you can import the network just by writing the KEGG
pathway ID in the "Layer definition file" described later.

### Layer definition file

"Layer definition file" is a TSV file for the Z-axis layout of the network
files.

A file that defines network layer index and the Z-height of the network
in 3D space. The format is as follows.

```
layer1  rno04910    2400
layer2  rno01100    1500
layer3  rno01100    1
```

The 1st column is the network layer index.
This information is added to the node table column `LAYER_INDEX`.

The 2nd column is the KEGG pathway ID or the network file name in the directory
of the 1st argument of `create3Dnetwork`.
You don't need to prepare a network file for the KEGG pathway.
You can import the KEGG pathway simply by writing the KEGG pathway ID.
The last column is the Z-height of the network.

### A style file of Cytoscape

A Cytoscape style file.
For more information about Cytoscape style file, see the
[Cytoscape user manual](http://manual.cytoscape.org/en/stable/Styles.html).
Note that you can only use style properties that are supported by Cy3D.


### Trans-omic interaction file

"Trans-omic interaction file" is a TSV file that defines the edges
that connect the different network layers.
The format is as follows.

![Figure 2. Trans-omic interaction file](../man/figures/Transomic_interaction_file.png)

The 1st ~ 4th columns are the information about the node or edge 
at the "source" of the Trans-omic interaction.

The 5th ~ 8th columns are about the target node.

The 1st and 5th columns are the network layer index.

The 2nd and 6th columns are whether the source and target of the interaction
are node or edge.

The 3rd and 7th columns are the column name of the Cytoscape node or edge
table.

The 4th and 8th columns are the string to be searched from the column
with the name of the 3rd and 7th column.
The Cytoscape node or edge that has the string will be the source or target
of the Trans-omic interaction.

The last column is the type of the Trans-omic interaction.
This information is added to the `interaction` column of the edge table.

## Example

You can reproduce Figure5 of
[Yugi 2014](https://www.cell.com/cell-reports/references/S2211-1247(14)00590-7)
with the code below.
This code execution will take some time to complete.
(Do not operate Cytoscape until the code execution is completed.)

```{r setup}
# suppressPackageStartupMessages(library(dplyr))
# suppressPackageStartupMessages(library(RCy3))
# suppressPackageStartupMessages(library(KEGGREST))
# Sys.setenv(LANGUAGE="en_US.UTF-8") 
library(transomics2cytoscape)
networkDataDir <- tempfile(); dir.create(networkDataDir)
networkLayers <- system.file("extdata", "yugi2014.tsv",
    package = "transomics2cytoscape")
stylexml <- system.file("extdata", "yugi2014styles.xml",
    package = "transomics2cytoscape")
suid <- create3Dnetwork(networkDataDir, networkLayers, stylexml)

layer1to2 <- system.file("extdata", "kinase2enzyme_gene2rea.tsv",
    package = "transomics2cytoscape")
suid <- createTransomicEdges(suid, layer1to2)

layer2to3 <- system.file("extdata", "allosteric.tsv",
    package = "transomics2cytoscape")
suid <- createTransomicEdges(suid, layer2to3)
```

Then, you should have a 3D view with layered networks and transomic
interactions between them.
(Note that you need to perform operations such as zooming out or adjusting the
camera angle.)

![Figure 3. Reproduction of Yugi's Trans-omics visualizaion (Yugi 2014)](../man/figures/allosteric_result.png)

# Conversion from EC number to KEGG reaction ID

For those who have seen the enzyme reaction database such as
[BRENDA](https://www.brenda-enzymes.org/) [@chang_brenda_2021],
it is not intuitive that the ID of the allosteric regulatory target
(8th column of the `allosteric.tsv`)
is the ID of the metabolic reaction rather than the EC number.

This is because KEGG uses the reaction ID instead of the EC number as the ID of
the pathway object of the global metabolism map.

So transomics2cytoscape has a function `ec2reaction` that converts the EC number
column of the Trans-omic interaction file into the KEGG reaction ID.

![Figure 4. How the ec2reaction function works](../man/figures/ec2reaction.png)

```{r}
ecnum <- system.file("extdata", "allosteric_ecnumber.tsv",
    package = "transomics2cytoscape")
ec2reaction(ecnum, 8, "allosteric.tsv")
```


# References