2. Create microtable-object

Now that we’ve successfully imported five datasets, it’s time to combine them into a single object. This is a critical step, and here’s the catch: errors tend to pop up here if the data wasn’t properly imported or its integrity wasn’t checked earlier. If your datasets aren’t in the correct format, you won’t be able to proceed further—so double-check everything!

We’ll now create an object of the microtable class (let’s call it mt) using only the imported OTU (or ASV) table. This is the foundation of our analysis. Once created, you can use the class() function to confirm that the object is properly recognized as a microtable.

Here’s the process:

# In R6 class, '$new' is the method used to create a new object of class
# Let's try something simple first with just abundance table, the class can help you create a sample info table
mt <- microtable$new(otu_table = otu_table_16S)
class(mt) # Checking

Don’t panic if you see an error when running the code aobe—it’s not an error in fact, it’s expected. This happens because we haven’t provided metadata when creating the microtable yet. Even though we imported the metadata, we haven’t linked it to the table. Not to worry, the function will create a sample table automatically, and we’ll refine it later.

[1] "microtable" "R6" 

Now it’s time to add more depth to our microtable by incorporating the metadata (aka sample_info). Think of this as attaching the labels and context to the raw numbers—this is where your experiment’s story begins to take shape!

If you skip the previous step and try running this one directly, you’ll notice something interesting: the issue with the sample table doesn’t arise. Why? Because this time, we’re providing the metadata upfront, which eliminates the need for an automatically generated sample table.

mt <- microtable$new(sample_table = sample_info_16S, otu_table = otu_table_16S, tax_table = taxonomy_table_16s, phylo_tree = phylo_tree_16S)
mt
class(mt)

Just like we made sure the data import and formatting were done correctly, now’s the time to check if the micro table was created properly. This step is essential to ensure that all your data is aligned and ready for analysis. Take a moment to review the micro table and verify everything is in order before moving on to the next phase! I’ve already included some solutions for the common issues.

head(rownames(mt$otu_table))  # Check feature names in the ASV table
rownames(mt$otu_table) <- rownames(otu_table_16S) # resolves the issue
head(rownames(mt$otu_table))  # Check feature names in the ASV table

head(rownames(mt$sample_table)) # Check feature names in the Sample table
rownames(mt$sample_table) <- sample_info_16S$SampleID # resolves the issue

head(rownames(mt$sample_table)) # Check feature names in taxonomy table
#rownames(mt$tax_table) <- taxonomy_table_16s$Feature.ID # Set the row names to Feature.ID and reolve the issue
head(rownames(mt$tax_table)) # Set the row names to Feature.ID

One way to verify that your micro table is formatted properly is by running the command below. We’ll use this command down the line anyway, so if it doesn’t resolve within a few seconds, then we have a problem and need to address it.

mt$tidy_dataset() # Check if resolved
mt

If everything is fine, you should see something like this: pay attention to the matching numbers.

> mt
microtable-class object:
sample_table have 72 rows and 5 columns
otu_table have 21215 rows and 72 columns
tax_table have 21215 rows and 9 columns
phylo_tree have 21215 tips

If everything looks good with the taxonomy table and Feature.ID has been successfully set as the row names, we’re ready to move on and start filtering our data 🚀.

However, if something doesn’t look right, don’t ignore it. It’s important to troubleshoot and resolve any issues with the table before proceeding.