Skip to content

Instantly share code, notes, and snippets.

View GuangchuangYu's full-sized avatar
🎯
Focusing

Guangchuang Yu GuangchuangYu

🎯
Focusing
View GitHub Profile
@GuangchuangYu
GuangchuangYu / Antithetic_variates.R
Created February 29, 2012 06:40
The antithetic variates method is a variance reduction technique used in Monte Carlo methods.
## Antithetic sampling reframes our estimate as a sum of negatively
## correlated random variables, using the fact that negative
## correlation reduces the variance of a sum.
## http://en.wikipedia.org/wiki/Antithetic_variates
g <- function(x) 1/(1+x)
N <- 1500
n <- 50
u1 <- matrix(runif(2 * n * N), ncol = n)
## devtools::install_github("stephenturner/msigdf")
library(msigdf)
library(dplyr)
library(clusterProfiler)
c2 <- msigdf.human %>%
filter(collection == "c2") %>% select(geneset, entrez) %>% as.data.frame
data(geneList)
de <- names(geneList)[1:100]
@GuangchuangYu
GuangchuangYu / ss-pkg.R
Created April 19, 2019 06:14
R packages for semantic similarity measurement
d <- data.frame(pkg = c("GOSim", "GOSemSim", "DOSE", "meshes",
"DOSim", "HPOSim", "ppiPre", "MeSHSim", "meshr"),
year = c(2007, 2010, 2015, 2018, 2011, 2015, 2013, 2015, 2015),
journal = c("BMC Bioinformatics", rep("Bioinformatics", 3),
"BMC Bioinformatics", "PLoS One", "BMC Systems Biology",
"Journal of Bioinformatics and computational biology",
"BMC Bioinformatics"),
y = c(1, 1, 2, 3, 2, 4, 5, 2.8, 3.2))
require(ggplot2)
Sample Date DateNr dDay1 dDay2 dDay3 Station Area 31UE_ED50 31UN_ED50 Year Month Season Salinity Temperature CHLFa
DANT.19900110 19900110 1990/10/1 7 9 9 DANT WZ 681379.62 5920571.24 1990 1 winter 29.19 4 1.3
DANT.19900206 19900206 1990/6/2 34 36 36 DANT WZ 681379.62 5920571.24 1990 2 winter 27.37 6 NA
DANT.19900308 19900308 1990/8/3 64 66 66 DANT WZ 681379.62 5920571.24 1990 3 spring 24.99 7.3 21.1
DANT.19900404 19900404 1990/4/4 91 93 93 DANT WZ 681379.62 5920571.24 1990 4 spring 28.79 8.2 25
DANT.19900509 19900509 1990/9/5 126 128 128 DANT WZ 681379.62 5920571.24 1990 5 spring 33.28 17.4 10.2
DANT.19900620 19900620 6/20/1990 168 170 170 DANT WZ 681379.62 5920571.24 1990 6 summer 32.69 18.1 6.2
DANT.19900718 19900718 7/18/1990 196 198 198 DANT WZ 681379.62 5920571.24 1990 7 summer 31.9 17 7.9
DANT.19900815 19900815 8/15/1990 224 226 226 DANT WZ 681379.62 5920571.24 1990 8 summer 33.76 21 7.85
DANT.19900919 19900919 9/19/1990 259 261 26
Sample Date DateNr dDay1 dDay2 dDay3 Station Area 31UE_ED50 31UN_ED50 Year Month Season Salinity Temperature CHLFa
DANT.19900110 19900110 1990/10/1 7 9 9 DANT WZ 681379.62 5920571.24 1990 1 winter 29.19 4 1.3
DANT.19900206 19900206 1990/6/2 34 36 36 DANT WZ 681379.62 5920571.24 1990 2 winter 27.37 6 NA
DANT.19900308 19900308 1990/8/3 64 66 66 DANT WZ 681379.62 5920571.24 1990 3 spring 24.99 7.3 21.1
DANT.19900404 19900404 1990/4/4 91 93 93 DANT WZ 681379.62 5920571.24 1990 4 spring 28.79 8.2 25
DANT.19900509 19900509 1990/9/5 126 128 128 DANT WZ 681379.62 5920571.24 1990 5 spring 33.28 17.4 10.2
DANT.19900620 19900620 6/20/1990 168 170 170 DANT WZ 681379.62 5920571.24 1990 6 summer 32.69 18.1 6.2
DANT.19900718 19900718 7/18/1990 196 198 198 DANT WZ 681379.62 5920571.24 1990 7 summer 31.9 17 7.9
DANT.19900815 19900815 8/15/1990 224 226 226 DANT WZ 681379.62 5920571.24 1990 8 summer 33.76 21 7.85
DANT.19900919 19900919 9/19/1990 259 261 26
d = structure(list(x = c(516.362976074219, 514.883316040039, 510.306549072266,
502.721382141113, 492.303680419922, 479.293769836426, 463.977825164795,
446.675720214844, 427.74100112915, 407.568737030029, 386.590072631836,
365.25927734375, 344.028457641602, 323.352523803711, 303.678215026855,
285.42236328125, 268.959743499756, 254.630310058594, 242.738302230835,
233.550735473633, 227.284624099731, 224.07541847229, 223.949848175049,
226.633100509644, 232.021848678589, 240.107601165771, 248.467231750488,
256.632625579834, 264.798046112061, 272.827682495117, 279.170124053955,
284.358814239502, 288.348812103271, 291.169918060303, 292.902908325195,
293.650428771973, 293.608024597168, 292.990119934082, 291.361457824707,
@GuangchuangYu
GuangchuangYu / valetine.R
Created February 14, 2012 05:38
generate heart plot for valentine's day
require(ggplot2)
t <- seq(0,2*pi, by=0.1)
x <- 16*sin(t)^3
y <- 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t)
d <- data.frame(x=x,y=y, f=0)
a <- x
b <- y
qbar <- function(x, verbose=TRUE) {
enc = encoding(quality(x))
qual <- sapply(seq_along(x), function(i) enc[to_char_vector(x[i])])
mq <- rowMeans(qual)
if (verbose) {
names(mq) <- NULL
print(mq)
}
@GuangchuangYu
GuangchuangYu / jiong.R
Created February 17, 2012 09:13
draw chinese character Jiong using ggplot2
f <- function(x) 1/(x^2-1)
x <- seq(-3,3, by=0.001)
y <- f(x)
d <- data.frame(x=x,y=y)
p <- ggplot()
p <- p+geom_rect(fill = "white",color="black",size=3,
aes(NULL, NULL,xmin=-3, xmax=3,
ymin=-3,ymax=3, alpha=0.1))