---
title: "Basis Species Comparison"
output: html_vignette
vignette: >
  %\VignetteIndexEntry{Basis Species Comparison}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
bibliography: data_sources.bib
csl: peerj.csl
---

```{r HTML, include=FALSE}
## some frequently used HTML expressions
# use lowercase here because these tend to be variable names in the examples
zc <- "<i>Z</i><sub>C</sub>"
o2 <- "O<sub>2</sub>"
h2o <- "H<sub>2</sub>O"
```

This [<span style="color:red;text-decoration:underline">vignette</span>](http://chnosz.net/canprot/doc/index.html) from the R package [canprot](http://github.com/jedick/canprot) shows projections of protein composition made using two sets of basis species.
Using the `CHNOS` basis species (CO<sub>2</sub>, NH<sub>3</sub>, H<sub>2</sub>S, `r h2o`, `r o2`), the plots show that *n*&#773;<sub>`r h2o`</sub> and *n*&#773;<sub>`r o2`</sub>, i.e. the number of `r h2o` and `r o2` in the formation per residue of the proteins from basis species, are both moderately correlated with `r zc` (average oxidation state of carbon).
Using the `QEC` basis species (glutamine, glutamic acid, cysteine, `r h2o`, `r o2`), we find that *n*&#773;<sub>`r o2`</sub> is strongly correlated with `r zc`, but *n*&#773;<sub>`r h2o`</sub> shows very little correlation.
Accordingly, the `QEC` basis more clearly exposes two compositional variables -- oxidation state and hydration state -- in proteomic data.

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

First, load the `canprot` and `CHNOSZ` packages.

```{r canprot, message=FALSE}
library(canprot)
library(CHNOSZ)
```

Here we define some labels used in the plot.

```{r labels}
nH2Olab <- expression(bar(italic(n))[H[2] * O])
nO2lab <- expression(bar(italic(n))[O[2]])
ZClab <- expression(italic(Z)[C])
QEClab <- CHNOSZ::syslab(c("glutamine", "glutamic acid", "cysteine", "H2O", "O2"))
CHNOSlab <- CHNOSZ::syslab(c("CO2", "NH3", "H2S", "H2O", "O2"))
```

Next, get the amino acid compositions of all proteins in the UniProt human proteome and calculate the protein formulas and `r zc`.
Note that `r zc` is a sum of elemental ratios and is independent of the choice of basis species.

```{r aa_formula}
aa <- get("human_base", canprot)
protein.formula <- CHNOSZ::protein.formula(aa)
ZC <- CHNOSZ::ZC(protein.formula)
```

Now set up the figure and plot the per-residue compositions of the proteins projected into different sets of basis species.

```{r basis_comp, fig.width=6, fig.height=6, fig.align="center"}
par(mfrow = c(2, 2))
par(mar = c(4, 4, 2.5, 1))
par(cex = 1.1)
par(mgp = c(2.5, 1, 0))
for(basis in c("QEC", "CHNOS")) {
  CHNOSZ::basis(basis)
  protein.basis <- CHNOSZ::protein.basis(aa)
  protein.length <- CHNOSZ::protein.length(aa)
  residue.basis <- protein.basis / protein.length
  smoothScatter(ZC, residue.basis[, "O2"], xlab = ZClab, ylab = nO2lab)
  smoothScatter(ZC, residue.basis[, "H2O"], xlab = ZClab, ylab = nH2Olab)
  if(basis=="QEC") mtext(QEClab, outer = TRUE, cex = 1.2, line = -1.5)
  if(basis=="CHNOS") mtext(CHNOSlab, outer = TRUE, cex = 1.2, line = -15)
}
```

This figure has been published as Figure S1 of Dick, 2017 (Chemical composition and the potential for proteomic transformation in cancer, hypoxia, and hyperosmotic stress. [*PeerJ* 5:e3421](https://doi.org/10.7717/peerj.3421)).
