Skip to content

Commit 2898a5d

Browse files
authored
Merge pull request #214 from warrenmcg/patch_misc
Miscellaneous bug fixes
2 parents fcfc475 + d56feb0 commit 2898a5d

17 files changed

+190
-63
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,4 @@ importFrom(lazyeval,interp)
8686
importFrom(lazyeval,lazy)
8787
importFrom(rhdf5,h5write)
8888
importFrom(rhdf5,h5write.default)
89+
importFrom(utils,head)

R/kallisto.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ subset_kallisto.kallisto <- function(obj, target_ids) {
118118

119119
subset_num <- length(unique(target_ids))
120120
new_obj <- obj
121-
new_obj$abundance <- new_obj$abundance[which(new_obj$abundance %in% target_ids), ]
121+
new_obj$abundance <- new_obj$abundance[which(new_obj$abundance$target_id %in% target_ids), ]
122122
new_obj$bootstrap <- lapply(new_obj$bootstrap, function(bs) {
123123
bs[which(bs$target_id %in% target_ids), ]
124124
})

R/matrix.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#' @examples
3030
#' sleuth_matrix <- sleuth_to_matrix(sleuth_obj, 'obs_norm', 'tpm')
3131
#' head(sleuth_matrix) # look at first 5 transcripts, sorted by name
32+
#' @importFrom utils head
3233
#' @export
3334
sleuth_to_matrix <- function(obj, which_df, which_units) {
3435
if ( !(which_df %in% c("obs_norm", "obs_raw")) ) {

R/plots.R

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ plot_transcript_heatmap <- function(obj,
10491049

10501050
rownames(tabd_df) <- tabd_df$target_id
10511051
tabd_df$target_id <- NULL
1052+
tabd_df <- tabd_df[transcripts, ]
10521053

10531054
if (nchar(trans) > 0 && !is.null(trans)) {
10541055
tFunc <- eval(parse(text = trans))
@@ -1075,16 +1076,10 @@ plot_transcript_heatmap <- function(obj,
10751076
colors <- colorRampPalette(c(color_low, color_mid, color_high))(100)
10761077
# the PDF code prevents the heatmap from printing before we modify the plot
10771078
pdf(file = NULL)
1078-
if (cluster_transcripts) {
1079-
p <- pheatmap::pheatmap(trans_mat, annotation_col = s2c, color = colors,
1080-
cluster_cols = TRUE,
1081-
cluster_rows = cluster_transcripts,
1082-
...)
1083-
} else {
1084-
p <- pheatmap::pheatmap(trans_mat, annotation_col = s2c, color = colors,
1085-
cluster_cols = TRUE,
1086-
...)
1087-
}
1079+
p <- pheatmap::pheatmap(trans_mat, annotation_col = s2c, color = colors,
1080+
cluster_cols = TRUE,
1081+
cluster_rows = cluster_transcripts,
1082+
...)
10881083
invisible(dev.off())
10891084
# modify the column labels with the x_axis_angle
10901085
# subtracting from 360 degrees to get it to align well without modifying

R/read_write.R

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#' @return a \code{kallisto} object
2828
#' @export
2929
read_kallisto <- function(path, read_bootstrap = TRUE, max_bootstrap = NULL) {
30-
stopifnot(is(path, "character"))
30+
path <- as.character(path)
3131

3232
kal_path <- get_kallisto_path(path)
3333

@@ -62,13 +62,36 @@ read_kallisto_h5 <- function(fname, read_bootstrap = TRUE, max_bootstrap = NULL)
6262
is(max_bootstrap, "numeric") ||
6363
is(max_bootstrap, "integer") )
6464

65+
kal_path <- get_kallisto_path(fname)
66+
if (kal_path$ext != "h5") {
67+
stop(paste0("File '", fname, "' does not appear to be an HDF5 file"))
68+
}
69+
6570
fname <- path.expand(fname)
6671

6772
if (!file.exists(fname)) {
6873
stop("Can't find file: '", fname, "'")
6974
}
7075

71-
target_id <- as.character(rhdf5::h5read(fname, "aux/ids"))
76+
tryCatch({
77+
target_id <- as.character(rhdf5::h5read(fname, "aux/ids"))
78+
}, error = function(e) {
79+
msg <- conditionMessage(e)
80+
err_msg <- paste0("The HDF5 file '", fname, "' exists but could not be ",
81+
"read. The most common reason is that the rdhf5 and ",
82+
"Rhdf5lib were built using bioconda without support ",
83+
"to read zlib-compressed HDF5 files, which is used ",
84+
"by kallisto to save space.\nPlease update R, rdhf5, ",
85+
"and Rhdf5lib to latest versions on bioconda, or ",
86+
"consider doing a Bioconductor installation of ",
87+
"Rhdf5lib, which usually automatically includes zlib ",
88+
"support.")
89+
err_msg <- paste0(err_msg, "\nThe actual error thrown was '", msg, "'")
90+
stop(err_msg)
91+
}, finally = {
92+
rhdf5::H5close()
93+
})
94+
7295
if ( length(target_id) != length(unique(target_id))) {
7396
tid_counts <- table(target_id)
7497
warning(

R/shiny.R

Lines changed: 127 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ sleuth_live <- function(obj, settings = sleuth_live_settings(),
140140
'enter a gene identifier that matches that column.',
141141
'The most significant gene by q-value for the first test within the currently selected test type is already entered.");',
142142
'} </script>'),
143-
value = textOutput("default_top_hit"))
143+
value = '')
144144
),
145145
column(3,
146146
selectInput('bsg_var_color_by',
@@ -277,7 +277,7 @@ sleuth_live <- function(obj, settings = sleuth_live_settings(),
277277
'alert("Enter a space-separated list of transcript names here to view a hierarchical clustering of those transcripts.",
278278
"The ten most significant transcripts for the first test of the currently selected test type have been listed for you by default.");',
279279
'} </script>'),
280-
value = textOutput("default_top_ten"))
280+
value = '')
281281
),
282282
column(8, style = "margin-top:15px;",
283283
checkboxGroupInput('hm_covars',
@@ -458,7 +458,10 @@ sleuth_live <- function(obj, settings = sleuth_live_settings(),
458458
uiOutput('group_by_lrt')
459459
)
460460
),
461-
dataTableOutput('lrt_de_dt')
461+
dataTableOutput('lrt_de_dt'),
462+
fluidRow(
463+
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
464+
downloadButton("download_test_table", "Download Table")))
462465
)
463466
),
464467

@@ -782,7 +785,10 @@ sleuth_live <- function(obj, settings = sleuth_live_settings(),
782785
),
783786
fluidRow(
784787
plotOutput('fld_plt')
785-
)
788+
),
789+
fluidRow(
790+
div(align = "right", style = "margin-right:15px; margin-bottom: 10px",
791+
downloadButton("download_fld_plt", "Download Table")))
786792
),
787793

788794
####
@@ -1044,7 +1050,8 @@ sleuth_live <- function(obj, settings = sleuth_live_settings(),
10441050
sample_table = NULL,
10451051
kallisto_table = NULL,
10461052
hm_plt = NULL,
1047-
bs_var_plt = NULL
1053+
bs_var_plt = NULL,
1054+
fld_plt = NULL
10481055
)
10491056
user_settings <- reactiveValues(save_width = 45, save_height = 11)
10501057
# TODO: Once user settings are available, read these values from input
@@ -1065,29 +1072,112 @@ sleuth_live <- function(obj, settings = sleuth_live_settings(),
10651072
current_ui
10661073
})
10671074

1068-
output$default_top_hit <- renderText({
1069-
default_test <- ifelse(length(valid_test_types) == 0, NULL,
1070-
ifelse(input$settings_test_type == 'wt',
1071-
obj$tests[['wt']][[1]][[1]],
1072-
obj$tests[['lrt']][[1]])
1073-
)
1075+
### CODE TO FILL IN DEFAULT VALUES FOR TEXT BOXES
1076+
defaults <- reactiveValues(
1077+
top_hit = '',
1078+
top_gene = '',
1079+
top_ten = ''
1080+
)
1081+
1082+
## Observe to see if the test type changes
1083+
## Pick the top transcript for the first test of that type
1084+
observe({
1085+
test_type <- input$settings_test_type
1086+
default_test <- if (length(valid_test_types) == 0) {
1087+
NULL
1088+
} else if (test_type == "wt") {
1089+
obj$tests[["wt"]][[1]][[1]]
1090+
} else {
1091+
obj$tests[["lrt"]][[1]]
1092+
}
1093+
1094+
default_id <- ifelse(is.null(default_test), "No tests found. This feature won't work",
1095+
default_test[order(default_test$qval), "target_id"][1])
1096+
defaults$top_hit <- default_id
1097+
})
1098+
1099+
## Observe to see if the test type changes
1100+
## Pick the top 10 hits for the first test of that type
1101+
observe({
1102+
test_type <- input$settings_test_type
1103+
default_test <- if (length(valid_test_types) == 0) {
1104+
NULL
1105+
} else if (test_type == "wt") {
1106+
obj$tests[["wt"]][[1]][[1]]
1107+
} else {
1108+
obj$tests[["lrt"]][[1]]
1109+
}
1110+
1111+
default_ids <- if (is.null(default_test)) {
1112+
c("No tests found. This feature won't work")
1113+
} else {
1114+
default_test[order(default_test$qval), "target_id"][1:10]
1115+
}
1116+
1117+
defaults$top_ten <- paste(default_ids, collapse = " ")
1118+
})
1119+
1120+
## Observe to see if the test type changes or the gene column changes
1121+
## Pick the gene with the most significant transcript for the first test of that type
1122+
observe({
1123+
gene_col <- input$gv_gene_colname
1124+
test_type <- input$settings_test_type
1125+
default_test <- if (length(valid_test_types) == 0) {
1126+
NULL
1127+
} else if (test_type == "wt") {
1128+
obj$tests[["wt"]][[1]][[1]]
1129+
} else {
1130+
obj$tests[["lrt"]][[1]]
1131+
}
10741132
default_id <- ifelse(is.null(default_test), "No tests found. This feature won't work",
1075-
default_test[order(default_test$qval), "target_id"][1])
1076-
default_id
1133+
default_test[order(default_test$qval), "target_id"][1])
1134+
id_row <- which(obj$target_mapping$target_id == default_id)
1135+
defaults$top_gene <- obj$target_mapping[id_row, gene_col]
1136+
})
1137+
1138+
## Check if the transcript input is empty or invalid
1139+
## Fill in with default value if either of above are true
1140+
observe({
1141+
var_input <- input$bs_var_input
1142+
if (is.null(var_input) || !var_input %in% obj$target_mapping$target_id) {
1143+
updateTextInput(session, "bs_var_input", value = defaults$top_hit)
1144+
}
1145+
})
1146+
1147+
## Check if the gene input is empty or invalid
1148+
## Fill in with default value if either of above are true
1149+
observe({
1150+
var_input <- input$bsg_var_input
1151+
gene_col <- obj$gene_column
1152+
genes <- obj$target_mapping[, gene_col]
1153+
if (is.null(genes)) {
1154+
updateTextInput(session, "bsg_var_input", value = "This won't work")
1155+
} else if (is.null(var_input) || !var_input %in% genes) {
1156+
updateTextInput(session, "bsg_var_input", value = defaults$top_hit)
1157+
}
10771158
})
10781159

1079-
output$default_top_ten <- renderText({
1080-
default_test <- ifelse(length(valid_test_types) == 0, NULL,
1081-
ifelse(input$settings_test_type == 'wt',
1082-
obj$tests[['wt']][[1]][[1]],
1083-
obj$tests[['lrt']][[1]])
1084-
)
1085-
default_ids <- ifelse(is.null(default_test), "No tests found. This feature won't work",
1086-
default_test[order(default_test$qval), "target_id"][1:10])
1087-
default_ids <- paste(default_ids, collapse = " ")
1088-
default_ids
1160+
## Check if the gene input is empty or invalid
1161+
## Fill in with default value if either of above are true
1162+
observe({
1163+
var_input <- input$gv_var_input
1164+
gene_col <- input$gene_col
1165+
genes <- obj$target_mapping[, gene_col]
1166+
if (is.null(var_input) || !var_input %in% genes) {
1167+
updateTextInput(session, "gv_var_input", value = defaults$top_gene)
1168+
}
10891169
})
10901170

1171+
## Check if the list of inputs is empty
1172+
## Fill in with default top 10 if either of above are true
1173+
observe({
1174+
hm_input <- input$hm_transcripts
1175+
if (is.null(hm_input) || hm_input == "") {
1176+
updateTextInput(session, "hm_transcripts", value = defaults$top_ten)
1177+
}
1178+
})
1179+
### END OF CODE FOR DEFAULT VALUES
1180+
10911181
output$qqplot <- renderPlot({
10921182
poss_tests <- list_tests(obj, input$settings_test_type)
10931183
current_test <- NULL
@@ -1378,6 +1468,19 @@ sleuth_live <- function(obj, settings = sleuth_live_settings(),
13781468

13791469
output$fld_plt <- renderPlot({
13801470
plot_fld(obj, input$fld_sample)
1471+
#saved_plots_and_tables$fld_plt <- plot_fld(obj, input$fld_sample)
1472+
#saved_plots_and_tables$fld_plt
1473+
})
1474+
1475+
output$download_fld_plt <- downloadHandler(
1476+
filename = function() {
1477+
"fld_plot.pdf"
1478+
},
1479+
content = function(file) {
1480+
ggsave(file, saved_plots_and_tables$fld_plt,
1481+
width = user_settings$save_width,
1482+
height = user_settings$save_height,
1483+
units = "cm")
13811484
})
13821485

13831486
output$bias_weights_table <- renderDataTable({
@@ -1700,7 +1803,7 @@ sleuth_live <- function(obj, settings = sleuth_live_settings(),
17001803
'You can find target_ids in the test table under Analyses. The most significant transcript',
17011804
'by q-value for the first test within the currently selected test type is already entered.");',
17021805
'} </script>'),
1703-
value = textOutput("default_top_hit"))
1806+
value = '')
17041807
),
17051808
column(4,
17061809
selectInput('bs_var_color_by',

R/sleuth.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ filter_df_by_groups <- function(df, fun, group_df, ...) {
121121
#' \itemize{
122122
#' \item \code{filter_fun}: the function to use when filtering. This function will be applied to the raw counts
123123
#' on a row-wise basis, meaning that each feature will be considered individually. The default is to filter out
124-
#' any features that do not have at least 5 estimated counts in at least 47% of the samples (see \code{\link{basic_filter}}
124+
#' any features that do not have at least 5 estimated counts in at least 47\% of the samples (see \code{\link{basic_filter}}
125125
#' for more information). If the preferred filtering method requires a matrix-wide transformation or otherwise
126126
#' needs to consider multiple features simultaneously instead of independently, please consider using
127127
#' \code{filter_target_id} below.
@@ -1095,6 +1095,7 @@ summary.sleuth <- function(obj, covariates = TRUE) {
10951095
#' which_group = 'ext_gene')
10961096
#' head(sleuth_genes) # show info for first 5 genes
10971097
#' sleuth_genes[1:5, 6] # show transcripts for first 5 genes
1098+
#' @importFrom utils head
10981099
#' @export
10991100
sleuth_gene_table <- function(obj, test, test_type = 'lrt', which_model = 'full', which_group = 'ens_gene') {
11001101

man/plot_loadings.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plot_sample_density.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plot_sample_heatmap.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)