forked from vineet1992/Gene-Selection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fit.NetworkBasedSVM.R
64 lines (52 loc) · 2.13 KB
/
fit.NetworkBasedSVM.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
## gets .csv file with the header manually added in
data <- read.csv("C:/Users/Marcus/Desktop/GSE1456_2.csv", header = TRUE, sep = ',') ## read in data
col <- colnames(data)
for(i in 1:length(col)) ## removes any leading X in the header names
{
if(substring(col[i], 1, 1) == 'X')
col[i] <- substr(col[i], 2, nchar(col[i]))
}
colnames(data) <- col
x <- (data)
y <- factor(data$y)
## creates a mapping using ENTREZID
library(hgu133a.db)
mapped.probes <- mappedkeys(hgu133aENTREZID)
refseq <- as.list(hgu133aENTREZID[mapped.probes])
times <- sapply(refseq, length)
mapping <- data.frame(probesetID=rep(names(refseq), times=times), graphID=unlist(refseq), row.names=NULL, stringsAsFactors=FALSE)
mapping <- unique(mapping)
library(graphite)
paths <- pathways("hsapiens", "kegg")
alledges <- NULL
## creates an adjacency matrix
for(i in 1:length(paths)) ## loop through each of the pathways
{
curr2 <- paths[[i]]
edges <-graphite::edges(curr2)
edges <- edges[,c("src","dest")]
alledges <- rbind(alledges, edges)
alledges = unique(alledges) ## Get the unique edges in the pathway just as a list of gene-gene interactions
}
src <- as.matrix(sort(as.numeric(unique(alledges[,c("src")]))))
dest <- as.matrix(sort(as.numeric(unique(alledges[,c("dest")]))))
vals <- unique(rbind(src, dest))
adjMatrix <- matrix(0, length(vals), length(vals))
rownames(adjMatrix) <- vals
colnames(adjMatrix) <- vals
for(i in 1:nrow(alledges))
{
col1 <- alledges[i,"src"]
col2 <- alledges[i,"dest"]
adjMatrix[toString(col1),toString(col2)] <- 1
adjMatrix[toString(col2),toString(col1)] <- 1
}
library(pathClass)
matched <- matchMatrices(x = x, adjacency = adjMatrix, mapping = mapping)
ad.list <- as.adjacencyList(adjMatrix)
## networkBasedSVM
res.nBSVM <- crossval(matched$x, y, theta.fit=fit.networkBasedSVM, folds=3, repeats=1, DEBUG=TRUE,
parallel=FALSE, adjacencyList=ad.list, lambdas=10^(-1:2), sd.cutoff=1)
## RRFE
res.rrfe <- crossval(x, y, DEBUG=TRUE, theta.fit=fit.rrfe, folds=3, repeats=1, parallel=TRUE,
Cs=10^(-3:3), mapping=mapping, Gsub=adjMatrix, d=1/2)