Beispiel #1
0
    def gene_panel(self, ax, feature):
        """
        Plots gene models on an Axes.

        Queries the database

        :param ax: matplotlib.Axes object
        :param feature: pybedtools.Interval

        """
        from gffutils.contrib.plotting import Gene

        extent = [feature.start, feature.stop]
        nearby_genes = self.db.region((feature.chrom, feature.start, feature.stop), featuretype="gene")
        ybase = 0
        ngenes = 0
        for nearby_gene in nearby_genes:
            ngenes += 1
            extent.extend([nearby_gene.start, nearby_gene.stop])
            gene_collection = Gene(
                self.db,
                nearby_gene,
                transcripts=["mRNA"],
                cds=["CDS"],
                utrs=["exon"],
                ybase=ybase,
                color="0.5",
                picker=5,
            )
            gene_collection.name = nearby_gene.id
            gene_collection.add_to_ax(ax)
            ybase += gene_collection.max_y

        xmin = min(extent)
        xmax = max(extent)
        ymax = ngenes

        # 1% padding seems to work well
        padding = (xmax - xmin) * 0.01
        ax.axis("tight")

        # add lines indicating extent of current feature
        vline_kwargs = dict(color="k", linestyle="--")
        ax.axvline(feature.start, **vline_kwargs)
        ax.axvline(feature.stop, **vline_kwargs)

        # Make a new feature to represent the region plus surrounding genes
        interval = pybedtools.create_interval_from_list(feature.fields)
        interval.start = xmin - padding
        interval.stop = xmax + padding
        interval.strand = "."
        return interval
Beispiel #2
0
    def gene_panel(self, ax, feature):
        """
        Plots gene models on an Axes.

        Queries the database

        :param ax: matplotlib.Axes object
        :param feature: pybedtools.Interval

        """
        from gffutils.contrib.plotting import Gene
        extent = [feature.start, feature.stop]
        nearby_genes = self.db.overlapping_features(feature.chrom,
                                                    feature.start,
                                                    feature.stop,
                                                    featuretype='gene')
        ybase = 0
        ngenes = 0
        for nearby_gene in nearby_genes:
            ngenes += 1
            extent.extend([nearby_gene.start, nearby_gene.stop])
            gene_collection = Gene(self.db,
                                   nearby_gene,
                                   transcripts=['mRNA'],
                                   cds=['CDS'],
                                   utrs=['exon'],
                                   ybase=ybase,
                                   color="0.5",
                                   picker=5)
            gene_collection.name = nearby_gene.id
            gene_collection.add_to_ax(ax)
            ybase += gene_collection.max_y

        xmin = min(extent)
        xmax = max(extent)
        ymax = ngenes

        # 1% padding seems to work well
        padding = (xmax - xmin) * 0.01
        ax.axis('tight')

        # add lines indicating extent of current feature
        vline_kwargs = dict(color='k', linestyle='--')
        ax.axvline(feature.start, **vline_kwargs)
        ax.axvline(feature.stop, **vline_kwargs)

        # Make a new feature to represent the region plus surrounding genes
        interval = pybedtools.create_interval_from_list(feature.fields)
        interval.start = xmin - padding
        interval.stop = xmax + padding
        interval.strand = '.'
        return interval
Beispiel #3
0
"""
Example to plot random genes
"""

import gffutils
from gffutils.contrib.plotting import Gene
from pylab import *

G = gffutils.FeatureDB('dmel-all-no-analysis-r5.43.gff.db')
gene = G.random_feature('gene')

gene_collection = Gene(
        G, 
        gene,
        utrs=['three_prime_UTR', 'five_prime_UTR'],
        color="0.5",
        edgecolor="None")

fig = figure()
ax = fig.add_subplot(111)
gene_collection.add_to_ax(ax)
ax.axis('tight')
show()
Beispiel #4
0
    def genes_panel(self, ax, feature):
        """
        Plots gene models on an Axes.

        Queries the database

        :param ax: matplotlib.Axes object
        :param feature: pybedtools.Interval

        """
        from gffutils.contrib.plotting import Gene

        extent = [feature.start, feature.stop]
        nearby_genes = self.db.region((feature.chrom, feature.start, feature.stop), featuretype="gene")
        ybase = 0
        ngenes = 0
        for nearby_gene in nearby_genes:
            # TODO: there should be a better way of identifying which gene is
            # the same as the feature requested.  Might need to expose an "ID"
            # kwarg.
            try:
                if nearby_gene["ID"][0] == feature["ID"]:
                    color = "0.2"
                else:
                    color = "0.5"
            except KeyError:
                color = "0.5"
            ngenes += 1
            extent.extend([nearby_gene.start, nearby_gene.stop])
            gene_collection = Gene(
                self.db, nearby_gene, transcripts=None, cds=["CDS"], utrs=["exon"], ybase=ybase, color=color
            )
            gene_collection.name = nearby_gene.id
            gene_collection.add_to_ax(ax)
            ybase += gene_collection.max_y

        xmin = min(extent)
        xmax = max(extent)
        ymax = ngenes

        # 1% padding seems to work well
        padding = (xmax - xmin) * 0.01
        ax.axis("tight")

        # add lines indicating extent of current feature
        # vline_kwargs = dict(color='k', linestyle='--')
        # ax.axvline(feature.start, **vline_kwargs)
        # ax.axvline(feature.stop, **vline_kwargs)

        # Make a new feature to represent the region plus surrounding genes
        interval = pybedtools.create_interval_from_list(feature.fields)
        interval.strand = "."
        for txt in ax.get_yticklabels():
            txt.set_visible(False)
        for tick in ax.get_yticklines():
            tick.set_visible(False)
        ax.set_ylabel("Genes")
        ax.spines["right"].set_color("None")
        ax.spines["left"].set_color("None")
        ax.spines["top"].set_color("None")
        ax.yaxis.set_ticks_position("none")
        ax.xaxis.set_ticks_position("bottom")
        ax.set_ylabel("Genes", rotation=0, horizontalalignment="right", verticalalignment="center")

        return interval
Beispiel #5
0
"""
Example to plot random genes
"""

import gffutils
from gffutils.contrib.plotting import Gene
from pylab import *

G = gffutils.FeatureDB('dmel-all-no-analysis-r5.43.gff.db')
gene = G.random_feature('gene')

gene_collection = Gene(G,
                       gene,
                       utrs=['three_prime_UTR', 'five_prime_UTR'],
                       color="0.5",
                       edgecolor="None")

fig = figure()
ax = fig.add_subplot(111)
gene_collection.add_to_ax(ax)
ax.axis('tight')
show()
Beispiel #6
0
    def genes_panel(self, ax, feature):
        """
        Plots gene models on an Axes.

        Queries the database

        :param ax: matplotlib.Axes object
        :param feature: pybedtools.Interval

        """
        from gffutils.contrib.plotting import Gene
        extent = [feature.start, feature.stop]
        nearby_genes = self.db.region(
            (feature.chrom, feature.start, feature.stop), featuretype='gene')
        ybase = 0
        ngenes = 0
        for nearby_gene in nearby_genes:
            # TODO: there should be a better way of identifying which gene is
            # the same as the feature requested.  Might need to expose an "ID"
            # kwarg.
            try:
                if nearby_gene['ID'][0] == feature['ID']:
                    color = '0.2'
                else:
                    color = '0.5'
            except KeyError:
                color = '0.5'
            ngenes += 1
            extent.extend([nearby_gene.start, nearby_gene.stop])
            gene_collection = Gene(self.db,
                                   nearby_gene,
                                   transcripts=None,
                                   cds=['CDS'],
                                   utrs=['exon'],
                                   ybase=ybase,
                                   color=color)
            gene_collection.name = nearby_gene.id
            gene_collection.add_to_ax(ax)
            ybase += gene_collection.max_y

        xmin = min(extent)
        xmax = max(extent)
        ymax = ngenes

        # 1% padding seems to work well
        padding = (xmax - xmin) * 0.01
        ax.axis('tight')

        # add lines indicating extent of current feature
        # vline_kwargs = dict(color='k', linestyle='--')
        # ax.axvline(feature.start, **vline_kwargs)
        # ax.axvline(feature.stop, **vline_kwargs)

        # Make a new feature to represent the region plus surrounding genes
        interval = pybedtools.create_interval_from_list(feature.fields)
        interval.strand = '.'
        for txt in ax.get_yticklabels():
            txt.set_visible(False)
        for tick in ax.get_yticklines():
            tick.set_visible(False)
        ax.set_ylabel('Genes')
        ax.spines['right'].set_color('None')
        ax.spines['left'].set_color('None')
        ax.spines['top'].set_color('None')
        ax.yaxis.set_ticks_position('none')
        ax.xaxis.set_ticks_position('bottom')
        ax.set_ylabel('Genes',
                      rotation=0,
                      horizontalalignment='right',
                      verticalalignment='center')

        return interval