Skip to content

Instantly share code, notes, and snippets.

@danielecook
Created August 13, 2014 19:55
Show Gist options
  • Save danielecook/8c31f6ca1fcc31d19022 to your computer and use it in GitHub Desktop.
Save danielecook/8c31f6ca1fcc31d19022 to your computer and use it in GitHub Desktop.
Plot Peaks from Homer
library(data.table)
library(stringr)
library(splitstackshape)
args <- commandArgs(trailing=T)
if (length(args) == 0) {
setwd("/Users/dancook/Dropbox/Andersen lab/LabFolders/Dan/ForOthers/Maneeshi")
}
df <- fread("Snail2_Twist_MergedPeaksPS1005kbSummit300bp_Sn_TwEBox.txt")
names(df)[1] <- "Peak"
names(df)[9] <- "Twist1"
names(df)[10] <- "Twist2"
names(df)[11] <- "Snail2"
# Format Columns
for (i in c("Twist1", "Twist2", "Snail2")) {
peak_name <- paste0(i,"_Peak")
strand_name <- paste0(i,"_Strand")
df[[peak_name]] <- sapply(str_split(df[[i]], ")"), function(x) {
gsub(",NA","",paste0(as.numeric(str_extract(x,"[-0-9]+")), collapse = ","))
})
df[[strand_name]] <- sapply(str_split(df[[i]], ")"), function(x) {
gsub("NA|,NA","",paste(gsub(",","",str_extract(x,"(,[+|-],)")), sep=",", collapse=","))
})
}
longform <- function(motif) {
peak <- paste0(motif,"_Peak")
strand <- paste0(motif, "_Strand")
S <- as.data.frame(cbind(Peak=df$Peak,Motif=motif, POS=df[[peak]], STRAND=df[[strand]]))
S <- concat.split.multiple(S, c("POS", "STRAND"), direction="long")
filter(S, !is.na(POS))
}
PEAKS <- rbind(longform("Twist1"), longform("Twist2"), longform("Snail2"))
hist(PEAKS$POS[PEAKS$Motif == "Twist1"])
hist(PEAKS$POS[PEAKS$Motif == "Twist2"])
hist(PEAKS$POS[PEAKS$Motif == "Snail2"])
# Plot densities
ggplot(PEAKS) +
geom_density(aes(x=POS, color=Motif, alpha = 0.05)) +
facet_wrap(~STRAND, ncol=1,nrow=2) +
scale_x_continuous(breaks=seq(-200,300,10))
qplot(PEAKS$time)
# Plot densities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment