def plot_Δcq(df): def iter_keys(): for sgrna in ['on', 'off', '11', '30']: for time in [30, 60, 90, 120]: for ligand in [False, True]: yield sgrna, time, ligand def name_from_key(key): sgrna, time, ligand = key return f"{sgrna} {time} ({'holo' if ligand else 'apo'})" fig, ax = plt.subplots(1, figsize=(6, 4)) xticks = [] xtick_labels = [] for i, key in enumerate(iter_keys()): row = df.loc[key] sgrna, time, ligand = key sgrna = { 'on': 'on', 'off': 'off', '11': 'rxb/11/1', '30': 'mhf/30' }[sgrna] fold_change = 2**(-row['Δcq_mean']) fold_change_bound = 2**(-row['Δcq_mean'] + row['Δcq_std']) fold_change_err = fold_change_bound - fold_change x = [i, i] y = [0, fold_change] style = dict( linewidth=5, color=pick_color(sgrna), ) ax.plot(x, y, **style) x = x[-1:] y = y[-1:] y_err = [fold_change_err] style = dict( ecolor=pick_color(sgrna), capsize=2.5, ) ax.errorbar(x, y, y_err, **style) xticks.append(i) xtick_labels.append(name_from_key(key)) ax.set_ylabel('GFP Expression\n[rel. to 16S rRNA]') ax.set_xlim(xticks[0] - 0.5, xticks[-1] + 0.5) ax.set_xticks(xticks) ax.set_xticklabels(xtick_labels, rotation='vertical') ax.grid(axis='y') #ax.yaxis.set_major_locator(FoldChangeLocator()) fig.tight_layout(pad=0) return fig
def plot_Δct_data(df): def iter_keys(): for promoter in ['j23119', 'j23150']: for sgrna in ['on', 'off', 'rxb 11,1']: for ligand in [False, True]: yield promoter, sgrna, ligand def name_from_key(key): promoter, sgrna, ligand = key return f"{promoter} {sgrna} ({'holo' if ligand else 'apo'})" fig, ax = plt.subplots(1, figsize=(4, 3.25)) xticks = [] xtick_labels = [] for i, key in enumerate(iter_keys()): row = df.loc[key] promoter, sgrna, ligand = key fold_change = 2**(-row['Δct_mean']) fold_change_bound = 2**(-row['Δct_mean'] + row['Δct_std']) fold_change_err = fold_change_bound - fold_change x = [i, i] y = [0, fold_change] style = dict( linewidth=5, color=pick_color(sgrna), ) ax.plot(x, y, **style) x = x[-1:] y = y[-1:] y_err = [fold_change_err] style = dict( ecolor=pick_color(sgrna), capsize=2.5, ) ax.errorbar(x, y, y_err, **style) xticks.append(i) xtick_labels.append(name_from_key(key)) ax.set_ylabel('RNA Expression\n[rel. to 16S rRNA]') ax.set_xlim(xticks[0] - 0.5, xticks[-1] + 0.5) ax.set_xticks(xticks) ax.set_xticklabels(xtick_labels, rotation='vertical') ax.grid(axis='y') #ax.yaxis.set_major_locator(FoldChangeLocator()) fig.tight_layout(pad=0) #fig.savefig('20181002_sgrna_qpcr_Δct.svg') return fig
def plot_ΔΔct_data(df): keys = [ ('on', False), ('on', True ), ('off', False), ('off', True ), ('rxb 11,1', False), ('rxb 11,1', True ), ] def name_from_key(key): sgrna, ligand = key return f"{sgrna} ({'holo' if ligand else 'apo'})" fig, ax = plt.subplots(1, figsize=(4, 3)) xticks = [] xtick_labels = [] for i, key in enumerate(keys): row = df.loc[key] sgrna, ligand = key x = [i, i] y = [0, row['fold_change']] style = dict( linewidth=5, color=pick_color(sgrna), ) ax.plot(x, y, **style) x = x[-1:] y = y[-1:] y_err = [row['upper_err']] style = dict( ecolor=pick_color(sgrna), capsize=2.5, ) ax.errorbar(x, y, y_err, **style) xticks.append(i) xtick_labels.append(name_from_key(key)) ax.set_ylabel('J23119 / J23150') ax.set_xlim(xticks[0] - 0.5, xticks[-1] + 0.5) ax.set_xticks(xticks) ax.set_xticklabels(xtick_labels, rotation='vertical') ax.grid(axis='y') ax.yaxis.set_major_locator(FoldChangeLocator()) fig.tight_layout(pad=0) fig.savefig('20181002_sgrna_qpcr_ΔΔct.svg') return fig
def plot_miller_units(rxns, stem, figure_mode=False): if figure_mode: return num_spacers = len({rxn.spacer for i, rxn in iter_reactions(rxns)}) fig, axes = plt.subplots(4, 1, figsize=(1 + 3 * num_spacers, 8)) style = dict(linewidth=5) xticks = [] for i, rxn in iter_reactions(rxns): style = dict( linewidth=5, color=pick_color(rxn.sgrna), ) raw_style = dict( linewidth=5, color=pick_color(rxn.sgrna, lightness=2), ) x = [i, i] ys = [ (0, [0, rxn.fit[0]], style), (1, [0, rxn.raw_od600], raw_style), (1, [0, rxn.od600], style), (2, [0, rxn.vol_mL], style), (3, [0, rxn.miller], style), ] xticks.append((i, f'{rxn.apo_holo} {rxn.label}')) for j, y, style in ys: axes[j].plot(x, y, **style) xticks, xticklabels = zip(*xticks) axes[3].set_xticklabels(xticklabels, rotation='vertical') for ax in axes: ax.set_ylim(0, ax.get_ylim()[1]) ax.set_xlim(xticks[0] - 0.5, xticks[-1] + 0.5) ax.set_xticks(xticks) if ax is not axes[3]: ax.tick_params(labelbottom=False) axes[0].set_ylabel('d[A420]/dt') axes[1].set_ylabel('OD600') axes[2].set_ylabel('volume (mL)') axes[3].set_ylabel('Miller units') finalize_plot(fig, stem, 'miller')
def _plot_condition(self, x, experiment, condition, wells): # Plot the fluorescence data. ys = np.array([x.linear_loc for x in wells]) xs = np.full(ys.shape, x) y = np.mean(ys) err = np.std(ys) label = experiment.get('family', experiment['label']).lower() bar_color = pick_color(label) dot_colors = pick_dot_colors(label, ys) self.axes.plot( [x, x], [0, y], color=bar_color, linewidth=self.bar_width, solid_capstyle='butt', zorder=1, ) self.axes.scatter( xs, ys, c=dot_colors, marker='+', zorder=2, ) #self.axes.errorbar( # x, y, yerr=err, # ecolor=color, # capsize=self.bar_width / 2, #) # Label the axis. self.x_ticks.append(x) self.x_tick_labels.append(condition)
def plot_fold_changes(rxns, stem, figure_mode=False): primary_keys, secondary_keys = load_keys(rxns) n1, n2 = len(primary_keys), len(secondary_keys) # 1.739: To get same axes height at TMP MIC panel. wh = (3.325, 1.739) if figure_mode else (1 + 1* len(primary_keys), 3) fig, ax = plt.subplots(figsize=wh) bar_style = dict(zorder=1, linewidth=5) dot_style = dict(zorder=2, marker='+') xticks = [] apos = {} holos = {} miller_units = {False: [], True: []} fold_changes = {} sgrnas = {} replicates = {} for i, rxn in iter_reactions(rxns): sgrnas[rxn.key] = rxn.sgrna replicates.setdefault(rxn.key, {})\ .setdefault(rxn.ligand, [])\ .append(rxn) for key in replicates: sgrna = sgrnas[key] apos = np.array([x.miller for x in replicates[key][False]]) holos = np.array([x.miller for x in replicates[key][True]]) fold_changes = holos / apos #i = primary_keys[key[0]] #j = secondary_keys[key[1]] #x0 = i * (len(primary_keys) + 1) + j #n = len(fold_changes) #for k, fold_change in enumerate(fold_changes): # x = [x0*n + k, x0*n + k] # y = [0, fold_change if fold_change > 1 else 1/fold_change] # xticks.append((x[0], ' '.join(key))) # ax.plot(x, y, color=colors[key], **style) i = primary_keys[key[0]] j = secondary_keys[key[1]] x = i * (len(primary_keys) + 1) + j xticks.append((x, ' '.join(key))) # For visualization purposes, I always want the fold_change to be # greater than one. But I don't want to enforce this until after the # mean fold change has been calculated. if np.mean(fold_changes) < 1: fold_changes = 1 / fold_changes ys = fold_changes xs = np.full(ys.shape, x) y = np.mean(ys) yerr = np.std(ys) ax.plot([x,x], [0,y], color=pick_color(sgrna), **bar_style) ax.scatter(xs, ys, color=pick_dot_colors(sgrna, ys), **dot_style) #ax.errorbar([x], [y], yerr, color=colors[key]) xticks, xticklabels = zip(*xticks) ax.set_xlim(xticks[0] - 0.5, xticks[-1] + 0.5) ax.set_xticks(xticks) ax.set_xticklabels(xticklabels, rotation='vertical') ax.set_ylabel('Fold change') ax.set_ylim(0, ax.get_ylim()[1]) ax.yaxis.set_major_locator(FoldChangeLocator(6)) ax.yaxis.grid() finalize_plot(fig, stem, 'fold')
def plot_miller_units(rxns, stem, figure_mode=False): primary_keys, secondary_keys = load_keys(rxns) n1, n2 = len(primary_keys), len(secondary_keys) fig, ax = plt.subplots(figsize=(1 + 1 * len(primary_keys), 3)) bar_style = dict(zorder=1, linewidth=5) dot_style = dict(zorder=2, marker='+') xticks = [] apos = {} holos = {} miller_units = {False: [], True: []} fold_changes = {} sgrnas = {} replicates = {} for i, rxn in iter_reactions(rxns): sgrnas[rxn.key] = rxn.sgrna replicates.setdefault(rxn.key, {})\ .setdefault(rxn.ligand, [])\ .append(rxn) for key in replicates: apos = np.array([x.miller for x in replicates[key][False]]) holos = np.array([x.miller for x in replicates[key][True]]) i = primary_keys[key[0]] j = secondary_keys[key[1]] x = i * (len(primary_keys) + 1) + j x_apo = 2 * x x_holo = 2 * x + 1 xs_apo = np.full(apos.shape, x_apo) xs_holo = np.full(apos.shape, x_holo) xticks.append((x_apo, ' '.join(key + ('apo',)))) xticks.append((x_holo, ' '.join(key + ('holo',)))) y_apo = np.mean(apos) y_apo_err = np.std(apos) y_holo = np.mean(holos) y_holo_err = np.std(holos) bar_color = pick_color(sgrnas[key]) apo_dot_colors = pick_dot_colors(sgrnas[key], apos) holo_dot_colors = pick_dot_colors(sgrnas[key], holos) ax.plot([x_apo,x_apo], [0,y_apo], color=bar_color, **bar_style) ax.plot([x_holo,x_holo], [0,y_holo], color=bar_color, **bar_style) ax.scatter(xs_apo, apos, c=apo_dot_colors, **dot_style) ax.scatter(xs_holo, holos, c=holo_dot_colors, **dot_style) #ax.errorbar([x_apo], [y_apo], y_apo_err, color=colors[key]) #ax.errorbar([x_holo], [y_holo], y_holo_err, color=colors[key]) xticks, xticklabels = zip(*xticks) ax.set_xlim(xticks[0] - 0.5, xticks[-1] + 0.5) ax.set_xticks(xticks) ax.set_xticklabels(xticklabels, rotation='vertical') ax.set_ylabel('Miller Units') ax.set_ylim(0, ax.get_ylim()[1]) ax.yaxis.set_major_locator(FoldChangeLocator(6)) ax.yaxis.grid() fig.tight_layout() finalize_plot(fig, stem, 'miller')