---
title: "Osmotic Stress in Halophiles"
output:
  html_vignette:
    mathjax: null
vignette: >
  %\VignetteIndexEntry{Osmotic Stress in Halophiles}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
bibliography: cpdat.bib
csl: peerj.csl
---

```{r setup, include=FALSE}
library(canprot)
library(CHNOSZ)
library(knitr)
## use pngquant to reduce size of PNG images
knit_hooks$set(pngquant = hook_pngquant)
pngquant <- "--speed=1 --quality=0-25"
# in case pngquant isn't available (R-Forge?)
if (!nzchar(Sys.which("pngquant"))) pngquant <- NULL 
```

This vignette from the R package [canprot](https://github.com/jedick/canprot) version `r packageDescription("canprot")$Version` shows compositional metrics for proteins that are differentially expressed in halophiles under hyperosmotic or hypoosmotic conditions.
Abbreviations:

  * <i>Z</i><sub>C</sub> &ndash; carbon oxidation state; <i>n</i><sub>H<sub>2</sub>O</sub> &ndash; stoichiometric hydration state per residue ([<span title="Distinct trends in chemical composition of proteins from metagenomes in redox and salinity gradients">Dick et al., 2020</span>](https://doi.org/10.1101/2020.04.01.020008); [<span title="Water as a reactant in the differential expression of proteins in cancer">Dick, 2020</a>](https://doi.org/10.1101/2020.04.09.035022)).
  * <i>n</i><sub>AA</sub> &ndash; protein length; MW &ndash; molecular weight per residue.


```{r options, echo=FALSE}
options(width = 90)
```

<style type="text/css">
body {
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}
</style>

```{r datasets}
datasets <- pdat_osmotic_halo(2020)
```

```{r comptab, results="hide", message=FALSE, echo = FALSE}
pdat1 <- lapply(datasets, pdat_osmotic_halo)
comptab1 <- lapply(pdat1, get_comptab)
comptab2 <- lapply(pdat1, get_comptab, "pI", "GRAVY")
comptab3 <- lapply(pdat1, get_comptab, "nAA", "MW")
```

Differences are calculated as (median value for up-regulated proteins) - (median value for down-regulated proteins).
Circles and squares represent hyperosmotic and hypoosmotic experiments, respectively.

```{r diffplot, fig.width=9, fig.height=8, fig.align = "center", echo = FALSE, pngquant = pngquant}
layout(matrix(c(0, 2, 1, 2, 1, 3, 0, 3), nrow = 2))
par(cex = 1, mar = c(4, 4, 1, 1), mgp = c(2.5, 1, 0))
pch <- ifelse(grepl("hypoosmotic", datasets), 0, 1)
diffplot(comptab1, labtext = NA, contour = FALSE, pch = pch)
diffplot(comptab2, c("pI", "GRAVY"), labtext = NA, contour = FALSE, pch = pch)
diffplot(comptab3, c("nAA", "MW"), labtext = NA, contour = FALSE, pch = pch)
```

In the table, values of &Delta;<i>Z</i><sub>C</sub>, &Delta;<i>n</i><sub>H<sub>2</sub>O</sub>, and &Delta;GRAVY are multiplied by 1000, values of &Delta;pI and &Delta;MW are multiplied by 100, and negative values are shown in bold.
Abbreviations:

  * _n_~down~ &ndash; number of down-regulated proteins; _n_~up~ &ndash; number of up-regulated proteins.

```{r xsummary, results="asis", echo = FALSE}
library(xtable)
out <- xsummary3(comptab1, comptab2, comptab3)
# round values and include dataset tags
tags <- sapply(sapply(strsplit(datasets, "="), "[", -1), paste, collapse = ";")
out <- cbind(out[, 1:2], tags = tags, out[, 3:19])
out[, 6:20] <- round(out[, 6:20], 4)
write.csv(out, "osmotic_halo.csv", row.names = FALSE, quote = 2)
```

## Data Sources

__a__. __b__. Tables 1 and 2 of @LRB+09.
__c__. __d__. Table S-1 of @ZLZ+16. Values of reporter intensities at each condition (6%, 10%, and 17.5% NaCl) were quantile normalized (R function preprocessCore::normalize.quantiles); normalized values were used to compute intensity ratios (6% / 10% NaCl and 17.5% / 10% NaCl). Only proteins with expression ratios > 1.3 in either direction [@ZLZ+16], p-values < 0.05, and at least 2 peptides were included.
__e__. __f__. Tables S2 and S3 of @LLYL17.
__g__. __h__. Supporting Table 1C of @JSP+19. Only proteins with at least 2-fold expression difference and marked as significant were included.

## References
