-
Notifications
You must be signed in to change notification settings - Fork 3
/
9.3_Percentile_filtering.R
25 lines (24 loc) · 1.19 KB
/
9.3_Percentile_filtering.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
################################################################################
# Filtering of square matrices by same quantile value (0.999)
# Author: Miguel Angel Garcia-Campos - https://github.com/AngelCampos
################################################################################
# Filtering network FOR loop
for (i in 0:4){
# Loading square matrix file
net <- as.matrix(read.delim(paste("SQnetwork_", i , "_Apo-Aut.txt", sep= ""),
header = T, sep = "\t", row.names = 1))
edges <- sum(net > 0) # Number of edges in original network
pct <- 0.90 # Cutting percentile
mmi <- quantile(net, pct) # Minimum Mutual Information to keep value
# Filtering MI values lower than "mmi"
netPRIME <- net
netPRIME[netPRIME <= mmi] <- 0
edgesPRIME <- sum(netPRIME > 0)
# Print process results
print(paste("Number of edges in original network =", edges))
print(paste ("Number of edges in filtered matrix =", edgesPRIME))
print(paste ("Percentage of conserved edges =", edgesPRIME*100/edges))
# Write filtered network to TXT file
write.table(netPRIME, file = paste("SQnetwork_", i, "_", pct, ".txt", sep = ""),
sep = "\t", col.names= NA, row.names= T, quote = F )
}