#export data into R. This code uses qiime2020.8 and R version 3.6.3 #in qiime2 #step 1: export OTU table qiime tools export \ --input-path table-phyla-no-mt-no-infrequent.qza \ --output-path phyloseq #step1b: convert to tsv biom convert \ -i phyloseq/feature-table.biom \ -o phyloseq/feature-table.txt \ --to-tsv #Step2: export taxonomy table qiime tools export \ --input-path taxonomy_16S.qza \ --output-path phyloseq #Step3: export tree qiime tools export \ --input-path unrooted-tree.qza \ --output-path phyloseq #in R #install packages we need for the session library(tidyverse) library(ggplot2) library(phyloseq) library(ape) library(xlsx) library(dplyr) library(vegan) library(RColorBrewer) #set working directory setwd("~/directory name") #read files generated in qiime otu <- read.table(file = "filepath/feature-table.txt",header = TRUE,fill = TRUE) head(otu) tax <- read.table(file = "filepath/taxonomy.tsv",header = TRUE, sep = '\t') head(tax) #merge them to make one file merged_file <- merge(otu,tax,by.x=c("OTUID"),by.y=c("OTUID")) head(merged_file) #output merged text file write.table(merged_file, file = "combined_otu_tax.txt", sep = '\t', col.names = TRUE, row.names = FALSE) #splitting the merged file as two separate documents - done in excel #and saved as csv otu_table = read.csv("otu_matrix.csv", sep=",", row.names=1) otu_table = as.matrix(otu_table) head(otu_table) taxonomy = read.csv("taxonomy.csv", sep=",", row.names=1) taxonomy = as.matrix(taxonomy) head(taxonomy) #import metadata and the tree #metadata = read.table("sample-metadata.tsv", row.names=1, fill = TRUE) #metadata metadata <- read.xlsx("sample-metadata.xlsx",sheetName = "sample-metadata", row.names=1) phy_tree = read_tree("tree.nwk") #convert otu,tax and metadata to phyloseq objects OTU = otu_table(otu_table,taxa_are_rows=TRUE) TAX = tax_table(taxonomy) META = sample_data(metadata) taxa_names(TAX) taxa_names(OTU) taxa_names(phy_tree) #now combine them in phyloseq physeq = phyloseq(OTU,TAX,META,phy_tree) physeq