metrics.R 855 bytes
library(dplyr)
library(tibble)
reads_input <- sapply(snakemake@config$SAMPLES, function(x) {
  as.numeric(system(
    sprintf(
      "unzip -p work/fastqc/%s_fastqc.zip  %s_fastqc/fastqc_data.txt | grep 'Total Sequences' | cut -f2",
      x, x),
    intern = TRUE
}) %>% as.data.frame() %>% rownames_to_column("Sample")
seqtab.nochim <- readRDS(snakemake@input$rds)
reads_output <- rowSums(seqtab.nochim) %>% as.data.frame() %>% rownames_to_column("Sample")
nb_asv <- rowSums(seqtab.nochim > 0) %>% as.data.frame() %>% rownames_to_column("Sample")
metrics <- dplyr::full_join(x = reads_input, y = reads_output, by = "Sample") %>% 
  dplyr::full_join(y = nb_asv, by = "Sample")
colnames(metrics) <- c('Sample', 'Input reads', 'Post-process reads', 'Nb ASV')
write.table(metrics, snakemake@output$tsv, sep = "\t", quote = FALSE, row.names = FALSE)