---
title: "PTM Analysis"
author: "Anthony Wu"
package: MSstatsBioNet
output: BiocStyle::html_document
vignette: >
  %\VignetteIndexEntry{MSstatsBioNet: PTM Analysis}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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


# Installation

Run this code below to install MSstatsBioNet from bioconductor

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

BiocManager::install("MSstatsBioNet")
```

## Dataset

We will be taking a subset of the dataset found in this [paper](https://www.biorxiv.org/content/10.1101/2024.10.21.619348v1).  The table is the output of the MSstatsPTM function `groupComparisonPTM` (filtered down to the columns that are actually needed)

```{r}
input = data.table::fread(system.file(
    "extdata/garrido-2024.csv",
    package = "MSstatsBioNet"
))
head(input)
```

## ID Conversion

First, we need to convert the group comparison results to a format that can be
processed by INDRA.  We can use the `annotateProteinInfoFromIndra` function
to obtain these mappings.

In the below example, we convert uniprot IDs to their corresponding Hgnc IDs. We
can also extract other information, such as hgnc gene name and protein function.

```{r}
library(MSstatsBioNet)
annotated_df = annotateProteinInfoFromIndra(input, "Uniprot")
head(annotated_df)
```

## Subnetwork Query

The package provides a function `getSubnetworkFromIndra` that retrieves a
subnetwork of proteins from the INDRA database based on differential abundance
analysis results.  This function may help finding off target subnetworks.  

```{r}
subnetwork <- getSubnetworkFromIndra(annotated_df, pvalueCutoff = 0.05, statement_types = c("Phosphorylation"), logfc_cutoff = 1, force_include_proteins = c("P00533_Y1110"))
head(subnetwork$nodes)
head(subnetwork$edges)
```

## Network Visualization

Visualize the subnetwork on your browser

```{r}
previewNetworkInBrowser(subnetwork$nodes, subnetwork$edges, displayLabelType = "hgncName")
```

# Session info

```{r}
sessionInfo()
```
