@@ -201,11 +201,19 @@ sleuth_prep <- function(
201
201
msg(' reading in kallisto results' )
202
202
sample_to_covariates $ sample <- as.character(sample_to_covariates $ sample )
203
203
204
+ if (nrow(sample_to_covariates ) == 1 && ! is.null(full_model )) {
205
+ warning(" There is only one sample present, but you also provided a model. " ,
206
+ " The model will be set to NULL to prevent downstream errors.\n " ,
207
+ " The sample can be viewed using sleuth_live after preparation, " ,
208
+ " but you need more than one sample to run the other aspects of Sleuth." )
209
+ full_model <- NULL
210
+ }
211
+
204
212
kal_dirs <- sample_to_covariates $ path
205
213
sample_to_covariates $ path <- NULL
206
214
207
215
msg(' dropping unused factor levels' )
208
- samples_to_covariates <- droplevels(sample_to_covariates )
216
+ sample_to_covariates <- droplevels(sample_to_covariates )
209
217
210
218
nsamp <- 0
211
219
# append sample column to data
@@ -280,7 +288,7 @@ sleuth_prep <- function(
280
288
filter_true <- filter_bool [filter_bool ]
281
289
282
290
msg(paste0(sum(filter_bool ), ' targets passed the filter' ))
283
- est_counts_sf <- norm_fun_counts(est_counts_spread [filter_bool , ])
291
+ est_counts_sf <- norm_fun_counts(est_counts_spread [filter_bool , , drop = FALSE ])
284
292
285
293
filter_df <- adf(target_id = names(filter_true ))
286
294
@@ -298,7 +306,7 @@ sleuth_prep <- function(
298
306
msg(" normalizing tpm" )
299
307
tpm_spread <- spread_abundance_by(obs_raw , " tpm" ,
300
308
sample_to_covariates $ sample )
301
- tpm_sf <- norm_fun_tpm(tpm_spread [filter_bool , ])
309
+ tpm_sf <- norm_fun_tpm(tpm_spread [filter_bool , , drop = FALSE ])
302
310
tpm_norm <- as_df(t(t(tpm_spread ) / tpm_sf ))
303
311
tpm_norm $ target_id <- rownames(tpm_norm )
304
312
tpm_norm <- tidyr :: gather(tpm_norm , sample , tpm , - target_id )
@@ -349,6 +357,7 @@ sleuth_prep <- function(
349
357
# Get list of IDs to aggregate on (usually genes)
350
358
# Also get the filtered list and update the "filter_df" and "filter_bool"
351
359
# variables for the sleuth object
360
+ target_mapping <- data.table :: data.table(target_mapping )
352
361
target_mapping [target_mapping [[aggregation_column ]] == " " ,
353
362
aggregation_column ] <- NA
354
363
agg_id <- unique(target_mapping [, aggregation_column , with = FALSE ])
@@ -446,9 +455,10 @@ sleuth_prep <- function(
446
455
})
447
456
448
457
# if mclapply results in an error (a warning is shown), then print error and stop
449
- if (is(bs_results [[1 ]], " try-error" )) {
450
- print(attributes(bs_results [[1 ]])$ condition )
451
- stop(" mclapply had an error. See the above error message for more details." )
458
+ error_status <- sapply(bs_results , function (x ) is(x , " try-error" ))
459
+ if (any(error_status )) {
460
+ print(attributes(bs_results [error_status ])$ condition )
461
+ stop(" At least one core from mclapply had an error. See the above error message(s) for more details." )
452
462
}
453
463
454
464
# mclapply is expected to retun the bootstraps in order; this is a sanity check of that
@@ -471,10 +481,10 @@ sleuth_prep <- function(
471
481
# This is the rest of the gene_summary code
472
482
if (ret $ gene_mode ) {
473
483
names(sigma_q_sq ) <- which_agg_id
474
- obs_counts <- obs_to_matrix(ret , " scaled_reads_per_base" )[which_agg_id , ]
484
+ obs_counts <- obs_to_matrix(ret , " scaled_reads_per_base" )[which_agg_id , , drop = FALSE ]
475
485
} else {
476
486
names(sigma_q_sq ) <- which_target_id
477
- obs_counts <- obs_to_matrix(ret , " est_counts" )[which_target_id , ]
487
+ obs_counts <- obs_to_matrix(ret , " est_counts" )[which_target_id , , drop = FALSE ]
478
488
}
479
489
480
490
sigma_q_sq <- sigma_q_sq [order(names(sigma_q_sq ))]
@@ -560,7 +570,7 @@ check_target_mapping <- function(t_id, target_mapping) {
560
570
# ' @export
561
571
norm_factors <- function (mat ) {
562
572
nz <- apply(mat , 1 , function (row ) ! any(round(row ) == 0 ))
563
- mat_nz <- mat [nz , ]
573
+ mat_nz <- mat [nz , , drop = FALSE ]
564
574
p <- ncol(mat )
565
575
geo_means <- exp(apply(mat_nz , 1 , function (row ) mean(log(row ))))
566
576
s <- sweep(mat_nz , 1 , geo_means , `/` )
@@ -716,7 +726,7 @@ obs_to_matrix <- function(obj, value_name) {
716
726
rownames(obs_counts ) <- obs_counts $ target_id
717
727
obs_counts $ target_id <- NULL
718
728
obs_counts <- as.matrix(obs_counts )
719
- obs_counts <- obs_counts [, obj $ sample_to_covariates $ sample ]
729
+ obs_counts <- obs_counts [, obj $ sample_to_covariates $ sample , drop = FALSE ]
720
730
721
731
obs_counts
722
732
}
0 commit comments