Skip to content

Commit

Permalink
7th
Browse files Browse the repository at this point in the history
  • Loading branch information
farhadm1990 committed Feb 20, 2024
1 parent 1cc0689 commit 3b5c26d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
24 changes: 15 additions & 9 deletions R/lambda_rect.r
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@



lambda_rector <- function(ps,
lambda_rector <- function(ps,
lamba_id = "Lambda",
out_path = "./",
negative_cont = NULL,
Expand Down Expand Up @@ -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}"))

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))

}
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit 3b5c26d

Please sign in to comment.