示例#1
0
    def __call__(self,
                 labels=(2, 3),
                 filename='trajectory_plots.pdf',
                 exclude_labels=(0, )):

        cmap = unsupervised_cmap(self._nclusters)
        try:
            pdf = PdfPages(join(self._odir, filename))
            for title_, tracks in self._data.iteritems():
                title = '%s (%s)' % (self._position, title_.lower())

                # checking for binary matrix
                if np.unique(tracks).size == 2:
                    is_binary = True
                    labels_ = (1, )
                else:
                    is_binary = False
                    labels_ = labels

                # trajectory plots
                fig = plots.trajectories(tracks,
                                         labels_,
                                         title=title,
                                         cmap=cmap)
                pdf.savefig(fig)

                delchars = NameValidator.defaultdeletechars.copy()
                delchars.remove('-')
                validator = NameValidator(case_sensitive='lower',
                                          deletechars=delchars)
                fname = validator.validate(title)[0] + '.csv'
                np.savetxt(join(self._odir, fname),
                           tracks,
                           fmt='%d',
                           delimiter=',')

                # boxplots
                if not is_binary:
                    ylabel = "dwell time (%s)" % self.timeunit
                    xlabel = "class labels"

                    dwell_times = self.dwell_times(tracks)
                    fig1 = plots.dwell_boxplot(dwell_times,
                                               title,
                                               ylabel=ylabel,
                                               xlabel=xlabel,
                                               exclude_labels=exclude_labels,
                                               cmap=cmap)
                    fig2 = plots.barplot(dwell_times,
                                         title,
                                         xlabel=xlabel,
                                         ylabel=ylabel,
                                         exclude_labels=exclude_labels,
                                         cmap=cmap)
                    pdf.savefig(fig1)
                    pdf.savefig(fig2)
        finally:
            pdf.close()
示例#2
0
    def __call__(self, labels=(2,3), filename='trajectory_plots.pdf',
                 exclude_labels=(0, )):

        cmap = unsupervised_cmap(self._nclusters)
        try:
            pdf = PdfPages(join(self._odir, filename))
            for title_, tracks in self._data.iteritems():
                title = '%s (%s)' %(self._position, title_.lower())

                # checking for binary matrix
                if np.unique(tracks).size == 2:
                    is_binary = True
                    labels_ = (1, )
                else:
                    is_binary = False
                    labels_ = labels

                # trajectory plots
                fig = plots.trajectories(tracks, labels_, title=title, cmap=cmap)
                pdf.savefig(fig)

                delchars = NameValidator.defaultdeletechars.copy()
                delchars.remove('-')
                validator = NameValidator(case_sensitive='lower',
                                          deletechars=delchars)
                fname = validator.validate(title)[0]+'.csv'
                np.savetxt(join(self._odir, fname), tracks, fmt='%d',
                           delimiter=',')

                # boxplots
                if not is_binary:
                    ylabel = "dwell time (%s)" %self.timeunit
                    xlabel = "class labels"

                    dwell_times = self.dwell_times(tracks)
                    fig1 = plots.dwell_boxplot(dwell_times, title,
                                               ylabel=ylabel, xlabel=xlabel,
                                               exclude_labels=exclude_labels,
                                               cmap=cmap)
                    fig2 = plots.barplot(dwell_times, title, xlabel=xlabel,
                                         ylabel=ylabel,
                                         exclude_labels=exclude_labels,
                                         cmap=cmap)
                    pdf.savefig(fig1)
                    pdf.savefig(fig2)
        finally:
            pdf.close()
示例#3
0
    def overview(self, filename, figsize=(25, 20)):
        pdf = PdfPages(filename)
        sp_props = dict(top=0.95, bottom=0.05, hspace=0.2, wspace=0.2,
                        left=0.03, right=0.97)
        try:
            # nrows, _ =  5, len(self.data)
            fig, axarr = plt.subplots(nrows=5, ncols=6, figsize=figsize)
            fig.subplots_adjust(**sp_props)
            for j, name in enumerate(sorted(self.data.keys())):
                data = self.data[name]
                i = j%6
                if not i and j:
                    pdf.savefig(fig)
                    fig, axarr = plt.subplots(nrows=5, ncols=6, dpi=300,
                                              figsize=figsize)
                    fig.subplots_adjust(**sp_props)

                if data is None:
                    self._empty_figure(axarr, name, i, nrows=5)
                    continue

                title = '%s, (%d tracks)' %(name, data.ntracks)
                # hmm network
                clcol = dict([(k, self.classdef.hexcolors[v])
                             for k, v in self.classdef.class_names.iteritems()
                              if k in data.states])

                plots.hmm_network(data.transmat, clcol, title=title,
                                  axes=axarr[0][i])

                # trajectories
                plots.trajectories(data.labels,
                                   labels=self.ecopts.sorting_sequence,
                                   cmap=self.classdef.colormap,
                                   norm=self.classdef.normalize,
                                   axes = axarr[1][i])

                plots.trajectories(data.hmm_labels,
                                   labels=self.ecopts.sorting_sequence,
                                   cmap=self.classdef.colormap,
                                   norm=self.classdef.normalize,
                                   axes = axarr[2][i])

                # dwell box/barplots
                ylabel = "dwell time (%s)" %self.ecopts.timeunit
                xlabel = "class labels"

                plots.dwell_boxplot(data.dwell_times,
                                    ylabel=ylabel,
                                    xlabel=xlabel,
                                    cmap=self.classdef.colormap,
                                    ymax=self.ecopts.tmax,
                                    axes=axarr[3][i])


                plots.barplot(data.dwell_times, xlabel=xlabel, ylabel=ylabel,
                              cmap=self.classdef.colormap,
                              ymax=self.ecopts.tmax,
                              axes=axarr[4][i])
            self._frame_off(axarr, i, 5)
            pdf.savefig(fig)
        finally:
            pdf.close()
示例#4
0
    def overview(self, filename, figsize=(25, 20)):
        pdf = PdfPages(filename)
        sp_props = dict(top=0.95,
                        bottom=0.05,
                        hspace=0.2,
                        wspace=0.2,
                        left=0.03,
                        right=0.97)
        try:
            # nrows, _ =  5, len(self.data)
            fig, axarr = plt.subplots(nrows=5, ncols=6, figsize=figsize)
            fig.subplots_adjust(**sp_props)
            for j, name in enumerate(sorted(self.data.keys())):
                data = self.data[name]
                i = j % 6
                if not i and j:
                    pdf.savefig(fig)
                    fig, axarr = plt.subplots(nrows=5,
                                              ncols=6,
                                              dpi=300,
                                              figsize=figsize)
                    fig.subplots_adjust(**sp_props)

                if data is None:
                    self._empty_figure(axarr, name, i, nrows=5)
                    continue

                title = '%s, (%d tracks)' % (name, data.ntracks)
                # hmm network
                clcol = dict([
                    (k, self.classdef.hexcolors[v])
                    for k, v in self.classdef.class_names.iteritems()
                    if k in data.states
                ])

                plots.hmm_network(data.transmat,
                                  clcol,
                                  title=title,
                                  axes=axarr[0][i])

                # trajectories
                plots.trajectories(data.labels,
                                   labels=self.ecopts.sorting_sequence,
                                   cmap=self.classdef.colormap,
                                   norm=self.classdef.normalize,
                                   axes=axarr[1][i],
                                   stepwidth=data.stepwidth)

                plots.trajectories(data.hmm_labels,
                                   labels=self.ecopts.sorting_sequence,
                                   cmap=self.classdef.colormap,
                                   norm=self.classdef.normalize,
                                   axes=axarr[2][i],
                                   stepwidth=data.stepwidth)

                # dwell box/barplots
                ylabel = "dwell time (%s)" % self.ecopts.timeunit
                xlabel = "class labels"

                plots.dwell_boxplot(data.dwell_times,
                                    ylabel=ylabel,
                                    xlabel=xlabel,
                                    cmap=self.classdef.colormap,
                                    ymax=self.ecopts.tmax,
                                    axes=axarr[3][i])

                plots.barplot(data.dwell_times,
                              xlabel=xlabel,
                              ylabel=ylabel,
                              cmap=self.classdef.colormap,
                              ymax=self.ecopts.tmax,
                              axes=axarr[4][i])
            self._frame_off(axarr, i, 5)
            pdf.savefig(fig)
        finally:
            pdf.close()