예제 #1
0
    def _make_coverage_graph(self, index, figsize=(14, 4), cbar=True, **fig_kwargs):
        peptides = self.series[index]

        cmap = fig_kwargs.get('cmap', 'jet')
        if cbar:
            fig, (ax_main, ax_cbar) = plt.subplots(1, 2, figsize=figsize, gridspec_kw={'width_ratios': [40, 1], 'wspace': 0.025})

            norm = mpl.colors.Normalize(vmin=0, vmax=100)
            cmap = mpl.cm.get_cmap(cmap)
            cb1 = mpl.colorbar.ColorbarBase(ax_cbar, cmap=mpl.cm.get_cmap(cmap),
                                            norm=norm,
                                            orientation='vertical', ticks=[0, 100])
            cb1.set_label('Uptake %', x=-1, rotation=270)
            # cbar_ax.xaxis.set_ticks_position('top')
            cb1.set_ticks([0, 100])

        else:
            fig, ax_main = plt.subplots(figsize=figsize)

        wrap = autowrap(peptides)
        plot_peptides(peptides, wrap, ax_main, **fig_kwargs)
        ax_main.set_xlabel('Residue number')
        t_unit = fig_kwargs.get('time_unit', '')
        fig.suptitle(f'Deuterium uptake at t={peptides.exposure} ' + t_unit)
        plt.tight_layout()

        return fig
예제 #2
0
파일: transforms.py 프로젝트: sajetan/PyHDX
    def apply(self, table):
        if not self.wrap:
            self.wrap = autowrap(table[self.left],
                                 table[self.right],
                                 margin=self.margin,
                                 step=self.step)

        # Order of columns determines their role, not the names
        columns = ['x0', 'y0', 'x1',
                   'y1']  # bottom-left (x0, y0) and top right (x1, y1)
        output_table = pd.DataFrame(index=table.index, columns=columns)
        output_table['x0'] = table[self.left] - 0.5
        output_table['x1'] = table[self.right] - 0.5
        cycle = itertools.cycle(
            range(self.height * self.wrap, 0,
                  -self.height))  # Starts at y top, cyles with wrap
        yvals = np.array(list(itertools.islice(
            cycle, len(table))))  # Repeat cycle until the correct length
        output_table['y0'] = yvals - self.height
        output_table['y1'] = yvals

        if self.value:
            output_table['value'] = table[self.value]

        return output_table
예제 #3
0
파일: transforms.py 프로젝트: Jhsmit/PyHDX
    def transform(self):
        df = self.source.get()
        if df is None:
            return None

        df = df.dropna(subset=[self.left, self.right]).sort_values(
            by=[self.left, self.right]
        )

        # todo fix types to be ints in the df
        left = df[self.left].to_numpy(dtype=int)
        right = df[self.right].to_numpy(dtype=int)

        if not self.wrap:
            wrap = autowrap(left, right, margin=self.margin, step=self.step)
        else:
            wrap = self.wrap

        # Order of columns determines their role, not the names
        columns = [
            "x0",
            "y0",
            "x1",
            "y1",
        ]  # bottom-left (x0, y0) and top right (x1, y1)
        output_df = pd.DataFrame(index=df.index, columns=columns)
        output_df["x0"] = left - 0.5
        output_df["x1"] = right - 0.5
        cycle = itertools.cycle(
            range(self.height * wrap, 0, -self.height)
        )  # Starts at y top, cyles with wrap
        yvals = np.array(
            list(itertools.islice(cycle, len(df)))
        )  # Repeat cycle until the correct length
        output_df["y0"] = yvals - self.height
        output_df["y1"] = yvals

        if self.passthrough:
            for item in self.passthrough:
                assert item not in [
                    "value",
                    "index",
                ], "Invalid field name, 'index' and 'value' names are reserved"
                output_df[item] = df[item]
        output_df["index"] = df.index

        return output_df
예제 #4
0
def plot_peptides(pm,
                  ax,
                  wrap=None,
                  color=True,
                  labels=False,
                  cbar=False,
                  intervals='corrected',
                  cmap='jet',
                  **kwargs):
    """

    TODO: needs to be checked if intervals (start, end) are still accurately taking inclusive, exclusive into account
    Plots peptides as rectangles in the provided axes

    Parameters
    ----------
    pm
    wrap
    ax
    color
    labels
    cmap
    kwargs

    Returns
    -------

    """

    wrap = wrap or autowrap(pm.data['start'], pm.data['end'])
    rect_kwargs = {'linewidth': 1, 'linestyle': '-', 'edgecolor': 'k'}
    rect_kwargs.update(kwargs)

    cmap = mpl.cm.get_cmap(cmap)
    norm = mpl.colors.Normalize(vmin=0, vmax=1)
    i = -1

    for p_num, e in enumerate(pm.data):
        if i < -wrap:
            i = -1

        if color:
            c = cmap(norm(e['rfu']))
        else:
            c = '#707070'

        if intervals == 'corrected':
            start, end = 'start', 'end'
        elif intervals == 'original':
            start, end = '_start', '_end'
        else:
            raise ValueError(
                f"Invalid value '{intervals}' for keyword 'intervals', options are 'corrected' or 'original'"
            )

        width = e[end] - e[start]
        rect = Rectangle((e[start] - 0.5, i),
                         width,
                         1,
                         facecolor=c,
                         **rect_kwargs)
        ax.add_patch(rect)
        if labels:
            rx, ry = rect.get_xy()
            cy = ry
            cx = rx
            ax.annotate(str(p_num), (cx, cy),
                        color='k',
                        fontsize=6,
                        va='bottom',
                        ha='right')

        i -= 1

    if cbar:
        scalar_mappable = mpl.cm.ScalarMappable(norm=norm, cmap=cmap)
        plt.colorbar(scalar_mappable, label='Percentage D')

    ax.set_ylim(-wrap, 0)
    end = pm.interval[1]
    ax.set_xlim(0, end)
    ax.set_yticks([])