> For the complete documentation index, see [llms.txt](https://www.microbiomestat.wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.microbiomestat.wiki/setting-up-microbiomestat-installation-and-data-preparation/laying-the-foundation-creating-the-microbiomestat-data-object/fetching-data-from-mothur-into-microbiomestat.md).

# Importing Data from Mothur into MicrobiomeStat

This guide details the procedure to seamlessly import data generated by Mothur into the MicrobiomeStat environment.

{% file src="/files/9YQn8MwxPCISZVLhrk9q" %}
This compressed file contains the list file from Mothur, which typically encompasses OTU clustering information for various thresholds.
{% endfile %}

{% file src="/files/o0s4QSmxYOiQxGed8qZv" %}
The shared file provides a breakdown of the abundance of OTUs in each sample.
{% endfile %}

{% file src="/files/NoYO3XLiySJjcvqghlvL" %}
Group file indicating the sample assignment for each sequence.
{% endfile %}

{% file src="/files/yzitMiRNqCcroBr4dCWY" %}
Phylogenetic tree file representing the evolutionary relationships among OTUs.
{% endfile %}

```r
# Make sure the plyr package is installed
if (!require(plyr)) {
    install.packages("plyr")
    library(plyr)
} else {
    library(plyr)
}

# Specify the paths to your Mothur files
path_to_list_file <- "/path_to_your_files/esophagus.fn.list.gz"
path_to_group_file <- "/path_to_your_files/esophagus.good.groups.gz"
path_to_tree_file <- "/path_to_your_files/esophagus.tree.gz"
path_to_shared_file <- "/path_to_your_files/esophagus.fn.shared.gz"

# Import Mothur data into a MicrobiomeStat data object
data_obj <- mStat_import_mothur_as_data_obj(
    mothur_list_file = path_to_list_file,
    mothur_group_file = path_to_group_file,
    mothur_tree_file = path_to_tree_file,
    mothur_shared_file = path_to_shared_file
)

# After constructing data_obj, detach the plyr package to avoid conflicts with dplyr
if ("package:plyr" %in% search()) {
    detach("package:plyr", unload = TRUE)
    message("Detached plyr package to avoid potential conflicts with dplyr.")
}
```

The `mStat_import_mothur_as_data_obj` function facilitates the conversion of the Mothur dataset to the basic MicrobiomeStat data objects. Here are the key components:

* **mothur\_list\_file** (Optional): Mothur-generated list file.
* **mothur\_group\_file** (Optional): Group designation file from Mothur.
* **mothur\_tree\_file** (Optional): Phylogenetic tree representation.
* **mothur\_shared\_file** (Optional): OTU Abundance data across samples.
* **mothur\_constaxonomy\_file** (Optional): Classification of OTUs at various taxonomic levels.
* **parseFunction** (Optional): Custom function for taxonomy parsing, with 'parse\_taxonomy\_default' as an available option.

<figure><img src="/files/mYcLDf6VRn6OhG4nOcdZ" alt=""><figcaption><p>Structural overview of the `data_obj` generated after importing Mothur datasets into MicrobiomeStat.</p></figcaption></figure>
