Skip to content

Commit

Permalink
Merge pull request #160 from warrenmcg/patch3
Browse files Browse the repository at this point in the history
Fix behavior of sleuth_results when gene_mode is TRUE (and error reporting)
  • Loading branch information
pimentel authored Mar 13, 2018
2 parents df2d0be + 223efb8 commit 9c88822
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -398,24 +398,7 @@ sleuth_results <- function(obj, test, test_type = 'wt',
data.table::as.data.table(obj$target_mapping),
data.table::as.data.table(res),
by = 'target_id')
}

if ( pval_aggregate ) {
if (is.null(obj$target_mapping) ) {
stop('Must provide transcript to gene mapping table in order to aggregate p-values')
}
res <- data.table::as.data.table(res)
res <- res[, .(
num_aggregated_transcripts = length(!is.na(pval)),
sum_mean_obs_counts = sum(mean_obs, na.rm=TRUE),
pval = as.numeric(aggregation::lancaster(pval, mean_obs))),
by=eval(obj$gene_column)]

res <- res[, qval:=p.adjust(pval, 'BH')]
res <- as_df(res)
}

if (show_all && !is.null(obj$target_mapping) && obj$gene_mode) {
} else if (!is.null(obj$target_mapping) && obj$gene_mode) {
# after removing the target_id column
# there are several redundant columns for each gene
# this line gets the unique line for each gene
Expand All @@ -433,6 +416,22 @@ sleuth_results <- function(obj, test, test_type = 'wt',
names(res)[1] <- "target_id"
}

if ( pval_aggregate ) {
if (is.null(obj$target_mapping) ) {
stop('Must provide transcript to gene mapping table in order to aggregate p-values. ',
'Please rerun "sleuth_prep" using the "target_mapping" argument.')
}
res <- data.table::as.data.table(res)
res <- res[, .(
num_aggregated_transcripts = length(!is.na(pval)),
sum_mean_obs_counts = sum(mean_obs, na.rm=TRUE),
pval = as.numeric(aggregation::lancaster(pval, mean_obs))),
by=eval(obj$gene_column)]

res <- res[, qval:=p.adjust(pval, 'BH')]
res <- as_df(res)
}

res <- as_df(res)

dplyr::arrange(res, qval)
Expand Down

0 comments on commit 9c88822

Please sign in to comment.