Index: /mds-and-trees/tree-genealogy.py
===================================================================
--- /mds-and-trees/tree-genealogy.py	(revision 571)
+++ /mds-and-trees/tree-genealogy.py	(revision 572)
@@ -85,14 +85,24 @@
                 #print("B" +str(creature))
                 if "FromIDs" in creature:
-                    #assert(len(creature["FromIDs"]) == 1)
-                    nodes[creature["ID"]] = creature["FromIDs"][0]
+                    if not creature["ID"] in nodes:
+                        nodes[creature["ID"]] = {}
+                        # we assign to each parent its contribution to the genotype of the child
+                        for i in range(0, len(creature["FromIDs"])):
+                            inherited = 1 #(creature["Inherited"][i] if 'Inherited' in creature else 1) #ONLY FOR NOW
+                            nodes[creature["ID"]][creature["FromIDs"][i]] = inherited
+                    else:
+                        print("Doubled entry for " + creature["ID"])
+                        quit()
+
                     if not creature["FromIDs"][0] in nodes:
                         firstnode = creature["FromIDs"][0]
+
                 if "Time" in creature:
                     time[creature["ID"]] = creature["Time"]
 
     for k, v in sorted(nodes.items()):
-        inv_nodes[v] = inv_nodes.get(v, [])
-        inv_nodes[v].append(k)
+        for val in sorted(v):
+            inv_nodes[val] = inv_nodes.get(val, [])
+            inv_nodes[val].append(k)
 
 
@@ -157,30 +167,52 @@
 
 def prepos_children_reccurent(node):
+    global visited
     for c in inv_nodes[node]:
-        #print(node + "->" + c)
-        if JITTER == True:
-            dissimilarity = random.gauss(0,1)
+
+        # we want to visit the node just once, after all of its parents
+        if not all_parents_visited(c):
+            continue
         else:
-            dissimilarity = 1
-            #TODO take this info from proper fields
-
+            visited[c] = True
+
+        # if JITTER == True:
+        #     dissimilarity = random.gauss(0,1)
+        # else:
+        #     dissimilarity = 1
+        #     #TODO take this info from proper fields
+
+        cy = 0
         if TIME == "BIRTHS":
-            id = ""
             if c[0] == "c":
-                id = int(c[1:])
+                cy = int(c[1:])
             else:
-                id = int(c)
-            positions[c] = [xmin_crowd(positions[node][0]-dissimilarity, positions[node][0]+dissimilarity, id), id]
+                cy = int(c)
         elif TIME == "GENERATIONAL":
-            positions[c] = [xmin_crowd(positions[node][0]-dissimilarity, positions[node][0]+dissimilarity, positions[node][1]+1), positions[node][1]+1]
+            cy = positions[node][1]+1
         elif TIME == "REAL":
-            positions[c] = [xmin_crowd(positions[node][0]-dissimilarity, positions[node][0]+dissimilarity, time[c]), time[c]]
-
-    for c in inv_nodes[node]:
+            cy = time[c]
+
+        if len(nodes[c]) == 1:
+            dissimilarity = 0
+            if JITTER == True:
+                dissimilarity = random.gauss(0,1)
+            else:
+                dissimilarity = 1
+            positions[c] = [xmin_crowd(positions[node][0]-dissimilarity, positions[node][0]+dissimilarity, cy), cy]
+        else:
+            vsum = sum([v for k, v in nodes[c].items()])
+            cx = sum([positions[k][0]*v/vsum for k, v in nodes[c].items()])
+
+            if JITTER == True:
+                positions[c] = [cx + random.gauss(0, 0.1), cy]
+            else:
+                positions[c] = [cx, cy]
+
+
         if c in inv_nodes:
             prepos_children_reccurent(c)
 
 def prepos_children():
-    global max_height, max_width, min_width
+    global max_height, max_width, min_width, visited
 
     if not bool(time):
@@ -190,4 +222,6 @@
     positions[firstnode] = [0, 0]
 
+    visited = {}
+    visited[firstnode] = True
     prepos_children_reccurent(firstnode)
 
@@ -199,13 +233,31 @@
 # ------------------------------------
 
+def all_parents_visited(node):
+    apv = True
+    for k, v in sorted(nodes[node].items()):
+        if not k in visited:
+            apv = False
+            break
+    return apv
+# ------------------------------------
+
 def draw_children_recurrent(node, max_depth):
-    global max_height, max_width, min_width
+    global visited
+
     for c in inv_nodes[node]:
+
+        # we want to draw the node just once
+        if not all_parents_visited(c):
+            continue
+        else:
+            visited[c] = True
+
         if c in inv_nodes:
             draw_children_recurrent(c, max_depth)
 
         line_style = (svg_line_style if args.mono_tree else svg_generate_line_style(depth[c]/max_depth))
-        svg_add_line( (w_margin+w_no_margs*(positions[node][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[node][1]/max_height),
-            (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), line_style)
+        for k, v in sorted(nodes[c].items()):
+            svg_add_line( (w_margin+w_no_margs*(positions[k][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[k][1]/max_height),
+                (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), line_style)
 
         if DOT_STYLE == "NONE":
@@ -217,4 +269,8 @@
         svg_add_dot( (w_margin+w_no_margs*(positions[c][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[c][1]/max_height), dot_style)
 def draw_children():
+    global visited
+    visited = {}
+    visited[firstnode] = True
+
     max_depth = 0
     for k, v in depth.items():
@@ -231,5 +287,4 @@
 
 def draw_spine_recurrent(node):
-    global max_height, max_width, min_width
     for c in inv_nodes[node]:
         if depth[c] == depth[node] - 1:
@@ -246,5 +301,4 @@
 
 def draw_skeleton_reccurent(node, max_depth):
-    global max_height, max_width, min_width
     for c in inv_nodes[node]:
         if depth[c] >= min_skeleton_depth or depth[c] == max([depth[q] for q in inv_nodes[node]]):
@@ -289,4 +343,5 @@
 inv_nodes = {}
 positions = {}
+visited= {}
 depth = {}
 time = {}
