Skip to content

Commit

Permalink
Added rds support for ggplot output and reformatted a table
Browse files Browse the repository at this point in the history
  • Loading branch information
gerverska committed Feb 2, 2023
1 parent 4835a90 commit c8aaee7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 8 additions & 6 deletions code/00-functions.r
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ denoise <- function(marker){
err.fwd <- learnErrors(marker.fwd, multithread = threads, randomize = T)
err.fwd.plot <- plotErrors(err.fwd, nominalQ = T) + ggtitle(paste(insert, 'forward read error model'))
file.path(logs, paste0(marker, '-error-fwd.png')) |> ggsave(err.fwd.plot, width = 12, height = 9)
file.path(logs, paste0(marker, '-error-fwd.rds')) |> saveRDS(err.fwd.plot, file = _)
err.rev <- learnErrors(marker.rev, multithread = threads, randomize = T)
err.rev.plot <- plotErrors(err.rev, nominalQ = T) + ggtitle(paste(insert, 'reverse read error model'))
file.path(logs, paste0(marker, '-error-rev.png')) |> ggsave(err.rev.plot, width = 12, height = 9)
file.path(logs, paste0(marker, '-error-rev.rds')) |> saveRDS(err.rev.plot, file = _)

# Denoise reads in both directions ####
dada.fwd <- dada(derep.fwd, err = err.fwd, multithread = threads, pool = 'pseudo')
Expand Down Expand Up @@ -112,11 +114,10 @@ denoise <- function(marker){
in.start <- which(shift$pair == start) + 1
in.sum <- shift[in.start:nrow(shift), 'depth'] |> sum()

paste0(correct, ' / ', total, '\n', insert, '-trimmed reads\ncorrectly demultiplexed', '\n\n',
del.sum, ' reads with deletions in ', stop, '\n',
in.sum, ' reads with insertions in ', start, '\n\n') |>
cat(file = file.path(logs, paste0(marker, '-indel.txt')
))
indel <- data.frame(primers = insert, total = total, correct = correct,
deletions = del.sum, insertions = in.sum)

file.path(logs, paste0(marker, '-indel.txt')) |> write.table(indel, file = _, row.names = F, quote = F)

# Plot frameshift errors ####
frameshift <- ggplot(shift, aes(x = pair, y = depth)) +
Expand All @@ -132,7 +133,8 @@ denoise <- function(marker){
axis.title.x = element_text(face = 'bold'),
axis.title.y = element_text(face = 'bold'))

file.path(logs, paste0(marker, '-frameshift.png')) |> ggsave(frameshift, width = 12, height = 9)
file.path(out, paste0(marker, '-frameshift.png')) |> ggsave(frameshift, width = 12, height = 9)
file.path(out, paste0(marker, '-frameshift.rds')) |> saveRDS(frameshift, file = _)
}

# 04-compile.r ####
Expand Down
4 changes: 3 additions & 1 deletion code/06-analyze.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Determine the viability of hamPCR ####

# Load packages ####
library(patchwork)
library(ggplot2)
library(caret)
library(nlme)
Expand Down Expand Up @@ -128,6 +127,7 @@ load <- ggplot(standard, aes(x = log10(dilution), y = log10(mean_noga_load)
legend.title = element_text(face = 'bold'))

file.path(out, 'load.png') |> ggsave(load, width = 12, height = 9)
file.path(out, 'load.rds') |> saveRDS(load, file = _)

# Plot the relationship between frameshift pairs and model residuals ####
set.seed(666)
Expand All @@ -145,6 +145,7 @@ shifts <- ggplot(standard, aes(x = fun_n, y = gi_n, color = res)) +
legend.title = element_text(face = 'bold'))

file.path(out, 'residuals.png') |> ggsave(shifts, width = 9, height = 6)
file.path(out, 'residuals.rds') |> saveRDS(shifts, file = _)

# Extract OTU tables from the entire dataset ####
fun.tab <- subset(meta, template == 'dfssmt',
Expand Down Expand Up @@ -195,6 +196,7 @@ taxa <- ggplot(long, aes(x = id, y = value, fill = OTU)) +
axis.ticks.x = element_blank())

file.path(out, 'taxa.png') |> ggsave(taxa, width = 6, height = 6)
file.path(out, 'taxa.rds') |> saveRDS(taxa, file = _)

# Compare relative abundance and load hierarchical clustering assignments ####
rownames(fun.ra) <- 1:nrow(fun.ra)
Expand Down

0 comments on commit c8aaee7

Please sign in to comment.