`r opts_chunk$set(cache=TRUE, fig.width=8)`
<link href="http://joey711.github.com/phyloseq/markdown.css" rel="stylesheet"></link>

# Load pre-imported HMPv35 data

## Load phyloseq package
```{r, message=FALSE, warning=FALSE}
library("phyloseq"); packageVersion("phyloseq")
date()
```

## Load HMP data
The data was previously imported when [the HMP import demo](HMP_import_example.html) was interpreted and built. At the end of that demo is a `save` command that stores the `HMPv35` R data object in a compact R binary form that is easy to re-load back into R. That same data file is saved in the phyloseq-demo repository [here](https://raw.github.com/joey711/phyloseq-demo/gh-pages/HMPv35.RData).

If you've already downloaded [the HMPv35.RData binary file](https://raw.github.com/joey711/phyloseq-demo/gh-pages/HMPv35.RData) to the working directory of your current R session, then you can easily `load` the `HMPv35` data into your workspace roughly 100X faster than to re-import the data from the raw files:
```{r}
system.time(load("HMPv35.RData"))
```


### Investigate the phyloseq-class representation of the data
```{r}
HMPv35
```
```{r}
rank_names(HMPv35)
```

Here is a way to check for the presence of particular taxonomic elements in the dataset.
```{r}
all( tax_table(HMPv35)[, "Rank1"] == "Root" )
any( "Crenarchaeota" %in% tax_table(HMPv35)[, "Phylum"] )
any( "Bacteroidetes" %in% tax_table(HMPv35)[, "Phylum"] )
any( "Firmicutes" %in% tax_table(HMPv35)[, "Phylum"] )
```


### Root the tree
Is the tree rooted?
```{r}
is.rooted(phy_tree(HMPv35))
```

This is how you could root (verb) the tree in `HMPv35` by randomly selecting an OTU as outgroup to root the tree
```{r}
phy_tree(HMPv35) = root(phy_tree(HMPv35), sample(taxa_names(HMPv35), 1), resolve.root=TRUE)
phy_tree(HMPv35)
```


### Richness
```{r HMPv35-richness-plot, fig.width=16}
sample_variables(HMPv35)
levels(sample_data(HMPv35)$HMPbodysubsite)
HMPv35saliva = subset_samples(HMPv35, HMPbodysubsite=="Saliva")
HMPv35saliva
# plot_richness(HMPv35saliva, x="HMPbodysubsite", color="sex")
```

