How to use the merlin.plots._base.AbstractPlot function in merlin

To help you get started, we’ve selected a few merlin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emanuega / MERlin / merlin / plots / testplots.py View on Github external
import numpy as np
from matplotlib import pyplot as plt

from merlin.plots._base import AbstractPlot
from merlin.plots._base import PlotMetadata


class TestPlot(AbstractPlot):

    def __init__(self, analysisTask):
        super().__init__(analysisTask)

    def get_required_tasks(self):
        return {'test_task': 'all'}

    def get_required_metadata(self):
        return [TestPlotMetadata]

    def _generate_plot(self, inputTasks, inputMetadata):
        fig = plt.figure(figsize=(10, 10))
        plt.plot(inputMetadata['testplots/TestPlotMetadata'].get_mean_values(),
                 'x')
        return fig
github emanuega / MERlin / merlin / plots / decodeplots.py View on Github external
'decodeplots/DecodedBarcodesMetadata']
        intensityX = decodeMetadata.intensityBins[:-1]
        shift = (intensityX[0] + intensityX[1]) / 2
        intensityX = [x + shift for x in intensityX]

        fig = plt.figure(figsize=(4, 4))
        plt.bar(intensityX, decodeMetadata.intensityCounts,
                width=2*shift)
        plt.xlabel('Mean intensity ($log_{10}$)')
        plt.ylabel('Count')
        plt.title('Intensity distribution for all barcodes')

        return fig


class DecodedBarcodeAbundancePlot(AbstractPlot):

    def __init__(self, analysisTask):
        super().__init__(analysisTask)

    def get_required_tasks(self):
        return {'decode_task': 'all'}

    def get_required_metadata(self):
        return [DecodedBarcodesMetadata]

    def _generate_plot(self, inputTasks, inputMetadata):
        decodeTask = inputTasks['decode_task']
        codebook = decodeTask.get_codebook()
        decodeMetadata = inputMetadata[
            'decodeplots/DecodedBarcodesMetadata']
github emanuega / MERlin / merlin / plots / __init__.py View on Github external
def get_available_plots() -> Set:
    """ Get all plots defined within any submodule of merlin.plots

    Returns: a set of references to the plots
    """
    plotSet = set()
    for importer, modname, ispkg in pkgutil.iter_modules(merlin.plots.__path__):
        currentModule = importlib.import_module(
            merlin.plots.__name__ + '.' + modname)
        for name, obj in inspect.getmembers(currentModule):
            if inspect.isclass(obj)\
                    and issubclass(obj, AbstractPlot)\
                    and obj != AbstractPlot:
                plotSet.add(obj)
    return plotSet
github emanuega / MERlin / merlin / plots / __init__.py View on Github external
def get_available_plots() -> Set:
    """ Get all plots defined within any submodule of merlin.plots

    Returns: a set of references to the plots
    """
    plotSet = set()
    for importer, modname, ispkg in pkgutil.iter_modules(merlin.plots.__path__):
        currentModule = importlib.import_module(
            merlin.plots.__name__ + '.' + modname)
        for name, obj in inspect.getmembers(currentModule):
            if inspect.isclass(obj)\
                    and issubclass(obj, AbstractPlot)\
                    and obj != AbstractPlot:
                plotSet.add(obj)
    return plotSet
github emanuega / MERlin / merlin / plots / filterplots.py View on Github external
plt.xlabel('Minimum distance')
            if i == 0:
                plt.title('Distribution of normalized blank fraction')

            plt.subplot(6, 4, 4*i+4)
            plt.imshow(blankFraction[:, :, i].T < threshold, extent=plotExtent,
                       origin='lower', aspect='auto', cmap='OrRd')
            plt.ylabel('Mean intensity (log10)')
            plt.xlabel('Minimum distance')
            if i == 0:
                plt.title('Accepted pixels')

        return fig


class AdaptiveFilterMisidentificationVsAbundance(AbstractPlot):

    def __init__(self, analysisTask):
        super().__init__(analysisTask)

    def get_required_tasks(self):
        return {'filter_task': filterbarcodes.AdaptiveFilterBarcodes}

    def get_required_metadata(self):
        return []

    def _generate_plot(self, inputTasks, inputMetadata):
        filterTask = inputTasks['filter_task']
        adaptiveTask = inputTasks['filter_task'].get_adaptive_thresholds()

        fig = plt.figure(figsize=(7, 7))
        sampleThresholds = np.arange(0.01, 0.5, 0.01)
github emanuega / MERlin / merlin / plots / filterplots.py View on Github external
spatialMetadata = inputMetadata[
            'filterplots/GlobalSpatialDistributionMetadata']
        plt.imshow(spatialMetadata.spatialBlankCounts,
                   extent=spatialMetadata.get_spatial_extents(),
                   cmap=plt.get_cmap('Greys'))
        plt.xlabel('X position (pixels)')
        plt.ylabel('Y position (pixels)')
        plt.title('Spatial distribution of blank barcodes')
        cbar = plt.colorbar(ax=ax)
        cbar.set_label('Barcode count', rotation=270)

        return fig


class BarcodeRadialDensityPlot(AbstractPlot):

    def __init__(self, analysisTask):
        super().__init__(analysisTask)

    def get_required_tasks(self):
        return {'filter_task': 'all'}

    def get_required_metadata(self):
        return [FOVSpatialDistributionMetadata]

    def _generate_plot(self, inputTasks, inputMetadata):
        fig = plt.figure(figsize=(7, 7))

        spatialMetadata = inputMetadata[
            'filterplots/FOVSpatialDistributionMetadata']
        singleColorCounts = spatialMetadata.singleColorCounts
github emanuega / MERlin / merlin / plots / filterplots.py View on Github external
spatialMetadata = inputMetadata[
            'filterplots/GlobalSpatialDistributionMetadata']
        plt.imshow(spatialMetadata.spatialCodingCounts,
                   extent=spatialMetadata.get_spatial_extents(),
                   cmap=plt.get_cmap('Greys'))
        plt.xlabel('X position (pixels)')
        plt.ylabel('Y position (pixels)')
        plt.title('Spatial distribution of coding barcodes')
        cbar = plt.colorbar(ax=ax)
        cbar.set_label('Barcode count', rotation=270)

        return fig


class BlankBarcodeSpatialDistribution(AbstractPlot):

    def __init__(self, analysisTask):
        super().__init__(analysisTask)

    def get_required_tasks(self):
        return {'filter_task': 'all',
                'global_align_task': 'all'}

    def get_required_metadata(self):
        return [GlobalSpatialDistributionMetadata]

    def _generate_plot(self, inputTasks, inputMetadata):
        fig = plt.figure(figsize=(7, 7))
        ax = fig.add_subplot(111)

        spatialMetadata = inputMetadata[
github emanuega / MERlin / merlin / plots / filterplots.py View on Github external
spatialMetadata = inputMetadata[
            'filterplots/FOVSpatialDistributionMetadata']
        plt.imshow(spatialMetadata.spatialBlankCounts,
                   extent=spatialMetadata.get_spatial_extents(),
                   cmap=plt.get_cmap('Greys'))
        plt.xlabel('X position (pixels)')
        plt.ylabel('Y position (pixels)')
        plt.title('Spatial distribution of blank barcodes within FOV')
        cbar = plt.colorbar(ax=ax)
        cbar.set_label('Barcode count', rotation=270)

        return fig


class FilteredBarcodeAbundancePlot(AbstractPlot):

    def __init__(self, analysisTask):
        super().__init__(analysisTask)

    def get_required_tasks(self):
        return {'filter_task': 'all'}

    def get_required_metadata(self):
        return [FilteredBarcodesMetadata]

    def _generate_plot(self, inputTasks, inputMetadata):
        filterTask = inputTasks['filter_task']
        codebook = filterTask.get_codebook()
        decodeMetadata = inputMetadata[
            'filterplots/FilteredBarcodesMetadata']
github emanuega / MERlin / merlin / plots / filterplots.py View on Github external
from matplotlib import pyplot as plt
import numpy as np
import pandas
from typing import List

from merlin.plots._base import AbstractPlot, PlotMetadata
from merlin.analysis import filterbarcodes


class CodingBarcodeSpatialDistribution(AbstractPlot):

    def __init__(self, analysisTask):
        super().__init__(analysisTask)

    def get_required_tasks(self):
        return {'filter_task': 'all',
                'global_align_task': 'all'}

    def get_required_metadata(self):
        return [GlobalSpatialDistributionMetadata]

    def _generate_plot(self, inputTasks, inputMetadata):
        fig = plt.figure(figsize=(7, 7))
        ax = fig.add_subplot(111)

        spatialMetadata = inputMetadata[
github emanuega / MERlin / merlin / plots / decodeplots.py View on Github external
.sort_values(by='counts', ascending=False)

        fig = plt.figure(figsize=(10, 5))
        plt.plot(np.arange(len(codingDF)), np.log10(codingDF['counts']),
                 'b.')
        plt.plot(np.arange(len(codingDF), len(countDF)),
                 np.log10(blankDF['counts']), 'r.')
        plt.xlabel('Sorted barcode index')
        plt.ylabel('Count (log10)')
        plt.title('Barcode abundances')
        plt.legend(['Coding', 'Blank'])

        return fig


class AreaIntensityViolinPlot(AbstractPlot):

    def __init__(self, analysisTask):
        super().__init__(analysisTask)

    def get_required_tasks(self):
        return {'decode_task': 'all'}

    def get_required_metadata(self):
        return [DecodedBarcodesMetadata]

    def _generate_plot(self, inputTasks, inputMetadata):
        decodeTask = inputTasks['decode_task']
        decodeMetadata = inputMetadata[
            'decodeplots/DecodedBarcodesMetadata']

        bins = decodeMetadata.intensityBins[:-1]