---
title: "The auxiliary commands which can help to the users"
author: "Selcen Ari"
date: "`r Sys.Date()`"
output: 
  rmarkdown::html_vignette:
   toc: true
vignette: >
  %\VignetteIndexEntry{auxiliary_commands}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup, warning= FALSE, message=FALSE}
library(ceRNAnetsim)
```

# 1. Introduction

In the other package vignettes, usage of ceRNAnetsim is explained in details. But in this vignette, some of commands which facitate to use of other vignettes.

# 2. Installation

```{r, eval=FALSE}
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("ceRNAnetsim")
```

# 3. Selection of perturbing element from dataset

```{r}
data("TCGA_E9_A1N5_tumor")
data("TCGA_E9_A1N5_normal")
data("mirtarbasegene")
data("TCGA_E9_A1N5_mirnanormal")
```

## 3.1. Selection of HIST1H3H gene at vignette [How does the system behave in mirtarbase dataset without interaction factors?](https://selcenari.github.io/ceRNAnetsim/articles/mirtarbase_example.html)

```{r}
TCGA_E9_A1N5_mirnanormal %>%
  inner_join(mirtarbasegene, by= "miRNA") %>%
  inner_join(TCGA_E9_A1N5_normal, 
             by = c("Target"= "external_gene_name")) %>%
  select(Target, miRNA, total_read, gene_expression) %>%
  distinct() -> TCGA_E9_A1N5_mirnagene
```


```{r}
TCGA_E9_A1N5_tumor%>%
  inner_join(TCGA_E9_A1N5_normal, by= "external_gene_name")%>%
  select(patient = patient.x, 
         external_gene_name, 
         tumor_exp = gene_expression.x, 
         normal_exp = gene_expression.y)%>%
  distinct()%>%
  inner_join(TCGA_E9_A1N5_mirnagene, by = c("external_gene_name"= "Target"))%>%
  filter(tumor_exp != 0, normal_exp != 0)%>%
  mutate(FC= tumor_exp/normal_exp)%>%
  filter(external_gene_name== "HIST1H3H")

#HIST1H3H: interacts with various miRNA in dataset, so we can say that HIST1H3H is non-isolated competing element and increases to 30-fold.

```

## 3.2. Selection of ACTB gene at vignette [How does the system behave in mirtarbase dataset without interaction factors?](https://selcenari.github.io/ceRNAnetsim/articles/mirtarbase_example.html)

```{r}
TCGA_E9_A1N5_tumor%>%
  inner_join(TCGA_E9_A1N5_normal, by= "external_gene_name") %>%
  select(patient = patient.x, 
         external_gene_name, 
         tumor_exp = gene_expression.x, 
         normal_exp = gene_expression.y) %>%
  distinct() %>%
  inner_join(TCGA_E9_A1N5_mirnagene, 
             by = c("external_gene_name"= "Target")) %>%
  filter(tumor_exp != 0, normal_exp != 0) %>%
  mutate(FC= tumor_exp/normal_exp) %>%
  filter(external_gene_name == "ACTB")

#ACTB: interacts with various miRNA in dataset, so ACTB is not isolated node in network and increases to 1.87-fold.

```

## 4. Determination of ACTB gene perturbation efficiency with different expression level changes

Firstly, clean dataset as individual gene has one expression value. And then filter genes which have expression values greater than 10.

```{r}
TCGA_E9_A1N5_mirnagene %>%    
  group_by(Target) %>%        
  mutate(gene_expression= max(gene_expression)) %>%
  distinct() %>%
  ungroup() -> TCGA_E9_A1N5_mirnagene

TCGA_E9_A1N5_mirnagene%>%
  filter(gene_expression > 10)->TCGA_E9_A1N5_mirnagene

```

We can determine perturbation efficiency of an element on entire network as following:

```{r, warning=FALSE, eval=FALSE}
TCGA_E9_A1N5_mirnagene %>% 
  priming_graph(competing_count = gene_expression, 
                miRNA_count = total_read)%>%
  calc_perturbation(node_name= "ACTB", cycle=10, how= 1.87,limit = 0.1)
```

On the other hand, the perturbation eficiency of ATCB gene is higher, when this gene is regulated with 30-fold upregulation like in HIST1H3H.

```{r, warning=FALSE, eval=FALSE}
TCGA_E9_A1N5_mirnagene %>% 
  priming_graph(competing_count = gene_expression, 
                miRNA_count = total_read)%>%
  calc_perturbation(node_name= "ACTB", cycle=10, how= 30,limit = 0.1)
```

# 5. Session Info
```{r sessioninfo}
sessionInfo()
```
