-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategories_paths.R
More file actions
72 lines (64 loc) · 1.96 KB
/
categories_paths.R
File metadata and controls
72 lines (64 loc) · 1.96 KB
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
65
66
67
68
69
70
71
72
####Borrar todas las variables y gráficos previos#####
rm(list = setdiff(ls(), lsf.str()))
graphics.off()
####################################################
####################################################
groups <- function(x,n){ #divide x in n categories from 1 to n dividing range almost equally
d<-length(unique(x))
if(d < n){n <- d}
d<-ceiling(d/n)
a<-min(x)
b<-a+d
res<-x
for(i in 1:(n-1)){
res[which(x >= a & x < b)]<-i
a<- b
b<-b+d
}
res[which(x >= a)]<-n
return(res)
}
groupDatabase<-function(db,n){
res<-db
for(i in 1:length(db)){
res[,i]<-groups(db[,i],n)
}
return(res)
}
####################################################
setwd("C:/Users/Jesús/Desktop/DataMining-SNPs/6_110118_pathways")
md<-read.csv('path_database_notZero.csv')
md$X<-NULL
n<-nrow(md)
path<-md[,352:358]
pav<-sapply(1:length(path), function(x) mean(path[,x]))
psd<-sapply(1:length(path), function(x) sd(path[,x]))
#sapply(1:length(path), function(x) sum(path[,x]<(pav[x]-psd[x])))
#sapply(1:length(path), function(x) sum(path[,x]>(pav[x]+psd[x])))
#sapply(1:length(path), function(x) sum(path[,x]<=(pav[x]+psd[x]) & path[,x]>=(pav[x]-psd[x])))
pathA<-path
pathB<-path
for(i in 1:length(path)){
idxA1<-which(path[,i]<(pav[i]-psd[i]))
idxA2<-which(path[,i]<=(pav[i]+psd[i]) & path[,i]>=(pav[i]-psd[i]))
idxA3<-which(path[,i]>(pav[i]+psd[i]))
idxB0<-which(path[,i]<pav[i])
idxB1<-which(path[,i]>=pav[i])
pathA[idxA1,i]<-1
pathA[idxA2,i]<-2
pathA[idxA3,i]<-3
pathB[idxB0,i]<-0
pathB[idxB1,i]<-1
}
clinic<-md[,1:4]
SNP<-md[,5:351]
write.csv(cbind(clinic,pathA,SNP),'pathA.csv')
write.csv(cbind(clinic,pathB,SNP),'pathB.csv')
#############################################################################
##
path3g<-groupDatabase(path,3)
write.csv(cbind(clinic,path3g,SNP),'path3g.csv')
path4g<-groupDatabase(path,4)
write.csv(cbind(clinic,path4g,SNP),'path4g.csv')
path5g<-groupDatabase(path,5)
write.csv(cbind(clinic,path5g,SNP),'path5g.csv')