%load_ext rpy2.ipython

%%R
physeqDir = '/var/seq_data/fullCyc/MiSeq_16SrRNA/515f-806r/lib1-7/phyloseq/'
physeq_bulk_core = 'bulk-core'
physeq_SIP_core = 'SIP-core_unk'

"""
Explanation: Description

The relatively abundant taxa seem to be present in all gradient fractions.
>0.1% pre-fractionation abundance (at least for 1 12C-con gradient)
Goal: 
For all 12C-Con gradients determine the detection threshold:
What is the % abundance cutoff where taxa are no longer detected in all gradients



Setting parameters
End of explanation
"""


%%R
library(dplyr)
library(tidyr)
library(ggplot2)
library(phyloseq)

"""
Explanation: Init
End of explanation
"""


%%R
F = file.path(physeqDir, physeq_SIP_core)
physeq.SIP = readRDS(F)
physeq.SIP.m = physeq.SIP %>% sample_data
physeq.SIP

"""
Explanation: Mapping bulk and SIP data
SIP dataset
End of explanation
"""


%%R
F = file.path(physeqDir, physeq_bulk_core)
physeq.bulk = readRDS(F)
physeq.bulk.m = physeq.bulk %>% sample_data
physeq.bulk

%%R 
# parsing out to just 12C-Con gradients
physeq.bulk.f = prune_samples((physeq.bulk.m$Exp_type == 'microcosm_bulk') | 
                         (physeq.bulk.m$Exp_type == 'SIP' & 
                          physeq.bulk.m$Substrate == '12C-Con'),
                         physeq) %>% 
    filter_taxa(function(x) sum(x) > 0, TRUE)
physeq.bulk.f.m = physeq.bulk.f %>% sample_data %>% as.matrix %>% as.data.frame 
physeq.bulk.f         

"""
Explanation: Pre-fraction dataset
End of explanation
"""


