Changeset 577
- Timestamp:
- 08/09/16 19:38:35 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mds-and-trees/tree-genealogy.py
r576 r577 16 16 svg_file = 0 17 17 18 svg_line_style = 'stroke="rgb(90%,10%,16%)" stroke-width="1" stroke-opacity="0.8"' 18 svg_line_style = 'stroke="rgb(90%,10%,16%)" stroke-width="1" stroke-opacity="0.7"' 19 svg_mutation_line_style = 'stroke="black" stroke-width="1" stroke-opacity="0.7"' 20 svg_crossover_line_style = 'stroke="darkviolet" stroke-width="1" stroke-opacity="0.7"' 21 svg_spine_line_style = 'stroke="rgb(0%,90%,40%)" stroke-width="2" stroke-opacity="1"' 22 svg_scale_line_style = 'stroke="black" stroke-width="0.5" stroke-opacity="1" stroke-dasharray="5, 5"' 23 19 24 svg_dot_style = 'r="2" stroke="black" stroke-width="0.2" fill="red"' 20 25 svg_clear_dot_style = 'r="2" stroke="black" stroke-width="0.4" fill="none"' 21 22 svg_spine_line_style = 'stroke="rgb(0%,0%,80%)" stroke-width="2" stroke-opacity="1"'23 26 svg_spine_dot_style = 'r="1" stroke="black" stroke-width="0.2" fill="rgb(50%,50%,100%)"' 24 27 25 svg_scale_line_style = 'stroke="black" stroke-width="0.5" stroke-opacity="1" stroke-dasharray="5, 5"'26 28 svg_scale_text_style = 'style="font-family: Arial; font-size: 12; fill: #000000;"' 27 29 … … 60 62 + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" stroke-width="' + str(stroke) + '" stroke-opacity="' + str(opa) + '"' 61 63 62 def svg_generate_dot_style(percent): 63 from_col = [100, 70, 0] 64 to_col = [60, 0, 0] 65 # neon 66 # from_col = [30, 200, 255] 67 # to_col = [240, 0, 220] 68 69 from_opa = 0.2 70 to_opa = 1.0 71 72 opa = from_opa*(1-percent) + to_opa*percent 73 74 percent = 1 - ((1-percent)**20) 75 76 return 'fill="rgb(' + str(from_col[0]*(1-percent) + to_col[0]*percent) + '%,' \ 77 + str(from_col[1]*(1-percent) + to_col[1]*percent) + '%,' \ 78 + str(from_col[2]*(1-percent) + to_col[2]*percent) + '%)" r="1.5" stroke="black" stroke-width="0.2" fill-opacity="' + str(opa) + '" ' \ 79 'stroke-opacity="' + str(opa) + '"' 64 def svg_generate_dot_style(kind): 65 kinds = ["red", "lawngreen", "royalblue", "magenta", "yellow", "cyan", "white", "black"] 66 67 r = min(2500/len(nodes), 10) 68 69 return 'fill="' + kinds[kind] + '" r="' + str(r) + '" stroke="black" stroke-width="' + str(r/10) + '" fill-opacity="1.0" ' \ 70 'stroke-opacity="1.0"' 80 71 81 72 # ------------------- … … 106 97 if "Time" in creature: 107 98 time[creature["ID"]] = creature["Time"] 99 100 if "Kind" in creature: 101 kind[creature["ID"]] = creature["Kind"] 108 102 109 103 for k, v in sorted(nodes.items()): … … 182 176 visited[c] = True 183 177 184 # if JITTER == True:185 # dissimilarity = random.gauss(0,1)186 # else:187 # dissimilarity = 1188 # #TODO take this info from proper fields189 190 178 cy = 0 191 179 if TIME == "BIRTHS": … … 262 250 draw_children_recurrent(c, max_depth) 263 251 264 line_style = (svg_line_style if args.mono_tree else svg_generate_line_style(depth[c]/max_depth)) 252 line_style = "" 253 if COLORING == "NONE": 254 line_style = svg_line_style 255 elif COLORING == "TYPE": 256 line_style = (svg_mutation_line_style if len(nodes[c]) == 1 else svg_crossover_line_style) 257 else: # IMPORTANCE, default 258 line_style = svg_generate_line_style(depth[c]/max_depth) 259 265 260 for k, v in sorted(nodes[c].items()): 266 261 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), … … 269 264 if DOT_STYLE == "NONE": 270 265 continue 271 elif DOT_STYLE == " CLEAR":272 dot_style = svg_ clear_dot_style266 elif DOT_STYLE == "KIND": 267 dot_style = svg_generate_dot_style(kind[c] if c in kind else 0) #type 273 268 else: # NORMAL, default 274 dot_style = svg_ generate_dot_style(depth[c]/max_depth)269 dot_style = svg_clear_dot_style #svg_generate_dot_style(depth[c]/max_depth) 275 270 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) 276 271 def draw_children(): … … 286 281 if DOT_STYLE == "NONE": 287 282 return 288 elif DOT_STYLE == " CLEAR":289 dot_style = svg_ clear_dot_style283 elif DOT_STYLE == "KIND": 284 dot_style = svg_generate_dot_style(kind[firstnode] if firstnode in kind else 0) 290 285 else: # NORMAL, default 291 dot_style = svg_ generate_dot_style(depth[firstnode]/max_depth)286 dot_style = svg_clear_dot_style #svg_generate_dot_style(depth[c]/max_depth) 292 287 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) 293 288 … … 350 345 if TIME == "GENERATIONAL": 351 346 end_text = "Depth " + str(max([v for k, v in depth.items()])) 352 svg_add_text( end_text, (w, h-h_margin -5), "end")347 svg_add_text( end_text, (w, h-h_margin + 15), "end") 353 348 354 349 … … 377 372 depth = {} 378 373 time = {} 374 kind = {} 379 375 380 376 def main(): 381 global svg_file, min_skeleton_depth, args, TIME, BALANCE, DOT_STYLE, JITTER377 global svg_file, min_skeleton_depth, args, TIME, BALANCE, DOT_STYLE, COLORING, JITTER 382 378 383 379 parser = argparse.ArgumentParser(description='Process some integers.') … … 402 398 'REAL: real time of the simulation') 403 399 parser.add_argument('-b', '--balance', default='MIN', dest='balance', help='method of placing node in the tree (RANDOM/MIN/DENSITY)') 404 405 parser.add_argument('-s', '--scale', default='NONE', dest='scale', help='type of timescale added to the tree (NONE/SIMPLE/FULL)') 406 407 parser.add_argument('-d', '--dots', default='NORMAL', dest='dots', help='method of drawing dots (individuals) (NONE/NORMAL/CLEAR)') 408 400 parser.add_argument('-s', '--scale', default='NONE', dest='scale', help='type of timescale added to the tree (NONE/SIMPLE)') 401 parser.add_argument('-c', '--coloring', default='IMPORTANCE', dest="coloring", help='method of coloring the tree (NONE/IMPORTANCE/TYPE)') 402 parser.add_argument('-d', '--dots', default='NORMAL', dest='dots', help='method of drawing dots (individuals) (NONE/NORMAL/TYPE)') 409 403 parser.add_argument('-j', '--jitter', dest="jitter", action='store_true', help='draw horizontal positions of children from the normal distribution') 410 411 mono_tree_parser = parser.add_mutually_exclusive_group(required=False)412 mono_tree_parser.add_argument('--mono-tree', dest='mono_tree', action='store_true', help='whether the tree should be drawn with a single color')413 mono_tree_parser.add_argument('--no-mono-tree', dest='mono_tree', action='store_false')414 404 415 405 parser.add_argument('--min-skeleton-depth', type=int, default=2, dest='min_skeleton_depth', help='minimal distance from the leafs for the nodes in the skeleton') … … 418 408 parser.add_argument('--simple-data', type=bool, dest='simple_data', help='input data are given in a simple format (#child #parent)') 419 409 420 parser.set_defaults(mono_tree=False)421 410 parser.set_defaults(draw_tree=True) 422 411 parser.set_defaults(draw_skeleton=False) … … 430 419 BALANCE = args.balance 431 420 DOT_STYLE = args.dots 421 COLORING = args.coloring 432 422 JITTER = args.jitter 433 423
Note: See TracChangeset
for help on using the changeset viewer.