Changeset 585 for mds-and-trees


Ignore:
Timestamp:
08/18/16 21:58:00 (8 years ago)
Author:
konrad
Message:

Added an option for defining colors of crossover / mutation lines from the command line

File:
1 edited

Legend:

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

    r577 r585  
    1717
    1818svg_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"'
     19svg_mutation_line_style = 'stroke-width="1"'
     20svg_crossover_line_style = 'stroke-width="1"'
    2121svg_spine_line_style = 'stroke="rgb(0%,90%,40%)" stroke-width="2" stroke-opacity="1"'
    2222svg_scale_line_style = 'stroke="black" stroke-width="0.5" stroke-opacity="1" stroke-dasharray="5, 5"'
     
    2727
    2828svg_scale_text_style = 'style="font-family: Arial; font-size: 12; fill: #000000;"'
     29
     30def hex_to_style(hex):
     31    if hex[0] == "#":
     32        hex = hex[1:]
     33
     34    if len(hex) == 6 or len(hex) == 8:
     35        try:
     36            int(hex, 16)
     37        except:
     38            print("Wrong characters in the color's hex #" + hex + "! Assuming black.")
     39            return ' stroke="black" stroke-opacity="0.5" '
     40        red = 100*int(hex[0:2], 16)/255
     41        green = 100*int(hex[2:4], 16)/255
     42        blue = 100*int(hex[4:6], 16)/255
     43        opacity = 0.5
     44        if len(hex) == 8:
     45            opacity = int(hex[6:8], 16)/255
     46        return ' stroke="rgb(' +str(red)+ '%,' +str(green)+ '%,' +str(blue)+ '%)" stroke-opacity="' +str(opacity)+ '" '
     47    else:
     48        print("Wrong number of digits in the color's hex #" + hex + "! Assuming black.")
     49        return ' stroke="black" stroke-opacity="0.5" '
    2950
    3051def svg_add_line(from_pos, to_pos, style=svg_line_style):
     
    4162    from_col = [100, 70, 0]
    4263    to_col = [60, 0, 0]
     64    from_col = [0, 0, 0]
     65    to_col = [80, 0, 80]
    4366    # lava
    4467    # from_col = [100, 80, 0]
     
    264287        if DOT_STYLE == "NONE":
    265288            continue
    266         elif DOT_STYLE == "KIND":
     289        elif DOT_STYLE == "TYPE":
    267290            dot_style = svg_generate_dot_style(kind[c] if c in kind else 0) #type
    268291        else: # NORMAL, default
     
    281304    if DOT_STYLE == "NONE":
    282305        return
    283     elif DOT_STYLE == "KIND":
     306    elif DOT_STYLE == "TYPE":
    284307        dot_style = svg_generate_dot_style(kind[firstnode] if firstnode in kind else 0)
    285308    else: # NORMAL, default
     
    375398
    376399def main():
    377     global svg_file, min_skeleton_depth, args, TIME, BALANCE, DOT_STYLE, COLORING, JITTER
     400    global svg_file, min_skeleton_depth, args, \
     401        TIME, BALANCE, DOT_STYLE, COLORING, JITTER, \
     402        svg_mutation_line_style, svg_crossover_line_style
    378403
    379404    parser = argparse.ArgumentParser(description='Process some integers.')
     
    393418
    394419    #TODO: better names for those parameters
    395     parser.add_argument('-t', '--time', default='BIRTHS', dest='time', help='values on vertical axis (BIRTHS/GENERATIONAL/REAL); '
     420    parser.add_argument('-t', '--time', default='GENERATIONAL', dest='time', help='values on vertical axis (BIRTHS/GENERATIONAL/REAL); '
    396421                                                                      'BIRTHS: time measured as the number of births since the beggining; '
    397422                                                                      'GENERATIONAL: time measured as number of ancestors; '
    398423                                                                      'REAL: real time of the simulation')
    399     parser.add_argument('-b', '--balance', default='MIN', dest='balance', help='method of placing node in the tree (RANDOM/MIN/DENSITY)')
     424    parser.add_argument('-b', '--balance', default='DENSITY', dest='balance', help='method of placing node in the tree (RANDOM/MIN/DENSITY)')
    400425    parser.add_argument('-s', '--scale', default='NONE', dest='scale', help='type of timescale added to the tree (NONE/SIMPLE)')
    401426    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)')
     427    parser.add_argument('-d', '--dots', default='TYPE', dest='dots', help='method of drawing dots (individuals) (NONE/NORMAL/TYPE)')
    403428    parser.add_argument('-j', '--jitter', dest="jitter", action='store_true', help='draw horizontal positions of children from the normal distribution')
     429
     430    parser.add_argument('--color-mut', default="#000000", dest="color_mut", help='color of clone/mutation lines in rgba (e.g. #FF60B240) for TYPE coloring')
     431    parser.add_argument('--color-cross', default="#660198", dest="color_cross", help='color of crossover lines in rgba (e.g. #FF60B240) for TYPE coloring')
    404432
    405433    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')
     
    421449    COLORING = args.coloring
    422450    JITTER = args.jitter
     451
     452    svg_mutation_line_style += hex_to_style(args.color_mut)
     453    svg_crossover_line_style += hex_to_style(args.color_cross)
    423454
    424455    dir = args.input
Note: See TracChangeset for help on using the changeset viewer.