def test_Logo_style_xticks(): good_crp_df = logomaker.get_example_matrix('crp_energy_matrix', print_description=False) # test parameter anchor test_parameter_values(func=logomaker.Logo(good_crp_df).style_xticks, var_name='anchor', fail_list=['x', None, 0.5, 1.0], success_list=[-1, 1, 2]) # test parameter spacing test_parameter_values(func=logomaker.Logo(good_crp_df).style_xticks, var_name='spacing', fail_list=['x', None, 0, 0.5], success_list=[1, 2]) # test parameter fmt # TODO: fmt = 'x' seems to passing in the following. This should be fixed. test_parameter_values(func=logomaker.Logo(good_crp_df).style_xticks, var_name='fmt', fail_list=[None, 0], success_list=['%d']) # test parameter rotation test_parameter_values(func=logomaker.Logo(good_crp_df).style_xticks, var_name='rotation', fail_list=[None, 'x'], success_list=[-12, 0, 1.4, 200])
def test_Logo_style_glyphs_below(): good_crp_df = logomaker.get_example_matrix('crp_energy_matrix', print_description=False) # test parameter color test_parameter_values( func=logomaker.Logo(good_crp_df).style_glyphs_below, var_name='color', fail_list=[0, 'xxx', True, [0, 0, -1]], success_list=['red', [1, 1, 1], [0, 0, 0], [0.1, 0.2, 0.3], None]) # test parameter alpha test_parameter_values(func=logomaker.Logo(good_crp_df).style_glyphs_below, var_name='alpha', fail_list=[-1, 'x', 1.1], success_list=[0, 1, 0.5]) # test parameter shade test_parameter_values(func=logomaker.Logo(good_crp_df).style_glyphs_below, var_name='shade', fail_list=[-1, 'x', 1.1], success_list=[0, 1, 0.5]) # test parameter fade test_parameter_values(func=logomaker.Logo(good_crp_df).style_glyphs_below, var_name='fade', fail_list=[-1, 'x', 1.1], success_list=[0, 1, 0.5]) # test parameter flip test_parameter_values(func=logomaker.Logo(good_crp_df).style_glyphs_below, var_name='flip', fail_list=bool_fail_list, success_list=bool_success_list)
def test_Logo_highlight_position(): good_crp_df = logomaker.get_example_matrix('crp_energy_matrix', print_description=False) # test parameter p test_parameter_values(func=logomaker.Logo(good_crp_df).highlight_position, var_name='p', fail_list=['x', 1.5], success_list=[0, 1, 10])
def test_Logo_style_glyphs(): good_crp_df = logomaker.get_example_matrix('crp_energy_matrix', print_description=False) # test parameter color_scheme test_parameter_values(func=logomaker.Logo(good_crp_df).style_glyphs, var_name='color_scheme', fail_list=['bad_color_scheme', 1, True], success_list=['classic', 'gray', 'salmon'])
def test_Logo_style_single_glyph(): good_crp_df = logomaker.get_example_matrix('crp_energy_matrix', print_description=False) # test parameter p test_parameter_values(func=logomaker.Logo(good_crp_df).style_single_glyph, var_name='p', fail_list=[-1, 'x', 1.1, 10000], success_list=[0, 1, 10], c='A') # test parameter c test_parameter_values(func=logomaker.Logo(good_crp_df).style_single_glyph, var_name='c', fail_list=[-1, 'x', 1.1], success_list=['A', 'C', 'G', 'T'], p=1)
def test_Logo_fade_glyphs_in_probability_logo(): good_prob_df = logomaker.get_example_matrix('ss_probability_matrix', print_description=False) # test parameter v_alpha0 test_parameter_values( func=logomaker.Logo(good_prob_df).fade_glyphs_in_probability_logo, var_name='v_alpha0', fail_list=[-1, 1.1, 1, 1.0, 'xxx', True], success_list=[0, 0.0, 0.999, 0.5]) # TODO: a value of True v_alpha_1 works now, this should probably be fixed. # test parameter v_alpha1 test_parameter_values( func=logomaker.Logo(good_prob_df).fade_glyphs_in_probability_logo, var_name='v_alpha1', fail_list=[1.1, -1, 'xxx'], success_list=[0.999, 0.5, 1.0])
def test_Logo_draw_baseline(): good_crp_df = logomaker.get_example_matrix('crp_energy_matrix', print_description=False) # test parameter zorder test_parameter_values(func=logomaker.Logo(good_crp_df).draw_baseline, var_name='zorder', fail_list=['x', None], success_list=[-1, 0.5, 1]) # test parameter color test_parameter_values(func=logomaker.Logo(good_crp_df).draw_baseline, var_name='color', fail_list=['x', 1, True, 'wrong_color'], success_list=['pink', 'red', [1, 1, 1]]) # test parameter linewidth test_parameter_values(func=logomaker.Logo(good_crp_df).draw_baseline, var_name='linewidth', fail_list=['x', -1, '1', None], success_list=[0, 1, 1.5, 2])
def test_Logo_style_glyphs_in_sequence(): good_crp_df = logomaker.get_example_matrix('crp_energy_matrix', print_description=False) # randomly make up a sequence of the correct length test_good_sequence = np.random.choice(['A', 'C', 'G', 'T'], size=26, p=[0.25, 0.25, 0.25, 0.25]) test_good_sequence = "".join(test_good_sequence) # randomly make up a sequence of the incorrect length test_bad_sequence = np.random.choice(['A', 'C', 'G', 'T'], size=10, p=[0.25, 0.25, 0.25, 0.25]) test_bad_sequence = "".join(test_bad_sequence) # test parameter sequence test_parameter_values( func=logomaker.Logo(good_crp_df).style_glyphs_in_sequence, var_name='sequence', fail_list=[-1, 'x', 1.1, test_bad_sequence], success_list=[test_good_sequence])
def test_Logo_style_spines(): good_crp_df = logomaker.get_example_matrix('crp_energy_matrix', print_description=False) # test parameter anchor test_parameter_values(func=logomaker.Logo(good_crp_df).style_spines, var_name='spines', fail_list=['x', None, 0.5, 1.0, 'top'], success_list=[('top', 'bottom', 'left', 'right'), ['top', 'bottom', 'left', 'right'], ('top', 'bottom', 'left'), ('top', 'bottom'), ['top']]) # test parameter visible test_parameter_values(func=logomaker.Logo(good_crp_df).style_spines, var_name='visible', fail_list=bool_fail_list, success_list=bool_success_list) # test parameter color test_parameter_values(func=logomaker.Logo(good_crp_df).style_spines, var_name='color', fail_list=['wrong_color', 3, [0.5, 0.5, 0.5, 0.5]], success_list=['black', 'green', [0.4, 0.5, 1.0]]) # test parameter linewidth test_parameter_values(func=logomaker.Logo(good_crp_df).style_spines, var_name='linewidth', fail_list=['xxx', -1], success_list=[0.0, 0, 1]) # test parameter bounds test_parameter_values(func=logomaker.Logo(good_crp_df).style_spines, var_name='bounds', fail_list=['xxx', -1], success_list=[None, [0, 1]])
def test_transform_matrix(): good_crp_weight_df = logomaker.get_example_matrix('crp_energy_matrix', print_description=False) good_crp_counts_df = logomaker.get_example_matrix('crp_counts_matrix', print_description=False) # test parameter df test_parameter_values(func=logomaker.transform_matrix, var_name='df', fail_list=['x', good_crp_weight_df, None], success_list=[good_crp_counts_df], from_type='counts', to_type='probability') test_parameter_values(func=logomaker.transform_matrix, var_name='df', fail_list=[], success_list=[good_crp_counts_df], from_type='counts', to_type='weight') test_parameter_values(func=logomaker.transform_matrix, var_name='df', fail_list=[], success_list=[good_crp_counts_df], from_type='counts', to_type='information') # test parameter center_values test_parameter_values(func=logomaker.transform_matrix, var_name='center_values', fail_list=bool_fail_list, success_list=bool_success_list, df=good_crp_counts_df) # test parameter normalize_values test_parameter_values(func=logomaker.transform_matrix, var_name='normalize_values', fail_list=bool_fail_list, success_list=bool_success_list, df=good_crp_counts_df) # test parameter from_type test_parameter_values(func=logomaker.transform_matrix, var_name='from_type', fail_list=[1, 'x', None], success_list=['counts'], df=good_crp_counts_df, to_type='probability') # test parameter to_type test_parameter_values( func=logomaker.transform_matrix, var_name='to_type', fail_list=[1, 'x', None], success_list=['probability', 'weight', 'information'], df=good_crp_counts_df, from_type='counts') # test parameter background test_parameter_values(func=logomaker.transform_matrix, var_name='background', fail_list=[1, 'x', [-1, 1, 1, 1]], success_list=[None, [0.25, 0.25, 0.25, 0.25]], df=good_crp_counts_df, from_type='counts', to_type='information') # test parameter pseudocount test_parameter_values(func=logomaker.transform_matrix, var_name='pseudocount', fail_list=[None, 'x', -1], success_list=[0, 1, 10], df=good_crp_counts_df, from_type='counts', to_type='probability')
def test_Logo_highlight_position_range(): good_crp_df = logomaker.get_example_matrix('crp_energy_matrix', print_description=False) # test parameter pmin test_parameter_values( func=logomaker.Logo(good_crp_df).highlight_position_range, var_name='pmin', fail_list=['x', 20], success_list=[0, 1, 10], pmax=15) # test parameter pmax test_parameter_values( func=logomaker.Logo(good_crp_df).highlight_position_range, var_name='pmax', fail_list=['x', 1], success_list=[5.5, 6, 10], pmin=5) # test parameter padding test_parameter_values( func=logomaker.Logo(good_crp_df).highlight_position_range, var_name='padding', fail_list=['x', -1], success_list=[-0.5, 0, 10], pmin=5, pmax=10) # test parameter color test_parameter_values( func=logomaker.Logo(good_crp_df).highlight_position_range, var_name='color', fail_list=['x', 1, True, 'wrong_color'], success_list=['pink', 'red', [1, 1, 1]], pmin=5, pmax=10) # test parameter edgecolor test_parameter_values( func=logomaker.Logo(good_crp_df).highlight_position_range, var_name='edgecolor', fail_list=['x', 1, True, 'wrong_color'], success_list=[None, 'pink', 'red', [1, 1, 1]], pmin=5, pmax=10) # test parameter floor test_parameter_values( func=logomaker.Logo(good_crp_df).highlight_position_range, var_name='floor', fail_list=['x', 10], success_list=[-1, 1, None], pmin=5, pmax=10) # test parameter ceiling test_parameter_values( func=logomaker.Logo(good_crp_df).highlight_position_range, var_name='ceiling', fail_list=['x', -10], success_list=[-1, 1, None], pmin=5, pmax=10) # test parameter zorder. Note that a value of False passes for this parameter. This should be fixed. test_parameter_values( func=logomaker.Logo(good_crp_df).highlight_position_range, var_name='zorder', fail_list=['x', None], success_list=[-1, 0.5, 1], pmin=5, pmax=10)
# do imports import matplotlib.pyplot as plt import numpy as np import logomaker as logomaker # load saliency matrix nn_df = logomaker.get_example_matrix('nn_saliency_matrix', print_description=False) # create Logo object nn_logo = logomaker.Logo(nn_df) # style using Logo methods nn_logo.style_spines(visible=False) nn_logo.style_spines(spines=['left'], visible=True, bounds=[0, .75]) # style using Axes methods nn_logo.ax.set_xlim([20, 115]) nn_logo.ax.set_xticks([]) nn_logo.ax.set_ylim([-.6, .75]) nn_logo.ax.set_yticks([0, .75]) nn_logo.ax.set_yticklabels(['0', '0.75']) nn_logo.ax.set_ylabel(' saliency', labelpad=-1) # set parameters for drawing gene exon_start = 55 - .5 exon_stop = 90 + .5 y = -.2 xs = np.arange(-3, len(nn_df), 10) ys = y * np.ones(len(xs))
def test_Logo(): # df inputs that successfully execute when entered into Logo. good_crp_df = logomaker.get_example_matrix('crp_energy_matrix', print_description=False) good_prob_df = logomaker.get_example_matrix('ss_probability_matrix', print_description=False) random_df = pd.DataFrame(np.random.randint(0, 3, size=(10, 4)), columns=list('ACGT')) # df inputs that fail when entered into Logo. bad_df1 = 'x' # test parameter df test_parameter_values(func=logomaker.Logo, var_name='df', fail_list=[bool_fail_list, bad_df1], success_list=[good_crp_df, random_df]) # test parameter colors test_parameter_values( func=logomaker.Logo, var_name='color_scheme', fail_list=['x', 'bad_color_name', 3], success_list=['classic', 'grays', 'charge', 'salmon'], df=good_crp_df) # test parameter font names test_parameter_values(func=logomaker.Logo, var_name='font_name', fail_list=[True, None, good_crp_df], success_list=[ 'DejaVu Sans', 'Arial Rounded MT Bold', 'Times New Roman' ], df=good_crp_df) # test parameter stack_order test_parameter_values(func=logomaker.Logo, var_name='stack_order', fail_list=['incorrect argument', 0.0, None], success_list=['small_on_top', 'big_on_top', 'fixed'], df=good_crp_df) # test parameter center_values test_parameter_values(func=logomaker.Logo, var_name='center_values', fail_list=['incorrect argument', 0.0, None], success_list=[True, False], df=good_crp_df) # test parameter baseline_width test_parameter_values(func=logomaker.Logo, var_name='baseline_width', fail_list=['incorrect argument', -0.1, None], success_list=[0, 0.5, 3], df=good_crp_df) # test parameter flip_below test_parameter_values(func=logomaker.Logo, var_name='flip_below', fail_list=['incorrect argument', -0.1, None], success_list=[True, False], df=good_crp_df) # test parameter shade_below test_parameter_values(func=logomaker.Logo, var_name='shade_below', fail_list=['incorrect argument', -0.1, 1.4, None], success_list=[0, 0.0, 0.5, 1, 1.0], df=good_crp_df) # test parameter fade_below test_parameter_values(func=logomaker.Logo, var_name='fade_below', fail_list=['incorrect argument', -0.1, 1.4, None], success_list=[0, 0.0, 0.5, 1, 1.0], df=good_crp_df) # test parameter fade_probabilities test_parameter_values(func=logomaker.Logo, var_name='fade_probabilities', fail_list=['incorrect argument', -0.1, 1.4, None], success_list=[True, False], df=good_prob_df) # test parameter vsep test_parameter_values(func=logomaker.Logo, var_name='vsep', fail_list=['incorrect argument', -0.1, None], success_list=[0.0, 0, 0.3, 10], df=good_crp_df) # test parameter vsep # TODO: note that a value of True/False is still causing a logo to be drawn, eventhough draw_now = False test_parameter_values(func=logomaker.Logo, var_name='show_spines', fail_list=['incorrect argument', -0.1], success_list=[None, True, False], df=good_crp_df) # test parameter zorder. Need to review zorder's input check in Logo test_parameter_values(func=logomaker.Logo, var_name='zorder', fail_list=['incorrect argument'], success_list=[0, 1, 3], df=good_crp_df) # test parameter figsize test_parameter_values(func=logomaker.Logo, var_name='figsize', fail_list=[ 'incorrect argument', -0.1, [-1, -1], [-1], [0, 0], ['x', 'y'], (1, 2, 3) ], success_list=[(10, 2.5), [5, 5]], df=good_crp_df) # validate ax _, temp_ax = plt.subplots(figsize=[3, 3]) test_parameter_values(func=logomaker.Logo, var_name='ax', fail_list=['x', 1, True], success_list=[temp_ax, None], df=good_crp_df)
# do imports import matplotlib.pyplot as plt import logomaker as logomaker # load ww information matrix ww_df = logomaker.get_example_matrix('ww_information_matrix', print_description=False) # create Logo object ww_logo = logomaker.Logo(ww_df, font_name='Stencil Std', color_scheme='NajafabadiEtAl2017', vpad=.1, width=.8) # style using Logo methods ww_logo.style_xticks(anchor=0, spacing=5, rotation=45) ww_logo.highlight_position(p=4, color='gold', alpha=.5) ww_logo.highlight_position(p=26, color='gold', alpha=.5) # style using Axes methods ww_logo.ax.set_ylabel('information (bits)') ww_logo.ax.set_xlim([-1, len(ww_df)]) # show plot ww_logo.fig.show()
# do imports import matplotlib.pyplot as plt import logomaker as logomaker # load crp energy matrix crp_df = -logomaker.get_example_matrix('crp_energy_matrix', print_description=False) # create Logo object crp_logo = logomaker.Logo(crp_df, shade_below=.5, fade_below=.5, font_name='Arial Rounded MT Bold') # style using Logo methods crp_logo.style_spines(visible=False) crp_logo.style_spines(spines=['left', 'bottom'], visible=True) crp_logo.style_xticks(rotation=90, fmt='%d', anchor=0) # style using Axes methods crp_logo.ax.set_ylabel("$-\Delta \Delta G$ (kcal/mol)", labelpad=-1) crp_logo.ax.xaxis.set_ticks_position('none') crp_logo.ax.xaxis.set_tick_params(pad=-1) # style and show figure crp_logo.fig.show()
# do imports import matplotlib.pyplot as plt import logomaker as logomaker # load ss probability matrix ss_df = logomaker.get_example_matrix('ss_probability_matrix', print_description=False) # create Logo object ss_logo = logomaker.Logo(ss_df, width=.8, vpad=.05, fade_probabilities=True, stack_order='small_on_top', color_scheme='dodgerblue', font_name='Rosewood Std') # style using Logo methods ss_logo.style_spines(spines=['left', 'right'], visible=False) # style using Axes methods ss_logo.ax.set_xticks(range(len(ss_df))) ss_logo.ax.set_xticklabels('%+d'%x for x in [-3, -2, -1, 1, 2, 3, 4, 5, 6]) ss_logo.ax.set_yticks([0, .5, 1]) ss_logo.ax.axvline(2.5, color='k', linewidth=1, linestyle=':') ss_logo.ax.set_ylabel('probability') # show plot ss_logo.fig.show()
# do imports import matplotlib.pyplot as plt import logomaker as logomaker # make Figure and Axes objects fig, ax = plt.subplots(1, 1, figsize=[4, 2]) # load logo matrix logo_df = logomaker.get_example_matrix('logomaker_logo_matrix', print_description=False) # create color scheme color_scheme = { 'L': [0, .5, 0], 'O': [1, 0, 0], 'G': [1, .65, 0], 'maker': 'gray' } # create Logo object logo_logo = logomaker.Logo(logo_df, ax=ax, color_scheme=color_scheme, baseline_width=0, font_name='Arial', show_spines=False, vsep=.005, width=.95) # color the 'O' at the end of the logo a different color logo_logo.style_single_glyph(c='O', p=3, color=[0, 0, 1])
# do imports import matplotlib.pyplot as plt import logomaker as logomaker # load ARS enrichment matrix ars_df = logomaker.get_example_matrix('ars_enrichment_matrix', print_description=False) # load wild-type ARS1 sequence with logomaker.open_example_datafile('ars_wt_sequence.txt', print_description=False) as f: lines = f.readlines() lines = [l.strip() for l in lines if '#' not in l] ars_seq = ''.join(lines) # trim matrix and sequence start = 10 stop = 100 ars_df = ars_df.iloc[start:stop, :] ars_df.reset_index(inplace=True, drop=True) ars_seq = ars_seq[start:stop] # create Logo object ars_logo = logomaker.Logo(ars_df, color_scheme='dimgray', font_name='Luxi Mono') # color wild-type ARS1 sequence within logo ars_logo.style_glyphs_in_sequence(sequence=ars_seq, color='darkorange') # highlight functional regions of ARS1