clustering_tfit_window.R 5.51 KB
Newer Older
Gosset Simon's avatar
Gosset Simon committed
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
clustering_tfit <- function(organism, network) {
  
  mainpath <- getwd()
  
  cat("\n\n>CLUSTERING : TFIT\n")
  
  # Lecture des donnees
  tab <- load_network(network)
  network <- as.matrix(tab)
  
  # Creation des dossiers de sauvegarde
  setwd(mainpath)
  organism <- gsub(" ", "-", organism)
  organism.path <- paste(mainpath, organism, sep = '/')
  dir.create(organism.path, showWarnings = FALSE)  
  analyze.path <- paste(organism.path, "Analysis", sep = '/')
  dir.create(analyze.path, showWarnings = FALSE)  
  saveTFit.path <- paste(analyze.path, '/TFit', sep = '')
  dir.create(saveTFit.path, showWarnings = FALSE)
  
  # Generation d'un fichier contenant les paires de proteines en interaction dans le reseau analyse
  write.table(t(as.matrix(c("Edge1","Edge2"))), file = paste(saveTFit.path, '/graph.gr', sep = ''), row.names = F, quote = F, col.names = F, sep = " ")
  write.table(network[,c(1,3)], file = paste(saveTFit.path, '/graph.gr', sep = ''), row.names = F, quote = F, col.names = F, sep = " ", append = TRUE)
  File.clas <- paste(saveTFit.path, '/class.clas', sep = '')
  File.gr <-  paste(saveTFit.path, '/graph.gr', sep = '')
  setwd(mainpath)
  
  # run TFitW
  cat('\n>Running TFit...')
  
  # Appel de la fonction tfit: TODO = save results somewhere
32
33
  result_tfit = tfit(File.gr) ##################################################

34
35
  clust = "init"
  
36
37
  clust_tab = NULL
  
38
39
  i = 0
  
40
  while(length(clust) > 0) {
41
42
43
    
    clust = NULL
    
44
45
    row = NULL
    
46
47
48
49
    
    i = i+1
    
    clust = grep(pattern = i, x = result_tfit[[1]])
50

51
    
52
    clust = unlist(result_tfit[[2]][clust])
53
    
54
    
55
56
57
    if(length(clust) > 0) {
    
      row = cbind(i, paste(clust, collapse = ";"))
58
    
59
60
61
      clust_tab = rbind(clust_tab, row)
      
    }
62
63
64
    
    
  }
65
66
67
  
  colnames(clust_tab) = c("cluster","proteins")
  
68
  write.table(x = clust_tab, file = File.clas, row.names = F, col.names = T, quote = F, sep = "\t")
69
70
  
  
71
  
72

73
  
Gosset Simon's avatar
Gosset Simon committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
  
  cat("OK\n\n>Clustering TFit is done.\n")
  cat(paste('\n>Results are stocked in : ', saveTFit.path))
  setwd(mainpath)
}

clustering_tfit_window <- function(f_pos, mainpanel, panb, mainpath) {

	network <- c()
	return.parameter <- c()

	panel_para <- gwindow("TFit :", parent = f_pos, visible = T)
	pp <- gvbox(container = panel_para)
	pp$set_borderwidth(10L)

	flyt <- gformlayout(container = pp, expand = TRUE)

	# Selection des parametres
92
	gcombobox(c('Caenorhabditis elegans', 'Drosophila melanogaster', 'Escherichia coli', 'Homo sapiens', 'Mus musculus', 'Rattus norvegicus', 'Saccharomyces cerevisiae','Arabidopsis thaliana', 'Other'), label = "Organism", selected = 7, container = flyt)
Gosset Simon's avatar
Gosset Simon committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201

	# Selection du fichier
	chdb <- ggroup(container = pp, horizontale = T)
	addSpring(chdb)
	bouton1 <- gbutton("Network", container = chdb, handler = function(...) {
		network <<- gfile(text = "Select a file", type = "open", multi = F, container = chdb)
		if (is.null(network) == T) {
			gmessage('Selected file is null', icon = 'error')
		}
		if (is.null(network) == F) {
			bouton1$set_value(paste(length(network), 'network file selected'))
			cat(paste('\n>File selected : ', network, sep = ''))
		}
	})

	ppb <- ggroup(container = pp)
	addSpring(ppb)
	gbutton("Clustering", handler = function(h,...) {

		return.parameter <<- svalue(flyt)
		visible(panel_para) <- F
		# Memorisation des parametres de recherche selectionnes
		organism <- as.character(return.parameter[1])


		# Execution de la fonction lorsque tous les parametres sont fournis
		if (is.null(network) == F) {
			######################################################################################
			########################### Execution de la fonction #################################
  
			mainpath <- getwd()

			cat("\n\n>CLUSTERING : TFIT\n")

			if (organism == "Other") {
			  panelorganism <- gwindow("Organism description", parent = f_pos, visible = F, expand = T)
			  
			  pc <- ggroup(container = panelorganism, horizontal = F, use.scrollwindow = T)
			  pcsb <- ggroup(container = pc, horizontal = F, use.scrollwindow = F)
			  lg <- gvbox(container = pcsb)
			  fllg <- gformlayout(container = lg)
			  
			  organismName <- gedit(initial.msg = 'Organism Name', label = "NAME", container = fllg)
			  
			  visible(panelorganism)  <- T
			  
			  bpc <- ggroup(container = pc); addSpring(bpc)
			  
			  # 1 : Autre organism
			  bouton1 <- gbutton("OK", handler = function(h,...) {
			    # Rassemblement des modifications a apporter
			    org.name <- cbind(names(svalue(fllg)), svalue(fllg))
			    org.name <- data.frame(org.name, row.names = NULL)
			    
			    org <- cbind(org.name)
			    colnames(org) <-  c('Organism_name')
			    
			    organism <- as.character(org[1,2])
			    setwd(mainpath)
			    visible(mainpanel) <<- T
			    clustering_tfit(organism, network)
					dispose(bpc)
				}, container = bpc)

			}

			# Parametres : organism,network
			else{
			  setwd(mainpath)
			  visible(mainpanel) <<- T
			  clustering_tfit(organism, network)
			}
			dispose(panel_para)
			dispose(ppb)

		}

		# Tests de la presence de tous les elements necessaires a l'execution de la fonction
		else if (is.null(network) == T) {
			gmessage('Network file selected is null', icon = 'error')

			dispose(ppb)
			visible(panel_para) <- F
			visible(mainpanel) <<- T

		}
		else {
			gmessage('Error : Unable to start clustering', icon = 'error')

			dispose(ppb)
			visible(panel_para) <- F
			visible(mainpanel) <<- T

		}

	}, container=ppb)

	# Retour
	gbutton("Return", handler = function(h,...) {
		dispose(panel_para)
		visible(panb) <<- T
	}, container = ppb)
	
	visible(panel_para) <- T

}