library(vegan)
library(ROBITools)

litere_col_clean <- readRDS("litere_col_clean.rds")
litere_col_clean <- metabarcoding.data(reads = litere_col_clean$reads,
                                       motus = litere_col_clean$motus,
                                       samples = litere_col_clean$samp)

litere_bac_clean <- readRDS("litere_bac_clean.rds")
litere_bac_clean <- metabarcoding.data(reads = litere_bac_clean$reads,
                                       motus = litere_bac_clean$motus,
                                       samples = litere_bac_clean$samp)




litere_ins_clean <- readRDS("litere_ins_clean.rds")
litere_ins_clean <- metabarcoding.data(reads = litere_ins_clean$reads,
                                       motus = litere_ins_clean$motus,
                                       samples = litere_ins_clean$samp)

litere_euk_clean <- readRDS("litere_euk_clean.rds")
litere_euk_clean <- metabarcoding.data(reads = litere_euk_clean$reads,
                                       motus = litere_euk_clean$motus,
                                       samples = litere_euk_clean$samp)


# Remove rare motus

litere_col_norare <- litere_col_clean[,apply(decostand(litere_col_clean$reads,method = "total"),MARGIN = 2,max) >= 0.01]
litere_euk_norare <- litere_euk_clean[,apply(decostand(litere_euk_clean$reads,method = "total"),MARGIN = 2,max) >= 0.01]
litere_ins_norare <- litere_ins_clean[,apply(decostand(litere_ins_clean$reads,method = "total"),MARGIN = 2,max) >= 0.01]
litere_bac_norare <- litere_bac_clean[,apply(decostand(litere_bac_clean$reads,method = "total"),MARGIN = 2,max) >= 0.01]
