Skip to content

Commit

Permalink
PomaNormPlot
Browse files Browse the repository at this point in the history
  • Loading branch information
pcastellanoescuder committed Sep 4, 2019
1 parent 5373016 commit d92f4dd
Show file tree
Hide file tree
Showing 9 changed files with 709 additions and 16 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
^\.Rproj\.user$
^\.travis\.yml$
^codecov\.yml$
^LICENSE\.md$
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
cache: packages
language: r

r_packages:
- covr
- devtools

r_github_packages:
- r-lib/covr
- codecov/POMA

after_success:
- Rscript -e 'covr::codecov()'
- Rscript -e 'library(covr);codecov()'
23 changes: 15 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
Package: POMA
Title: What the Package Does (One Line, Title Case)
Title: R Package for Statistical Analysis of Metabolomic Data
Version: 0.0.0.9000
Authors@R:
person(given = "First",
family = "Last",
person(given = "Pol",
family = "Castellano-Escuder",
role = c("aut", "cre"),
email = "first.last@example.com",
comment = c(ORCID = "YOUR-ORCID-ID"))
email = "polcaes@gmail.com",
comment = c(ORCID = "0000-0001-6466-877X"))
Description: What the package does (one paragraph).
License: What license it uses
License: GPL-3
Encoding: UTF-8
LazyData: true
Imports:
tidyverse
crayon
clisymbols
impute
reshape2
Suggests:
covr,
testthat (>= 2.1.0),
tidyverse
testthat (>= 2.1.0)
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1
595 changes: 595 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions R/PomaImpute.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ PomaImpute <- function(data,
cutoff = 20,
method = c("none", "half_min", "median", "mean", "min", "knn")){

if (!(method %in% c("none", "half_min", "median", "mean", "min", "knn"))) {
stop(crayon::red(clisymbols::symbol$cross, "Incorrect value for method argument!"))
}
if (missing(method)) {
method <- "knn"
warning("method argument is empty! KNN will be used")
}

data <- as.data.frame(data)
samples_groups <- data[, 1:2]
to_imp_data <- data[, c(3:ncol(data))]
Expand Down
55 changes: 55 additions & 0 deletions R/PomaNormPlot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

PomaNormPlot <- function(data, group = c("subjects", "metabolites")){

if (missing(group)) {
group <- "subjects"
warning("group argument is empty! subjects will be used")
}

colnames(data)[1:2] <- c("ID", "Group")
data <- data %>% mutate(ID = paste0(row_number(), "_", ID))

normtable_metabolites <- select(data, -ID) %>%
reshape2::melt()

normtable_subjects <- select(data, -Group) %>%
as_tibble() %>%
gather(var, value, -ID) %>%
spread(ID, value) %>%
reshape2::melt()

normtable_subjects <- normtable_subjects %>%
mutate(variable = str_replace_all(variable, "._", ""))

if(group == "subjects"){

normtable_subjects %>%
group_by(variable) %>%
ggplot(aes(variable, value, color = variable)) +
geom_boxplot() +
geom_jitter() +
theme(legend.position = "none") +
theme_minimal() +
xlab("") +
ggtitle("Normalization Plot by Subjects") +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none")

}
else{

normtable_metabolites %>%
group_by(Group) %>%
ggplot(aes(variable, value, color = Group)) +
geom_boxplot() +
geom_jitter() +
theme(legend.position = "none") +
theme_minimal() +
xlab("") +
ggtitle("Normalization Plot by Metabolites") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))

}

}

12 changes: 12 additions & 0 deletions R/PomaUnivariate.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ PomaUnivariate <- function(data_uni,
var_equal = FALSE,
adjust = c("fdr", "holm", "hochberg", "hommel", "bonferroni", "BH", "BY")){

if (missing(method)) {
stop(crayon::red(clisymbols::symbol$cross, "Select a method!"))
}
if (!(method %in% c("ttest", "anova", "mann", "kruskal"))) {
stop(crayon::red(clisymbols::symbol$cross, "Incorrect value for method argument!"))
}
if (missing(adjust)) {
adjust <- "fdr"
warning("adjust argument is empty! FDR will be used")
}


colnames(data_uni)[1:2] <- c("ID", "Group")
Group <- data_uni$Group

Expand Down
18 changes: 14 additions & 4 deletions R/PomaVolcano.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ PomaVolcano <- function(data,
FC_cutoff = 1.5,
xlim = 2){

if (missing(pval)) {
pval <- "raw"
warning("pval argument is empty! Raw p-value will be used")
}
if (!(pval %in% c("raw", "adjusted"))) {
stop(crayon::red(clisymbols::symbol$cross, "Incorrect value for pval argument!"))
}

names <- rownames(data)

if(pval == "raw"){
Expand All @@ -26,15 +34,17 @@ PomaVolcano <- function(data,
ggplot(data = df, aes(x = log2(FC), y = -log10(P.Value), colour = threshold)) +
geom_point(size=1.75) +
xlim(c(-(xlim), xlim)) +
xlab("log2 fold change") + ylab("-log10 p-value")+
xlab("log2 fold change") +
ylab("-log10 p-value") +
scale_y_continuous(trans = "log1p")+
ggtitle("Comparisson: Group2/Group1") +
geom_label(data = df[df$P.Value < Pval_cutoff & (df$FC > FC_cutoff | log2(df$FC) < -log2(FC_cutoff)),],
aes(x = log2(FC), y = -log10(P.Value)+0.12, label = names), show.legend = FALSE) +
ggrepel::geom_label_repel(data = df[df$P.Value < Pval_cutoff & (df$FC > FC_cutoff | log2(df$FC) < -log2(FC_cutoff)),],
aes(x = log2(FC), y = -log10(P.Value), label = names), show.legend = FALSE) +
geom_vline(xintercept = -log2(FC_cutoff), colour = "black") +
geom_vline(xintercept = log2(FC_cutoff), colour = "black") +
geom_hline(yintercept = -log10(Pval_cutoff), colour = "black") +
theme(legend.position = "none")+ theme_minimal() +
theme(legend.position = "none") +
theme_minimal() +
scale_color_manual(values = c("Down-regulated" = "#E64B35", "Up-regulated" = "#3182bd", "none" = "#636363"))

}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# POMA package

## R Package for Statistical Analysis of Metabolomic Data

<!-- badges: start -->
[![Codecov test coverage](https://codecov.io/gh/pcastellanoescuder/POMA_package/branch/master/graph/badge.svg)](https://codecov.io/gh/pcastellanoescuder/POMA_package?branch=master)
<!-- badges: end -->

0 comments on commit d92f4dd

Please sign in to comment.