Skip to content

Commit

Permalink
add fractional and total ID rate modules to DART tab
Browse files Browse the repository at this point in the history
  • Loading branch information
atc3 committed May 10, 2019
1 parent 2603a5f commit 3869157
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 0 deletions.
89 changes: 89 additions & 0 deletions modules/070_DART-ID/dart_04_fractional_ID_rate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
init <- function() {

type <- 'plot'
box_title <- 'Fractional ID Rate'
help_text <- 'Fractional rate of confident PSMs and PSMs from all MS2 scan events'
source_file <- 'evidence, msmsScans'

.validate <- function(data, input) {
validate(need(data()[['evidence']], paste0('Upload evidence.txt')))
validate(need(data()[['msmsScans']], paste0('Upload msmsScans.txt')))

# ensure that table has the DART-ID residual RT
validate(need(
'dart_PEP' %in% colnames(data()[['evidence']]),
paste0('Provide evidence.txt from DART-ID output, with updated dart_PEP column')
))
}

.plotdata <- function(data, input) {

# MS2 Scans and PSMs
a <- data()[['msmsScans']] %>%
dplyr::select('Raw.file', 'Sequence') %>%
dplyr::group_by(Raw.file) %>%
dplyr::summarise(scans=dplyr::n(),
psms=sum(as.character(Sequence) != ' ', na.rm=T)) %>%
dplyr::arrange(Raw.file)

# IDs at 1e-2 PEP, 1e-2 DART PEP
b <- data()[['evidence']] %>%
dplyr::select('Raw.file', 'Sequence', 'PEP', 'dart_PEP') %>%
dplyr::group_by(Raw.file) %>%
dplyr::summarise(ids=sum(PEP < 0.01, na.rm=T),
dart_ids=sum(dart_PEP < 0.01, na.rm=T)) %>%
dplyr::arrange(Raw.file)
if(nrow(a) == nrow(b)){
plotdata <- cbind(a, b[,-1]) %>%
# get fractional rates, i.e., fraction of MSMS scans
dplyr::mutate(psms = psms / scans,
ids = ids / scans,
dart_ids = dart_ids / scans) %>%
# gather = dplyr equiv. of reshape2::melt
tidyr::gather(key, value, -Raw.file) %>%
# remove msms scans
dplyr::filter(key != 'scans') %>%
# rename levels
dplyr::mutate(key=factor(key, labels=c('IDs @ DART PEP < 0.01', 'IDs @ PEP < 0.01', 'PSMs')))
}else if((nrow(a) > 0) & (nrow(b) == 0)){
plotdata <- a %>%
tidyr::gather(key, value, -Raw.file) %>%
# rename levels
dplyr::mutate(key=factor(key, labels=c('PSMs')))
}else if((nrow(a) == 0) & (nrow(b) > 0)){
plotdata <- b %>%
tidyr::gather(key, value, -Raw.file) %>%
# rename levels
dplyr::mutate(key=factor(key, labels=c('IDs @ DART PEP < 0.01', 'IDs @ PEP < 0.01', 'PSMs')))
}
return(plotdata)
}

.plot <- function(data, input) {
.validate(data, input)
plotdata <- .plotdata(data, input)

validate(need((nrow(plotdata) > 1), paste0('No Rows selected')))

ggplot(plotdata, aes(Raw.file, value, fill=key)) +
geom_bar(stat='identity', position='dodge') +
labs(x='Experiment', y='Fraction', fill='Category') +
theme_base(input=input, show_legend=T) +
# keep the legend
theme(legend.position='right',
legend.key=element_rect(fill='white'))
}

return(list(
type=type,
box_title=box_title,
help_text=help_text,
source_file=source_file,
validate_func=.validate,
plotdata_func=.plotdata,
plot_func=.plot,
dynamic_width=150,
dynamic_width_base=300
))
}

83 changes: 83 additions & 0 deletions modules/070_DART-ID/dart_05_total_ID_rate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
init <- function() {

type <- 'plot'
box_title <- 'Total ID Rate'
help_text <- 'Number of MSMS scans, PSMs, and confident PSMs'
source_file <- 'evidence, msmsScans'

.validate <- function(data, input) {
validate(need(data()[['evidence']], paste0('Upload evidence.txt')))
validate(need(data()[['msmsScans']], paste0('Upload msmsScans.txt')))

# ensure that table has the DART-ID residual RT
validate(need(
'dart_PEP' %in% colnames(data()[['evidence']]),
paste0('Provide evidence.txt from DART-ID output, with updated dart_PEP column')
))
}

.plotdata <- function(data, input) {

# MS2 Scans and PSMs
a <- data()[['msmsScans']] %>%
dplyr::select('Raw.file', 'Sequence') %>%
dplyr::group_by(Raw.file) %>%
dplyr::summarise(scans=dplyr::n(),
psms=sum(as.character(Sequence) != ' ', na.rm=T)) %>%
dplyr::arrange(Raw.file)

# IDs at 5e-2 and 1e-2 PEP
b <- data()[['evidence']] %>%
dplyr::select('Raw.file', 'Sequence', 'PEP', 'dart_PEP') %>%
dplyr::group_by(Raw.file) %>%
dplyr::summarise(ids=sum(PEP < 0.01, na.rm=T),
dart_ids=sum(dart_PEP < 0.01, na.rm=T)) %>%
dplyr::arrange(Raw.file)
if(nrow(a) == nrow(b)){
plotdata <- cbind(a, b[,-1]) %>%
# gather = dplyr equiv. of reshape2::melt
tidyr::gather(key, value, -Raw.file) %>%
# rename levels
dplyr::mutate(key=factor(key, labels=c('IDs @ DART PEP < 0.01', 'IDs @ PEP < 0.01', 'PSMs', 'MSMSs')))
}else if((nrow(a) > 0) & (nrow(b) == 0)){
plotdata <- a %>%
tidyr::gather(key, value, -Raw.file) %>%
# rename levels
dplyr::mutate(key=factor(key, labels=c('PSMs', 'MSMSs')))
}else if((nrow(a) == 0) & (nrow(b) > 0)){
plotdata <- b %>%
tidyr::gather(key, value, -Raw.file) %>%
# rename levels
dplyr::mutate(key=factor(key, labels=c('IDs @ DART PEP < 0.01', 'IDs @ PEP < 0.01')))
}
return(plotdata)
}

.plot <- function(data, input) {
.validate(data, input)
plotdata <- .plotdata(data, input)

validate(need((nrow(plotdata) > 1), paste0('No Rows selected')))

ggplot(plotdata, aes(Raw.file, value, fill=key)) +
geom_bar(stat='identity', position='dodge') +
labs(x='Experiment', y='Fraction', fill='Category') +
theme_base(input=input, show_legend=T) +
# keep the legend
theme(legend.position='right',
legend.key=element_rect(fill='white'))
}

return(list(
type=type,
box_title=box_title,
help_text=help_text,
source_file=source_file,
validate_func=.validate,
plotdata_func=.plotdata,
plot_func=.plot,
dynamic_width=150,
dynamic_width_base=300
))
}

0 comments on commit 3869157

Please sign in to comment.