Skip to content

Commit

Permalink
Add extract_surface()
Browse files Browse the repository at this point in the history
  • Loading branch information
heavywatal committed May 15, 2016
1 parent 38dd57d commit 8ad1291
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(exclusive_ancestors)
export(exclusive_ancestors_ss)
export(extract_ancestor)
export(extract_demography)
export(extract_surface)
export(gglattice2d)
export(maxabs)
export(plot_tumor3d)
Expand Down
20 changes: 20 additions & 0 deletions R/extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ altered_params = function(conf) {
unlist() %>>% (.[. > 1]) %>>% names()
}

#' subfunction
.extract_surface = function(mtrx, plane=c('x', 'y'), axis='z') {
tmpl = 'genealogy[which.%s(%s)]'
dplyr::group_by_(mtrx, .dots=plane) %>>%
dplyr::summarise_(min=sprintf(tmpl, 'min', axis),
max=sprintf(tmpl, 'max', axis)) %>>%
{union(.$min, .$max)}
}

#' extract cells on suface
#' @param mtrx a data.frame with (x, y, z) columns
#' @return a string vector
#' @rdname extract
#' @export
extract_surface = function(mtrx) {
.extract_surface(mtrx, c('x', 'y'), 'z') %>>%
union(.extract_surface(mtrx, c('y', 'z'), 'x')) %>>%
union(.extract_surface(mtrx, c('z', 'x'), 'y'))
}

#' extract demography from population data
#' @param grouped_df a grouped_df
#' @return a grouped data.frame
Expand Down
2 changes: 0 additions & 2 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ plot_tumor3d = function(.data, .color='ancestor', .palette='Spectral') {
.data[.color] = as.factor(.data[[.color]])
num_colors = length(levels(.data[[.color]]))
.palette = RColorBrewer::brewer.pal(num_colors, .palette)
thres = sphere_radius(nrow(.data)) * 0.6
.data %>>%
dplyr::filter_(~sqrt(x^2 + y^2 + z^2) > thres) %>>%
{rgl::spheres3d(.$x, .$y, .$z, color=.palette[.[[.color]]],
radius=1, alpha=1)}
rgl::box3d()
Expand Down
3 changes: 2 additions & 1 deletion R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ read_conf = function(indir='.') {
read_population = function(conf, params=NULL) {
dplyr::group_by_(conf, .dots=c('path', params)) %>>%
dplyr::do({
x = readr::read_tsv(file.path(.$path, 'population.tsv.gz'))
x = readr::read_tsv(file.path(.$path, 'population.tsv.gz')) %>>%
dplyr::mutate_(surface=~ genealogy %in% extract_surface(.))
if (.$coord == 'hex') {
x = trans_coord_hex(x)
}
Expand Down
9 changes: 9 additions & 0 deletions man/extract.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8ad1291

Please sign in to comment.