# Introduction

## heavy-SIP method workflow:

Prior to the development of these HTS-SIP analysis methods, DNA- and RNA-SIP experiments that utilized Sanger or high throughput sequencing were usually analyzed with standard statistical processes (e.g. t-tests), in order to identify incorporators. Previous work suggests that these methods generally have low senstivity and/or high false positive rates when applied to sequence data. Here, these analysis methods will be referred to “heavy-SIP” methods. While the work of Youngblut et al., (https://doi.org/10.3389/fmicb.2018.00570) suggests that HR-SIP analysis methods (eg., MW-HR-SIP) should be used for processing HTS-SIP datasets, the HTSSIP R package provides heavy-SIP methods so researchers have the option of using these methods and making their own comparisons to HR-SIP methods.

heavy-SIP is performed with the `heavy_SIP()` function, which consists of multiple possible tests. See `?heavy_SIP` for more details. This vignette demonstrates the use of `heavy_SIP()`.

# Initialization

First, let's load some packages including `HTSSIP`.

    library(dplyr)
    library(ggplot2)
    library(HTSSIP)

    # adjusted P-value cutoff
    padj_cutoff = 0.1

# Unreplicated dataset

For unreplicated datasets (no experiment replicates of controls or treatments), the options are limited on how to identify incorporators.

## Parsing the dataset

We will be using a dataset that is already parsed. See HTSSIP introduction vignette for a description on why dataset parsing (all treatment-control comparisons) is needed.

    physeq_S2D2_l

    ## $`(Substrate=='12C-Con' & Day=='3') | (Substrate=='13C-Cel' & Day == '3')`
    ## phyloseq-class experiment-level object
    ## otu_table()   OTU Table:         [ 1072 taxa and 46 samples ]
    ## sample_data() Sample Data:       [ 46 samples by 17 sample variables ]
    ## tax_table()   Taxonomy Table:    [ 1072 taxa by 8 taxonomic ranks ]
    ## phy_tree()    Phylogenetic Tree: [ 1072 tips and 1071 internal nodes ]
    ##
    ## $`(Substrate=='12C-Con' & Day=='14') | (Substrate=='13C-Cel' & Day == '14')`
    ## phyloseq-class experiment-level object
    ## otu_table()   OTU Table:         [ 1072 taxa and 46 samples ]
    ## sample_data() Sample Data:       [ 46 samples by 17 sample variables ]
    ## tax_table()   Taxonomy Table:    [ 1072 taxa by 8 taxonomic ranks ]
    ## phy_tree()    Phylogenetic Tree: [ 1072 tips and 1071 internal nodes ]
    ##
    ## $`(Substrate=='12C-Con' & Day=='14') | (Substrate=='13C-Glu' & Day == '14')`
    ## phyloseq-class experiment-level object
    ## otu_table()   OTU Table:         [ 1072 taxa and 47 samples ]
    ## sample_data() Sample Data:       [ 47 samples by 17 sample variables ]
    ## tax_table()   Taxonomy Table:    [ 1072 taxa by 8 taxonomic ranks ]
    ## phy_tree()    Phylogenetic Tree: [ 1072 tips and 1071 internal nodes ]
    ##
    ## $`(Substrate=='12C-Con' & Day=='3') | (Substrate=='13C-Glu' & Day == '3')`
    ## phyloseq-class experiment-level object
    ## otu_table()   OTU Table:         [ 1072 taxa and 46 samples ]
    ## sample_data() Sample Data:       [ 46 samples by 17 sample variables ]
    ## tax_table()   Taxonomy Table:    [ 1072 taxa by 8 taxonomic ranks ]
    ## phy_tree()    Phylogenetic Tree: [ 1072 tips and 1071 internal nodes ]

# One treatment-control comparison

First, we'll just focus on 1 treatment-control comparison. Let's get the individual phyloseq object.

    physeq = physeq_S2D2_l[[1]]
    physeq

    ## phyloseq-class experiment-level object
    ## otu_table()   OTU Table:         [ 1072 taxa and 46 samples ]
    ## sample_data() Sample Data:       [ 46 samples by 17 sample variables ]
    ## tax_table()   Taxonomy Table:    [ 1072 taxa by 8 taxonomic ranks ]
    ## phy_tree()    Phylogenetic Tree: [ 1072 tips and 1071 internal nodes ]

Let's check that the samples belong to either a 13C-treatment or 12C-control.

    physeq %>% sample_data %>% .$Substrate %>% table

    ## .
    ## 12C-Con 13C-Cel
    ##      23      23

Since this dataset is an unreplicated comparison between treatment & control, we are just going to use the 'binary' method, which will call incorporators if they are present in the “heavy” gradient fractions of the treatment and not present in the “heavy” fractions of the control. Note that the “heavy” fractions are user-defined.

    df_res = heavy_SIP(physeq, ex="Substrate=='12C-Con'",
                       comparison='H-v-H', hypo_test='binary')
    df_res %>% head(n=3)

    ##         statistic  p padj
    ## OTU.514         0 NA   NA
    ## OTU.729         0 NA   NA
    ## OTU.322         0 NA   NA

Since no real statistical test, the “statistic” is just 0 (not an incorporator) or 1 (an incorporator). Also, the “p” and “padj” columns are thus “NA”.

How many “incorporators”?

    df_res$statistic %>% table

    ## .
    ##   0   1
    ## 980  65

# Replicated dataset

Experimental replicates allows us to use tradional hypothesis testing (e.g., t-tests) for determining significantly differ OTU abundances between treatment and controls. Note that there is a reason why more suffisticated statistical methods have been developed for assessing differentially abundant features in high throughput sequencing datasets (e.g., DESeq2, EdgeR, or MetagenomeSeq). The traditional methods don't account for many challenging aspects of identifying statistically different abundances in sequence data such as i) a high number of multiple hypotheses ii) zero-inflation iii) compositional data (relative abundances; the sum-to-one constraint).

With that said, let's try out these heavy-SIP methods on a replicated dataset, with 3 experimental replicates of the control and treatment (total gradients = 6)

    physeq_rep3

    ## phyloseq-class experiment-level object
    ## otu_table()   OTU Table:         [ 6 taxa and 144 samples ]
    ## sample_data() Sample Data:       [ 144 samples by 5 sample variables ]

    physeq_rep3 %>% sample_data %>% head(n=3)

    ## Sample Data:        [3 samples by 5 sample variables]:
    ##                             Gradient Buoyant_density Fraction Treatment
    ## 12C-Con_rep1_1.668185_1 12C-Con_rep1        1.668185        1   12C-Con
    ## 12C-Con_rep1_1.680254_2 12C-Con_rep1        1.680254        2   12C-Con
    ## 12C-Con_rep1_1.679431_3 12C-Con_rep1        1.679431        3   12C-Con
    ##                         Replicate
    ## 12C-Con_rep1_1.668185_1         1
    ## 12C-Con_rep1_1.680254_2         1
    ## 12C-Con_rep1_1.679431_3         1

## t-tests

To compare “heavy” fractions in the treatment versus “heavy” fractions in the control, we will use the “H-v-H” comparison method. See `?heavy_SIP` for details on other possible comparisons.

    df_res = heavy_SIP(physeq_rep3, ex="Treatment=='12C-Con'",
                       comparison='H-v-H', hypo_test='t-test')
    df_res %>% head(n=3)

    ##         statistic         p      padj
    ## OTU.1 -0.09563691 0.5336654 0.5641843
    ## OTU.2 -0.18450596 0.5641843 0.5641843
    ## OTU.3  1.14859160 0.2280138 0.3519149

“padj” is p-values adjusted with the Benjamini Hochberg method.

How many incorporators?

    df_res %>%
      filter(padj < padj_cutoff) %>%
      nrow

    ## [1] 0

No incorporators. Obviously, the sensitivity of this method is pretty low. What's the distribution of p-values?

    df_res$p %>% summary

    ##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
    ##  0.1619  0.2180  0.2313  0.3228  0.4589  0.5642

## Mann Whitney U test

Does anything change when we use a nonparametric test? Here, we will use the Mann Whitney U test (a nonparametric t-test).

    df_res = heavy_SIP(physeq_rep3, ex="Treatment=='12C-Con'",
                       comparison='H-v-H', hypo_test='wilcox')
    df_res %>% head(n=3)

    ##       statistic         p      padj
    ## OTU.1         2 0.6666667 0.6666667
    ## OTU.2         2 0.6666667 0.6666667
    ## OTU.3         4 0.1666667 0.2500000

What's the p-value and adjusted-pvalue distribution?

    df_res$p %>% summary %>% print

    ##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
    ##  0.1667  0.1667  0.1667  0.3333  0.5417  0.6667

    df_res$padj %>% summary %>% print

    ##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
    ##  0.2500  0.2500  0.2500  0.3889  0.5625  0.6667

Again, no incorporators. The change in abundances must be pretty dramatic for heavy-SIP methods to ID incorporators, especially when there's many multiple hypotheses.

# Session info

    sessionInfo()

    ## R version 3.4.3 (2017-11-30)
    ## Platform: x86_64-apple-darwin15.6.0 (64-bit)
    ## Running under: macOS Sierra 10.12.6
    ##
    ## Matrix products: default
    ## BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
    ## LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
    ##
    ## locale:
    ## [1] C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    ##
    ## attached base packages:
    ## [1] stats     graphics  grDevices utils     datasets  methods   base
    ##
    ## other attached packages:
    ## [1] phyloseq_1.22.3 HTSSIP_1.4.1    ggplot2_3.2.0   tidyr_0.8.3
    ## [5] dplyr_0.8.0.1
    ##
    ## loaded via a namespace (and not attached):
    ##   [1] nlme_3.1-131               bitops_1.0-6
    ##   [3] matrixStats_0.54.0         bit64_0.9-7
    ##   [5] doParallel_1.0.14          RColorBrewer_1.1-2
    ##   [7] GenomeInfoDb_1.14.0        tools_3.4.3
    ##   [9] backports_1.1.4            utf8_1.1.4
    ##  [11] R6_2.4.0                   coenocliner_0.2-2
    ##  [13] vegan_2.5-1                rpart_4.1-15
    ##  [15] Hmisc_4.2-0                DBI_1.0.0
    ##  [17] lazyeval_0.2.2             BiocGenerics_0.24.0
    ##  [19] mgcv_1.8-28                colorspace_1.4-1
    ##  [21] permute_0.9-5              ade4_1.7-13
    ##  [23] nnet_7.3-12                withr_2.1.2
    ##  [25] tidyselect_0.2.5           gridExtra_2.3
    ##  [27] DESeq2_1.18.1              bit_1.1-14
    ##  [29] compiler_3.4.3             cli_1.1.0
    ##  [31] Biobase_2.38.0             htmlTable_1.13.1
    ##  [33] DelayedArray_0.4.1         labeling_0.3
    ##  [35] scales_1.0.0               checkmate_1.9.3
    ##  [37] genefilter_1.60.0          stringr_1.4.0
    ##  [39] digest_0.6.19              foreign_0.8-71
    ##  [41] XVector_0.18.0             base64enc_0.1-3
    ##  [43] pkgconfig_2.0.2            htmltools_0.3.6
    ##  [45] highr_0.8                  htmlwidgets_1.3
    ##  [47] rlang_0.4.0                RSQLite_2.1.1
    ##  [49] rstudioapi_0.10            jsonlite_1.6
    ##  [51] BiocParallel_1.12.0        acepack_1.4.1
    ##  [53] RCurl_1.95-4.12            magrittr_1.5
    ##  [55] GenomeInfoDbData_1.0.0     Formula_1.2-3
    ##  [57] biomformat_1.6.0           Matrix_1.2-17
    ##  [59] fansi_0.4.0                Rcpp_1.0.1
    ##  [61] munsell_0.5.0              S4Vectors_0.16.0
    ##  [63] ape_5.3                    stringi_1.4.3
    ##  [65] MASS_7.3-51.4              SummarizedExperiment_1.8.1
    ##  [67] zlibbioc_1.24.0            rhdf5_2.22.0
    ##  [69] plyr_1.8.4                 blob_1.1.1
    ##  [71] grid_3.4.3                 parallel_3.4.3
    ##  [73] crayon_1.3.4               lattice_0.20-38
    ##  [75] Biostrings_2.46.0          splines_3.4.3
    ##  [77] multtest_2.34.0            annotate_1.56.2
    ##  [79] locfit_1.5-9.1             zeallot_0.1.0
    ##  [81] knitr_1.18                 pillar_1.4.1
    ##  [83] igraph_1.2.4               GenomicRanges_1.30.3
    ##  [85] markdown_0.9               geneplotter_1.56.0
    ##  [87] reshape2_1.4.3             codetools_0.2-16
    ##  [89] stats4_3.4.3               XML_3.98-1.19
    ##  [91] glue_1.3.1                 evaluate_0.14
    ##  [93] latticeExtra_0.6-28        data.table_1.10.4-3
    ##  [95] vctrs_0.1.0                foreach_1.4.4
    ##  [97] gtable_0.3.0               purrr_0.3.2
    ##  [99] assertthat_0.2.1           mime_0.6
    ## [101] xtable_1.8-4               survival_2.44-1.1
    ## [103] tibble_2.1.1               iterators_1.0.10
    ## [105] memoise_1.1.0              AnnotationDbi_1.40.0
    ## [107] IRanges_2.12.0             cluster_2.0.6