Skip to content

Commit

Permalink
mutliple genes can be selected from the table
Browse files Browse the repository at this point in the history
  • Loading branch information
oganm committed Oct 17, 2016
1 parent c4bd413 commit c3ce212
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
27 changes: 12 additions & 15 deletions global.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ library(dplyr)
library(Matrix)
library(plotly)
library(magrittr)
source('regexMerge.R')

barcodes = read_tsv('Data/redstone_1_barcodes.tsv', col_names = 'Barcode')
genes = read_tsv('Data/redstone_1_genes.tsv',col_names = c('ID','Symbol'))
Expand All @@ -18,20 +19,19 @@ rowMax <- expression %>% apply(1,max)
expression <- expression[rowMax>0,]
genes <- genes[rowMax > 0,]

normalizeExpression = function(mat) {
mat<-expression
mat<-t(mat)

# for each cell, compute total expression
expression_sum_for_each_cell <- rowSums(mat)
# get the overall median expression value
overall_median_expression <- median(expression_sum_for_each_cell)

normalized_expression <- mat/(expression_sum_for_each_cell/overall_median_expression)
t(normalized_expression)
normalizeExpresion = function(v) {
# for each cell, compute total expression
expression_sum_for_each_cell <- colSums(expression)
# get the overall median expression value
overall_median_expression <- median(expression_sum_for_each_cell)
# scale each expression value by the cell-specific scale factor
scale_factor_for_each_cell <- (expression_sum_for_each_cell/overall_median_expression)
normalized_expression <- expression/scale_factor_for_each_cell

normalized_expression
}

expression = normalizeExpression(expression)
expression = normalizeExpresion(expression)

genes$Symbol_ID <- paste(genes$Symbol,genes$ID, sep="_")
list_of_genesymbols <- sort(genes$Symbol_ID)
Expand All @@ -53,9 +53,6 @@ plot_geneExpr <- function(gene_of_interest, gene_name, input_midplot=1,
barcode = barcodes$Barcode,
expr = expression[gene_of_interest,]) %>%
tbl_df()

input_midplot <- max(gene_expr$expr)*input_midplot

## Join with tSNE
tsne1 <-
left_join(tsne, gene_expr, by="barcode")
Expand Down
9 changes: 9 additions & 0 deletions regexMerge.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
regexMerge = function(regexList, exact = FALSE){
assertthat::assert_that(is.logical(exact))
exact = as.character(exact)
out = switch (exact,
'FALSE' = {paste0('(',paste0(regexList,collapse=')|('),')')},
'TRUE' = {paste0('(\\Q',paste0(regexList,collapse='\\E)|(\\Q'),'\\E)')}
)
out = paste0('(',out,')')
}
4 changes: 2 additions & 2 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ shinyServer(function(input, output, session) {

output$difGeneTable = renderDataTable({
if(!is.null(differentiallyExpressed())){
datatable(differentiallyExpressed(),selection = 'single')
datatable(differentiallyExpressed(),selection = 'multiple')
}
})
# if a gene is selected from the data table, select that gene in the expression window
observe({
if(!is.null(input$difGeneTable_rows_selected)){
gene = differentiallyExpressed()[input$difGeneTable_rows_selected,]$`Gene Symbol`
selectedGene = list_of_genesymbols[grepl(paste0('^',gene,'_'),list_of_genesymbols)]
selectedGene = list_of_genesymbols[grepl(regexMerge(paste0('^',gene,'_')),list_of_genesymbols)]
updateSelectInput(session, 'input_genes', selected = selectedGene)
}
})
Expand Down

0 comments on commit c3ce212

Please sign in to comment.