Changeset 576


Ignore:
Timestamp:
08/09/16 18:30:33 (8 years ago)
Author:
konrad
Message:

Simple scale

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mds-and-trees/tree-genealogy.py

    r572 r576  
    2323svg_spine_dot_style = 'r="1" stroke="black" stroke-width="0.2" fill="rgb(50%,50%,100%)"'
    2424
     25svg_scale_line_style = 'stroke="black" stroke-width="0.5" stroke-opacity="1" stroke-dasharray="5, 5"'
     26svg_scale_text_style = 'style="font-family: Arial; font-size: 12; fill: #000000;"'
     27
    2528def svg_add_line(from_pos, to_pos, style=svg_line_style):
    2629    svg_file.write('<line ' + style + ' x1="' + str(from_pos[0]) + '" x2="' + str(to_pos[0]) + '" y1="' + str(from_pos[1]) + '" y2="' + str(to_pos[1]) + '" />')
     30
     31def svg_add_text(text, pos, anchor, style=svg_scale_text_style):
     32    svg_file.write('<text ' + style + ' text-anchor="' + anchor + '" x="' + str(pos[0]) + '" y="' + str(pos[1]) + '" >' + text + '</text>')
    2733
    2834def svg_add_dot(pos, style=svg_dot_style):
     
    320326    #             svg_spine_dot_style)
    321327
     328# ------------------------------------
     329
     330def draw_scale(filename ,type):
     331
     332    svg_add_text( "Generated from " + filename.split("\\")[-1], (5, 15), "start")
     333
     334    svg_add_line( (w*0.7, h_margin), (w, h_margin), svg_scale_line_style)
     335    start_text = ""
     336    if TIME == "BIRTHS":
     337       start_text = "Birth #" + str(min([int(k[1:]) for k, v in nodes.items()]))
     338    if TIME == "REAL":
     339       start_text = "Time " + str(min([v for k, v in time.items()]))
     340    if TIME == "GENERATIONAL":
     341       start_text = "Depth " + str(min([v for k, v in depth.items()]))
     342    svg_add_text( start_text, (w, h_margin + 15), "end")
     343
     344    svg_add_line( (w*0.7, h-h_margin), (w, h-h_margin), svg_scale_line_style)
     345    end_text = ""
     346    if TIME == "BIRTHS":
     347       end_text = "Birth #" + str(max([int(k[1:]) for k, v in nodes.items()]))
     348    if TIME == "REAL":
     349       end_text = "Time " + str(max([v for k, v in time.items()]))
     350    if TIME == "GENERATIONAL":
     351       end_text = "Depth " + str(max([v for k, v in depth.items()]))
     352    svg_add_text( end_text, (w, h-h_margin - 5), "end")
    322353
    323354
     
    328359h = 800
    329360w = 600
    330 h_margin = 10
     361h_margin = 20
    331362w_margin = 10
    332363h_no_margs = h - 2* h_margin
     
    351382
    352383    parser = argparse.ArgumentParser(description='Process some integers.')
    353     parser.add_argument('--in', dest='input', required=True, help='input file with stuctured evolutionary data')
    354     parser.add_argument('--out', dest='output', required=True, help='output file for the evolutionary tree')
     384    parser.add_argument('-i', '--in', dest='input', required=True, help='input file with stuctured evolutionary data')
     385    parser.add_argument('-o', '--out', dest='output', required=True, help='output file for the evolutionary tree')
    355386    draw_tree_parser = parser.add_mutually_exclusive_group(required=False)
    356387    draw_tree_parser.add_argument('--draw-tree', dest='draw_tree', action='store_true', help='whether drawing the full tree should be skipped')
     
    366397
    367398    #TODO: better names for those parameters
    368     parser.add_argument('--time', default='BIRTHS', dest='time', help='values on vertical axis (BIRTHS/GENERATIONAL/REAL); '
     399    parser.add_argument('-t', '--time', default='BIRTHS', dest='time', help='values on vertical axis (BIRTHS/GENERATIONAL/REAL); '
    369400                                                                      'BIRTHS: time measured as the number of births since the beggining; '
    370401                                                                      'GENERATIONAL: time measured as number of ancestors; '
    371402                                                                      'REAL: real time of the simulation')
    372     parser.add_argument('--balance', default='MIN', dest='balance', help='method of placing node in the tree (RANDOM/MIN/DENSITY)')
    373 
    374     parser.add_argument('--dots', default='NORMAL', dest='dots', help='method of drawing dots (individuals) (NONE/NORMAL/CLEAR)')
     403    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)')
    375408
    376409    parser.add_argument('-j', '--jitter', dest="jitter", action='store_true', help='draw horizontal positions of children from the normal distribution')
     
    427460        draw_spine()
    428461
     462    draw_scale(dir, args.scale)
     463
    429464    svg_file.write("</svg>")
    430465    svg_file.close()
Note: See TracChangeset for help on using the changeset viewer.