Code Monkey home page Code Monkey logo

superexacttest's Introduction

SuperExactTest CRAN Downloads Total downloads

Current version 1.1.2

Description

SuperExactTest is an R package for statistical testing and visualization of mult-set intersections.

Installation

SuperExactTest is available from CRAN so the simplest way to install in R is by running install.packages("SuperExactTest").

To install the latest update from here in github, run devtools::install_github("mw201608/SuperExactTest") in R.

Reference

Minghui Wang, Yongzhong Zhao, and Bin Zhang (2015) Efficient Test and Visualization of Multi-Set Intersections. Scientific Reports 5: 16923.

Vignette

Detailed description about the package and sample analysis code is available from vignette("set_html",package="SuperExactTest") (link) after installation.

SuperExactTest shiny

A shiny application has been deployed at shinyapps.io (see also github), allowing users to run and visualize SuperExactTest analysis online.

Examples

1 Show selected overlapping elements

library(SuperExactTest)
set.seed(1234)
#generate random strings
n=400
r_strings <- do.call(paste0, replicate(5, sample(LETTERS, n, TRUE), FALSE))
input=lapply(c(40,60,80,200),function(x,s) sample(s,x),s=r_strings)
Result=supertest(input,n=n)
#Plot the intersections with a split y-axis and 
#show elements of the intersections with no more than 20 elements
#png('examples/ex1.png',width=2000,height=2000,res=300)
plot(Result, Layout="landscape", sort.by="size", keep=FALSE,
	bar.split=c(70,180), show.elements=TRUE, elements.cex=0.7,
	elements.list=subset(summary(Result)$Table,Observed.Overlap <= 20),
	show.expected.overlap=TRUE,expected.overlap.style="hatchedBox",
	color.expected.overlap='red')
#dev.off()

sample output

Assign discrete colors to denote the sets that are involved in each intersection by setting color.on to NULL or a vector of colors.

#png('examples/ex1color.png',width=2000,height=2000,res=300)
plot(Result, Layout="landscape", sort.by="size", keep=FALSE,
	bar.split=c(70,180), show.elements=TRUE, elements.cex=0.7,
	elements.list=subset(summary(Result)$Table,Observed.Overlap <= 20),
	show.expected.overlap=TRUE,expected.overlap.style="hatchedBox",
	color.expected.overlap='red', color.on = NULL)
#dev.off()

sample output

2 Sort and/or subset intersection bars for plotting

As of version 1.0.7, we can change the order of the intersection bars in a customized way through option sort.by. For example, let us switch the orders of the fourth and fifth bars in the above figure.

#First extract the intersection barcodes ordered by size
order1=names(sort(Result$overlap.sizes,decreasing=TRUE))
#Then switch the orders of the fourth and fifth element
order2=order1[c(1:3,5,4,6:length(order1))]
print(order1)
print(order2)
#Now plot with the new order
#png('examples/ex2.png',width=2000,height=2000,res=300)
plot(Result, Layout="landscape", sort.by=order2, keep=FALSE,
        bar.split=c(70,180), show.elements=TRUE, elements.cex=0.7,
        elements.list=subset(summary(Result)$Table,Observed.Overlap <= 20),
        show.expected.overlap=TRUE,expected.overlap.style="hatchedBox",
        color.expected.overlap='red', color.on = NULL)
#dev.off()

sample output

With this option sort.by, we can also show a subset of the intersection bars easily. Eg, let us plot the 10 largest overlaps.

order3=order1[1:10]
#png('examples/ex2b.png',width=2000,height=2000,res=300)
plot(Result, Layout="landscape", sort.by=order3,
        bar.split=c(70,180), show.elements=TRUE, elements.cex=0.7,
        elements.list=subset(summary(Result)$Table,Observed.Overlap <= 20),
        show.expected.overlap=TRUE,expected.overlap.style="hatchedBox",
        color.expected.overlap='red', color.on = NULL)
#dev.off()

sample output

3 Flip the bars upside down

We can also flip the bars upside down using option flip.vertical=TRUE.

#png('examples/ex3.png',width=2000,height=2000,res=300)
plot(Result, Layout="landscape", sort.by=order2, keep=FALSE,
        bar.split=c(70,180), show.elements=TRUE, elements.cex=0.7,
        elements.list=subset(summary(Result)$Table,Observed.Overlap <= 20),
        show.expected.overlap=TRUE,expected.overlap.style="hatchedBox",
        color.expected.overlap='red', color.on = NULL, flip.vertical=TRUE)
#dev.off()

sample output

4 Show fold enrichment

Show fold enrichment rather than overlp size on top of the bars (since v1.0.7.1).

#png('examples/ex4.png',width=2000,height=2000,res=300)
plot(Result, Layout="landscape", sort.by=order2, keep=FALSE,
        bar.split=c(70,180), show.elements=TRUE, elements.cex=0.7,
		show.fold.enrichment=TRUE,
		elements.list=subset(summary(Result)$Table,Observed.Overlap <= 20),elements.rot=45,
        show.expected.overlap=TRUE,expected.overlap.style="hatchedBox",
        color.expected.overlap='red', color.on = NULL)
#dev.off()

sample output

5 Place multiple SuperExactTest plots on the same page

We can combine multiple SuperExactTest plots on the same page by setting new.gridPage = FALSE. For example, to arrange two SuperExactTest figures side by side, we can:

#png('examples/ex5.png',width=4000,height=2000,res=300)
grid.newpage()
vp0 <- viewport(layout = grid.layout(1, 2))
vp1 <- viewport(layout.pos.col = 1, layout.pos.row = 1, name = "plot_left")
vp2 <- viewport(layout.pos.col = 2, layout.pos.row = 1, name = "plot_right")
vps <- vpTree(vp0, vpList(vp1, vp2))
pushViewport(vps)
seekViewport("plot_left")
plot(Result, Layout="landscape", sort.by='size', keep=FALSE,
        bar.split=c(70,180), show.fold.enrichment=TRUE,
        show.expected.overlap=TRUE, expected.overlap.style="hatchedBox",
        color.expected.overlap='red', color.on = NULL,
        title = 'Figure A. Landscape layout', new.gridPage = FALSE)
seekViewport("plot_right")
plot(Result, Layout="circular", sort.by='size', keep=FALSE,
        show.expected.overlap=TRUE,expected.overlap.style="hatchedBox",
        color.expected.overlap='red', color.on = NULL,
        title = 'Figure B. Circular layout', new.gridPage = FALSE)
#dev.off()

sample output

superexacttest's People

Contributors

mw201608 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

superexacttest's Issues

show expected values in logscale when log.scale=T

Dear mw201608,

Thank you for the development and active maintaining of SuperExactTest

Under this combination of values, log.scale is not applied to the show.expected.overlap white bars. They end up rescaling outside of the ylim shown upon applying log.scale.

Is this something that can be tested/confirmed? Maybe I am not having something alright. Happy to send input files in any case.

plot(res, Layout="landscape", sort.by='p-value', log.scale=T, show.expected.overlap=T,
    elements.list=t1, elements.rot=0, show.elements=T, color.on='black', color.off='white',
     legend.text.cex=2.0, ylim = c(0, 2000),
    show.expected.overlap=TRUE, expected.overlap.style="box", expected.overlap.lwd=0.4,
    overlap.size.cex=1.0, intersection.size.rotate=T,  flip.vertical=F)

Best regards,

Plotting Pvalue Adjustment

I'm a bit of a novice coder, so this is an overlap of a general "how to" question, and a question specific for this package.

I intend to use this software to look for the overlap between 6 different lists. I am grateful for how simple and approachable this was. However, 6 lists lends itself to 57 (63-6) hypotheses tested on over laps.

Very simply, I would like to run multiple hypothesis test correction on the results of the analysis AND plot these results using the plot functions outlined in the vignettes.

The closest I have been able to get is saving the summary table as its own variable and then adding a new column with the adjusted p values.

res_table <- summary(res)$Table res_table$padj <- stats::p.adjust(res_table %>% pull(., P.value), method = "BH", n = length(res_table %>% pull(., P.value)))

But now that this is a separate table and not the S3 class object, it is incompatible with plot function. How do i add these adjusted p values to the S3 class object and then select to plot those instead of the P.value column?

Thank you for the help!

Save the plot as pdf and multiple same plots were generated

Hi,

thanks for developing this nice tool!

I ran into a problem when I was trying to export the plot into pdf. A multi-pages plots were generated with same figure. I think this is only the case for the landscape layout.

Could you please take a look into the issue?

Many thanks!
Rui

segmentation fault caused by c stack overflow when n is > 1,000,000

Dear Minghui,

thanks a lot for your great software, which has helped me a lot. Unfortunately, I recently ran into a problem when using the SuperExactTest with a large background population (n=1238970). Irrespective of the version used (I also tried 1.0.5), R crashed because of a segmentation fault caused by c stack overflow.

Is there anything I can do myself to fix this or is there another simple solution to this? I have accordingly attached a test dataset that caused the problem.

Thanks a lot for your help,

cheers, Martin
example.tar.gz

Plotting a defined number of bars

Hi,

Thanks for the package. It is very useful, flexible, and well-documented.

I am currently comparing 9 sets which results in 511 combinations of intersection. I want to select specific intersections to plot (which can be achieved by sorting the data in a pre-defined order), but I cannot figure out how to select the number of bars to show. Say, I'm interested in plotting only the first 10 bars. How would I do that? I would appreciate any suggestions.

Best,
Lucas

Memory exception in specific cases [attached]

Hi,

In the following attached example I get a memory error. Is there any obvious reason for this? I have observed this ~3-4 times in 20 cases that I have run in bulk.
https://www.dropbox.com/s/cw534rczhwy34pe/debugCaseSuperExactTest.rds?dl=0

events <- readRDS('debugCaseSuperExactTest.rds') # total = 1010
total <- 1010 # this is the number of rows in the original dataframe
res=supertest(events, n=total)
*** Error in `/g/scb/zaugg/rio/miniconda2/lib/R/bin/exec/R': double free or corruption (!prev): 0x0000000002598720 ***
======= Backtrace: =========

Thanks!
Ignacio

Save as PDF

Dear mw201608,

Thank you for the development of this package.

I am intersecting multiple datasets and I would like to combine them using the UpSet visualization. For this I would like to save them as PDFs before editing. However, I get the following error when executing plot.msets on the res object instance:

            pdf(pdf_path, width=w, height=h)
            plot.msets(res)
            dev.off()
Error in grid.Call(C_convert, x, as.integer(whatfrom), as.integer(whatto),  :
  Viewport has zero dimension(s)

Is there an example for saving PDFs? So far I just see an example for PNGs.

Thank you,
Ignacio

Feature request: add expected overlap values to bar plots

Dear Minghui,

It's me again. I wanted to kindly ask for a favour. Since I would like to visually present the expected vs. the observed overlap in the generic barplot output of SuperExactTest, I wanted to ask if there is an easy way to add this feature, e.g. by overlaying the observed value bars with semitransparent bars showing the expected overlap. I tried to do this myself but have difficulties to implement your nice feature to show the comparison by colored bullets underneath the bars.

Thanks a lot.

Best, Martin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.