Permalink
Browse files

progress on network drawing

  • Loading branch information...
1 parent 5a73e21 commit 5efcb2ef7af046f7d45ee5b4edf6a5a0eda796e2 @bwallace committed Mar 8, 2010
View
Binary file not shown.
View
@@ -109,6 +109,14 @@ def add_group(self, group_name):
ma_unit.add_group(group_name)
print "added group: %s. cur groups: %s" % (group_name, self.get_group_names())
+ def remove_group(self, group_name):
+ for study in self.studies:
+ for outcome_name in study.outcomes_to_follow_ups.keys():
+ cur_outcome = study.outcomes_to_follow_ups[outcome_name]
+ for ma_unit in cur_outcome.values():
+ ma_unit.remove_group(group_name)
+ print "removed group: %s. cur groups: %s" % (group_name, self.get_group_names())
+
def add_follow_up_to_outcome(self, outcome, follow_up_name):
cur_group_names = self.get_group_names()
if len(cur_group_names) == 0:
@@ -132,17 +140,19 @@ def get_group_names(self):
return list(set(group_names))
def get_network(self, outcome, time_point):
- adjacency_list = []
+ node_list = [] # list of all nodes
+ adjacency_list = [] # list of edges
for study in self.studies:
ma_unit = study.outcomes_to_follow_ups[outcome][time_point]
group_names = ma_unit.get_group_names()
for g1 in group_names:
+ node_list.append(g1)
for g2 in [group for group in group_names if group != g1]:
if self.ma_unit_has_edge_between_groups(ma_unit, [g1, g2]) and\
not (g1, g2) in adjacency_list and not (g2, g1) in adjacency_list:
adjacency_list.append((g1,g2))
- return adjacency_list
+ return (list(set(node_list)), adjacency_list)
def ma_unit_has_edge_between_groups(self, ma_unit, groups):
# TODO this will need to be updated; right now
@@ -305,6 +315,9 @@ def add_group(self, name, raw_data=None):
raw_data = ["" for x in range(self.raw_data_length)]
self.tx_groups[name] = TreatmentGroup(id, name, raw_data)
+ def remove_group(self, name):
+ self.tx_groups.pop(name)
+
def get_raw_data_for_group(self, group_name):
return self.tx_groups[group_name].raw_data
View
Binary file not shown.
View
@@ -145,7 +145,7 @@ def add_new(self):
# then the user clicked ok and has added a new outcome.
# here we want to add the outcome to the dataset, and then
# display it
- new_outcome_name = form.outcome_name_le.text()
+ new_outcome_name = unicode(form.outcome_name_le.text().toUtf8(), "utf-8")
type = str(form.datatype_cbo_box.currentText())
self.model.add_new_outcome(new_outcome_name, type)
self.display_outcome(new_outcome_name)
@@ -164,6 +164,7 @@ def add_new(self):
follow_up_lbl = form.follow_up_name_le.text()
self.model.add_follow_up_to_current_outcome(follow_up_lbl)
print "ok. added new follow-up: %s" % follow_up_lbl
+
def next(self):
# probably you should disable next for the current dimension
@@ -186,7 +187,7 @@ def next(self):
redo_f = lambda: self.display_follow_up(next_follow_up_t_point)
undo_f = lambda: self.display_follow_up(old_follow_up_t_point)
- next_command = CommandNext(redo_f, undo_f)
+ next_command = CommandGenericDo(redo_f, undo_f)
self.tableView.undoStack.push(next_command)
@@ -207,7 +208,7 @@ def previous(self):
next_t_point, next_follow_up_name = self.model.get_previous_follow_up()
redo_f = lambda x: self.set_current_time_point(next_t_point)
undo_f = lambda x: self.set_current_time_point(old_t_point)
- prev_command = CommandNext(redo_f, undo_f)
+ prev_command = CommandGenericDo(redo_f, undo_f)
self.tableView.undoStack.push(prev_command)
def next_dimension(self):
@@ -239,6 +240,7 @@ def display_groups(self, groups):
print "displaying groups: %s" % groups
self.model.set_groups(groups)
self.model.try_to_update_outcomes()
+ self.model.reset()
self.tableView.resizeColumnsToContents()
def display_outcome(self, outcome_name):
@@ -310,6 +312,21 @@ def save(self):
raise Exception, "whoops. exception thrown attempting to save."
+class CommandGenericDo(QUndoCommand):
+ '''
+ This is a generic undo/redo command that takes
+ '''
+ def __init__(self, redo_f, undo_f, description=""):
+ super(CommandGenericDo, self).__init__(description)
+ self.redo_f = redo_f
+ self.undo_f = undo_f
+
+ def redo(self):
+ self.redo_f()
+
+ def undo(self):
+ self.undo_f()
+
class CommandNext(QUndoCommand):
'''
This is an undo command for user navigation
View
@@ -99,7 +99,7 @@ def ma_dataset_to_binary_robj(table_model, var_name):
pass
-def draw_network(edge_list, network_path = '"./r_tmp/network.png"'):
+def draw_network(edge_list, unconnected_vertices, network_path = '"./r_tmp/network.png"'):
'''
This draws the parametric network specified by edge_list.
The latter is assumed to be in form:
@@ -109,9 +109,15 @@ def draw_network(edge_list, network_path = '"./r_tmp/network.png"'):
implementing a method on the R side that takes a graph/
edge list. We may want to change this eventually.
'''
- edge_str = ", ".join(["'%s'" % x for x in edge_list])
+ edge_str = ", ".join([" '%s' " % x for x in edge_list])
+ print "el <- matrix(c(%s), nc=2, byrow=TRUE)" % edge_str
ro.r("el <- matrix(c(%s), nc=2, byrow=TRUE)" % edge_str)
ro.r("g <- graph.edgelist(el, directed=FALSE)")
+ if len(unconnected_vertices) > 0:
+ print unconnected_vertices
+ vertices_str = ", ".join([" '%s' " % x for x in unconnected_vertices])
+ print "g <- add.vertices(g, %s, name=c(%s))" % (len(unconnected_vertices), vertices_str)
+ ro.r("g <- add.vertices(g, %s, name=c(%s))" % (len(unconnected_vertices), vertices_str))
ro.r("png(%s)" % network_path)
ro.r("plot(g, vertex.label=V(g)$name, layout=layout.circle, vertex.size=25, asp=.3, margin=-.05)")
ro.r("dev.off()")
View
Binary file not shown.
View
@@ -23,16 +23,25 @@ def __init__(self, dataset, parent=None):
#pdb.set_trace()
def graph_network(self):
- edges = self.dataset.get_network("death", "baseline")
+ nodes, edges = self.dataset.get_network("death", "baseline")
# get_network returns a list of tuples, wherein
# each tuple is an edge with group names representing
# nodes, e.g., [("tx a", "tx b"), ("tx b", "tx c")]. however the igraph
# library wants a flat list, e.g., ["tx_a", "tx_b", "tx_b", "tx_c"]
# thus we flatten out the list here
+ print "\n nodes:"
+ print nodes
flattened_edges = []
for edge in edges:
flattened_edges.extend(edge)
- img_path = meta_py_r.draw_network(flattened_edges)
+
+ # now add nodes that have no connections
+ unconnected_vertices = []
+ for node in nodes:
+ if node not in flattened_edges:
+ unconnected_vertices.append(node)
+
+ img_path = meta_py_r.draw_network(flattened_edges, unconnected_vertices)
print img_path
# now add the image to the display
pixmap = QPixmap(img_path)
View
Binary file not shown.
View
@@ -0,0 +1,135 @@
+<ui version="4.0" >
+ <class>new_follow_up_dialog</class>
+ <widget class="QDialog" name="new_follow_up_dialog" >
+ <property name="enabled" >
+ <bool>true</bool>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>301</width>
+ <height>132</height>
+ </rect>
+ </property>
+ <property name="minimumSize" >
+ <size>
+ <width>301</width>
+ <height>132</height>
+ </size>
+ </property>
+ <property name="maximumSize" >
+ <size>
+ <width>301</width>
+ <height>132</height>
+ </size>
+ </property>
+ <property name="font" >
+ <font>
+ <family>Verdana</family>
+ </font>
+ </property>
+ <property name="windowTitle" >
+ <string>add new follow-up</string>
+ </property>
+ <property name="windowIcon" >
+ <iconset resource="images/icons.qrc" >
+ <normaloff>:/images/meta.png</normaloff>:/images/meta.png</iconset>
+ </property>
+ <widget class="QDialogButtonBox" name="buttonBox" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>90</y>
+ <width>281</width>
+ <height>32</height>
+ </rect>
+ </property>
+ <property name="font" >
+ <font>
+ <family>Verdana</family>
+ </font>
+ </property>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons" >
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ <widget class="QWidget" name="layoutWidget" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>10</y>
+ <width>281</width>
+ <height>71</height>
+ </rect>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label_2" >
+ <property name="font" >
+ <font>
+ <family>Verdana</family>
+ <pointsize>10</pointsize>
+ </font>
+ </property>
+ <property name="text" >
+ <string>follow-up label</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="follow_up_name_le" >
+ <property name="font" >
+ <font>
+ <family>Verdana</family>
+ </font>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <resources>
+ <include location="images/icons.qrc" />
+ </resources>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>new_follow_up_dialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>new_follow_up_dialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
Oops, something went wrong.

0 comments on commit 5efcb2e

Please sign in to comment.