From 3b5c26d4cbc046065ab46b6816f353692b379e0d Mon Sep 17 00:00:00 2001 From: farhadm1990 Date: Tue, 20 Feb 2024 09:43:57 +0100 Subject: [PATCH] 7th --- R/lambda_rect.r | 24 +++++++++++++++--------- README.md | 13 +++++++------ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/R/lambda_rect.r b/R/lambda_rect.r index 7aca962..9265de6 100644 --- a/R/lambda_rect.r +++ b/R/lambda_rect.r @@ -10,7 +10,7 @@ -lambda_rector <- function(ps, +lambda_rector <- function(ps, lamba_id = "Lambda", out_path = "./", negative_cont = NULL, @@ -454,7 +454,7 @@ ps_rel <- transform_sample_counts(glomed_ps, function(x){x/sum(x)}) # Removing suspected samples within each lamgda concentration group -sus_samp <<- psmelt(ps_rel) %>% select(Kingdom, Sample, lambda_ng_ul, mock_ng_ul, Abundance) %>% filter(Abundance <=0.98, Abundance > 0.001, mock_ng_ul > 0.002, lambda_ng_ul > 0 ) %>% group_by(Sample, lambda_ng_ul, mock_ng_ul, Kingdom) %>% summarise(mean = sum(Abundance), .groups = "drop") %>% group_by(Sample, lambda_ng_ul, mock_ng_ul) %>% summarise(groups = sum(mean)) %>% mutate(sanity = ifelse(groups <0.8, "Suspicous", "Okay")) %>% filter(sanity == "Suspicous") %>% select(Sample) %>% pull() +sus_samp <<- psmelt(ps_rel) %>% select(Kingdom, Sample, lambda_ng_ul, mock_ng_ul, Abundance) %>% filter(Abundance <=0.98, Abundance > 0.001, mock_ng_ul > 0.002, lambda_ng_ul > 0 ) %>% group_by(Sample, lambda_ng_ul, mock_ng_ul, Kingdom) %>% summarise(mean = sum(Abundance), .groups = "drop") %>% group_by(Sample, lambda_ng_ul, mock_ng_ul) %>% summarise(groups = sum(mean)) %>% mutate(sanity = ifelse(groups <0.7, "Suspicous", "Okay")) %>% filter(sanity == "Suspicous") %>% select(Sample) %>% pull() print(glue("{sus_samp} samples seem to be suspicous and I am going to remove them!\n But first take a look at them in {out_path}")) @@ -517,10 +517,13 @@ melt_df$mock_ng_ul <- factor(melt_df$mock_ng_ul, levels = c(20,2,0.2,0.02), labe melt_df$lambda_ng_ul <- factor(melt_df$lambda_ng_ul, levels = c(1e-04, 1e-05, 1e-06), labels = unique(melt_df$lambda_ng_ul)) +lambda_con_1 = unique(melt_df$lambda_ng_ul)[1] +lambda_con_2 = unique(melt_df$lambda_ng_ul)[2] +lambda_con_3 = unique(melt_df$lambda_ng_ul)[3] -df1 = melt_df %>% filter(lambda_ng_ul == "1e-04") -df2 = melt_df %>% filter(lambda_ng_ul == "1e-05") -df3 = melt_df %>% filter(lambda_ng_ul == "1e-06") +df1 = melt_df %>% filter(lambda_ng_ul == lambda_con_1) +df2 = melt_df %>% filter(lambda_ng_ul == lambda_con_2) +df3 = melt_df %>% filter(lambda_ng_ul == lambda_con_3) n = length(unique(melt_df$OTU)) set.seed(1990) @@ -570,10 +573,13 @@ melt_df$mock_ng_ul <- factor(melt_df$mock_ng_ul, levels = c(20,2,0.2,0.02), labe melt_df$lambda_ng_ul <- factor(melt_df$lambda_ng_ul, levels = c(1e-04, 1e-05, 1e-06), labels = unique(melt_df$lambda_ng_ul)) +lambda_con_1 = unique(melt_df$lambda_ng_ul)[1] +lambda_con_2 = unique(melt_df$lambda_ng_ul)[2] +lambda_con_3 = unique(melt_df$lambda_ng_ul)[3] -df1 = melt_df %>% filter(lambda_ng_ul == "1e-04") -df2 = melt_df %>% filter(lambda_ng_ul == "1e-05") -df3 = melt_df %>% filter(lambda_ng_ul == "1e-06") +df1 = melt_df %>% filter(lambda_ng_ul == lambda_con_1) +df2 = melt_df %>% filter(lambda_ng_ul == lambda_con_2) +df3 = melt_df %>% filter(lambda_ng_ul == lambda_con_3) n = length(unique(melt_df$OTU)) set.seed(1990) @@ -615,6 +621,6 @@ pl_cp = p1 + p2 + p3 + plot_layout(nrow = 3, widths = 10) + plot_annotation("16S ggsave(plot =pl_cp, paste0(out_path,"/", taxa_level, "_copy_number.jpeg"), width = 15, height = 10, dpi =300) - structure(list(copy_corrected_ps = copy_corrected_ps, ps_gloomed = glomed_ps, ps_rel = ps_rel, raw_ps = ps)) + structure(list(copy_corrected_ps = copy_corrected_ps, ps_gloomed = glomed_ps, ps_rel = ps_rel, raw_ps = ps, suspected_samples = sus_samp)) } \ No newline at end of file diff --git a/README.md b/README.md index fd65bd5..3145f80 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,16 @@ ## An R package to correct relatvie abundance of sequeneincg reads into 16S rRNA gene copy-number based on an internal Lambda Phage standard. **This is the supporting package for paper DOIXXXXX** + # Installation -## 1. Isntall and library devtools pakcage on your machine +## 1. Install and library devtools pakcage on your machine ```R -install.packages("devtools") +if(!require("devtools")){install.packages("devtools")} library(devtools) ``` -## 2. Download and isntall `lambda_rector` +## 2. Download and install `lambda_rector` ```R devtools::install_github("farhadm1990/lambda_rector") library(lambda.rector) @@ -25,7 +26,7 @@ test = lambda_rector( negative_cont = NULL, negative_filt = TRUE, rare_depth = 10000, - taxa_level = "Order" + taxa_level = "Species" ) # This will return a list of differnt phyloseq objects and saves the output plots @@ -34,11 +35,11 @@ test = lambda_rector( ![plot1](https://github.com/farhadm1990/lambda_rector/blob/main/pix/plot_without_bad_samples.jpeg) -### Fig2. An example of filtering output of by the package on suspicious samples. +### Fig1. An example of filtering output by the package on suspicious samples. ![plot2](https://github.com/farhadm1990/lambda_rector/blob/main/pix/Order_relative.jpeg) -### Fig3. Relative abundance of 16S rRNA gene sequencing reads at order level in different Mock and Lambda concentrations. +### Fig2. Relative abundance of 16S rRNA gene sequencing reads at order level in different Mock and Lambda concentrations. ![plot3](https://github.com/farhadm1990/lambda_rector/blob/main/pix/Order_copy_number.jpeg)