Skip to content

Commit

Permalink
generalize density calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
whelena committed Nov 24, 2024
1 parent 93c3c7e commit f8d6f03
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 266 deletions.
19 changes: 19 additions & 0 deletions R/calculate.density.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
calculate.density <- function(
x,
value = 'genome.pos',
group = 'clone.id',
scale = TRUE,
...
) {

if (nrow(x) <= 1) {
return(NULL);
}
density <- density(x = x[[value]], bw = 'nrd', na.rm = TRUE, ...);
density.df <- as.data.frame(density[c('x', 'y')]);
density.df$clone.id <- unique(x[[group]]);
if (scale) {
density.df$y <- nrow(x) / sum(density.df$y) * density.df$y;
}
return(density.df)
}
17 changes: 0 additions & 17 deletions R/calculate.density.each.clone.R

This file was deleted.

16 changes: 1 addition & 15 deletions R/create.clone.genome.distribution.densityplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ create.clone.genome.distribution.densityplot <- function(

return(BoutrosLab.plotting.general::create.scatterplot(
filename = save.plt,
formula = count ~ x,
formula = y ~ x,
data = density.df,
groups = density.df$clone.id,
xlab.label = 'Chromosome',
Expand All @@ -24,17 +24,3 @@ create.clone.genome.distribution.densityplot <- function(
...
));
}

calculate.density.and.scale <- function(
x,
value = 'genome.pos',
group = 'clone.id'
) {

density <- density(x = x[[value]], bw = 'nrd', adjust = 0.05, na.rm = TRUE);
density.df <- as.data.frame(density[c('x', 'y')]);
density.df$clone.id <- unique(x[[group]]);
density.df$count <- nrow(x) / sum(density.df$y) * density.df$y;

return(density.df)
}
5 changes: 3 additions & 2 deletions R/create.clone.genome.distribution.plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ create.clone.genome.distribution.plot.per.sample <- function(
warning(paste('Skipping clone', k, 'in sample', unique(sample.df$ID), 'since there is only one SNV'));
next;
}
density.list[[k]] <- calculate.density.and.scale(
x = sample.df[sample.df$clone.id == k, ]
density.list[[k]] <- calculate.density(
x = sample.df[sample.df$clone.id == k, ],
adjust = 0.05
);
}
density.df <- do.call(rbind, density.list);
Expand Down
103 changes: 0 additions & 103 deletions R/plot.clone.densityplot.R

This file was deleted.

49 changes: 0 additions & 49 deletions R/plot.clones.densityplot.histogram.R

This file was deleted.

80 changes: 0 additions & 80 deletions R/plot.snv.histogram.R

This file was deleted.

0 comments on commit f8d6f03

Please sign in to comment.