Exemple #1
0
def plot_slopes(df, fits):
    fig, ax = plt.subplots()
    ax.set_ylabel('slope [RFU/min]')

    x = 0
    x_ticks = []
    x_labels = []

    groups = df.groupby(['control', 'rnase_U_mL', 'well'])
    for color, ((control, _, well), g) in iter_colors(sorted(groups)):
        m, b, r, p, err = fits[well]

        rnase_U_mL = one(uniq(g['rnase_U_mL']))
        title = one(uniq(g['title']))
        label = f'{title}' if control else f'{rnase_U_mL} U/mL'

        if title == 'FAM':
            continue

        ax.plot(
                [x,x],
                [0,m],
                color=color,
                linewidth=6,
        )
        #ax.plot(
        #        [x,x],
        #        [0,m],
        #        marker='_',
        #        color='black',
        #)
        ax.errorbar(
                [x],
                [m],
                yerr=err,
                color=color,
                capsize=3,
        )
        x_ticks.append(x)
        x_labels.append(label)
        x += 1

    ax.set_xticks(x_ticks)
    ax.set_xticklabels(x_labels, rotation='vertical')
    ax.set_xlim(min(x_ticks) - 0.5, max(x_ticks) + 0.5)
    ax.set_ylim(0, ax.get_ylim()[1])

    fig.tight_layout()

    return fig, ax
    def _key_from_group(self, g, cols):
        try:
            key = tuple(
                    one(uniq(g[col]))
                    for col in cols
            )
            return self._normalize_key(key)

        except ValueError:
            raise KeyError(cols)
Exemple #3
0
def plot_linear_fits(df, fits):
    fig, axes = plt.subplots(1, 2, sharex=True, sharey=True)

    axes[0].set_title('Controls')
    axes[1].set_title('Experiments')

    for ax in axes[:0]:
        ax.set_ylabel('RFU')
    for ax in axes[-1:]:
        ax.set_xlabel('time [min]')

    for control, gi in df.groupby(['control']):
        ax = axes[0 if control else 1]

        for color, (well, gj) in iter_colors(gi.groupby(['well'])):
            rnase_U_mL = one(uniq(gj['rnase_U_mL']))
            title = one(uniq(gj['title']))
            label = f'{title}' if control else f'{rnase_U_mL} U/mL'

            plot_linear_fit(ax, gj, fits[well], color=color, label=label)

        ax.legend(loc='best')

    return fig, axes
    def format_label(self, g):
        params = {
                col: ','.join(map(str, uniq(g[col])))
                for col in g
        }

        if not isinstance(self.label, list):
            labels = [self.label]
        else:
            labels = self.labels

        for label in labels:
            try:
                return label.format(**params)
            except KeyError:
                continue
Exemple #5
0
 def preclean(x):
     x = remove_non_ascii(' '.join(i for i in uniq(x.split())))
     return to_single_space(x).strip()
Exemple #6
0
 def preclean(x):
     return strip(remove_non_ascii(
         to_single_space(
             ' '.join(i for i in uniq(x.split()))
                 )))