Commit bebfbfe4 authored by Etienne Rifa's avatar Etienne Rifa
Browse files

Merge branch 'core_m'

parent a8b44692
Pipeline #27877 passed with stage
in 16 seconds
......@@ -81,6 +81,8 @@ importFrom(metacoder,heat_tree)
importFrom(metacoder,parse_phyloseq)
importFrom(metacoder,zero_low_counts)
importFrom(microbiome,aggregate_top_taxa)
importFrom(microbiome,core_members)
importFrom(microbiome,transform)
importFrom(nlme,lme)
importFrom(phangorn,NJ)
importFrom(phangorn,dist.ml)
......
#' core_soft_fun
#'
#' @description Define core microbiome, soft micriome and transitory microbiome.
#'
#' @param data A phyloseq object
#' @param fact Factor to test (must be in sample_variables(data))
#' @param group Choose which level of the factor, if NULL generate a list for each level.
#' @param freq frequence threshold of microbiome::core_members function
#' @param prev prevalence threshold of microbiome::core_members function
#'
#' @importFrom microbiome transform core_members
core_soft_fun <- function(data = NULL, fact = NULL, group = NULL, freq = 0.001, prev = 0.5, rank = "ASV"){
if(is.null(data)|is.null(fact)){stop("Require a phyloseq object, factor and group...")}
if(! any( sample_variables(data) == fact ) ){stop(glue::glue("{fact} is not in sample_variables(phyloseq_object)..."))}
if(rank == "ASV"){
glomps <- data
}else{
glomps <- tax_glom(data, taxrank = rank)
taxa_names(glomps) = glomps@tax_table@.Data[,rank]
}
fun2 <- function(glomps = glomps, fact = fact, group = group){
LL = list()
fun <- glue::glue("sub_phy <- subset_samples(glomps, {fact} == '{group}')")
eval(parse(text=fun))
sub_phy <- prune_taxa(taxa_sums(sub_phy) > 0, sub_phy)
sub_phy.rel <- microbiome::transform(sub_phy, "compositional")
#core
LL$core <- core.taxa.standard <- core_members(sub_phy.rel, detection = freq, prevalence = prev)
#soft in at least 1 sample
core.plus <- core_members(sub_phy.rel, detection = freq, prevalence = 1/nsamples(data))
LL$soft = setdiff(core.plus, core.taxa.standard)
# transit
LL$transit = setdiff(taxa_names(sub_phy.rel), core.plus)
return(LL)
}
if(!is.null(group)){
return(fun2(glomps = glomps, fact = fact , group = group))
}else{
LL2 = list()
for(group in levels(as.data.frame(as.matrix(sample_data(data)))[,fact])){
nlist = gsub(" ", "_" ,group)
fun <- glue::glue("LL2${nlist} <- fun2(glomps = glomps, fact = fact, group = '{group}')")
eval(parse(text=fun))
}
return(LL2)
}
}
#' List generator for venndiagram
#'
#' @description Output list to generate venn diagram with VENNFUN function.
#'
#' @param inlist Output of core_soft_fun() function
#' @param part which part of microbiome to output (core, soft or transit)
list_venn_fun <- function(inlist = NULL, part="core"){
if(! any(part == c("core", "soft", "transit"))){stop("Choose 'core', 'soft' or 'transit' for 'part' argument")}
outlist = list()
for( i in names(inlist)){
fun = glue::glue("outlist${i} = inlist${i}${part}")
eval(parse(text=fun))
}
return(outlist)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/core_soft.R
\name{core_soft_fun}
\alias{core_soft_fun}
\title{core_soft_fun}
\usage{
core_soft_fun(
data = NULL,
fact = NULL,
group = NULL,
freq = 0.001,
prev = 0.5,
rank = "ASV"
)
}
\arguments{
\item{data}{A phyloseq object}
\item{fact}{Factor to test (must be in sample_variables(data))}
\item{group}{Choose which level of the factor, if NULL generate a list for each level.}
\item{freq}{frequence threshold of microbiome::core_members function}
\item{prev}{prevalence threshold of microbiome::core_members function}
}
\description{
Define core microbiome, soft micriome and transitory microbiome.
}
......@@ -20,7 +20,8 @@ dada2_fun(
returnval = TRUE,
paired = TRUE,
trim_l = 15,
trim_r = 0
trim_r = 0,
orient_torrent = NULL
)
}
\arguments{
......@@ -54,6 +55,8 @@ dada2_fun(
\item{trim_r}{Trim right size.}
\item{orient_torrent}{Forward primer sequence to orient all reads to same strand.}
\item{pool}{option for dada function (FALSE, TRUE or "pseudo"), default is "pseudo". See ? dada.}
\item{torrent_trim}{Sequence length to trim at 3' and 5' for single end torrent data. (0 = no trim)}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/core_soft.R
\name{list_venn_fun}
\alias{list_venn_fun}
\title{List generator for venndiagram}
\usage{
list_venn_fun(inlist = NULL, part = "core")
}
\arguments{
\item{inlist}{Output of core_soft_fun() function}
\item{part}{which part of microbiome to output (core, soft or transit)}
}
\description{
Output list to generate venn diagram with VENNFUN function.
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment