Changeset 571
- Timestamp:
- 08/08/16 16:10:18 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mds-and-trees/tree-genealogy.py
r566 r571 6 6 import argparse 7 7 8 TIME = "GENERATIONAL" 9 BALANCE = "MIN" 8 TIME = "" # BIRTHS / GENERATIONAL / REAL 9 BALANCE = "" # MIN / DENSITY 10 11 DOT_STYLE = "" # NONE / NORMAL / CLEAR 12 13 JITTER = "" # 10 14 11 15 # ------SVG--------- … … 14 18 svg_line_style = 'stroke="rgb(90%,10%,16%)" stroke-width="1" stroke-opacity="0.8"' 15 19 svg_dot_style = 'r="2" stroke="black" stroke-width="0.2" fill="red"' 20 svg_clear_dot_style = 'r="2" stroke="black" stroke-width="0.4" fill="none"' 21 16 22 svg_spine_line_style = 'stroke="rgb(0%,0%,80%)" stroke-width="2" stroke-opacity="1"' 17 #svg_spine_dot_style = 'r="3" stroke="black" stroke-width="0.4" fill="rgb(50%,50%,100%)"'18 23 svg_spine_dot_style = 'r="1" stroke="black" stroke-width="0.2" fill="rgb(50%,50%,100%)"' 19 24 … … 26 31 def svg_generate_line_style(percent): 27 32 # hotdog 33 from_col = [100, 70, 0] 34 to_col = [60, 0, 0] 35 # lava 36 # from_col = [100, 80, 0] 37 # to_col = [100, 0, 0] 38 # neon 39 # from_col = [30, 200, 255] 40 # to_col = [240, 0, 220] 41 42 from_opa = 0.2 43 to_opa = 1.0 44 from_stroke = 1 45 to_stroke = 3 46 47 opa = from_opa*(1-percent) + to_opa*percent 48 stroke = from_stroke*(1-percent) + to_stroke*percent 49 50 percent = 1 - ((1-percent)**20) 51 52 return 'stroke="rgb(' + str(from_col[0]*(1-percent) + to_col[0]*percent) + '%,' \ 53 + str(from_col[1]*(1-percent) + to_col[1]*percent) + '%,' \ 54 + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" stroke-width="' + str(stroke) + '" stroke-opacity="' + str(opa) + '"' 55 56 def svg_generate_dot_style(percent): 28 57 from_col = [100, 70, 0] 29 58 to_col = [60, 0, 0] … … 34 63 from_opa = 0.2 35 64 to_opa = 1.0 36 from_stroke = 137 to_stroke = 338 39 opa = from_opa*(1-percent) + to_opa*percent40 stroke = from_stroke*(1-percent) + to_stroke*percent41 42 percent = 1 - ((1-percent)**20)43 44 return 'stroke="rgb(' + str(from_col[0]*(1-percent) + to_col[0]*percent) + '%,' \45 + str(from_col[1]*(1-percent) + to_col[1]*percent) + '%,' \46 + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" stroke-width="' + str(stroke) + '" stroke-opacity="' + str(opa) + '"'47 48 def svg_generate_dot_style(percent):49 from_col = [100, 90, 0]50 to_col = [60, 0, 0]51 # neon52 # from_col = [30, 200, 255]53 # to_col = [240, 0, 220]54 55 from_opa = 0.256 to_opa = 1.057 65 58 66 opa = from_opa*(1-percent) + to_opa*percent … … 68 76 69 77 def load_data(dir): 70 global firstnode, nodes, inv_nodes 78 global firstnode, nodes, inv_nodes, time 71 79 f = open(dir) 72 80 for line in f: 73 sline = line.split(' ', 2)74 if len(sline) == 3:75 if sline[ 1] == "[OFFSPRING]":76 creature = json.loads(sline[ 2])81 sline = line.split(' ', 1) 82 if len(sline) == 2: 83 if sline[0] == "[OFFSPRING]": 84 creature = json.loads(sline[1]) 77 85 #print("B" +str(creature)) 78 86 if "FromIDs" in creature: 79 assert(len(creature["FromIDs"]) == 1)87 #assert(len(creature["FromIDs"]) == 1) 80 88 nodes[creature["ID"]] = creature["FromIDs"][0] 81 89 if not creature["FromIDs"][0] in nodes: … … 151 159 for c in inv_nodes[node]: 152 160 #print(node + "->" + c) 153 dissimilarity = 0.5 #random.gauss(0,0.3) 161 if JITTER == True: 162 dissimilarity = random.gauss(0,1) 163 else: 164 dissimilarity = 1 165 #TODO take this info from proper fields 166 154 167 if TIME == "BIRTHS": 155 168 id = "" … … 193 206 194 207 line_style = (svg_line_style if args.mono_tree else svg_generate_line_style(depth[c]/max_depth)) 195 dot_style = (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[c]/max_depth))196 197 208 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), 198 209 (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) 210 211 if DOT_STYLE == "NONE": 212 continue 213 elif DOT_STYLE == "CLEAR": 214 dot_style = svg_clear_dot_style 215 else: # NORMAL, default 216 dot_style = svg_generate_dot_style(depth[c]/max_depth) 199 217 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) 200 218 def draw_children(): … … 203 221 max_depth = max(max_depth, v) 204 222 draw_children_recurrent(firstnode, max_depth) 205 dot_style = (svg_dot_style if args.mono_tree else svg_generate_dot_style(depth[firstnode]/max_depth)) 223 224 if DOT_STYLE == "NONE": 225 return 226 elif DOT_STYLE == "CLEAR": 227 dot_style = svg_clear_dot_style 228 else: # NORMAL, default 229 dot_style = svg_generate_dot_style(depth[firstnode]/max_depth) 206 230 svg_add_dot( (w_margin+w_no_margs*(positions[firstnode][0]-min_width)/(max_width-min_width), h_margin+h_no_margs*positions[firstnode][1]/max_height), dot_style) 207 231 … … 269 293 270 294 def main(): 271 global svg_file, min_skeleton_depth, args, TIME, BALANCE 295 global svg_file, min_skeleton_depth, args, TIME, BALANCE, DOT_STYLE, JITTER 272 296 273 297 parser = argparse.ArgumentParser(description='Process some integers.') … … 287 311 288 312 #TODO: better names for those parameters 289 parser.add_argument('--time', default='BIRTHS', dest='time', help='values on vertical axis (REAL/GENERATIONAL)') 290 parser.add_argument('--balance', default='MIN',dest='balance', help='method of placing node in the tree (RANDOM/MIN/DENSITY)') 313 parser.add_argument('--time', default='BIRTHS', dest='time', help='values on vertical axis (BIRTHS/GENERATIONAL/REAL); ' 314 'BIRTHS: time measured as the number of births since the beggining; ' 315 'GENERATIONAL: time measured as number of ancestors; ' 316 'REAL: real time of the simulation') 317 parser.add_argument('--balance', default='MIN', dest='balance', help='method of placing node in the tree (RANDOM/MIN/DENSITY)') 318 319 parser.add_argument('--dots', default='NORMAL', dest='dots', help='method of drawing dots (individuals) (NONE/NORMAL/CLEAR)') 320 321 parser.add_argument('-j', '--jitter', dest="jitter", action='store_true', help='draw horizontal positions of children from the normal distribution') 291 322 292 323 mono_tree_parser = parser.add_mutually_exclusive_group(required=False) … … 310 341 TIME = args.time 311 342 BALANCE = args.balance 343 DOT_STYLE = args.dots 344 JITTER = args.jitter 312 345 313 346 dir = args.input
Note: See TracChangeset
for help on using the changeset viewer.