Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
atusy committed Nov 29, 2018
2 parents 42f8a40 + ac0fed6 commit 033fb50
Show file tree
Hide file tree
Showing 102 changed files with 1,421 additions and 4,745 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
^README\.Rmd$
^docs$
^_pkgdown\.yml$
^.*\.Rproj$
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
.Rprofile
qntmap.Rproj
*.sync-conflict*

vignettes/center_add\.csv

vignettes/centers0\.csv

vignettes/\.build\.timestamp
21 changes: 11 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: qntmap
Type: Package
Title: Enhance quantitative analysis of EPMA data
Version: 0.2.2
Title: Enhance quantitative analysis of EPMA map
Version: 0.3.0
Authors@R: c(
person(given = 'YASUMOTO Atsushi', role = c('aut', 'cph', 'cre'), email = '[email protected]'),
person(given = 'YOSHIDA Kenta', role = c('ctb')),
Expand All @@ -17,16 +17,17 @@ Description: A main function of this packages is
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
Depends: R(>= 3.1.2)
Imports: curl,
data.table,
dplyr,
ggplot2,
DT,
easycsv,
imager,
ggplot2,
htmltools,
knitr,
matrixStats,
plotly,
pipeR,
PoiClaClu,
png,
Expand All @@ -35,6 +36,7 @@ Imports: curl,
scales,
stringr,
shiny,
shinyWidgets,
tibble,
tidyr,
utils
Expand All @@ -56,15 +58,13 @@ Collate:
'find_centers_kpp.R'
'group_cluster.R'
'mean.R'
'plot-shiny.R'
'plot.R'
'plot_shiny.R'
'plotly.R'
'plot_gg.R'
'print.R'
'qntmap.R'
'quantify.R'
'read_cnd.R'
'read_map_beam.R'
'read_map_pos.R'
'read_qnt.R'
'read_qnt_elemw.R'
'read_xmap.R'
Expand All @@ -78,6 +78,7 @@ Collate:
Roxygen: list(markdown = TRUE)
Suggests:
knitr,
pkgdown,
rmarkdown,
testthat
VignetteBuilder: knitr
61 changes: 46 additions & 15 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

S3method(mean,qntmap)
S3method(pick,qm_xmap)
S3method(plot,qm_cluster)
S3method(plot,qm_raster)
S3method(plot,qm_xmap)
S3method(plot,qntmap)
S3method(print,qntmap)
Expand Down Expand Up @@ -30,14 +32,18 @@ export(read_xmap)
export(save4qm)
export(segment)
export(tidy_epma)
import(shiny)
importFrom(DT,dataTableOutput)
importFrom(DT,datatable)
importFrom(DT,formatRound)
importFrom(DT,renderDT)
importFrom(PoiClaClu,Classify)
importFrom(data.table,fread)
importFrom(data.table,fwrite)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_cols)
importFrom(dplyr,bind_rows)
importFrom(dplyr,distinct)
importFrom(dplyr,everything)
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,left_join)
Expand All @@ -49,55 +55,80 @@ importFrom(dplyr,right_join)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(dplyr,summarize)
importFrom(dplyr,summarize_if)
importFrom(dplyr,transmute)
importFrom(dplyr,transmute_at)
importFrom(dplyr,ungroup)
importFrom(easycsv,choose_dir)
importFrom(ggplot2,aes)
importFrom(ggplot2,aes_string)
importFrom(ggplot2,coord_cartesian)
importFrom(ggplot2,coord_fixed)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_rect)
importFrom(ggplot2,geom_col)
importFrom(ggplot2,geom_bar)
importFrom(ggplot2,geom_histogram)
importFrom(ggplot2,geom_raster)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggtitle)
importFrom(ggplot2,scale_fill_gradientn)
importFrom(ggplot2,guide_colorbar)
importFrom(ggplot2,guide_legend)
importFrom(ggplot2,guides)
importFrom(ggplot2,scale_fill_gradient)
importFrom(ggplot2,scale_fill_manual)
importFrom(ggplot2,scale_fill_viridis_c)
importFrom(ggplot2,scale_y_reverse)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_classic)
importFrom(grDevices,col2rgb)
importFrom(grDevices,dev.copy)
importFrom(grDevices,dev.off)
importFrom(grDevices,nclass.FD)
importFrom(grDevices,png)
importFrom(grDevices,rgb)
importFrom(graphics,hist)
importFrom(graphics,pie)
importFrom(graphics,plot)
importFrom(imager,load.image)
importFrom(grid,unit)
importFrom(htmltools,br)
importFrom(htmltools,tags)
importFrom(knitr,kable)
importFrom(matrixStats,rowMaxs)
importFrom(matrixStats,weightedMedian)
importFrom(pipeR,"%>>%")
importFrom(pipeR,pipeline)
importFrom(plotly,event_data)
importFrom(plotly,ggplotly)
importFrom(plotly,layout)
importFrom(plotly,plot_ly)
importFrom(plotly,plotlyOutput)
importFrom(plotly,renderPlotly)
importFrom(png,readPNG)
importFrom(png,writePNG)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map2_dbl)
importFrom(purrr,map_at)
importFrom(purrr,map_dbl)
importFrom(purrr,map_if)
importFrom(purrr,map_int)
importFrom(purrr,pmap)
importFrom(purrr,walk2)
importFrom(scales,gradient_n_pal)
importFrom(rlang,sym)
importFrom(scales,squish)
importFrom(scales,viridis_pal)
importFrom(shiny,brushOpts)
importFrom(shiny,checkboxInput)
importFrom(shiny,fluidPage)
importFrom(shiny,hoverOpts)
importFrom(shiny,htmlOutput)
importFrom(shiny,mainPanel)
importFrom(shiny,numericInput)
importFrom(shiny,observeEvent)
importFrom(shiny,plotOutput)
importFrom(shiny,reactive)
importFrom(shiny,reactiveValues)
importFrom(shiny,renderPlot)
importFrom(shiny,renderPrint)
importFrom(shiny,renderUI)
importFrom(shiny,req)
importFrom(shiny,selectInput)
importFrom(shiny,shinyApp)
importFrom(shiny,sidebarLayout)
importFrom(shiny,sidebarPanel)
importFrom(shiny,splitLayout)
importFrom(shiny,uiOutput)
importFrom(shinyWidgets,radioGroupButtons)
importFrom(stats,coef)
importFrom(stats,lm)
importFrom(stats,lsfit)
Expand Down
19 changes: 19 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# qntmap 0.3.0

## Major changes

- `plot()`
- Interactive plot is a combination of shiny, ggplot2, and more. No more using plotly.
- Color control with histogram
- Hover information of pixels
- Zooming
- Moving
- Summarizing data in a table below heatmap
- Double click to keep pixel data
- Box select to keep mean values of data
- Grayscale is supported in addition to viridis.
- Clustering result is supported.
- `segment()`
- Only allows PNG format as an input.
No more JPG nor BMP allowed.

# qntmap 0.2.2

## Major changes
Expand Down
23 changes: 10 additions & 13 deletions R/add_centers.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#'
#' Add centroids manually by picking X-ray counts of selected pixels in X-ray maps.
#'
#' @seealso [pick()]
#' @seealso [find_centers()]
#' @seealso [pick()], [find_centers()]
#'
#' @examples
#' centers <- data.frame(
Expand All @@ -25,20 +24,18 @@
#' @inheritParams pick
#'
#' @importFrom dplyr bind_rows
#' @importFrom pipeR pipeline
#' @export
add_centers <- function(
centers,
xmap
) {
pipeline({
as.data.frame(centers)
add_centers <- function (centers, xmap) {
save4qm(
structure(
bind_rows(
as.data.frame(centers),
pick(xmap, x = x, y = y, phase = phase, i = i)[names(centers)]
)
`class<-`(class(centers))
save4qm(nm = saveas, saving = is.character(saveas))
})
),
class = class(centers)
),
nm = saveas, saving = is.character(saveas)
)
}
formals(add_centers) <- c(
formals(add_centers),
Expand Down
51 changes: 29 additions & 22 deletions R/cluster.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#' Poisson distribution based custering based on `PoiClaClu:Classify()`
#' Poisson distribution based custering based on [`PoiClaClu::Classify()`]
#'
#' @param centers c-by-p matrix returned by `find_centers()` or by manually; c clusters and p features. Used to guess initial centers (or centroids) of clusters. A value returned by , typically `data.frame` or `matrix`, indicating initial guess centers (or centroids) or clusters. See `find_centers()`.
#' @param centers c-by-p matrix returned by [`find_centers()`] or by manually;
#' c clusters and p features.
#' Used to guess initial centers (or centroids) of clusters.
#' A value returned by , typically [`data.frame`] or [`matrix`],
#' indicating initial guess centers (or centroids) or clusters.
#' See [`find_centers()`].
#' @inheritParams PoiClaClu::Classify
#' @inheritDotParams PoiClaClu::Classify -x -y -xte
#' @inherit PoiClaClu::Classify return
#' @inherit PoiClaClu::Classify references
#' @seealso \link[PoiClaClu]{Classify}
#' @inherit PoiClaClu::Classify return references
#' @seealso [PoiClaClu::Classify()], [find_centers()]
#'
#' @importFrom PoiClaClu Classify
#' @export
cluster <- function(x, centers, xte = NULL, ...) {
x_trans <- t(x)
y <- pipeline({
centers
apply(1, function(y) colSums((x_trans - y) ^ 2))
apply(1, which.min)
apply(1L, function(y) colSums((x_trans - y) ^ 2L))
apply(1L, which.min)
})
rm(x_trans)
Classify(x, y, `if`(is.null(xte), x, xte), ...)
Expand All @@ -25,16 +29,19 @@ cluster <- function(x, centers, xte = NULL, ...) {
#' Cluster mapping data into mineral species
#'
#' @inheritParams cluster
#' @param xmap a `qm_xmap` class object returned by `read_xmap`
#' @param elements A character vector indicating which elements to be utilized in cluster analysis. `NULL`, in default, selects as much elements as possible are utilized in cluster analysis.
#' @param xmap a `qm_xmap` class object returned by [`read_xmap()`]
#' @param elements
#' A character vector to chose elements to be utilized in cluster analysis.
#' `NULL` (default) selects as much elements as possible.
#' @param saving `TRUE` or `FALSE` to save result.
#' @param group_cluster `TRUE` (default) or `FALSE` to integrate same phase subgrouped using suffix. For example, when there are clusters named as Pl_NaRich and Pl_NaPoor, they are grouped as Pl.
#' @param group_cluster
#' `FALSE` (default) or `TRUE` to integrate same phase subgrouped using suffix.
#' For example,
#' clusters named "Pl_NaRich" and "Pl_NaPoor" are integrated to "Pl" cluster .
#'
#' @importFrom dplyr group_by
#' @importFrom dplyr ungroup
#' @importFrom dplyr group_by ungroup
#' @importFrom pipeR pipeline
#' @importFrom tidyr gather
#' @importFrom tidyr spread
#' @importFrom tidyr gather spread
#' @importFrom matrixStats rowMaxs
#'
#' @export
Expand Down Expand Up @@ -86,20 +93,20 @@ cluster_xmap <- function(
if(nrow(centers) == ncol(result$membership)) {
colnames(result$membership) <- centers$phase
} else {
if(ncol(result$membership) == 1) {
colnames(result$membership) <- names(result$ytehat[1])
if(ncol(result$membership) == 1L) {
colnames(result$membership) <- names(result$ytehat[1L])
} else {
TF <- !duplicated(result$cluster)
colnames(result$membership)[apply(result$membership[TF, ], 1, which.max)] <-
colnames(result$membership)[apply(result$membership[TF, ], 1L, which.max)] <-
result$cluster[TF]
rm(TF)
}
missings <- setdiff(centers$phase, colnames(result$membership))
result$membership <- cbind(
result$membership,
matrix(
0,
nrow(result$membership),
0L,
nrow = nrow(result$membership),
ncol = length(missings),
dimnames = list(NULL, missings)
)
Expand All @@ -122,9 +129,10 @@ cluster_xmap <- function(



#' (Deprecated) Use `cluster_xmap()`
#' (DEPRECATED) Use `cluster_xmap()`
#'
#' @param centers_initial Equivalent to `centers_initial` parameter of `cluster_xmap`
#' @param centers_initial
#' Equivalent to `centers_initial` parameter of `cluster_xmap`
#' @param qltmap Equivalent to `xmap` parameter of `cluster_xmap`
#' @param wd Path to the working directory.
#' @param integration Equivalent to `group_cluster` parameter of `cluster_xmap`
Expand Down Expand Up @@ -153,7 +161,6 @@ qntmap_cls_pois <- function(
if(is.null(elements)) elements <-
intersect(names(qltmap), colnames(centers_initial))

xmap <-
cluster_xmap(
qltmap,
centers_initial,
Expand Down
Loading

0 comments on commit 033fb50

Please sign in to comment.