Skip to content

Commit

Permalink
add exp name pattern and apply button
Browse files Browse the repository at this point in the history
  • Loading branch information
atc3 committed Feb 4, 2019
1 parent ecbfa10 commit b72638c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions example/config_file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ exclude_files: '180614_S_A'
# %e -- raw file name
exp_name_format: 'Exp %f %i'

# optional regular expression pattern to extract
# from the experiment names after applying the format string
exp_name_pattern: '[0-9]{6}'

# custom names for files
exp_names:
- Control
Expand Down
20 changes: 19 additions & 1 deletion server.R
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,17 @@ shinyServer(function(input, output, session) {
file_levels(.file_levels)
})

exp_name_format <- debounce(reactive({ input$exp_name_format }), 1000)
exp_name_format <- reactiveVal(config[['exp_name_format']])
# only change the exp_name_pattern when the apply button is pressed
observeEvent(input$exp_name_format_apply, {
exp_name_format(input$exp_name_format)
})

exp_name_pattern <- reactiveVal(config[['exp_name_pattern']])
# only change the exp_name_pattern when the apply button is pressed
observeEvent(input$exp_name_pattern_apply, {
exp_name_pattern(input$exp_name_pattern)
})

file_levels <- reactiveVal()

Expand All @@ -490,6 +500,7 @@ shinyServer(function(input, output, session) {

# load naming format
.format <- exp_name_format()
.pattern <- exp_name_pattern()
.file_levels <- rep(.format, length(.raw_files))

# replace flags in the format
Expand All @@ -505,6 +516,13 @@ shinyServer(function(input, output, session) {
# replace %e with the raw file name
.file_levels <- str_replace(.file_levels, '\\%e', .raw_files)

# apply custom string extraction expression to file levels
if(!is.null(.pattern) & length(.pattern) > 0 & nchar(.pattern) > 0) {
.file_levels <- str_extract(.file_levels, .pattern)
# if string extraction failed, then will return NA. set NAs to "default"
.file_levels[is.na(.file_levels)] <- 'default'
}

file_levels(.file_levels)
})

Expand Down
1 change: 1 addition & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ remove_decoy: REV_
remove_contam: CON_

exp_name_format: 'Exp %f %i'
exp_name_pattern: ''

## Figure rendering options

Expand Down
18 changes: 16 additions & 2 deletions ui/import_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,22 @@ import_tab <- tabItem(tabName='import', fluidPage(
tags$li(tags$b('%e'), tags$span(' Name of the experiment raw file.'))
),
p('For example, "file_%f-%i" would render to "file_SCOPE-3" given the folder "SCOPE" and the index 3'),
textInput('exp_name_format', 'Experiment Label Format', value=config[['exp_name_format']],
width=NULL, placeholder='Experiment naming format'),
fixedRow(style='display:flex;flex-direction:row;align-items:center;',
column(9,
textInput('exp_name_format', 'Experiment Label Format', value=config[['exp_name_format']],
width=NULL, placeholder='Experiment naming format')),
column(3,
actionButton('exp_name_format_apply', 'Apply', width=100))
),
p('Further process file names after applying the format string with a string extraction pattern'),
p('For example, a pattern "[0-9]{6}" would extract the first 6 sequential numbers in the experiment name.'),
fixedRow(style='display:flex;flex-direction:row;align-items:center;',
column(9,
textInput('exp_name_pattern', 'Experiment Extraction Pattern', value=config[['exp_name_pattern']],
width=NULL, placeholder='Regular expression. e.g., [0-9]{6}')),
column(3,
actionButton('exp_name_pattern_apply', 'Apply', width=100))
),
p('Or, use the table below to manually rename experiments'),
p('Double click on an entry in the "Label" column to begin editing. Press enter or click outside of the table to finish editing and confirm the changes.'),
DT::dataTableOutput('exp_name_table'),
Expand Down

0 comments on commit b72638c

Please sign in to comment.