Skip to content

Instantly share code, notes, and snippets.

View Swarchal's full-sized avatar

Scott Warchal Swarchal

View GitHub Profile
@Swarchal
Swarchal / source_https.R
Last active August 29, 2015 14:15
source() for https (eg. raw.github)
source_https <- function(url, ...) {
# load package
require(RCurl)
# parse and evaluate each .R script
sapply(c(url, ...), function(u) {
eval(
parse(
text = getURL(u, followlocation = TRUE,
cainfo = system.file("CurlSSL",
@Swarchal
Swarchal / read_all.R
Created August 7, 2015 08:06
load all csv files in the current directory
path <- paste(getwd(), "\\", sep = "")
files <- list.files(path=path, pattern="*.csv")
for(file in files)
{
perpos <- which(strsplit(file, "")[[1]]==".")
assign(
gsub(" ","",substr(file, 1, perpos-1)),
read.csv(paste(path,file,sep="")))
}
import matplotlib.pyplot as plt
from skimage.io import imread
from skimage.morphology import disk
from skimage.filters import rank
import numpy as np
im_all = imread("/home/scott/Dropbox/wally/ww2.jpg")
all_red = im_all[:, :, 0]
im_wally = imread("/home/scott/Dropbox/wally/wally2.png")
wally_red = im_wally[:, :, 0]
import matplotlib.pyplot as plt
from skimage.io import imread
from skimage.feature import match_template
import matplotlib.pyplot as plt
import numpy as np
image = imread("image.jpg")
wally = imread("wally.png")
# select just the red channel
library(raster)
# load images
image_DNA <- raster('~/BBBC007_v1_images/A9/A9 p5d.tif')
image_actin <- raster('~/BBBC007_v1_images/A9/A9 p5f.tif')
# display images
plot(image_DNA, col = gray.colors(max(values(image_DNA))))
plot(image_actin, col = gray.colors(max(values(image_actin))))
# merge channels
image_stack <- brick(image_DNA, image_actin)
# display merged image
plotRGB(image_stack, stretch = 'lin')
# change colours of channels
plotRGB(image_stack, stretch = 'lin' g = 2, b = 1)
@Swarchal
Swarchal / heatmap.R
Last active September 27, 2019 22:02
heatmap.R
library(ggplot2)
library(reshape2)
df_expression <- read.csv("expression.csv")
df_molten <- melt(df_expression)
ggplot(data = df_molten,
aes(x = variable, y = MouseID, fill = value)) +
geom_raster() +
xlab("Protein") +
scale_fill_distiller(palette = "RdYlBu", trans = "log10") +
dat <- df_expression[,2:78] # numerical columns
rownames(dat) <- df_expression[,1]
row.order <- hclust(dist(dat))$order # clustering
col.order <- hclust(dist(t(dat)))$order
dat_new <- dat[row.order, col.order] # re-order matrix accoring to clustering
df_molten_dat <- melt(as.matrix(dat_new)) # reshape into dataframe
names(df_molten_dat)[c(1:2)] <- c("MouseID", "Protein")
ggplot(data = df_molten_dat,