|
| 1 | +# Uses output from Rscript 'read_counts_to_annotation.R' to consider the unique taxa observed at each site |
| 2 | + |
| 3 | +#rm(list=ls()) |
| 4 | + |
| 5 | +par(mfrow=c(2,3), mar= c(4,3,3,1) + 0.2, mgp = c(2,0.75,0)) |
| 6 | +options(scipen = 9999999) |
| 7 | + |
| 8 | +# Choose dataset |
| 9 | +datatypes <- c("C3_val", "C3_COI", "C3_16s", "SOG_val", "SOG_16s") |
| 10 | + |
| 11 | +# Collect information of uniq taxa and total reads per site |
| 12 | +# Also plots uniq taxa by read count |
| 13 | + |
| 14 | +# Set Nulls |
| 15 | +taxa.read.counts.list <- list(); uniq.taxa <- NULL; reads.per.site <- NULL |
| 16 | + |
| 17 | +for(d in datatypes){ |
| 18 | + # Set working directory |
| 19 | + working.dir <- paste("~/Documents/03_eDNA/eDNA_metabarcoding_", d, sep = "") |
| 20 | + setwd(working.dir) |
| 21 | + |
| 22 | + # Import filename for the 'x count' filtered count file |
| 23 | + filename <- paste("05_annotated/", d, "_count_by_taxa_filt_at_10.csv", sep = "") |
| 24 | + counts <- read.delim2(filename, sep = ",", row.names = 1) |
| 25 | + |
| 26 | + # Record number of taxa per site |
| 27 | + uniq.taxa <- colSums(counts != 0) # if the value is 0 it is FALSE, if not 0, is TRUE, then the num of true is summed |
| 28 | + |
| 29 | + # Record number of reads per site |
| 30 | + reads.per.site <- colSums(counts) |
| 31 | + |
| 32 | + taxa.read.counts.list[[d]] <- rbind(uniq.taxa, reads.per.site) |
| 33 | + |
| 34 | + # plot but without mock sample |
| 35 | + plot(uniq.taxa[uniq.taxa != "sample.Mock"] |
| 36 | + ~ reads.per.site[reads.per.site != "sample.Mock"] |
| 37 | + , main = d |
| 38 | + , xlab = "Number Reads", ylab = "Number Taxa", las = 1) |
| 39 | + |
| 40 | +} |
| 41 | + |
| 42 | + |
| 43 | +### Plot unique taxa per location for each amplicon (in progress) |
| 44 | + |
| 45 | +# make filename this way: filename <- paste("05_annotated/", datatype, "_unassigned_unknown_counts.csv", sep = "") |
| 46 | +# pdf(file = filename, width = 10, height = 8) |
| 47 | + |
| 48 | +## plot taxa C3 |
| 49 | +c3.amplicons <- c("C3_16s", "C3_val", "C3_COI") |
| 50 | +par(mfrow=c(3,1), mar=c(5,5,3,1)) |
| 51 | + |
| 52 | +for(a in c3.amplicons){ |
| 53 | + barplot(taxa.read.counts.list[[a]][1,], las = 2, main = a |
| 54 | + , ylab = "Number unique taxa") |
| 55 | +} |
| 56 | + |
| 57 | + |
| 58 | +## plot taxa SOG |
| 59 | +# problem with taxa naming |
| 60 | +colnames(taxa.read.counts.list[["SOG_val"]]) <- gsub(colnames(taxa.read.counts.list[["SOG_val"]]), pattern = "sample.", replacement = "") |
| 61 | +data <- taxa.read.counts.list[["SOG_val"]] |
| 62 | +data <- t(data) |
| 63 | +data <- data[order(rownames(data)),] |
| 64 | + |
| 65 | +data <- t(data) |
| 66 | + |
| 67 | +taxa.read.counts.list[["SOG_val"]] <- data |
| 68 | + |
| 69 | +# For SOG_16s |
| 70 | +taxa.read.counts.list[["SOG_16s"]] |
| 71 | +colnames(taxa.read.counts.list[["SOG_16s"]]) <- gsub(colnames(taxa.read.counts.list[["SOG_16s"]]), pattern = "sample.S_", replacement = "") |
| 72 | +data <- taxa.read.counts.list[["SOG_16s"]] |
| 73 | +data <- t(data) |
| 74 | +data <- data[order(rownames(data)),] |
| 75 | + |
| 76 | +data <- t(data) |
| 77 | + |
| 78 | +taxa.read.counts.list[["SOG_16s"]] <- data |
| 79 | + |
| 80 | + |
| 81 | +# Choose amplicons |
| 82 | +sog.amplicons <- c("SOG_val", "SOG_16s") |
| 83 | + |
| 84 | +par(mfrow=c(2,1), mar=c(5,5,3,1)) |
| 85 | + |
| 86 | +for(a in sog.amplicons){ |
| 87 | + barplot(taxa.read.counts.list[[a]][1,], las = 2, main = a) |
| 88 | + |
| 89 | +} |
| 90 | + |
| 91 | +# ## plot taxa all |
| 92 | +# datatypes |
| 93 | +# par(mfrow=c(5,1), mar=c(5,5,3,1)) |
| 94 | +# |
| 95 | +# # intro |
| 96 | +# |
| 97 | +# for(a in datatypes){ |
| 98 | +# barplot(taxa.read.counts.list[[a]][1,], las = 2, main = a) |
| 99 | +# } |
| 100 | +# |
| 101 | + |
| 102 | +## write out |
0 commit comments