dieterich-lab / JACUSA2helper

Auxiliary R package for assessment of JACUSA2 results
https://dieterich-lab.github.io/JACUSA2helper/
GNU General Public License v3.0
3 stars 2 forks source link

Error in .from_character_to_GRanges(from) #19

Open kwonej0617 opened 2 years ago

kwonej0617 commented 2 years ago

Hi, developer! Thanks for developing a great tool. While running the R code provided in the document, https://dieterich-lab.github.io/JACUSA2helper/articles/web_only/JACUSA2helper-nanopore.html#ref-Piechotta20221, I had an error like the below.

> results <- unlist(results))
Error in .from_character_to_GRanges(from) : 
  The character vector to convert to a GRanges object must contain
  strings of the form "chr:start-end" or "chr:start-end:strand", with end
  >= start - 1, or "chr:pos" or "chr:pos:strand". For example:
  "chr1:2501-2900", "chr1:2501-2900:+", or "chr1:740". Note that ".." is
  a valid alternate start/end separator. Strand can be "+", "-", "*", or
  missing.

Based on the error message, I guess the variable, 'results' has to have genomic location-based information. However, mine didn't look like so. Do you know how to fix this problem?

FYI, while running the code, I made a little bit of change to your code because some steps didn't work for me (such as the command with mcols and the command to make wt_vs_ko_filtered). Anyway, I got my results and wt_vs_ko_filtered as below. Please check if it looks correct.!

> str(results)
'data.frame':   2544255 obs. of  4 variables:
 $ meta_cond      : Factor w/ 2 levels "WT_vs_KO","WT100_vs_WT0": 2 2 2 2 2 2 2 2 2 2 ...
 $ call2_score    : num  0.2459 1.5272 0.0503 0.9132 0.2817 ...
 $ insertion_score: num  NA 0.232 0.642 1.309 1.308 ...
 $ deletion_score : num  0.4197 1.518 0.0526 0.0468 0.1152 ...
> str(wt_vs_ko_filtered)
'data.frame':   2015555 obs. of  4 variables:
 $ meta_cond      : Factor w/ 2 levels "WT_vs_KO","WT100_vs_WT0": 1 1 1 1 1 1 1 1 1 1 ...
 $ call2_score    : num  0.182 0.2 0.28 0.312 1.264 ...
 $ insertion_score: num  0.974 NA NA 1.741 0.236 ...
 $ deletion_score : num  -0.000849 0.840319 NA 0.014438 0.137437 ...

Thank you so much!

piechottam commented 2 years ago

Hi, can you specify the exact part of: https://dieterich-lab.github.io/JACUSA2helper/articles/web_only/JACUSA2helper-nanopore.html#ref-Piechotta20221

It seems that you should run:

results <- unlist(GRangesList(results))
kwonej0617 commented 2 years ago

Hi, Piechottam,

Sorry, I mistyped the command line 'results <- unlist(results))' in the posting above. Actually, I run results <- unlist(GRangesList(results)) as shown in your document and got the error.

Error in .from_character_to_GRanges(from) : 
  The character vector to convert to a GRanges object must contain
  strings of the form "chr:start-end" or "chr:start-end:strand", with end
  >= start - 1, or "chr:pos" or "chr:pos:strand". For example:
  "chr1:2501-2900", "chr1:2501-2900:+", or "chr1:740". Note that ".." is
  a valid alternate start/end separator. Strand can be "+", "-", "*", or
  missing.
kwonej0617 commented 2 years ago

Maybe there might be some problem when I changed your code in some steps that didn't work for me. I want to make sure whether or not what I've done is correct.

Firstly, I got an error in this step.

> files <- c("WT_vs_KO_call2_result.out.gz", "WT100_vs_WT0_call2_result.out.gz")
meta_conds = c("WT_vs_KO", "WT100_vs_WT0")
i <- 1
print(files[i])
print(meta_conds[i])
[1] "WT_vs_KO_call2_result.out.gz"
[1] "WT_vs_KO"
> wt_vs_ko_res <- read_result(files[i], nThread = 1)
|--------------------------------------------------|
|==================================================|
> print(paste0("Sites BEFORE filtering: ", length(wt_vs_ko_res)))
[1] "Sites BEFORE filtering: 8891484"

> wt_vs_ko_filtered <- wt_vs_ko_res %>% filter(
    ref == "A",
    seqnames %in% c(as.character(1:22), "X"),
    ! grepl("Y", filter, fixed = TRUE)
)
Error in UseMethod("filter") : 
  no applicable method for 'filter' applied to an object of class "c('GRanges', 'GenomicRanges', 'Ranges', 'GenomicRanges_OR_missing', 'GenomicRanges_OR_GenomicRangesList', 'GenomicRanges_OR_GRangesList', 'List', 'Vector', 'list_OR_List', 'Annotated', 'vector_OR_Vector')"

So I changed it to this code below

> wt_vs_ko_filtered <- as.data.frame(wt_vs_ko_res) %>% dplyr::filter(
    ref == "A",
    seqnames %in% c(as.character(1:22), "X"),
    ! grepl("Y", filter, fixed = TRUE)
 )
> str(wt_vs_ko_filtered)
'data.frame':   2015555 obs. of  14 variables:
 $ seqnames   : Factor w/ 31 levels "1","10","11",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ start      : int  14411 14415 14416 14418 14419 14420 14422 14423 14426 14427 ...
 $ end        : int  14411 14415 14416 14418 14419 14420 14422 14423 14426 14427 ...
 $ width      : int  1 1 1 1 1 1 1 1 1 1 ...
 $ strand     : Factor w/ 3 levels "+","-","*": 2 2 2 2 2 2 2 2 2 2 ...
 $ name       : chr  "call-2" "call-2" "call-2" "call-2" ...
 $ score      : num  0.182 0.2 0.28 0.312 1.264 ...
 $ info       : chr  "del11=0,18;del12=0,6;del21=1,21;del22=0,19;deletion_pvalue=1.0;deletion_score=-8.485801081405953E-4;ins11=1,18;"| __truncated__ "del11=1,22;del12=0,7;del21=0,23;del22=0,22;deletion_pvalue=0.35930568047800504;deletion_score=0.8403185527422465" "*" "del11=1,23;del12=0,7;del21=0,23;del22=2,23;deletion_pvalue=0.9043567612946222;deletion_score=0.0144383170554647"| __truncated__ ...
 $ filter     : chr  "D" "D" "*" "D" ...
 $ ref        : chr  "A" "A" "A" "A" ...
 $ bases.cond1: tibble [2,015,555 × 2] (S3: tbl_df/tbl/data.frame)
  ..$ rep1: tibble [2,015,555 × 4] (S3: tbl_df/tbl/data.frame)
  .. ..$ A: num  17 21 22 22 22 22 21 21 22 22 ...
  .. ..$ C: num  0 0 0 0 1 0 1 0 0 0 ...
  .. ..$ G: num  1 0 0 0 0 1 0 2 1 0 ...
  .. ..$ T: num  0 0 1 0 0 0 0 0 0 1 ...
  ..$ rep2: tibble [2,015,555 × 4] (S3: tbl_df/tbl/data.frame)
  .. ..$ A: num  6 7 7 6 6 7 7 7 8 8 ...
  .. ..$ C: num  0 0 0 0 0 0 1 0 0 0 ...
  .. ..$ G: num  0 0 0 1 1 0 0 1 0 0 ...
  .. ..$ T: num  0 0 0 0 0 1 0 0 0 0 ...
 $ bases.cond2: tibble [2,015,555 × 2] (S3: tbl_df/tbl/data.frame)
  ..$ rep1: tibble [2,015,555 × 4] (S3: tbl_df/tbl/data.frame)
  .. ..$ A: num  20 22 23 23 23 23 20 22 24 24 ...
  .. ..$ C: num  0 0 0 0 0 0 1 0 0 0 ...
  .. ..$ G: num  0 0 0 0 0 0 2 1 0 0 ...
  .. ..$ T: num  0 1 0 0 0 0 0 0 0 0 ...
  ..$ rep2: tibble [2,015,555 × 4] (S3: tbl_df/tbl/data.frame)
  .. ..$ A: num  17 22 22 21 21 21 23 23 22 22 ...
  .. ..$ C: num  0 0 0 0 0 0 0 0 1 0 ...
  .. ..$ G: num  1 0 0 0 0 0 0 0 0 1 ...
  .. ..$ T: num  1 0 0 0 0 0 0 0 0 0 ...
 $ cov.cond1  : tibble [2,015,555 × 2] (S3: tbl_df/tbl/data.frame)
  ..$ rep1: num  18 21 23 22 23 23 22 23 23 23 ...
  ..$ rep2: num  6 7 7 7 7 8 8 8 8 8 ...
 $ cov.cond2  : tibble [2,015,555 × 2] (S3: tbl_df/tbl/data.frame)
  ..$ rep1: num  20 23 23 23 23 23 23 23 24 24 ...
  ..$ rep2: num  19 22 22 21 21 21 23 23 23 23 ...

It seems it's correct to your result, so I run the next code.

> wt_vs_ko_filtered$meta_cond <- factor(meta_conds[1], meta_conds)

table(wt_vs_ko_filtered$meta_cond)

unpacked_info <- unpack_info(
    wt_vs_ko_filtered$info, 
    cond_count = 2, 
    keys=c("insertion_score", "deletion_score")
  )

    WT_vs_KO WT100_vs_WT0 
     2015555            0 
> mcols(wt_vs_ko_filtered) <- cbind(mcols(wt_vs_ko_filtered), unpacked_info)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘mcols’ for signature ‘"data.frame"’

Secondly, I got an error when running the command with mcols. I didn't know how to figure out the mcols-related problem and I am new to R so I changed the code like below.

> wt_vs_ko_filtered_unpacked_info <-cbind(wt_vs_ko_filtered, unpacked_info)
wt_vs_ko_filtered_unpacked_info_filtered <-wt_vs_ko_filtered_unpacked_info[-c(1:6)]
wt_vs_ko_filtered_unpacked_info_filtered <-wt_vs_ko_filtered_unpacked_info_filtered[-c(2:8)]
colnames(wt_vs_ko_filtered_unpacked_info_filtered)
[1] "score"           "meta_cond"       "insertion_score" "deletion_score" 
> wt_vs_ko_filtered_unpacked_info_filtered_reorder <-wt_vs_ko_filtered_unpacked_info_filtered[,c("meta_cond", "score", "insertion_score", "deletion_score")]
> colnames(wt_vs_ko_filtered_unpacked_info_filtered_reorder)
[1] "meta_cond"       "call2_score"     "insertion_score" "deletion_score" 
>colnames(wt_vs_ko_filtered_unpacked_info_filtered_reorder) [colnames(wt_vs_ko_filtered_unpacked_info_filtered_reorder) == "score"] <- "call2_score"

Sorry, it is a long code but could you please check if is correct? I run the same code but change the file name and variables for running WT100_vs_WT0_call2_result.out.gz. Therefore, if my code is wrong, it would affect running with WT100_vs_WT0_call2_result.out.gz.

Thank you for your time!

piechottam commented 2 years ago

no applicable method for 'filter' applied to an object of class "c('GRanges', 'GenomicRanges', 'Ranges', 'GenomicRanges_OR_missing', 'GenomicRanges_OR_GenomicRangesList', 'GenomicRanges_OR_GRangesList', 'List', 'Vector', 'list_OR_List', 'Annotated', 'vector_OR_Vector')"

Please install install.packages("plyranges") manually or devtools::install_deps("JACUSA2helper")

Does the problem persist?

kwonej0617 commented 2 years ago

Hi, From your document, https://github.com/dieterich-lab/JACUSA2helper/blob/HEAD/vignettes/web_only/JACUSA2helper-nanopore.Rmd, I found you loaded several libraries before running jacusa2helper code. So I loaded those libraries, which help to run your code without having an error.

library(JACUSA2helper)
library(GenomicRanges)
library(BSgenome)
library(plyranges)
library(magrittr)
library(dplyr)
library(ggplot2)
library(pROC)
library(VennDiagram)

The code was running successfully but I had an issue making venn diagram. Do you know what the problem is? I run this script in linux. Is this error telling me there is a problem in connecting SSH?

> meta_cond_plt <- venn.diagram(
  tapply(results$id, results$meta_cond, c),
  filename = NULL,
  lwd = 1,
  cex = 0.5,
  fontfamily = "sans",
  cat.cex = 0.9,
  cat.default.pos = "outer",
  cat.fontfamily = "sans",
)
grid.newpage()
grid.draw(meta_cond_plt)
Error in .External2(C_X11, d$display, d$width, d$height, d$pointsize,  : 
  unable to start device X11cairo
In addition: Warning message:
In (function (display = "", width, height, pointsize, gamma, bg,  :
  unable to open connection to X11 display ''
piechottam commented 2 years ago
  1. plyranges By mistake - plyranges is from bioconductor:
    
    if (!require("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("plyranges")



2. **venn.diagram**
a.) connect via `ssh -X...`
OR
b.) Write to a file: `venn.diagram(... filename = NULL ... ` replace with `... filename = "output.pdf" ... `
kwonej0617 commented 2 years ago

Thanks for your reply!

Actually, I wanted to make an output file including m6a modification sites as you showed in 13059_2022_2676_MOESM4_ESM.xlsx from supplementary materials. Since I am quite unexperienced in R, I am not pretty sure in which step in your document (https://dieterich-lab.github.io/JACUSA2helper/articles/web_only/JACUSA2helper-nanopore.html#evaluation) I could make the result like that. Could you please help me with that?

Thank you so much!