zentnerlab / TSRexploreR

Other
3 stars 11 forks source link

tss_export() fail #198

Open perinom opened 3 years ago

perinom commented 3 years ago

Hi,

I'm trying to export the counts to a table to works around #193 but

tss_export(exp,
           samples = "all",
           file_type = "table",
           out_dir = testing_out,
           diff_tss = FALSE,
           sep = "\t")

fails with

"Error in fwrite(x, export_file, sep = sep, col.names = TRUE, row.names = FALSE, : is.list(x) is not TRUE
8.
stop(simpleError(msg, call = if (p <- sys.parent(1L)) sys.call(p)))
7.
stopifnot(is.list(x), identical(quote, "auto") || isTRUEorFALSE(quote), is.character(sep) && length(sep) == 1L && nchar(sep) == 1L, is.character(sep2) && length(sep2) == 3L && nchar(sep2[2L]) == 1L, is.character(dec) && length(dec) == 1L && nchar(dec) == ...
6.
fwrite(x, export_file, sep = sep, col.names = TRUE, row.names = FALSE, quote = FALSE)
5.
.f(.x[[i]], .y[[i]], ...)
4.
map2(.x, .y, .f, ...)
3.
walk2(.x, vec_index(.x), .f, ...)
2.
iwalk(export_samples, function(x, y) { export_file <- file.path(ifelse(is.na(out_dir), getwd(), out_dir), str_c(y, "_TSSs.tsv")) fwrite(x, export_file, sep = sep, col.names = TRUE, row.names = FALSE, ...
1.
tss_export(exp, samples = "all", file_type = "table", out_dir = testing_out, diff_tss = FALSE, sep = "\t")
"

the following (code taken from data_export.R) works, though

sample_names <- names(exp@counts$TSSs$raw)
export_samples <- exp@counts$TSSs$raw[sample_names]

## add column with sample name, remove unecessary columns
small_frames = imap(export_samples, function(sample_df, sample_name){
  sample_df %>% 
  mutate(sample_name = sample_name) %>% 
  select(sample_name, FHASH, score)
})

## Combine all observations, convert to matrix for DESeq2
count_matrix = bind_rows(small_frames) %>% 
  pivot_wider(names_from = sample_name, values_from = score) %>% 
  column_to_rownames(., var = "FHASH") %>% 
  as.matrix()

#convert NA to zero
count_matrix[is.na(count_matrix)] <- 0
gzentner commented 3 years ago

I get this error when attempting to export bedgraphs:

> tss_export(exp)
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'i' in selecting a method for function '[': could not find function "strand"

However, it's fixed by loading the plyranges package. Does that do anything for your error?

perinom commented 2 years ago

Hi, thanks for looking into it!

I can reproduce your behaviour for bedgraphs but plyranges doesn't help for exporting to table