---
title: "Importing from phyloseq"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Importing from phyloseq}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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

```{r setup}
if (!requireNamespace("phyloseq", quietly = TRUE)) {
  message("Suggested package: 'phyloseq' is not installed")
  knitr::opts_chunk$set(eval = FALSE)
} else {
  library(phyloseq)
}
library(strollur)
```

`strollur` includes functionality for the reading and writing of `phyloseq` objects. To convert a phyloseq object to a strollur object, you need to run the `strollur::read_phyloseq()` function. 

```{r}
phyloseq_object <- readRDS(strollur_example("GlobalPatterns.RDS"))
class(phyloseq_object)
strollur_object <- strollur::read_phyloseq(phyloseq_object)
class(strollur_object)
```

Now that are phyloseq object is converted into a strollur object, we can utilize functions like `strollur::count()`, `strollur::abundance()`, and `strollur::names()` to inspect the data. 
```{r rdataset_functions}
strollur::count(strollur_object, type = "sample")
head(strollur::names(strollur_object, type = "sequence"))
head(strollur::abundance(strollur_object, type = "sequence"))
```

Furthermore, we can output strollur objects as phyloseq objects using the `strollur::write_phyloseq()` function.

```{r write_phyloseq} 
phyloseq_object <- strollur::write_phyloseq(strollur_object)
phyloseq_object

miseq <- strollur::miseq_sop_example()
miseq_phyloseq <- strollur::write_phyloseq(miseq)
miseq_phyloseq
```

