In [1]:
workDir = '/ebio/abt3_projects/methanogen_host_evo/SIPSim_pt2/data/bac_genome1147/atomIncorp_taxaIncorp/'
In [2]:
library(dplyr)
library(tidyr)
library(ggplot2)
In [3]:
# classifying true positives, neg, ...
clsfy = function(guess,known){
if(is.na(guess) | is.na(known)){
return(NA)
}
if(guess == TRUE){
if(guess == known){
return('True positive')
} else {
return('False positive')
}
} else
if(guess == FALSE){
if(guess == known){
return('True negative')
} else {
return('False negative')
}
} else {
stop('Error: true or false needed')
}
}
In [4]:
BDshift_files = list.files(path=workDir, pattern='BD-shift_stats.txt', full.names=TRUE, recursive=TRUE)
BDshift_files %>% length %>% print
In [5]:
df_shift = list()
for(F in BDshift_files){
tmp = read.delim(F, sep='\t')
FF = strsplit(F, '/') %>% unlist
FFl = length(FF)
tmp$percIncorp = FF[FFl-3]
tmp$percTaxa = FF[FFl-2]
tmp$rep = FF[FFl-1]
tmp$file = FF[FFl]
df_shift[[F]] = tmp
}
df_shift = do.call(rbind, df_shift)
rownames(df_shift) = 1:nrow(df_shift)
df_shift = df_shift %>%
filter(library %in% c(2,4,6)) %>%
group_by(taxon, percIncorp, percTaxa, rep) %>%
summarize(median = median(median)) %>%
ungroup() %>%
rename('median_true_BD_shift' = median)
# status
df_shift %>% nrow %>% print
df_shift %>% head(n=3)
In [6]:
incorp_files = list.files(path=workDir, pattern='OTU_abs1e9_PCR_sub_filt_MW_DESeq2_incorp.txt', full.names=TRUE, recursive=TRUE)
incorp_files %>% length %>% print
In [7]:
df_incorp = list()
for(F in incorp_files){
tmp = read.delim(F, sep='\t')
FF = strsplit(F, '/') %>% unlist
FFl = length(FF)
tmp$percIncorp = FF[FFl-3]
tmp$percTaxa = FF[FFl-2]
tmp$rep = FF[FFl-1]
tmp$file = FF[FFl]
df_incorp[[F]] = tmp
}
df_incorp = do.call(rbind, df_incorp)
rownames(df_incorp) = 1:nrow(df_incorp)
df_incorp %>% head(n=3) %>% print
In [8]:
# just incorporators
df_incorp = df_incorp %>%
filter(incorp == TRUE) %>%
dplyr::distinct(taxon, incorp, percIncorp, percTaxa, rep) %>%
rename('HWHRSIP_incorp' = incorp)
df_incorp %>% nrow %>% print
df_incorp %>% head(n=3) %>% print
In [ ]:
atomX_files = list.files(path=workDir, pattern='*_qSIP_atom.txt', full.names=TRUE, recursive=TRUE)
atomX_files %>% length %>% print
In [10]:
df_atomX = list()
for(F in atomX_files){
tmp = read.delim(F, sep='\t')
FF = strsplit(F, '/') %>% unlist
FFl = length(FF)
tmp$percIncorp = FF[FFl-3]
tmp$percTaxa = FF[FFl-2]
tmp$rep = FF[FFl-1]
tmp$file = FF[FFl]
df_atomX[[F]] = tmp
}
df_atomX = do.call(rbind, df_atomX)
rownames(df_atomX) = 1:nrow(df_atomX)
df_atomX %>% head(n=3) %>% print
In [53]:
# table join
df_atomX %>% nrow %>% print
df_atomX_j = left_join(df_atomX, df_shift, c('taxon' = 'taxon',
'percIncorp'='percIncorp',
'percTaxa'='percTaxa',
'rep'='rep')) %>%
filter(!is.na(BD_diff)) %>%
mutate(true_incorporator = ifelse(median_true_BD_shift > 0.002, TRUE, FALSE),
true_atom_fraction_excess = median_true_BD_shift / 0.036,
atom_fraction_excess = ifelse(is.na(atom_CI_low), 0, atom_fraction_excess))
df_atomX_j %>% nrow %>% print
df_atomX_j %>% head(n=3) %>% print
In [54]:
df_atomX_j = left_join(df_atomX_j, df_incorp, c('taxon' = 'taxon',
'percIncorp'='percIncorp',
'percTaxa'='percTaxa',
'rep'='rep')) %>%
mutate(HWHRSIP_incorp = ifelse(is.na(HWHRSIP_incorp), FALSE, TRUE))
df_atomX_j %>% nrow %>% print
df_atomX_j %>% head(n=3) %>% print
In [18]:
dBD_files = list.files(path=workDir, pattern='*_dBD.txt', full.names=TRUE, recursive=TRUE)
dBD_files %>% length %>% print
In [19]:
df_dBD = list()
for(F in dBD_files){
tmp = read.delim(F, sep='\t')
FF = strsplit(F, '/') %>% unlist
FFl = length(FF)
tmp$percIncorp = FF[FFl-3]
tmp$percTaxa = FF[FFl-2]
tmp$rep = FF[FFl-1]
tmp$file = FF[FFl]
df_dBD[[F]] = tmp
}
df_dBD = do.call(rbind, df_dBD)
rownames(df_dBD) = 1:nrow(df_dBD)
df_dBD %>% head(n=3) %>% print
In [51]:
df_dBD %>% dim %>% print
df_dBD_j = inner_join(df_dBD, df_shift, c('taxon' = 'taxon',
'percIncorp'='percIncorp',
'percTaxa'='percTaxa',
'rep'='rep')) %>%
filter(!is.na(delta_BD)) %>%
mutate(true_incorporator = ifelse(median_true_BD_shift > 0.002, TRUE, FALSE),
true_atom_fraction_excess = median_true_BD_shift / 0.036,
atom_fraction_excess = delta_BD / 0.036)
df_dBD_j %>% dim %>% print
df_dBD_j %>% head(n=3)
In [52]:
df_dBD_j %>% nrow %>% print
df_dBD_j = left_join(df_dBD_j, df_incorp, c('taxon' = 'taxon',
'percIncorp'='percIncorp',
'percTaxa'='percTaxa',
'rep'='rep')) %>%
mutate(HWHRSIP_incorp = ifelse(is.na(HWHRSIP_incorp), FALSE, TRUE))
df_dBD_j %>% nrow %>% print
df_dBD_j %>% head(n=3)
In [191]:
# q-SIP
df_atomX_j_true = df_atomX_j %>%
filter(true_incorporator == TRUE) %>% # just incorporators identified by q-SIP
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100) %>%
group_by(percIncorp, percTaxa, true_incorporator) %>%
summarize(mean_delta_excess = mean(delta_excess),
sd_delta_excess = sd(delta_excess)) %>%
ungroup() %>%
mutate(percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric),
method = 'q-SIP')
df_atomX_j_true %>% head(n=3)
In [192]:
# delta-BD
df_dBD_j_true = df_dBD_j %>%
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100) %>%
filter(true_incorporator == TRUE) %>%
group_by(percIncorp, percTaxa, true_incorporator) %>%
summarize(mean_delta_excess = mean(delta_excess),
sd_delta_excess = sd(delta_excess)) %>%
ungroup() %>%
mutate(percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric),
method = 'delta BD')
df_dBD_j_true %>% head(n=3)
In [193]:
# plotting
tmp = rbind(df_atomX_j_true, df_dBD_j_true)
options(repr.plot.width=8, repr.plot.height=2.5)
p_BDshift_true = ggplot(tmp, aes(percIncorp, mean_delta_excess,
color=percTaxa, group=percTaxa,
ymin=mean_delta_excess-sd_delta_excess,
ymax=mean_delta_excess+sd_delta_excess)) +
geom_line() +
geom_linerange(alpha=0.4, size=1) +
geom_point() +
scale_color_discrete('% incorp-\norators') +
facet_grid(. ~ method) +
labs(x='13C atom % excess (truth)',
y='13C atom % excess\n(truth - estimate)') +
theme_bw()
plot(p_BDshift_true)
In [194]:
df_atomX_j_all = df_atomX_j %>%
filter(atom_CI_low > 0) %>%
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100) %>%
group_by(percIncorp, percTaxa) %>%
summarize(mean_delta_excess = mean(delta_excess),
sd_delta_excess = sd(delta_excess)) %>%
ungroup() %>%
mutate(percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric),
method = 'q-SIP')
df_atomX_j %>% head(n=3)
In [195]:
# delta-BD
df_dBD_j_all = df_dBD_j %>%
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100) %>%
group_by(percIncorp, percTaxa) %>%
summarize(mean_delta_excess = mean(delta_excess),
sd_delta_excess = sd(delta_excess)) %>%
ungroup() %>%
mutate(percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric),
method = 'delta BD')
df_dBD_j %>% head(n=3)
In [196]:
# plotting
tmp = rbind(df_atomX_j_all, df_dBD_j_all)
options(repr.plot.width=8, repr.plot.height=2.5)
p_BDshift_all = ggplot(tmp, aes(percIncorp, mean_delta_excess,
color=percTaxa, group=percTaxa,
ymin=mean_delta_excess-sd_delta_excess,
ymax=mean_delta_excess+sd_delta_excess)) +
geom_line() +
geom_linerange(alpha=0.4, size=1) +
geom_point() +
scale_color_discrete('% incorp-\norators') +
facet_grid(. ~ method) +
labs(x='13C atom % excess (truth)',
y='13C atom % excess\n(truth - estimate)') +
theme_bw()
plot(p_BDshift_all)
In [197]:
# q-SIP
tmp_all = df_atomX_j %>%
filter(atom_CI_low > 0) %>%
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100,
true_incorporator = 'All incorp.') %>%
group_by(percIncorp, percTaxa, true_incorporator) %>%
summarize(mean_delta_excess = mean(delta_excess),
sd_delta_excess = sd(delta_excess)) %>%
ungroup() %>%
mutate(percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric),
method = 'q-SIP')
tmp_split = df_atomX_j %>%
filter(atom_CI_low > 0) %>%
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100,
true_incorporator = ifelse(true_incorporator == TRUE, 'True incorp.', 'False incorp.')) %>%
group_by(percIncorp, percTaxa, true_incorporator) %>%
summarize(mean_delta_excess = mean(delta_excess),
sd_delta_excess = sd(delta_excess)) %>%
ungroup() %>%
mutate(percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric),
method = 'q-SIP')
df_atomX_j_s = rbind(tmp_all, tmp_split) %>%
mutate(method = 'q-SIP')
df_atomX_j_s %>% head(n=3)
In [198]:
# delta BD
tmp_all = df_dBD_j %>%
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100,
true_incorporator = ifelse(true_incorporator == TRUE, 'True incorp.', 'False incorp.')) %>%
group_by(percIncorp, percTaxa, true_incorporator) %>%
summarize(mean_delta_excess = mean(delta_excess),
sd_delta_excess = sd(delta_excess)) %>%
ungroup() %>%
mutate(percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric))
tmp_split = df_dBD_j %>%
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100,
true_incorporator = 'All incorp.') %>%
group_by(percIncorp, percTaxa, true_incorporator) %>%
summarize(mean_delta_excess = mean(delta_excess),
sd_delta_excess = sd(delta_excess)) %>%
ungroup() %>%
mutate(percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric))
df_dBD_j_s = rbind(tmp_all, tmp_split) %>%
mutate(method = 'delta BD')
df_dBD_j_s %>% head(n=3)
In [199]:
levs = c('All incorp.', 'True incorp.', 'False incorp.')
tmp = rbind(df_atomX_j_s, df_dBD_j_s) %>%
mutate(true_incorporator = factor(true_incorporator, levels=levs))
# plotting
options(repr.plot.width=8, repr.plot.height=3)
p_BDshift_facet = ggplot(tmp, aes(percIncorp, mean_delta_excess,
color=percTaxa, group=percTaxa,
ymin=mean_delta_excess-sd_delta_excess,
ymax=mean_delta_excess+sd_delta_excess)) +
geom_line() +
geom_linerange(alpha=0.4, size=1) +
geom_point() +
facet_grid(method ~ true_incorporator) +
scale_color_discrete('% incorp-\norators') +
labs(x='13C atom % excess (truth)',
y='13C atom % excess\n(truth - estimate)') +
theme_bw()
plot(p_BDshift_facet)
In [211]:
# q-SIP
tmp_atomX = df_atomX_j %>%
filter(percTaxa == '10',
true_incorporator == TRUE,
atom_fraction_excess > 0) %>%
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100,
percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric),
atom_perc_excess = atom_fraction_excess * 100,
true_atom_perc_excess = true_atom_fraction_excess * 100) %>%
dplyr::select(atom_perc_excess, true_atom_perc_excess, percIncorp, percTaxa) %>%
mutate(method = 'q-SIP')
tmp_atomX %>% head(n=3)
In [212]:
# delta BD
tmp_dBD = df_dBD_j %>%
filter(percTaxa == '10',
true_incorporator == TRUE) %>%
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100,
percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric),
atom_perc_excess = atom_fraction_excess * 100,
true_atom_perc_excess = true_atom_fraction_excess * 100) %>%
dplyr::select(atom_perc_excess, true_atom_perc_excess, percIncorp, percTaxa) %>%
mutate(method = 'delta BD')
tmp_dBD %>% head(n=3)
In [213]:
# for vline
df_j = rbind(tmp_atomX, tmp_dBD)
tmp = df_j %>%
distinct(percIncorp) %>%
mutate(true_atom_perc_excess = percIncorp %>% as.character %>% as.numeric)
options(repr.plot.width=10, repr.plot.height=3)
p_dens_true = ggplot(df_j, aes(atom_perc_excess)) +
geom_density(alpha=0.5, fill='grey70') +
geom_vline(data=tmp, aes(xintercept=true_atom_perc_excess), linetype='dashed', alpha=0.4) +
scale_x_continuous(limits=c(-20, 120)) +
labs(x='atom % excess 13C (estimate)', y='Probability density') +
facet_grid(method ~ percIncorp) +
theme_bw()
plot(p_dens_true)
In [214]:
# delta BD
tmp_atomX = df_atomX_j %>%
filter(percTaxa == '10',
atom_CI_low > 0) %>%
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100,
percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric),
atom_perc_excess = atom_fraction_excess * 100,
true_atom_perc_excess = true_atom_fraction_excess * 100) %>%
dplyr::select(atom_perc_excess, true_atom_perc_excess, percIncorp, percTaxa, true_incorporator) %>%
mutate(method = 'q-SIP')
tmp_atomX %>% head(n=3)
In [215]:
# delta BD
tmp_dBD = df_dBD_j %>%
filter(percTaxa == '10') %>%
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100,
percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric),
atom_perc_excess = atom_fraction_excess * 100,
true_atom_perc_excess = true_atom_fraction_excess * 100) %>%
dplyr::select(atom_perc_excess, true_atom_perc_excess, percIncorp, percTaxa, true_incorporator) %>%
mutate(method = 'delta BD')
tmp_dBD %>% head(n=3)
In [216]:
# for vline
df_j = rbind(tmp_atomX, tmp_dBD)
tmp = df_j %>%
distinct(percIncorp) %>%
mutate(true_atom_perc_excess = percIncorp %>% as.character %>% as.numeric)
options(repr.plot.width=10, repr.plot.height=3)
p_dens_all = ggplot(df_j, aes(atom_perc_excess)) +
geom_density(alpha=0.5, fill='grey70') +
geom_vline(data=tmp, aes(xintercept=true_atom_perc_excess), linetype='dashed', alpha=0.4) +
scale_x_continuous(limits=c(-20, 120)) +
scale_fill_discrete('True incorp-\norator?') +
labs(x='atom % excess 13C (estimate)', y='Probability density') +
facet_grid(method ~ percIncorp) +
theme_bw()
plot(p_dens_all)
In [217]:
# for vline
df_j = rbind(tmp_atomX, tmp_dBD)
tmp = df_j %>%
distinct(percIncorp) %>%
mutate(true_atom_perc_excess = percIncorp %>% as.character %>% as.numeric)
options(repr.plot.width=10, repr.plot.height=3)
p_dens_all_facet = ggplot(df_j, aes(atom_perc_excess)) +
geom_density(alpha=0.5, aes(fill=true_incorporator)) +
geom_vline(data=tmp, aes(xintercept=true_atom_perc_excess), linetype='dashed', alpha=0.4) +
scale_x_continuous(limits=c(-20, 120)) +
scale_fill_discrete('True incorp-\norator?') +
labs(x='atom % excess 13C (estimate)', y='Probability density') +
facet_grid(method ~ percIncorp) +
theme_bw()
plot(p_dens_all_facet)
In [218]:
options(repr.plot.width=10, repr.plot.height=6)
p_TE_dens_true = cowplot::ggdraw() +
cowplot::draw_plot(p_BDshift_true, 0, 0.6, 0.95, 0.4) +
cowplot::draw_plot(p_dens_true, 0, 0, 0.9, 0.6) +
cowplot::draw_plot_label(c('A)', 'B)'), c(0, 0), c(1, 0.6), size=12)
plot(p_TE_dens_true)
In [219]:
options(repr.plot.width=10, repr.plot.height=6)
p_TE_dens_all = cowplot::ggdraw() +
cowplot::draw_plot(p_BDshift_all, 0, 0.6, 0.95, 0.4) +
cowplot::draw_plot(p_dens_all, 0, 0, 0.9, 0.6) +
cowplot::draw_plot_label(c('A)', 'B)'), c(0, 0), c(1, 0.6), size=12)
plot(p_TE_dens_all)
In [220]:
options(repr.plot.width=10, repr.plot.height=7)
p_TE_dens_all_facet = cowplot::ggdraw() +
cowplot::draw_plot(p_BDshift_facet, 0, 0.5, 0.95, 0.5) +
cowplot::draw_plot(p_dens_all_facet, 0, 0, 1, 0.50) +
cowplot::draw_plot_label(c('A)', 'B)'), c(0, 0), c(1, 0.5), size=12)
plot(p_TE_dens_all_facet)
In [ ]:
In [ ]:
In [ ]:
In [175]:
df.jj = rbind(df.j.dis.qSIP %>% mutate(method='qSIP'),
df.j.dis.dBD %>% mutate(method='Delta BD')) %>%
mutate(method = gsub('qSIP', 'q-SIP', method))
options(repr.plot.width=8, repr.plot.height=4)
p.comb = ggplot(df.jj, aes(percIncorp, mean_delta_excess,
color=percTaxa, group=percTaxa,
ymin=mean_delta_excess-sd_delta_excess,
ymax=mean_delta_excess+sd_delta_excess)) +
geom_line() +
geom_linerange(alpha=0.5, size=1) +
geom_point() +
scale_color_discrete('% incorp-\norators') +
labs(x='atom % excess 13C (truth)',
y='atom % excess 13C\n(truth - estimate)') +
facet_grid(incorp_called ~ method) +
theme_bw()
p.comb
In [172]:
outF = file.path(workDir, 'atomIncorp_taxaIncorp_BDshift-MWHRSIP.pdf')
ggsave(outF, p.comb, width=8, height=4)
cat('File written:', outF, '\n')
In [173]:
outF = file.path(workDir, 'atomIncorp_taxaIncorp_BDshift-MWHRSIP.jpeg')
ggsave(outF, p.comb, width=8, height=4)
cat('File written:', outF, '\n')
In [ ]:
BDshift_files = list.files(path=workDir, pattern='BD-shift_stats.txt', full.names=TRUE, recursive=TRUE)
BDshift_files %>% length %>% print
In [ ]:
df_shift = list()
for(F in BDshift_files){
tmp = read.delim(F, sep='\t')
FF = strsplit(F, '/') %>% unlist
FFl = length(FF)
tmp$percIncorp = FF[FFl-3]
tmp$percTaxa = FF[FFl-2]
tmp$rep = FF[FFl-1]
tmp$file = FF[FFl]
df_shift[[F]] = tmp
}
df_shift = do.call(rbind, df_shift)
rownames(df_shift) = 1:nrow(df_shift)
df_shift = df_shift %>%
filter(library %in% c(2,4,6)) %>%
group_by(taxon, percIncorp, percTaxa, rep) %>%
summarize(median = median(median)) %>%
ungroup() %>%
rename('median_true_BD_shift' = median)
# status
df_shift %>% nrow %>% print
df_shift %>% head(n=3)
In [ ]:
atomX_files = list.files(path=workDir, pattern='*_qSIP_atom.txt', full.names=TRUE, recursive=TRUE)
atomX_files %>% length %>% print
In [ ]:
df_atomX = list()
for(F in atomX_files){
tmp = read.delim(F, sep='\t')
FF = strsplit(F, '/') %>% unlist
FFl = length(FF)
tmp$percIncorp = FF[FFl-3]
tmp$percTaxa = FF[FFl-2]
tmp$rep = FF[FFl-1]
tmp$file = FF[FFl]
df_atomX[[F]] = tmp
}
df_atomX = do.call(rbind, df_atomX)
rownames(df_atomX) = 1:nrow(df_atomX)
df_atomX %>% head(n=3) %>% print
In [ ]:
comm_files = list.files(path=workDir, pattern='comm.txt', full.names=TRUE, recursive=TRUE)
comm_files %>% length %>% print
In [ ]:
df_comm = list()
for(F in comm_files){
tmp = read.delim(F, sep='\t')
FF = strsplit(F, '/') %>% unlist
FFl = length(FF)
tmp$percIncorp = FF[FFl-3]
tmp$percTaxa = FF[FFl-2]
tmp$rep = FF[FFl-1]
tmp$file = FF[FFl]
df_comm[[F]] = tmp
}
df_comm = do.call(rbind, df_comm)
rownames(df_comm) = 1:nrow(df_comm)
# mean abund for libraries
df_comm = df_comm %>%
rename('taxon' = taxon_name) %>%
mutate(rel_abund_perc = ifelse(is.na(rel_abund_perc), 0, rel_abund_perc)) %>%
group_by(taxon, percIncorp, percTaxa, rep) %>%
summarize(any_zero = any(rel_abund_perc == 0),
mean_rel_abund_perc = mean(rel_abund_perc),
mean_rank_abund = mean(rank)) %>%
ungroup()
# status
df_comm %>% nrow %>% print
df_comm %>% head(n=3)
In [ ]:
df_comm$any_zero %>% table
In [ ]:
# table join
join_vars = c('taxon' = 'taxon',
'percIncorp'='percIncorp',
'percTaxa'='percTaxa',
'rep'='rep')
df_atomX %>% nrow %>% print
# joining q-SIP + true-BD
df.j = left_join(df_atomX, df_shift, join_vars) %>%
filter(atom_CI_low > 0) %>%
filter(!is.na(BD_diff)) %>%
mutate(true_incorporator = ifelse(median_true_BD_shift > 0.002, TRUE, FALSE),
true_atom_fraction_excess = median_true_BD_shift / 0.036,
atom_fraction_excess = ifelse(is.na(atom_CI_low), 0, atom_fraction_excess)) %>%
#filter(true_incorporator == TRUE) %>%
mutate(delta_excess = atom_fraction_excess * 100 - true_atom_fraction_excess * 100)
df.j %>% nrow %>% print
# joining with abundances
df.j = df.j %>%
inner_join(df_comm, join_vars) %>%
mutate(percIncorp = percIncorp %>% as.character,
percTaxa = percTaxa %>% as.character,
percIncorp = percIncorp %>% reorder(percIncorp %>% as.numeric),
percTaxa = percTaxa %>% reorder(percTaxa %>% as.numeric))
# status
df.j %>% nrow %>% print
df.j %>% head(n=3) %>% print
In [ ]:
options(repr.plot.width=8, repr.plot.height=6)
p.qSIP_abund = ggplot(df.j, aes(mean_rel_abund_perc, delta_excess,
color=true_incorporator, group=true_incorporator)) +
#geom_point(shape='O', alpha=0.15, size=0.5) +
geom_smooth(size=0.3) +
scale_x_log10() +
scale_color_discrete('True incorp-\norator') +
labs(x='% abundance',
y='atom % excess 13C\n(truth - estimate)') +
facet_grid(percIncorp ~ percTaxa) +
theme_bw()
p.qSIP_abund
In [ ]:
outF = file.path(workDir, 'atomIncorp_taxaIncorp_qSIP-abund.pdf')
ggsave(outF, p.qSIP_abund, width=9, height=6)
cat('File written:', outF, '\n')
In [ ]:
outF = file.path(workDir, 'atomIncorp_taxaIncorp_qSIP-abund.jpeg')
ggsave(outF, p.qSIP_abund, width=9, height=6)
cat('File written:', outF, '\n')
In [ ]: