-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspatial_coldness.R
More file actions
62 lines (42 loc) · 2.27 KB
/
Copy pathspatial_coldness.R
File metadata and controls
62 lines (42 loc) · 2.27 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
spatialdata.coldness.WSI <- function(input.folder = input.folder, output.folder = output.folder){
files <- Sys.glob(paste0(input.folder, "/PO*.csv"))
source("https://raw.githubusercontent.com/simonpcastillo/extra_codes/main/diversity_clusters.R")
spatial.coldness.WSI <- data.frame()
for(j in 1:length(files)){#1:length(files)
print(j)
sample.id <- substr(files[j],(nchar(files[j])-12), (nchar(files[j])-4))
stage <- substr(sample.id, 9,9)
data <- read.csv(files[j])
div0 <- diversity_clusters(df = data , types = c("n.C", "n.L"))
data0 <- cbind(data, div0)
data1 <- data0[data0$cluster != 0, ]
data1$LC <- data1$n.L/data1$n.C
data1$coldness <- NA
medL <- median(data1[data1$n.L>0,]$n.L)
for(l in 1:nrow(data1)){
if(data1$n.L[l]< medL){data1$coldness[l] <- "cold"}
if(data1$n.L[l]>= medL){data1$coldness[l] <- "hot"}
if(data1$n.L[l] == 0){data1$coldness[l] <- "depleted"}
}
for(l in 1:nrow(data1)){
if(data1$LC[l] < 1 & data1$LC[l] >0){data1$coldness2[l] <- "cold"}
if(data1$LC[l]>= 1){data1$coldness2[l] <- "hot"}
if(data1$LC[l] == 0){data1$coldness2[l] <- "depleted"}
}
#cor <- cor.test(data1$n.C, data1$n.L)
g.cluster <- data.frame(nclusters = nrow(data1),
hotcluster = nrow(data1[data1$coldness == "hot",]),
coldcluster = nrow(data1[data1$coldness == "cold",]),
depletedcluster = nrow(data1[data1$coldness == "depleted",]),
hotcluster2 = nrow(data1[data1$coldness2 == "hot",]),
coldcluster2 = nrow(data1[data1$coldness2 == "cold",]),
depletedcluster2 = nrow(data1[data1$coldness2 == "depleted",])
)
ecospace <- data.frame(j=j, sample.id, stage, g.cluster)
spatial.coldness.WSI <- rbind(spatial.coldness.WSI, ecospace)
}
return(spatial.coldness.WSI)
}#Fin
#input.folder = "E:/COMPATH_SPANET_FINAL/SpatialOncosystems/results_20201208"
#output.folder = "E:/COMPATH_SPANET_FINAL/SpatialOncosystems"
#spatialdata.coldness.WSI<- spatialdata.coldness.WSI(input.folder = input.folder, output.folder = output.folder)