Skip to content

Instantly share code, notes, and snippets.

Ling-Yun Wu wulingyun

Block or report user

Report or block wulingyun

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@wulingyun
wulingyun / Sumatra.edt
Created Jun 19, 2016
Using Sumatra with WinEdt, add the following code to "WinEdt\Exec\Acrobat OpenDoc.edt", before the line: // GSView
View Sumatra.edt
// Sumatra?
FindInString(`%$('AcroRead')`,'SumatraPDF',1,2,1000,1);
IfOK(!"Relax;",!"JMP('not_sumatra')");
Run('%$("AcroRead"); -reuse-instance -inverse-search "\"%B\WinEdt.exe\" \"[Open(|%%f|);SelPar(%%l,8);]\"" "%P\%N.pdf"','%P',0,0,'%N.pdf - SumatraPDF',1,1);
DDEOpen('',"SUMATRA","control",1);
// send a DDE command to perform forward-search
// the format of the DDE command is [ForwardSearch("<pdffilepath>","<sourcefilepath>",<line>,<column>[,<newwindow>, <setfocus>])]
// if newwindow = 1 then a new window is created even if the file is already open
// if focus = 1 then the focus is set to the window
@wulingyun
wulingyun / updown_colors.R
Created Jun 19, 2016
Color function for green-red heatmap
View updown_colors.R
updown_colors <- function(n = 50, down.col = 1/3, up.col=1, saturation = 1)
{
c(hsv(down.col, saturation, seq(1,0,length=n)), hsv(up.col, saturation, seq(0,1,length=n)))
}
@wulingyun
wulingyun / normal_test.R
Created Jun 19, 2016
Calculate normal test
View normal_test.R
# one sample normal test
norm_test1 <- function(x.n, x.mu, x.var, mu, side=0)
{
nu <- x.n - 1
z <- (x.mu - mu) / sqrt(x.var / x.n)
p <- p.value(pnorm, z, side=side)
data.frame(mean=x.mu, df=nu, statistic=z, p.value=p)
}
# two samples normal test
@wulingyun
wulingyun / t_test.R
Created Jun 19, 2016
Calculate student t-test
View t_test.R
# one sample t-test
t_test1 <- function(x.n, x.mu, x.var, mu, side=0)
{
nu <- x.n - 1
t <- (x.mu - mu) / sqrt(x.var / x.n)
p <- p.value(pt, t, params=nu, side=side)
data.frame(mean=x.mu, df=nu, statistic=t, p.value=p)
}
# two samples t-test
@wulingyun
wulingyun / p_value.R
Created Jun 19, 2016
Calculate P-value
View p_value.R
p_value <- function(cdf, z, params=numeric(0), side=0)
{
n <- length(params)
p <- switch(n+1,
cdf(z),
cdf(z, params),
cdf(z, params[1], params[2]),
cdf(z, params[1], params[2], params[3])
)
if (side < 0) p
@wulingyun
wulingyun / fold_change.R
Created Jun 19, 2016
Fold change with confidence interval
View fold_change.R
fold_change <- function(x, y, confidence.level=90, var.equal=F)
{
fc.interval(length(x), mean(x), var(x), length(y), mean(y), var(y), confidence.level, var.equal)
}
fc.interval <- function(x.n, x.mu, x.var, y.n, y.mu, y.var, confidence.level=90, var.equal=F)
{
mu <- x.mu - y.mu
if (var.equal) {
nu <- x.n + y.n - 2
View robust_fold_change.R
robust_fold_change <- function(case, control)
{
m <- dim(case)[2]
n <- dim(control)[2]
fc.raw <- matrix(nrow=dim(case)[1], ncol=m*n)
for (i in 1:m) {
for (j in 1:n) {
fc.raw[, (i-1)*m+j] <- case[,i] - control[,j]
}
}
@wulingyun
wulingyun / merge_rows.R
Created Jun 19, 2016
Merge matrix rows with same name
View merge_rows.R
merge_rows <- function(x, method=mean, na.rm=FALSE)
{
x <- as.matrix(x[!is.na(rownames(x)), ])
r <- unique(rownames(x))
m <- length(r)
if (dim(x)[1] != m) {
y <- matrix(nrow=m, ncol=dim(x)[2])
rownames(y) <- r
colnames(y) <- colnames(x)
for (i in 1:m) {
@wulingyun
wulingyun / diffusion_kernel.R
Created Jun 19, 2016
Network diffusion kernel
View diffusion_kernel.R
diffusion_kernel <- function(adj, beta = 1)
{
lap <- adj - diag(rowSums(adj))
eig <- eigen(lap)
dif <- eig$vectors %*% diag(exp(beta * eig$values)) %*% t(eig$vectors)
dif
}
You can’t perform that action at this time.