{
search.term <- gsub(' ', '%20', search.term)
if(quotes) search.term <- paste('%22', search.term, '%22', sep='')
getGoogleURL <- paste('http://www.google', domain, '/search?q=',
search.term, sep='')
}
getGoogleLinks <- function(google.url) {
doc <- getURL(google.url, httpheader = c("User-Agent" = "R
(2.10.0)"))
html <- htmlTreeParse(doc, useInternalNodes = TRUE, error=function
(...){})
nodes <- getNodeSet(html, "//h3[@class='r']//a")
return(sapply(nodes, function(x) x <- xmlAttrs(x)[["href"]]))
}
search.term <- "cran"
quotes <- "FALSE"
search.url <- getGoogleURL(search.term=search.term, quotes=quotes)
links <- getGoogleLinks(search.url)
search.url
getGoogleURL <- function(search.term, domain = '.com', quotes=TRUE)
{
search.term <- gsub(' ', '%20', search.term)
if(quotes) search.term <- paste('%22', search.term, '%22', sep='')
getGoogleURL <- paste('http://www.google', domain, '/search?q=',
search.term, sep='')
}
search.url <- getGoogleURL(search.term=search.term, quotes=quotes)
search.url
search.term
getGoogleLinks(search.url)
getURL(google.url, httpheader = c("User-Agent" = "R
(2.10.0)"))
getURL("http://www.google.com/search?q=cran", httpheader = c("User-Agent" = "R
(2.10.0)"))
getURL("http://www.google.com/search?q=cran")
getGoogleURL <- function(search.term, domain = '.co.uk', quotes=TRUE)
{
search.term <- gsub(' ', '%20', search.term)
if(quotes) search.term <- paste('%22', search.term, '%22', sep='')
getGoogleURL <- paste('http://www.google', domain, '/search?q=',
search.term, sep='')
}
search.url <- getGoogleURL(search.term=search.term, quotes=quotes)
search.url
doc <- getURL(search.url, httpheader = c("User-Agent" = "R
(2.10.0)"))
doc
doc <- getURL(search.url)#, httpheader = c("User-Agent" = "R
doc
doc <- getURL(search.url, httpheader = c("User-Agent" = "R
(2.10.0)"))
html <- htmlTreeParse(doc, useInternalNodes = TRUE, error=function
(...){})
html
nodes <- getNodeSet(html, "//h3[@class='r']//a")
nodes
search.term
paste('http://www.google', domain, '/search?q=',
search.term, sep='')
paste('http://www.google', "co.uk", '/search?q=',search.term, sep='')
paste('http://www.google', "o.uk", '/search?q=',search.term, sep='')
paste('http://www.google', ".co.uk", '/search?q=',search.term, sep='')
getGoogleURL
getGoogleURL(search.term=search.term, quotes=quotes)
search.term
quotes
getGoogleURL <- function(search.term, domain = '.co.uk', quotes=TRUE)
{
search.term <- gsub(' ', '%20', search.term)
if(quotes) search.term <- paste('%22', search.term, '%22', sep='')
getGoogleURL <- paste('http://www.google', domain, '/search?q=',
search.term, sep='')
}
getGoogleURL(search.term=search.term, quotes=quotes)
(getGoogleURL(search.term=search.term, quotes=quotes))
getGoogleURL <- function(search.term, domain = '.com', quotes=TRUE)
{
search.term <- gsub(' ', '%20', search.term)
if(quotes) search.term <- paste('%22', search.term, '%22', sep='')
getGoogleURL <- paste('http://www.google', domain, '/?gfe_rd=cr&ei=4sfOV-mQOMGBaK78tMgF&gws_rd=cr&fg=1#q=',
search.term, sep='')
}
search.term <- "cran"
quotes <- "FALSE"
search.url <- getGoogleURL(search.term=search.term, quotes=quotes)
search.url
links <- getGoogleLinks(search.url)
doc <- getURL(search.url, httpheader = c("User-Agent" = "R
(2.10.0)"))
doc
html <- htmlTreeParse(doc, useInternalNodes = TRUE, error=function
(...){})
html
nodes <- getNodeSet(html, "//h3[@class='r']//a")
return(sapply(nodes, function(x) x <- xmlAttrs(x)[["href"]]))
nodes
html
nodes <- getNodeSet(html, "/r:help/r:topic")#"//h3[@class='r']//a")
nodes <- getNodeSet(html)#, "/r:help/r:topic")#"//h3[@class='r']//a")
nodes <- getNodeSet(html,"//h3//a[@href]")#, "/r:help/r:topic")#"//h3[@class='r']//a")
nodes
nodes <- getNodeSet(html,"a[/html/@lang='en'][@href='help.php'][1]/@cran")#, "/r:help/r:topic")#"//h3[@class='r']//a")
nodes
devtools::load_all(".")
library(ctsGE)
library("ctsGE", lib.loc="~/R/x86_64-pc-linux-gnu-library/3.3")
library(GEOquery)
data_dir <- system.file("extdata", package = "ctsGE")
files <- dir(path=data_dir,pattern = "\\.xls$")
rts <- readTSGE(files, path = data_dir, labels = c("0h","6h","12h","24h","48h","72h") )
names(rts)
rts$timePoints
head(rts$samples)
head(rts$tags)
prts <- PreparingTheIndexes(x = rts, cutoff = 0.55, mad.scale = TRUE)
head(prts$tsTable)
head(prts$scaled)
indexPlot <- PlotIndexesClust(prts,idx = "1100-1-1",scaling = TRUE)
indexPlot$`Clust_4_1100-1-1`
head(prts$index)
class(prts$index)
head(rts$tags)
class(rts$tags)
as.data.frame(rts$tags[1:10],rts$tags[11:20])
h=as.data.frame(rts$tags[1:10],desc=rts$tags[11:20])
h
h=as.data.frame(desc=rts$tags[11:20],rts$tags[1:10])
h
as.data.frame(rts$tags[1:10],rts$tags[11:20])
as.data.frame(rts$tags[1:10],d=rts$tags[11:20])
as.data.frame(d=rts$tags[1:10],rts$tags[11:20])
c=as.data.frame(rts$tags[11:20])
c
rownames(c)
rownames(c)=rts$tags[1:10]
c
names(prts)
names(rts)
indexPlot$`Clust_4_1100-1-1`
detach("package:ctsGE", unload=TRUE)
library(ctsGE)
detach("package:ctsGE", unload=TRUE)
names(rts)
"samples" %in% names(rts)
"samps" %in% names(rts)
library(ctsGE)
data_dir <- system.file("extdata", package = "ctsGE")
files <- dir(path=data_dir,pattern = "\\.xls$")
rts <- readTSGE(files, path = data_dir,labels = c("0h","6h","12h","24h","48h","72h"))
nrow(rts$tsTable)
rts <- readTSGE(files, path = data_dir,labels = c("0h","6h","12h","24h","48h","72h"),desc = rep("hi",12625))
head(rts$desc)
class(rts$desc)
ctsGEShinyApp(rts,cutoff = 0.55)
prts <- PreparingTheIndexes(x = rts, cutoff = 0.55, mad.scale = TRUE)
indexPlot <- PlotIndexesClust(prts,idx = "1100-1-1",scaling = TRUE)
x=rts
names(x)==c("tsTable","samples","tags","timePoints")
sum(names(x)==c("tsTable","samples","tags","timePoints"))
names(x)
sum(names(x)==c("tsTable","samples","tags","timePoints","desc"))
PreparingTheIndexes = function(x,cutoff=1,mad.scale=TRUE){
if(!is.list(x)) stop ( "data must be a list")
if(sum(names(x)==c("tsTable","samples","tags","timePoints","desc")) < 4)
stop ( "Your List miss one or more of theses objects:
tsTable, samples, tags, timePoints")
tp <- x$timePoints
x$scaled <-
tmp <-
t(scale(t(x$tsTable),apply(t(x$tsTable),2,median),
apply(t(x$tsTable),2,mad)))
if(!mad.scale) x$scaled <- tmp <-  t(scale(t(x$tsTable)))
idx <- data.frame(t(apply(tmp,1,index,cutoff=cutoff)))
colnames(idx) <- x$samples
x$index <- cbind(as.data.frame(idx),index=apply(idx,1,paste,collapse=""))
x$cutoff <- cutoff
return(x)
}
prts <- PreparingTheIndexes(x = rts, cutoff = 0.55, mad.scale = TRUE)
indexPlot <- PlotIndexesClust(prts,idx = "1100-1-1",scaling = TRUE)
length(prts)
x=prts
idx="1100-1-1"
plot <- list()
ggplot_list <- list()
clust_tbl <-  list()
kindex <-  list()
genes <- rownames(x$index[x$index[,"index"]==idx,])
tbl <- x$scaled[genes,]
head(tbl)
length(genes)
tbl <- as.data.frame(tbl)
head(tbl)
is.null(k)
k=NULL
is.null(k)
!is.null(k)
length(x)
"optimalK" %in% names(x)
PlotIndexesClust = function(x,idx,k=NULL,scaling=TRUE){
set.seed(100)
plot <- list()
ggplot_list <- list()
clust_tbl <-  list()
kindex <-  list()
genes <- rownames(x$index[x$index[,"index"]==idx,])
if(length(x) < 7){stop("Please run PreparingTheIndexes first")}
if(!scaling){tbl <- x$tsTable[genes,]
} else{tbl <- x$scaled[genes,]}
if(length(genes) > 1 ) {tbl <- as.data.frame(tbl)
}else{
tbl <- data.frame(t(matrix(tbl)))
colnames(tbl) <- x$samples
rownames(tbl) <- genes
}
if(!is.null(k)){
fit_km <- kmeans(tbl,k)
tbl[names(fit_km$cluster),"clusters"] <- fit_km$cluster
K <- k
}else{
# checks if indexes were already made with PreparingTheIndexes
if("optimalK" %in% names(x)){
k <- x$optimalK[rownames(x$optimalK)==idx,"k"]
tbl1 <- x$ClusteredIdxTable
tags <- rownames(tbl1[tbl1[,"index"]==idx,])
tbl[tags,"clusters"] <- tbl1[tbl1[,"index"]==idx,"clusters"]
}else{
if(length(genes) > 9){
tbl <- as.data.frame(tbl)
k = 1
fit_km <- kmeans(tbl,k,nstart = 25)
opt <- fit_km$tot.withinss/fit_km$totss < 0.2
while (!opt) {
k=k+1
# Apply k-means to tbl: fit_km
fit_km <- kmeans(tbl,k,nstart = 25)
opt <- fit_km$tot.withinss/fit_km$totss < 0.2
}
K <-  k #where: WSS / TSS < 0.2 this is the optimal k
clust <-   fit_km$cluster
}else{
K <- 1
clust <- rep(1,nrow(tbl))}
kindex[[idx]] <-  c(nrow(tbl),K)
clust_tbl[[idx]] <- data.frame(clusters=clust,index=idx)
rownames(clust_tbl[[idx]]) <- rownames(tbl)
tbl[,"clusters"] <- clust
}
}
tmp <- cbind(tags=genes,tbl)
for(i in 1:K){
x.m <- reshape2::melt(tmp[tmp$cluster==i,c("tags",x$samples)])
colnames(x.m) <- c("tags","tp","exp")
gplot <-
ggplot2::ggplot(x.m,
ggplot2::aes_string(y="exp",x="tp",colour="tags",
group="tags"))+
ggplot2::labs(title =paste0("Index: ",idx," Cluster: ",i),
x = "Time", fill= NULL, y = "Expression Value") +
ggplot2::theme(legend.position="none")
gplot <- gplot +ggplot2::geom_line()
name <- paste0("Clust_",i,"_",idx)
ggplot_list[[name]] <- gplot
}
if ("desc" %in% names(x)) {tbl <- cbind(desc=x$desc[genes,], tbl)}
plot[[name]] <- tbl
plot$graphs <- ggplot_list
structure(plot,class = "list")
}
indexPlot <- PlotIndexesClust(prts,idx = "1100-1-1",scaling = TRUE)
head(x$desc)
readTSGE = function(files,path = NULL,columns=c(1,2),labels = NULL,desc = NULL,
...){
x <- list()
if(!is.list(files)){
d <- taglist <- list()
for (fn in files) {
if (!is.null(path))
fn <- file.path(path, fn)
d[[fn]] <- read.delim(fn, ..., stringsAsFactors = FALSE)
taglist[[fn]] <- as.character(d[[fn]][, columns[1]])
if (any(duplicated(taglist[[fn]]))) {
stop(paste("Repeated tag sequences in", fn))
}
}
}
else{
d <- files
taglist <- list()
for (fn in 1:length(files)) {
taglist[[fn]] <- as.character(d[[fn]][,columns[1]])
if (any(duplicated(taglist[[fn]]))) {
stop(paste(
"Repeated tag sequences in table no.",i,"in the list"))
}
}
}
tags <- unique(unlist(taglist))
ntags <- length(tags)
nfiles <- length(files)
x$tsTable <- matrix(0, ntags, nfiles)
rownames(x$tsTable) <- tags
colnames(x$tsTable) <- labels
if (is.null(colnames(x$tsTable))){
if(!is.list(files)){ colnames(x$tsTable) <-
x$samples <- limma::removeExt(files)
}else{colnames(x$tsTable) <- x$samples <- names(files)}
}else{x$samples <- colnames(x$tsTable)}
for (i in 1:nfiles) {
aa <- match(taglist[[i]], tags)
x$tsTable[aa, i] <- as.numeric(d[[i]][, columns[2]])
}
x$tags <- tags
x$timePoints <- nfiles
## filtering out genes with low expression
tmp <- apply(t(x$tsTable),2,mad)
if(sum(tmp==0)){
x$tsTable <- x$tsTable[names(which(tmp!=0)),]
x$tags <- names(which(tmp!=0))
print(paste0(sum(tmp==0)," Genes were remove"))}
if(!is.null(desc)){
x$desc <- desc
if(sum(tmp==0)){
desc <- desc[which(tmp!=0)]}
x$desc <- as.data.frame(desc)
rownames(x$desc) <- x$tags
colnames(x$desc) <- "desc"}
structure(x,class = "list")
}
rts <- readTSGE(files, path = data_dir,labels = c("0h","6h","12h","24h","48h","72h"),desc = rep("hi",12625))
head(rts$desc)
prts <- PreparingTheIndexes(x = rts, cutoff = 0.55, mad.scale = TRUE)
indexPlot <- PlotIndexesClust(prts,idx = "1100-1-1",scaling = TRUE)
indexPlot$graphs
indexPlot$`Clust_4_1100-1-1`
ctsGEShinyApp(rts,cutoff = 0.55)
ctsGEShinyApp <- function(rts, cutoff = 1, mad.scale = TRUE,title = NULL) {
prts <- PreparingTheIndexes(rts, cutoff, mad.scale)
idx <- as.character(unique(prts$index[,"index"]))
clusters <- function(tbl,g){
#set.seed(100)
tmp <- as.matrix(tbl[,c(1:rts$timePoints)])
fit <- kmeans(tmp, g,nstart = 25)
kmeans.groups <-
cbind(merge(data.frame(fit$cluster),tmp,by="row.names",all=TRUE),
index=tbl$index)
colnames(kmeans.groups)[1:2] <- c("genes","clusters")
return(kmeans.groups)
}
get_plot_output_list <- function(plot_list) {
#set.seed(100)
# Insert plot output objects the list
plot_output_list <- lapply(1:length(plot_list), function(i) {
plotname <- names(plot_list)[i]
plot_output_object <-
shiny::plotOutput(plotname, height = 280, width = 250)
plot_output_object <- shiny::renderPlot({
gg <- plot_list[[i]]
print(gg)
})
})
return(do.call(shiny::tagList,plot_output_list))
}
shiny::shinyApp(
ui = shiny::pageWithSidebar(
shiny::headerPanel(title),
shiny::sidebarPanel(width = 2,
shiny::selectInput("index","Select an Index:",
choices = idx,
selected = idx[1]),
shiny::sliderInput("n", "Number of clusters",
min = 1,max= 10,
value= 1,step= 1),
shiny::checkboxInput("scale",
"Unscaled values",value = FALSE)
),
shiny::mainPanel(width = 10,
shiny::tabsetPanel(
shiny::tabPanel("Time series",
icon =shiny::icon("line-chart"),
shiny::uiOutput("plots")),
shiny::tabPanel( "Genes Table",
icon = shiny::icon("table"),
shiny::uiOutput("table"))
)
)
),#pageWithSidebar
server = function(input, output,session) {
# filter input$index
filtered <- shiny::reactive({
if (is.null(input$index)) {
return(NULL)
}
set.seed(100)
if(!input$scale){
PlotIndexesClust(prts,input$index,k = input$n)
}else{
PlotIndexesClust(prts,input$index,k = input$n,
scaling = FALSE)}
})
shiny::observe({
list_plot <- filtered()[[2]]
output$plots <- shiny::renderUI({
get_plot_output_list(list_plot)
})
tbl <- filtered()[[1]]
tbl <- cbind(genes=rownames(tbl),
desc=as.factor(tbl$desc),
clusters=as.factor(tbl$clusters),
data.frame(tbl[,prts$samples]),
index=input$index)
rownames(tbl) <- NULL
output$table <- shiny::renderUI({
if (is.null(tbl)) {return()}
output$tmp <-
DT::renderDataTable(tbl,
rownames = FALSE,
extensions ='Buttons',
options = list(dom =
'TB<"clear">lfrtip',
buttons = c('copy',
'csv',
'excel',
'print'),
lengthMenu =
list(c(15,50,100,
nrow(tbl)),
c('15','50',
'100','All')
))
)
DT::dataTableOutput("tmp")
})#renderUI
})#end observe
}
)
}
ctsGEShinyApp(rts,cutoff = 0.55)
library(ctsGE)
detach("package:ctsGE", unload=TRUE)
remove.packages("ctsGE", lib="~/R/x86_64-pc-linux-gnu-library/3.3")
biocLite("ctsGE")
source("https://bioconductor.org/biocLite.R")
biocLite("ctsGE")
biocLite("ctsGE")
biocLite("ctsGE")
source("https://bioconductor.org/biocLite.R")
biocLite("ctsGE")
library(BiocInstaller)
useDevel()
biocValid()              # checks for out of date packages
biocLite()
biocLite("ctsGE")
source("https://bioconductor.org/biocLite.R")
biocLite("ctsGE")
devtools::install_github("michalsharabi/ctsGE")
library("ctsGE", lib.loc="~/R/x86_64-pc-linux-gnu-library/3.3")
library(GEOquery)
data_dir <- system.file("extdata", package = "ctsGE")
files <- dir(path=data_dir,pattern = "\\.xls$")
rts <- readTSGE(files, path = data_dir, labels = c("0h","6h","12h","24h","48h","72h"),desc = rep("jk",12625))
ctsGEShinyApp(rts,cutoff = 0.55)
source("https://bioconductor.org/biocLite.R")
source("http://bioconductor.org/biocLite.R")
remove.packages("BiocInstaller")
remove.packages("BiocInstaller")
source("https://bioconductor.org/biocLite.R")
biocValid()
remove.packages("FunciSNP", lib="~/R/x86_64-pc-linux-gnu-library/3.3")
remove.packages("FunciSNP.data", lib="~/R/x86_64-pc-linux-gnu-library/3.3")
remove.packages("fission", lib="/usr/local/lib/R/site-library")
remove.packages("fission", lib="/usr/local/lib/R/site-library")
remove.packages("fission", lib="~/R/x86_64-pc-linux-gnu-library/3.3")
biocLite("ctsGE")
remove.packages("ctsGE", lib="~/R/x86_64-pc-linux-gnu-library/3.3")
biocValid()
biocLite("ctsGE")
remove.packages("matrixStats", lib="~/R/x86_64-pc-linux-gnu-library/3.3")
source("https://bioconductor.org/biocLite.R")
library(BiocInstaller)
source("https://bioconductor.org/biocLite.R")
detach("package:BiocInstaller", unload=TRUE)
source("https://bioconductor.org/biocLite.R")
useDevel()
biocLite("ctsGE")
install.packages("ctsGE")
install.packages("ctsGE",lib = "/home/michal/R/x86_64-pc-linux-gnu-library/3.3-bioc-devel/")
sessionInfo()
install.packages("ctsGE",lib = "/home/michal/R/x86_64-pc-linux-gnu-library/3.3-bioc-devel/",type = "source")
biocLite("ctsGE",type="source")
install.packages("ggplot2",lib = "/home/michal/R/x86_64-pc-linux-gnu-library/3.3-bioc-devel/",type = "source")
install.packages("limma",lib = "/home/michal/R/x86_64-pc-linux-gnu-library/3.3-bioc-devel/",type = "source")
biocLite("limma",type="source")
biocLite("ggplot2",type="source")
biocLite("reshape2",type="source")
biocLite("shiny",type="source")
biocLite("stats",type="source")
biocLite("utils",type="source")
biocLite("ctsGE",type="source")
tmp=tempfile()
sourceURL = "http://bioconductor.org/packages/devel/bioc/src/contrib/ctsGE_0.99.12.tar.gz"
download.file(sourceURL, temp)
download.file(sourceURL, tmp)
install.packages(tmp, repos=NULL, type="source")
biocLite("phyloseq")
biocValid()
biocLite("ctsGE")
install.packages("foreign", type="source")
remove.packages("foreign", lib="/usr/local/lib/R/site-library")
library("foreign", lib.loc="/usr/lib/R/library")
biocLite("ctsGE")
biocLite("ctsGE")
