Skip to content

Commit

Permalink
Merge pull request #66 from uclahs-cds/nzeltser-fix-plotting-bug
Browse files Browse the repository at this point in the history
Nzeltser fix plotting bug
  • Loading branch information
alkaZeltser authored Oct 30, 2024
2 parents bbe9bf5 + 3621b31 commit a11ad47
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions R/plot-pgs.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ create.pgs.density.plot <- function(

# prettify x-axis labels (handle exponential notation)
basic.xaxis.formatting <- BoutrosLab.plotting.general::auto.axis(
stats::quantile(unlist(pgs.data.for.plotting), probs = c(0.1, 0.9)),
stats::quantile(unlist(pgs.data.for.plotting), probs = c(0.1, 0.9), na.rm = TRUE),
log.scaled = FALSE,
num.labels = 3,
include.origin = FALSE
Expand Down Expand Up @@ -200,7 +200,7 @@ create.pgs.density.plot <- function(
warning(paste0('Skipping colors for ', pgs.column, ' and ', phenotype, ' due to too many categories'));
# plot all lines in black
group.xaxis.formatting <- BoutrosLab.plotting.general::auto.axis(
quantile(unlist(pgs.data.for.plotting), probs = c(0.1, 0.9)),
quantile(unlist(pgs.data.for.plotting), probs = c(0.1, 0.9), na.rm = TRUE),
log.scaled = FALSE,
num.labels = 3,
include.origin = FALSE
Expand Down Expand Up @@ -237,7 +237,7 @@ create.pgs.density.plot <- function(
}

group.xaxis.formatting <- BoutrosLab.plotting.general::auto.axis(
quantile(unlist(pgs.data.for.plotting), probs = c(0.1, 0.9)),
quantile(unlist(pgs.data.for.plotting), probs = c(0.1, 0.9), na.rm = TRUE),
log.scaled = FALSE,
num.labels = 3,
include.origin = FALSE
Expand Down
Binary file modified tests/testthat/data/phenotype.test.data.Rda
Binary file not shown.
8 changes: 4 additions & 4 deletions tests/testthat/generate-test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ alt.alleles <- rep('T', length(genotypes));
alt.alleles[genotypes == 1] <- 'A';
alt.alleles[genotypes == 2] <- 'A';

binary.phenotype <- rbinom(n.samples, size = 1, prob = 0.5); # random binary phenotype values
binary.phenotype <- rbinom(n.samples + 1, size = 1, prob = 0.5); # random binary phenotype values
binary.factor.phenotype <- factor(binary.phenotype, levels = c(0, 1), labels = c('control', 'case'));
categorical.phenotype <- factor(sample(letters[1:5], n.samples, replace = TRUE)); # random categorical phenotype values
categorical.phenotype <- factor(sample(letters[1:5], n.samples + 1, replace = TRUE)); # random categorical phenotype values

phenotype.test.data <- list(
# vcf with 10 samples and 10 variants
Expand All @@ -249,8 +249,8 @@ phenotype.test.data <- list(
beta = rnorm(10) # random beta values
),
phenotype.data = data.frame(
Indiv = paste0('sample', 1:n.samples),
continuous.phenotype = rnorm(n.samples), # random phenotype values
Indiv = paste0('sample', 1:(n.samples + 1)), # add an extra sample with no genotype data
continuous.phenotype = rnorm(n.samples + 1), # random phenotype values
binary.phenotype = binary.phenotype,
binary.factor.phenotype = binary.factor.phenotype,
categorical.phenotype = categorical.phenotype
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-pgs-statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ test_that(
pgs <- seq(0, 1, length.out = nrow(phenotype.test.data$phenotype.data));
phenotype.columns <- c('continuous.phenotype', 'binary.phenotype');
phenotype.data <- phenotype.test.data$phenotype.data[ , phenotype.columns];
phenotype.data$binary.factor <- rep(c('a', 'b'), 5); # should be included in the regression
phenotype.data$categorical.phenotype <- rep(c('a', 'b', 'c', 'd', 'e'), 2); # should not be included in the regression
phenotype.data$binary.factor <- rep(c('a', 'b'), 5);
phenotype.data$binary.factor <- c(rep(c('a', 'b'), 5), 'a'); # should be included in the regression
phenotype.data$categorical.phenotype <- c(rep(c('a', 'b', 'c', 'd', 'e'), 2), 'f'); # should not be included in the regression
phenotype.data$binary.factor <- c(rep(c('a', 'b'), 5), 'a');

# run function
regression.data <- run.pgs.regression(pgs = pgs, phenotype.data = phenotype.data);
Expand Down Expand Up @@ -177,8 +177,8 @@ test_that(
pgs <- seq(0, 1, length.out = nrow(phenotype.test.data$phenotype.data));
phenotype.columns <- c('continuous.phenotype', 'binary.phenotype');
phenotype.data <- phenotype.test.data$phenotype.data[ , phenotype.columns];
phenotype.data$binary.factor <- rep(c('a', 'b'), 5); # should be included in the regression
phenotype.data$categorical.phenotype <- rep(c('a', 'b', 'c', 'd', 'e'), 2); # should not be included in the regression
phenotype.data$binary.factor <- c(rep(c('a', 'b'), 5), 'a'); # should be included in the regression
phenotype.data$categorical.phenotype <- c(rep(c('a', 'b', 'c', 'd', 'e'), 2), 'f'); # should not be included in the regression

# run function
regression.data <- run.pgs.regression(pgs = pgs, phenotype.data = phenotype.data);
Expand Down

0 comments on commit a11ad47

Please sign in to comment.