---
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(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 
# read 'basis' option
basis <- getOption("basis")
```

This vignette from the R package [canprot](https://github.com/jedick/canprot) version `r packageDescription("canprot")$Version` shows chemical metrics for proteins that are differentially expressed in halophiles under hyperosmotic or hypoosmotic conditions.
The analysis is described in more detail in a paper ([<span title="Uncovering chemical signatures of salinity gradients through compositional analysis of protein sequences">Dick et al., 2020</span>](https://doi.org/10.5194/bg-17-6145-2020)).
Abbreviations:

  * <i>Z</i><sub>C</sub> &ndash; average oxidation state of carbon.
  * <i>n</i><sub>H<sub>2</sub>O</sub> &ndash; stoichiometric hydration state per residue ([<span title="Uncovering chemical signatures of salinity gradients through compositional analysis of protein sequences">Dick et al., 2020</span>](https://doi.org/10.5194/bg-17-6145-2020)) computed using the **`r basis`** basis species (`r basis.text(basis)`, H~2~O, O~2~).
  * pI &ndash; isoelectric point; GRAVY &ndash; grand average of hydropathicity.
  * <i>n</i><sub>AA</sub> &ndash; protein length; MW &ndash; molecular weight per residue.

<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)
file <- paste0("osmotic_halo_", basis, ".csv")
write.csv(out, file, 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
