rrjavavenn-diagram

Error in .jnew("edu/uic/ncdm/venn/data/VennData", as.character(combinations), :


I have used a while ago it worked fine not sure what its not working now..

I used venneuler to create venn diagram. What im doing is I read two data frames which is cosmic_atac and cosmic_rna which have different length ,then combine them into a single data frame using the cbindPad then run venneuler. Not sure what is the error any help or suggestion would be really appreciated.

cbindPad <- function(...){
    args <- list(...)
    n <- sapply(args,nrow)
    mx <- max(n)
    pad <- function(x, mx){
      if (nrow(x) < mx){
        nms <- colnames(x)
        padTemp <- matrix(NA, mx - nrow(x), ncol(x))
        colnames(padTemp) <- nms
        if (ncol(x)==0) {
          return(padTemp)
        } else {
          return(rbind(x,padTemp))
        }
      }
      else{
        return(x)
      }
    }
    rs <- lapply(args,pad,mx)
    return(do.call(cbind,rs))
  } 


  dat <- cbindPad(cosmic_atac,cosmic_rna)


  vennfun <- function(x) { 
    x$id <- seq(1, nrow(x))  #add a column of numbers (required for melt)
    xm <- melt(x, id.vars="id", na.rm=TRUE)  #melt table into two columns (value & variable)
    xc <- dcast(xm, value~variable, fun.aggregate=length)  #remove NA's, list presence/absence of each value for each variable (1 or 0)
    rownames(xc) <- xc$value  #value column = rownames (required for Venneuler)
    xc$value <- NULL  #remove redundent value column
    xc  #output the new dataframe
  }
  
  #https://stackoverflow.com/questions/9121956/legend-venn-diagram-in-venneuler
  VennDat <- vennfun(dat)
  genes.venn <- venneuler(VennDat)

Error in .jnew("edu/uic/ncdm/venn/data/VennData", as.character(combinations), : java.lang.NoSuchMethodError:

dput(cosmic_atac)
structure(list(gene = c("ENSG00000136754", "ENSG00000143322", 
"ENSG00000196914", "ENSG00000143437", "ENSG00000129993", "ENSG00000067955", 
"ENSG00000114423", "ENSG00000142273", "ENSG00000165556", "ENSG00000109220", 
"ENSG00000172409", "ENSG00000124795", "ENSG00000119772", "ENSG00000102034", 
"ENSG00000187239", "ENSG00000163655", "ENSG00000106031", "ENSG00000123364", 
"ENSG00000128713", "ENSG00000083168", "ENSG00000073614", "ENSG00000002834", 
"ENSG00000130675", "ENSG00000133392", "ENSG00000165671", "ENSG00000110713", 
"ENSG00000116132", "ENSG00000164985", "ENSG00000163902", "ENSG00000079102", 
"ENSG00000184702", "ENSG00000125354", "ENSG00000072501", "ENSG00000138336", 
"ENSG00000100815")), row.names = c(NA, -35L), class = c("tbl_df", 
"tbl", "data.frame"))


dput(cosmic_rna)
structure(list(gene = c("ENSG00000136754", "ENSG00000143322", 
"ENSG00000196914", "ENSG00000143437", "ENSG00000129993", "ENSG00000067955", 
"ENSG00000114423", "ENSG00000165556", "ENSG00000109220", "ENSG00000172409", 
"ENSG00000124795", "ENSG00000119772", "ENSG00000102034", "ENSG00000187239", 
"ENSG00000163655", "ENSG00000106031", "ENSG00000083168", "ENSG00000073614", 
"ENSG00000002834", "ENSG00000178053", "ENSG00000130675", "ENSG00000133392", 
"ENSG00000165671", "ENSG00000110713", "ENSG00000164985", "ENSG00000163902", 
"ENSG00000079102", "ENSG00000184702", "ENSG00000125354", "ENSG00000072501", 
"ENSG00000138336", "ENSG00000100815")), row.names = c(NA, -32L
), class = c("tbl_df", "tbl", "data.frame"))

Solution

  • It seems to work if you make dat a data.table and make the colnames unique:

    library(data.table)
    library(venneuler)
    #> Loading required package: rJava
    
    cosmic_atac <-
    structure(list(gene = c("ENSG00000136754", "ENSG00000143322", 
                            "ENSG00000196914", "ENSG00000143437", "ENSG00000129993", "ENSG00000067955", 
                            "ENSG00000114423", "ENSG00000142273", "ENSG00000165556", "ENSG00000109220", 
                            "ENSG00000172409", "ENSG00000124795", "ENSG00000119772", "ENSG00000102034", 
                            "ENSG00000187239", "ENSG00000163655", "ENSG00000106031", "ENSG00000123364", 
                            "ENSG00000128713", "ENSG00000083168", "ENSG00000073614", "ENSG00000002834", 
                            "ENSG00000130675", "ENSG00000133392", "ENSG00000165671", "ENSG00000110713", 
                            "ENSG00000116132", "ENSG00000164985", "ENSG00000163902", "ENSG00000079102", 
                            "ENSG00000184702", "ENSG00000125354", "ENSG00000072501", "ENSG00000138336", 
                            "ENSG00000100815")), row.names = c(NA, -35L), class = c("tbl_df", 
                                                                                    "tbl", "data.frame"))
    
    
    cosmic_rna <-
    structure(list(gene = c("ENSG00000136754", "ENSG00000143322", 
                            "ENSG00000196914", "ENSG00000143437", "ENSG00000129993", "ENSG00000067955", 
                            "ENSG00000114423", "ENSG00000165556", "ENSG00000109220", "ENSG00000172409", 
                            "ENSG00000124795", "ENSG00000119772", "ENSG00000102034", "ENSG00000187239", 
                            "ENSG00000163655", "ENSG00000106031", "ENSG00000083168", "ENSG00000073614", 
                            "ENSG00000002834", "ENSG00000178053", "ENSG00000130675", "ENSG00000133392", 
                            "ENSG00000165671", "ENSG00000110713", "ENSG00000164985", "ENSG00000163902", 
                            "ENSG00000079102", "ENSG00000184702", "ENSG00000125354", "ENSG00000072501", 
                            "ENSG00000138336", "ENSG00000100815")), row.names = c(NA, -32L
                            ), class = c("tbl_df", "tbl", "data.frame"))
    
    
    
    cbindPad <- function(...){
        args <- list(...)
        n <- sapply(args,nrow)
        mx <- max(n)
        pad <- function(x, mx){
            if (nrow(x) < mx){
                nms <- colnames(x)
                padTemp <- matrix(NA, mx - nrow(x), ncol(x))
                colnames(padTemp) <- nms
                if (ncol(x)==0) {
                    return(padTemp)
                } else {
                    return(rbind(x,padTemp))
                }
            }
            else{
                return(x)
            }
        }
        rs <- lapply(args,pad,mx)
        return(do.call(cbind,rs))
    } 
    
    
    dat <- cbindPad(cosmic_atac,cosmic_rna)
    setDT(dat)
    setnames(dat, make.unique(colnames(dat)))
    
    vennfun <- function(x) { 
        x$id <- seq(1, nrow(x))  #add a column of numbers (required for melt)
        xm <- melt(x, id.vars="id", na.rm=TRUE)  #melt table into two columns (value & variable)
        xc <- dcast(xm, value~variable, fun.aggregate=length)  #remove NA's, list presence/absence of each value for each variable (1 or 0)
        rownames(xc) <- xc$value  #value column = rownames (required for Venneuler)
        xc$value <- NULL  #remove redundent value column
        xc  #output the new dataframe
    }
    
    #https://stackoverflow.com/questions/9121956/legend-venn-diagram-in-venneuler
    VennDat <- vennfun(dat)
    genes.venn <- venneuler(VennDat)
    plot(genes.venn)
    

    Created on 2020-07-09 by the reprex package (v0.3.0)