# 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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET 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?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
