Skip to content

Commit

Permalink
added clusters.data.out.dir option to get_unsupervised_graph_from_files
Browse files Browse the repository at this point in the history
  • Loading branch information
pfgherardini committed Jul 25, 2018
1 parent 55858c9 commit e9f7427
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: vite
Type: Package
Title: Analyzing single-cell data using graphs
Version: 0.4.0
Version: 0.4.1
Authors@R: "Pier Federico Gherardini <pfgherardini@parkerici.org> [aut, cre]"
Description: This is a package for visualization and analysis of high-dimensional
single-cell data using graphs
Expand Down
7 changes: 5 additions & 2 deletions R/unsupervised.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,17 @@ get_unsupervised_graph <- function(tab, col.names, filtering.threshold) {
#' will be processed using the \code{\link{write_clusters_data}} function. This processing is used for downstream data visualization
#' but it is not strictly necessary to create the graph. If \code{use.basename} is \code{TRUE} the \code{basename} of the files in
#' \code{files.list} will be used for processing.
#' @param clusters.data.out.dir Only used if \code{process.clusters.data == TRUE}. The output directory where the clusters data
#' will be written
#' @param downsample.to The target number of events for downsampling. Only used if \code{process.clusters.data == TRUE}. This is only
#' used for downstream data visualization and does not affect the construction of the graph
#'
#' @return See the return value of \code{get_unsupervised_graph}
#'
#' @export
get_unsupervised_graph_from_files <- function(files.list, col.names, filtering.threshold,
metadata.tab = NULL, metadata.filename.col = NULL, use.basename = TRUE, process.clusters.data = TRUE, downsample.to = 1000) {
metadata.tab = NULL, metadata.filename.col = NULL, use.basename = TRUE, process.clusters.data = TRUE,
clusters.data.out.dir = "./", downsample.to = 1000) {
if(!is.null(metadata.tab) && c("sample", "name", "Label", "type") %in% names(metadata.tab))
stop("Metadata column names cannot include sample, name, Label or type")

Expand Down Expand Up @@ -166,7 +169,7 @@ get_unsupervised_graph_from_files <- function(files.list, col.names, filtering.t
tab <- downsample_by(tab, "cellType", downsample.to)
if(use.basename)
f <- basename(f)
write_clusters_data(tab, f, pooled.only = TRUE)
write_clusters_data(tab, f, output.dir = clusters.data.out.dir, pooled.only = TRUE)
}
}

Expand Down
23 changes: 12 additions & 11 deletions inst/shinyGUI/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ render_scaffold_ui <- function(working.directory, ...) {renderUI({
column(6,
checkboxInput("scaffoldui_transform_landmarks_data", "Transform landmarks data", value = TRUE)
),
column(6,
column(6,
conditionalPanel(condition = "input.scaffoldui_transform_landmarks_data",
numericInput("scaffoldui_asinh_cofactor", "Cofactor for asinh transformation", 5)
)
Expand All @@ -64,7 +64,7 @@ render_scaffold_ui <- function(working.directory, ...) {renderUI({
checkboxInput("scaffoldui_inter_cluster_connections", "Add inter-cluster connections", value = TRUE),
conditionalPanel(
condition = "input.scaffoldui_inter_cluster_connections == true",
selectInput("scaffoldui_markers_inter_cluster", "Markers for inter-cluster connections (if different)", choices = c(""), multiple = T, width = "100%"),
selectInput("scaffoldui_markers_inter_cluster", "Markers for inter-cluster connections (if different)", choices = c(""), multiple = T, width = "100%"),
numericInput("scaffoldui_inter_cluster_weight", "Weight factor for inter-cluster connections", 0.7, min = 0, max = 10, step = 0.1)
),
selectInput("scaffoldui_overlap_method", "Overlap resolution method", choices = c("Repel", "Expand")),
Expand All @@ -90,7 +90,7 @@ shinyServer(function(input, output, session) {
observeEvent(input$unsupervisedui_select_metadata, {
unsupervisedui.reactive.values$metadata.file <- file.choose()
})

observe({
if(!is.null(input$unsupervisedui_markers_file) && input$unsupervisedui_markers_file != "") {
tab <- read.table(file.path(working.directory, input$unsupervisedui_markers_file), header = TRUE, sep = "\t", check.names = FALSE)
Expand All @@ -114,16 +114,17 @@ shinyServer(function(input, output, session) {

files.list <- file.path(working.directory, input$unsupervisedui_files_list)
metadata.tab <- NULL

if(!is.null(input$unsupervisedui_metadata_file) && input$unsupervisedui_metadata_file != "")
metadata.tab <- read.table(input$unsupervisedui_metadata_file, header = TRUE, sep = "\t", check.names = FALSE, stringsAsFactors = FALSE)

G <- vite::get_unsupervised_graph_from_files(
files.list = files.list,
col.names = input$unsupervisedui_markers,
filtering.threshold = input$unsupervisedui_filtering_threshold,
metadata.tab = metadata.tab,
metadata.filename.col = "filename"
metadata.filename.col = "filename",
clusters.data.out.dir = working.directory
)

out.name <- file.path(working.directory, sprintf("%s.graphml", input$unsupervisedui_out_name))
Expand Down Expand Up @@ -177,11 +178,11 @@ shinyServer(function(input, output, session) {
))

files.list <- list.files(working.directory, pattern = "*.clustered.txt$", full.names = TRUE)
landmarks.data <- load_landmarks_from_dir(scaffoldui.reactive.values$landmarks.dir,
landmarks.data <- load_landmarks_from_dir(scaffoldui.reactive.values$landmarks.dir,
input$scaffoldui_asinh_cofactor, input$scaffoldui_transform_landmarks_data)

inter.cluster.col.names <- NULL

if(input$scaffoldui_inter_cluster_connections) {
if(length(input$scaffoldui_markers_inter_cluster) > 0)
inter.cluster.col.names <- input$scaffoldui_markers_inter_cluster
Expand All @@ -203,9 +204,9 @@ shinyServer(function(input, output, session) {
)


if(input$scaffoldui_ew_influence_type == "Fixed")
if(input$scaffoldui_ew_influence_type == "Fixed")
args.list <- c(args.list, list(ew.influence = input$scaffoldui_ew_influence))

do.call(vite::run_scaffold_analysis, args.list)

showModal(modalDialog(
Expand All @@ -214,4 +215,4 @@ shinyServer(function(input, output, session) {
))
})
})
})
})
6 changes: 5 additions & 1 deletion man/get_unsupervised_graph_from_files.Rd

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

0 comments on commit e9f7427

Please sign in to comment.