---
title: "SomaPreg, Aptamer-Based Proteomic Standards in Normal Pregnancy."
author: "Gaurav Bhatti, Bogdan Done, Adi L. Tarca"
date: "`r Sys.Date()`"
output:
  html_document:
    self_contained: no
vignette: >
  %\VignetteIndexEntry{Vignette Title}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---


## Introduction

An expanded verion of the Somascan aptamer-based platform [1,2] allows the measuring of over 7000 proteins [3]. The goal of this SomaPreg package is to define expected values for gestation age and maternal characteristics to enable the development of predictive models in obstretics. Maternal plasma protein abundance was determined using the SOMAmer (Slow Off-rate Modified Aptamers) platform and its reagents. 

The package SomaPreg implements linear mixed-effect models with quadratic splines (one knot) for predicting protein abundance as a function of gestational age. Maternal age, parity, body mass index, and smoking status were also considered as covariates and retained if they improved the model fit for a given protein. Covariate selection was based on the significance (p<0.05) of a likelihood ratio test implemented in the glmerselect function available in the StatisticalModels package under the R statistical language and environment (www.r-project.org). Linear mixed-effects models were fit using the lme4 package [4]. To account for the repeated, and possible correlated, measurements from the same patient, the models included patient identifiers as random effects.


## Input data

Two input data frames are necessary in order to employ all the features of the SomaPreg package:

1. ano 
  : data frame that contains the sample annotations to be used as predictors by the models, namely GA (gestational age), Smoker (smoking status), BMI (body mass index), Age (maternal age) and Nulliparous (mother's nulliparity). 
1. protdat 
  : data frame that contains the relative fluorescence units (RFU) for the proteins and samples of interest. 

The five predictors from the ano data frame are mandatory (their names should kept as listed). The rownames of the ano data frame should be the samples of the experiment. prodat data frame should reference the same samples as the ano data frame. An example of ano and prodat is listed below:

```{r, eval = FALSE}
library(SomaPreg)
ano = read.csv("ano.csv")
protdat = read.csv("protdat.csv")
```

```{r, echo = FALSE}
library(SomaPreg)
ano = anosel
protdat = protdatsel
```

```{r}
head(ano)

protdat[1:6,1:6]
```

## Predict protein abundance

predictRFU function is used to predict the protein abundance expressed as relative fluorescence units (RFU), for the proteins and samples provided by the user:
```{r, warning = FALSE}
predictRFU(protvect=rownames(protdat),ano)[1:6,1:4]
```

We can plot the protein abundance from protdat data frame provided by the user, across all samples, with the plotRFU function:
```{r, warning = FALSE}
plotRFU(prot="PGF.3078.1",protdat,ano)
```


## Compute MOMs
computeMOM calculates the predicted the log2 multiple of the mean (MoM) of protein abundance expressed as relative fluorescence units (RFU), for the proteins and samples provided by the user:
```{r, warning = FALSE}
computeMOM(rownames(protdat)[1:4],protdat,ano)[1:6,]
```

The estimates of the log2 multiple of the mean (MoM) of protein abundance predicted with computeMOM can be plotted with the plotMOM function:
```{r, warning = FALSE}
plotMOM(prot="PGF.3078.1",protdat,ano)
```


## Plot protein trend
log2 RFU trend for user selected values of the predictors can be plotted with the plotProtTrend function. The user selected values are given in a list called ano. This ano list contains one value for each predictor in the model, except for one of the predictors, which will have at least two values, and will be used for comparisons of the trends. Please note that the ano list argument of the plotProtTrend function is different from the ano input data frame.
```{r, warning = FALSE}
plotProtTrend(prot="PGF.3078.1",ano=list(Smoker="0",BMI=c(22,31),Age=24,Nulliparous=c("1")),
	legendgroups=c("BMI, 25th percentile","BMI, 75th percentile"))
```

The predictor with multiple values, used for the comparison of the trends, should have the same number of levels and colors in the legend. The vector of multiple values of this predictor can be either numeric (like BMI in the example above) or character (like Smoker in the example below):
```{r, warning = FALSE}
plotProtTrend(prot="PGF.3078.1",ano=list(Smoker=c("0","1"),BMI=26,Age=24,Nulliparous="1"),
	legendgroups=c("Non-smoker","Smoker"),ylim=c(9,14))
```

Please a allow a minute for the first call to any of the functions in the package to load lazily the models.


## References

1. DAVIES DR, GELINAS AD, ZHANG C, et al. Unique motifs and hydrophobic interactions shape the binding of modified DNA ligands to protein targets. Proceedings of the National Academy of Sciences of the United States of America 2012;109:19971-6.

1. GOLD L, AYERS D, BERTINO J, et al. Aptamer-based multiplexed proteomic technology for biomarker discovery. PloS one 2010;5:e15004.

1. SOMALOGIC. SOMAmer Technical notes: http://www.somalogic.com/somalogic/media/Assets/PDFs/SSM-017-Rev-3-SOMAmer-Technical-Note-3-7-15.pdf (vol March 3, 2016).

1. BATES D, MÄCHLER M, BOLKER B, WALKER S. Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical Software 2015;67.



