Commit a9824c2f authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Fix & rework not working function on GUI: get stats from static analysis menu

parent 2ff2f269
......@@ -139,13 +139,14 @@ class ChartStatControler(object):
def on_stat(self, widget):
"""
TODO
Fill window with model informations.
"""
reporter = CompilReporter()
# get stats from StaticAnalyzer
stan = StaticAnalyzer(reporter)
stan.build_from_chart_model(self.edit_mvc.model)
ststat = stan.get_str_statistics()
display_w = STATWindow(ststat, self.edit_mvc, self.reporter, self)
ststat = stan.get_statistics()
display_w = STATWindow(ststat, self.edit_mvc, self.reporter, self)
def win_register(self, win):
"""
......@@ -777,8 +778,7 @@ class STATWindow(BAGWindow):
text = wtree.get_widget("textview")
text_buffer = text.get_buffer()
mess = stat_str
mess = mess + '\n'
mess = str(stat_str) + '\n'
text_buffer.set_text(mess)
text.set_editable(False)
......
......@@ -45,6 +45,7 @@ import string
import networkx as nx
import matplotlib.pyplot as plt
import copy
from collections import OrderedDict
from cadbiom.antlr3 import ANTLRFileStream, CommonTokenStream
......@@ -132,91 +133,73 @@ class StaticAnalyzer(object):
return lpname
def get_statistics(self, sfile):
def get_statistics(self, sfile=False):
"""
Compute various informations on the model (assume PID encoding)
:param arg1: Opened file (optional).
:type arg1: <open file>
:return: Informations (status of nodes and their cellular locations).
:rtype: <str>
"""
gene_cpt = 0
input_cpt = 0
front_cpt = 0
final_cpt = 0
isolated_cpt = 0
membrane_cpt = 0
extra_cell_cpt = 0
cyto_cpt = 0
nucl_cpt = 0
other_cpt = 0
location_dict = dict()
location_dict['_transMb'] = 0
location_dict['_nucl'] = 0
location_dict['_intToMb'] = 0
location_dict['_cy'] = 0
location_dict['_plasmaMb'] = 0
location_dict['_exCellRegion'] = 0
location_dict['_ccJct'] = 0
location_dict['_en'] = 0
location_dict['_siteofdouble_strandbreak'] = 0
location_dict['_membraneraft'] = 0
locations = (
'_gene', '_transMb', '_nucl', '_intToMb', '_cy', '_plasmaMb',
'_exCellRegion', '_ccJct', '_en', '_siteofdouble_strandbreak',
'_membraneraft', 'other',
)
# Init counter of locations
location_dict = OrderedDict({location: 0 for location in locations})
# Iterate on model nodes
for node_name, node in self.model.node_dict.iteritems():
for location in locations:
if location in node_name:
location_dict[location] += 1
else:
location_dict['other'] += 1
# Check node status
nb_outgoing_trans = len(node.outgoing_trans)
nb_incoming_trans = len(node.incoming_trans)
node_dict = self.model.node_dict
node_names = node_dict.keys()
sfile.write(self.model.name)
sfile.write("\n\n\nNB PLACES: "+str(len(node_names)))
sfile.write("\nNB TRANSITIONS: "+str(len(self.model.transition_list)))
for pname in node_names:
if string.find(pname, 'gene') > 0:
gene_cpt += 1
elif string.find(pname, '_transMb') > 0 :
membrane_cpt += 1
location_dict['_transMb'] += 1
elif string.find(pname, '_nucl') > 0:
nucl_cpt += 1
location_dict['_nucl'] += 1
elif string.find(pname, '_intToMb') > 0:
location_dict['_intToMb'] += 1
elif string.find(pname, '_cy') > 0:
cyto_cpt += 1
location_dict['_cy'] += 1
elif string.find(pname, '_plasmaMb') > 0:
location_dict['_plasmaMb'] += 1
elif string.find(pname, '_exCellRegion') > 0 :
extra_cell_cpt += 1
location_dict['_exCellRegion'] += 1
elif string.find(pname, '_ccJct') > 0:
location_dict['_ccJct'] += 1
elif string.find(pname, '_en') > 0:
location_dict['_en'] += 1
elif string.find(pname, '_siteofdouble_strandbreak') > 0:
location_dict['_siteofdouble_strandbreak'] += 1
elif string.find(pname, '_membraneraft') > 0:
location_dict['_membraneraft'] += 1
else :
other_cpt +=1
node = node_dict[pname]
if node.is_input():
input_cpt += 1
if len(node.outgoing_trans) == 0 :
if nb_outgoing_trans == 0:
final_cpt += 1
if len(node.incoming_trans) == 0 :
front_cpt +=1
if len(node.outgoing_trans) == 0 and len(node.incoming_trans) == 0 :
if nb_incoming_trans == 0:
front_cpt += 1
if nb_outgoing_trans == 0 and nb_incoming_trans == 0:
isolated_cpt += 1
sfile.write("\nNB INPUTS: "+str(input_cpt))
sfile.write("\nNB FRONTIER: "+str(front_cpt))
sfile.write("\nNB TERMINAL: "+str(final_cpt))
sfile.write("\nNB ISOLATED: "+str(isolated_cpt))
# sfile.write("\nNB MEMBRANE: "+str(membrane_cpt))
# sfile.write("\nNB EXTRA CELLULAR: "+str(extra_cell_cpt))
# sfile.write("\nNB CYTOPLASM: "+str(cyto_cpt))
# sfile.write("\nNB NUCLEUS: "+str(nucl_cpt))
# sfile.write("\nNB GENES: "+str(gene_cpt))
# sfile.write("\nNB OTHER: "+str(other_cpt))
for key in location_dict.keys() :
sfile.write("\nNB" +key+" : "+str(location_dict[key]))
# Forge data header
data = OrderedDict({
"Model name": self.model.name,
"Nb places": len(self.model.node_dict),
"Nb transitions": len(self.model.transition_list),
"Nb inputs": input_cpt,
"Nb frontier (incoming transitions)": front_cpt,
"Nb terminal (outgoing transitions)": final_cpt,
"Nb isolated (frontier places in conditions)": isolated_cpt,
})
# Forge data locations
for k, v in location_dict.iteritems():
data['Nb ' + k] = v
# Forge text
text = "\n".join([k + ': ' + str(v) for k, v in data.iteritems()])
# Dump text if an opened file is given
if sfile != False:
sfile.write(text)
return text
def get_frontier_scc(self):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment