Exemplo n.º 1
0
def parse_struct_plot_settings(config_parser):
    ''' Parses custom settings for a structure plot from a configuration file. Returns a dictionary containing
    all of the settings

    config is a ConfigParser object which already contains all of the settings
    data is a pandas.DataFrame object containing all of the alternative splicing data

    '''
    print 'Parsing settings for structure plot...'
    
    settings = default_struct_settings()

    FLOAT_PARAMS = set(['plot_width',
                        'plot_height',
                        'left_margin',
                        'right_margin',
                        'top_margin',
                        'bottom_margin',
                        'axis_thickness',
                        'tick_length',
                        'horiz_label_size',
                        'horiz_label_spacing',
                        'horiz_axis_title_size',
                        'horiz_axis_title_spacing',
                        'vertical_tick_spacing',
                        'vert_label_size',
                        'vert_label_spacing',
                        'key_title_size',
                        'key_font_size'])
    BOOLEAN_PARAMS = set(['draw_struct_plot',
                        'use_vertical_ticks',
                        'include_key',
                        'use_custom_key_labels'])
    OTHER_PARAMS = set(['horiz_axis_title',
                        'colors',
                        'axis_color',
                        'output_file_path',
                        'key_text_color',
                        'key_position'])


    for option in config_parser.options('struct_plot'):
        if option in FLOAT_PARAMS:
            settings[option] = config_parser.getfloat('struct_plot',option)
        elif option in BOOLEAN_PARAMS:
            settings[option] = config_parser.getboolean('struct_plot',option)
        elif option in OTHER_PARAMS:
            settings[option] = ast.literal_eval(config_parser.get('struct_plot',option))


    # check to make sure entries in settings have the correct format
    

    if type(settings['colors']) is not list:
        print 'colors must be a list of 3 element lists'
        sys.exit(1)
    else:
        colorified = [None] * len(settings['colors'])
        try:
            for i in range(len(colorified)):
                colorified[i] = RGB.from_hex_string(settings['colors'][i])
            settings['colors'] = colorified
        except Exception:
            print 'Invalid colors in colors'
            sys.exit(1)

    try:
        settings['axis_color'] = RGB.from_hex_string(settings['axis_color'])
    except Exception:
        print 'Invalid color in axis_color'
        sys.exit(1)

    if settings['include_key']:
        try:
            settings['key_text_color'] = RGB.from_hex_string(settings['key_text_color'])
        except Exception:
            print 'Invalid color in key_text_color'
            sys.exit(1)

        if len(settings['key_position']) != 2:
            print 'Invalid number of components in key_position'
            sys.exit(1)

        for i in range(2):
            try:
                settings['key_position'][i] = float(settings['key_position'][i])
            except Exception:
                print 'Elements in key_position must be numbers'
                sys.exit(1)

    return settings
def parse_struct_plot_settings(config_parser):
    ''' Parses custom settings for a structure plot from a configuration file. Returns a dictionary containing
    all of the settings

    config is a ConfigParser object which already contains all of the settings
    data is a pandas.DataFrame object containing all of the alternative splicing data

    '''
    print 'Parsing settings for structure plot...'
    
    settings = default_struct_settings()

    FLOAT_PARAMS = set(['plot_width',
                        'plot_height',
                        'left_margin',
                        'right_margin',
                        'top_margin',
                        'bottom_margin',
                        'axis_thickness',
                        'tick_length',
                        'horiz_label_size',
                        'horiz_label_spacing',
                        'horiz_axis_title_size',
                        'horiz_axis_title_spacing',
                        'vertical_tick_spacing',
                        'vert_label_size',
                        'vert_label_spacing',
                        'key_title_size',
                        'key_font_size'])
    BOOLEAN_PARAMS = set(['draw_struct_plot',
                        'use_vertical_ticks',
                        'include_key',
                        'use_custom_key_labels'])
    OTHER_PARAMS = set(['horiz_axis_title',
                        'colors',
                        'axis_color',
                        'output_file_path',
                        'key_text_color',
                        'key_position'])


    for option in config_parser.options('struct_plot'):
        if option in FLOAT_PARAMS:
            settings[option] = config_parser.getfloat('struct_plot',option)
        elif option in BOOLEAN_PARAMS:
            settings[option] = config_parser.getboolean('struct_plot',option)
        elif option in OTHER_PARAMS:
            settings[option] = ast.literal_eval(config_parser.get('struct_plot',option))


    # check to make sure entries in settings have the correct format
    

    if type(settings['colors']) is not list:
        print 'colors must be a list of 3 element lists'
        sys.exit(1)
    else:
        colorified = [None] * len(settings['colors'])
        try:
            for i in range(len(colorified)):
                colorified[i] = RGB.from_hex_string(settings['colors'][i])
            settings['colors'] = colorified
        except Exception:
            print 'Invalid colors in colors'
            sys.exit(1)

    try:
        settings['axis_color'] = RGB.from_hex_string(settings['axis_color'])
    except Exception:
        print 'Invalid color in axis_color'
        sys.exit(1)

    if settings['include_key']:
        try:
            settings['key_text_color'] = RGB.from_hex_string(settings['key_text_color'])
        except Exception:
            print 'Invalid color in key_text_color'
            sys.exit(1)

        if len(settings['key_position']) != 2:
            print 'Invalid number of components in key_position'
            sys.exit(1)

        for i in range(2):
            try:
                settings['key_position'][i] = float(settings['key_position'][i])
            except Exception:
                print 'Elements in key_position must be numbers'
                sys.exit(1)

    return settings
Exemplo n.º 3
0
def parse_hive_plot_settings(config):

    ''' Parses custom settings for a hive plot from a configuration file. Returns a dictionary containing all
    of the settings

    config is a ConfigParser object which already contains all of the settings
    data is a pandas.DataFrame object containing all of the alternative splicing data

    '''
    print 'Parsing settings for hive plot...'

    settings = default_hive_settings()
    
    FLOAT_PARAMS = set(['dimension',
                        'axis_subdivision',
                        'tick_label_font_size',
                        'tick_label_distance',
                        'axis_start_radius',
                        'axis_end_radius',
                        'bezier_thickness',
                        'axis_thickness',
                        'tick_height',
                        'tick_thickness',
                        'axis_label_size',
                        'key_font_size',
                        'key_title_size'])
    BOOLEAN_PARAMS = set(['tick_marks',
                        'tick_labels',
                        'draw_bars',
                        'include_key',
                        'draw_hive_plot'])
    OTHER_PARAMS = set(['axis_colors',
                        'bezier_colors',
                        'axis_angles',
                        'custom_scale',
                        'axis_label_radius',
                        'key_position',
                        'key_text_color',
                        'key_position'])

    for option in config.options('hive_plot'):
        if option in FLOAT_PARAMS:
            settings[option] = config.getfloat('hive_plot',option)
        elif option in BOOLEAN_PARAMS:
            settings[option] = config.getboolean('hive_plot',option)
        elif option in OTHER_PARAMS:
            settings[option] = ast.literal_eval(config.get('hive_plot',option))

    # check to make sure that the settings have the right format and preprocess them
    colorified = [None] * len(settings['bezier_colors'])
    try:
        for i in range(len(colorified)):
            colorified[i] = RGB.from_hex_string(settings['bezier_colors'][i])
        settings['bezier_colors'] = colorified
    except Exception:
        print 'Invalid colors in bezier_colors'
        sys.exit(1)

    try:
        settings['axis_colors'] = RGB.from_hex_string(settings['axis_colors'])
    except Exception:
        print 'Invalid color in axis_colors'
        sys.exit(1)

    if settings['custom_scale']:
        if type(settings['custom_scale']) is not list:
            print 'custom_scale must be list'
            sys.exit(1)
        for item in settings['custom_scale']:
            if type(item) is not list:
                print 'Items in custom_scale must be list'
                sys.exit(1)
            elif len(item) != 2:
                print 'Invalid number of elements in element of custom_scale'
                sys.exit(1)
            elif item[0] < 0 or item[0] > 1 or item[1] < item[0] or item[1] > 1:
                print 'Invalid boundary in custom_scale'
                sys.exit(1)


    if settings['include_key']:
        if type(settings['key_position']) is not list:
            print 'key_position must be list'
            sys.exit(1)
        if len(settings['key_position']) != 2:
            print 'key_position can have exactly 2 coordinates'
            sys.exit(1)
        try:
            settings['key_text_color'] = RGB.from_hex_string(settings['key_text_color'])
        except:
            print 'key_text_color is not a valid color'
    
    return settings
def parse_hive_plot_settings(config):

    ''' Parses custom settings for a hive plot from a configuration file. Returns a dictionary containing all
    of the settings

    config is a ConfigParser object which already contains all of the settings
    data is a pandas.DataFrame object containing all of the alternative splicing data

    '''
    print 'Parsing settings for hive plot...'

    settings = default_hive_settings()
    
    FLOAT_PARAMS = set(['dimension',
                        'axis_subdivision',
                        'tick_label_font_size',
                        'tick_label_distance',
                        'axis_start_radius',
                        'axis_end_radius',
                        'bezier_thickness',
                        'axis_thickness',
                        'tick_height',
                        'tick_thickness',
                        'axis_label_size',
                        'key_font_size',
                        'key_title_size'])
    BOOLEAN_PARAMS = set(['tick_marks',
                        'tick_labels',
                        'draw_bars',
                        'include_key',
                        'draw_hive_plot'])
    OTHER_PARAMS = set(['axis_colors',
                        'bezier_colors',
                        'axis_angles',
                        'custom_scale',
                        'axis_label_radius',
                        'key_position',
                        'key_text_color',
                        'key_position'])

    for option in config.options('hive_plot'):
        if option in FLOAT_PARAMS:
            settings[option] = config.getfloat('hive_plot',option)
        elif option in BOOLEAN_PARAMS:
            settings[option] = config.getboolean('hive_plot',option)
        elif option in OTHER_PARAMS:
            settings[option] = ast.literal_eval(config.get('hive_plot',option))

    # check to make sure that the settings have the right format and preprocess them
    colorified = [None] * len(settings['bezier_colors'])
    try:
        for i in range(len(colorified)):
            colorified[i] = RGB.from_hex_string(settings['bezier_colors'][i])
        settings['bezier_colors'] = colorified
    except Exception:
        print 'Invalid colors in bezier_colors'
        sys.exit(1)

    try:
        settings['axis_colors'] = RGB.from_hex_string(settings['axis_colors'])
    except Exception:
        print 'Invalid color in axis_colors'
        sys.exit(1)

    if settings['custom_scale']:
        if type(settings['custom_scale']) is not list:
            print 'custom_scale must be list'
            sys.exit(1)
        for item in settings['custom_scale']:
            if type(item) is not list:
                print 'Items in custom_scale must be list'
                sys.exit(1)
            elif len(item) != 2:
                print 'Invalid number of elements in element of custom_scale'
                sys.exit(1)
            elif item[0] < 0 or item[0] > 1 or item[1] < item[0] or item[1] > 1:
                print 'Invalid boundary in custom_scale'
                sys.exit(1)


    if settings['include_key']:
        if type(settings['key_position']) is not list:
            print 'key_position must be list'
            sys.exit(1)
        if len(settings['key_position']) != 2:
            print 'key_position can have exactly 2 coordinates'
            sys.exit(1)
        try:
            settings['key_text_color'] = RGB.from_hex_string(settings['key_text_color'])
        except:
            print 'key_text_color is not a valid color'
    
    return settings