---
title: "Retrieve Feature Data"
author: "Nate D. Olson"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Vignette Title}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

## Overview  
* `metagenomeFeatures` and associated annotation packages can be used to obtain phylogentic trees, and representative sequences for 16S rRNA marker gene sequences when closed reference clustering is used.  
* QIITA (URL) is a public repository for sharing OTU tables and raw sequence data from 16S rRNA marker gene studies.  
* In this vignette we will demostrate using `metagenomeFeatures` and the Greengenes 16S rRNA database version 13.8 85\% OTUs to obtain a phylogenetic tree and representative sequences for __XYZ__ study obtained from QIITA.  

## Greengenes 13.8 85\% OTU MgDb
The gg 13.8 85% OTU is provided as part of the `metagenomeFeatures` package. 
```{r message = FALSE}
library(metagenomeFeatures)
gg85 <- get_gg13.8_85MgDb()
```

`gg85` is a `MgDb` class object with the taxonomic heirarchy, sequence data, and phylogeny for the Greengenes database clustered at the 0.85 similarity threshold. 
```{r}
gg85
```


##  QIITA Dataset 
For this vignette we are using 16S rRNA data from Rousk et al. 2010, a soil microbiome study, https://qiita.ucsd.edu/study/description/94. 
A BIOM and qiime mapping file for the study can be obtained from QIITA. 
A vector of Greengenes for the study cluster centers is included in this package for use in this vignette. 

```{r}
data_dir <- system.file("extdata", package = "metagenomeFeatures")
soil_gg_ids <-  readRDS(file.path(data_dir, "qiita_study_94_gg_ids.RDS"))
```

## Obtaining Sequences and Phylogenetic Tree 
```{r}
soil_mgF <- annotateFeatures(gg85, soil_gg_ids)
```

The resulting `mgFeatures` class object has the taxonomic heirarchy, phylogeny, and sequence data for the study OTUs. 
```{r}
soil_mgF
```

Sequence data
```{r}
mgF_seq(soil_mgF)
```

Tree data 
```{r}
mgF_tree(soil_mgF)
```

