コード例 #1
0
ファイル: makeplots.py プロジェクト: irelandb/sortseq
        plt.close()
        emat0 = emat_mean
        emat = emat0 - emat0.min(axis=0)
        

        # now make the plot
        site_seq = plottingutils.getwtseq(infofn[namedict[fn]],barcodefn,datafnbase)


        fig = plt.figure()
        ax1 = SubplotHost(fig, 1,1,1)
        fig.add_subplot(ax1)
        

        ax2 = ax1.twin()
        ax1.imshow(emat,interpolation='nearest')
        
        ax1.set_xlabel('Position w.r.t. transcription start site')
        ax1.set_yticks([0,1,2,3])
        ax1.set_yticklabels(['A','C','G','T'])


        # label positions with respect to transcription start site
        tick_start = int(start_dict[info_dict['exp_name']])+int(info_dict['mut_region_start'])
        tick_end = int(start_dict[info_dict['exp_name']])+int(info_dict['mut_region_start']) + int(info_dict['mut_region_length'])
        indices, xtick_labels = clean_up_xticklabels(tick_start,tick_end-tick_start)
        ax1.set_xticks(indices)
        ax1.set_xticklabels(xtick_labels)

        # put the sequence above it
        ax2.set_yticks([])
コード例 #2
0
        plt.title('MI, ' + fnname + ' MI: %.5f' % MI)
        plt.savefig(os.path.join(outputdir, fnname + '_MItrace.png'))
        plt.close()
        emat0 = emat_mean
        emat = emat0 - emat0.min(axis=0)

        # now make the plot
        site_seq = plottingutils.getwtseq(infofn[namedict[fn]], barcodefn,
                                          datafnbase)

        fig = plt.figure()
        ax1 = SubplotHost(fig, 1, 1, 1)
        fig.add_subplot(ax1)

        ax2 = ax1.twin()
        ax1.imshow(emat, interpolation='nearest')

        ax1.set_xlabel('Position w.r.t. transcription start site')
        ax1.set_yticks([0, 1, 2, 3])
        ax1.set_yticklabels(['A', 'C', 'G', 'T'])

        # label positions with respect to transcription start site
        tick_start = int(start_dict[info_dict['exp_name']]) + int(
            info_dict['mut_region_start'])
        tick_end = int(start_dict[info_dict['exp_name']]) + int(
            info_dict['mut_region_start']) + int(
                info_dict['mut_region_length'])
        indices, xtick_labels = clean_up_xticklabels(tick_start,
                                                     tick_end - tick_start)
        ax1.set_xticks(indices)
        ax1.set_xticklabels(xtick_labels)
コード例 #3
0
    def plot(self,
             r1=None,
             r2=None,
             nav_im=None,
             norm='log',
             scroll_step=1,
             alpha=0.3,
             cmap=None,
             pct=0.1,
             mradpp=None,
             widget=None):
        '''
        Interactive plotting of the virtual aperture images.

        The sliders control the parameters and may be clicked, dragged or scrolled.
        Clicking on inner (r1) and outer (r2) slider labels sets the radii values
        to the minimum and maximum, respectively.

        Parameters
        ----------
        r1 : scalar
            Inner radius of aperture in pixels.
        r2 : scalar
            Inner radius of aperture in pixels.
        nav_im : None or ndarray
            Image used for the navigation plot. If None, a blank image is used.
        norm : None or string:
            If not None and norm='log', a logarithmic cmap normalisation is used.
        scroll_step : int
            Step in pixels used for each scroll event.
        alpha : float
            Alpha for aperture plot in [0, 1].
        cmap : None or a matplotlib colormap
            If not None, the colormap used for both plots.
        pct : scalar
            Slice image percentile in [0, 50).
        mradpp : None or scalar
            mrad per pixel.
        widget : Pop_Up_Widget
            A custom class consisting of mutliple widgets

        '''

        from matplotlib.widgets import Slider

        self._scroll_step = max([1, int(scroll_step)])
        self._pct = pct

        if norm is not None:
            if norm.lower() == 'log':
                from matplotlib.colors import LogNorm
                norm = LogNorm()

        # condition rs
        if r1 is not None:
            self.r1 = r1
        else:
            if self.r1 is None:
                self.r1 = 0
        if r2 is not None:
            self.r2 = r2
        else:
            if self.r2 is None:
                self.r2 = int((self.data_shape[-2:] / 4).mean())
        self.rc = (self.r2 + self.r1) / 2.0

        if nav_im is None:
            nav_im = np.zeros(self.data_shape[-2:])

        # calculate data
        virtual_image = self.annular_slice(self.r1, self.r2)
        print("MRADPP", mradpp)
        # prepare plots
        if mradpp is None:
            if widget is not None:
                print("True")
                docked = widget.setup_docking("Virtual Annular",
                                              "Bottom",
                                              figsize=(8.4, 4.8))
                fig = docked.get_fig()
                fig.clf()
                (ax_nav, ax_cntrst) = fig.subplots(1, 2)
                self._f_nav = fig
            else:
                self._f_nav, (ax_nav, ax_cntrst) = plt.subplots(1,
                                                                2,
                                                                figsize=(8.4,
                                                                         4.8))

        else:
            # add 2nd x-axis
            # https://matplotlib.org/examples/axes_grid/parasite_simple2.html
            from mpl_toolkits.axes_grid1.parasite_axes import SubplotHost
            import matplotlib.transforms as mtransforms
            if widget is not None:
                print("False")
                docked = widget.setup_docking("Virtual Annular",
                                              "Bottom",
                                              figsize=(8.4, 4.8))
                self._f_nav = docked.get_fig()
                self._f_nav.clf()
            else:
                self._f_nav = plt.figure(figsize=(8.4, 4.8))
            ax_nav = SubplotHost(self._f_nav, 1, 2, 1)
            ax_cntrst = SubplotHost(self._f_nav, 1, 2, 2)

            aux_trans = mtransforms.Affine2D().scale(1.0 / mradpp, 1.0)
            ax_mrad = ax_cntrst.twin(aux_trans)
            ax_mrad.set_viewlim_mode("transform")

            self._f_nav.add_subplot(ax_nav)
            self._f_nav.add_subplot(ax_cntrst)

            ax_mrad.axis["top"].set_label('mrad')
            ax_mrad.axis["top"].label.set_visible(True)
            ax_mrad.axis["right"].major_ticklabels.set_visible(False)

        self._f_nav.subplots_adjust(bottom=0.3, wspace=0.3)
        if widget is not None:
            axr1 = fig.add_axes([0.10, 0.05, 0.80, 0.03])
            axr2 = fig.add_axes([0.10, 0.10, 0.80, 0.03])
            axr3 = fig.add_axes([0.10, 0.15, 0.80, 0.03])

        else:
            axr1 = plt.axes([0.10, 0.05, 0.80, 0.03])
            axr2 = plt.axes([0.10, 0.10, 0.80, 0.03])
            axr3 = plt.axes([0.10, 0.15, 0.80, 0.03])

        val_max = self.r_pix.max()
        try:
            self._sr1 = Slider(axr1,
                               'r1',
                               0,
                               val_max - 1,
                               valinit=self.r1,
                               valfmt='%0.0f',
                               valstep=1)
            self._sr2 = Slider(axr2,
                               'r2',
                               1,
                               val_max,
                               valinit=self.r2,
                               valfmt='%0.0f',
                               valstep=1)
        except AttributeError:
            self._sr1 = Slider(axr1,
                               'r1',
                               0,
                               val_max - 1,
                               valinit=self.r1,
                               valfmt='%0.0f')
            self._sr2 = Slider(axr2,
                               'r2',
                               1,
                               val_max,
                               valinit=self.r2,
                               valfmt='%0.0f')
        self._sr3 = Slider(axr3,
                           'rc',
                           1,
                           val_max,
                           valinit=self.rc,
                           valfmt='%0.1f')

        # these don't seem to work
        #self._sr1.slider_max = self._sr2
        #self._sr2.slider_min = self._sr1

        self._sr1.on_changed(self._update_r_from_slider)
        self._sr2.on_changed(self._update_r_from_slider)
        self._sr3.on_changed(self._update_rc_from_slider)

        ax_nav.imshow(nav_im, norm=norm, cmap=cmap)
        ax_nav.set_xlabel('Detector X (pixels)')
        ax_nav.set_ylabel('Detector Y (pixels)')

        # line plot
        r_cntrst_max = int(np.abs(self.data_shape[-2:] - self.cyx).max())
        dw = 1
        rs = np.arange(dw, r_cntrst_max)

        r1, r2 = self.r1, self.r2
        sls = np.array([self.annular_slice(r - dw, r) for r in rs])
        self.r1, self.r2 = r1, r2

        self._contrast_y = np.std(sls, (1, 2))**2 / np.mean(sls, (1, 2))
        self._contrast_x = rs - dw / 2.0
        ax_cntrst.plot(self._contrast_x, self._contrast_y)
        ax_cntrst.minorticks_on()
        ax_cntrst.set_xlabel('Radius (pixels)')
        ax_cntrst.set_ylabel('Contrast (std^2/mean)')
        self._span = ax_cntrst.axvspan(self.r1,
                                       self.r2,
                                       color=[1, 0, 0, 0.1],
                                       ec='r')

        # wedges
        fc = [0, 0, 0, alpha]
        ec = 'r'
        from matplotlib.patches import Wedge
        self._rmax = val_max + 1
        self._w2 = Wedge(self.cyx[::-1],
                         self._rmax,
                         0,
                         360,
                         width=self._rmax - self.r2,
                         fc=fc,
                         ec=ec)
        self._w1 = Wedge(self.cyx[::-1],
                         self.r1,
                         0,
                         360,
                         width=self.r1,
                         fc=fc,
                         ec=ec)
        ax_nav.add_artist(self._w2)
        ax_nav.add_artist(self._w1)

        if widget is not None:
            docked = widget.setup_docking("Virtual Annular",
                                          "Bottom",
                                          figsize=(8.4, 4.8))
            fig = docked.get_fig()
            fig.clf()
            ax_im = fig.subplots(1, 1)
            self._f_im = fig
        else:
            self._f_im, ax_im = plt.subplots(1, 1)
        vmin, vmax = np.percentile(virtual_image, [self._pct, 100 - self._pct])
        self._vim = ax_im.imshow(virtual_image,
                                 cmap=cmap,
                                 vmin=vmin,
                                 vmax=vmax)
        if widget is not None:
            self._cb = fig.colorbar(self._vim)
        else:
            self._cb = plt.colorbar(self._vim)
        self._cb.set_label('Counts')
        ax_im.set_xlabel('Scan X (pixels)')
        ax_im.set_ylabel('Scan Y (pixels)')

        cid = self._f_nav.canvas.mpl_connect('scroll_event', self._onscroll)

        self._sr1.label.set_picker(True)
        self._sr2.label.set_picker(True)
        cid_pick = self._f_nav.canvas.mpl_connect('pick_event', self._onpick)