Exemplo n.º 1
0
 def testNotTooManyFeaturesByDefault(self):
     """
     A new instance of L{_FeatureAdder} must be marked on creation as not
     having too many features to plot.
     """
     featureAdder = _FeatureAdder()
     self.assertFalse(featureAdder.tooManyFeaturesToPlot)
Exemplo n.º 2
0
    def testTooManyFeatures(self):
        """
        If the sequence fetcher used by a L{_FeatureAdder} returns too many
        features, the C{text} and C{axis} methods on the figure must be called
        correctly and the C{add} call must return the sequences.
        """

        def fetcher(title, db="database"):
            feature = SeqFeature(type="site", qualifiers={"a": ["b"]})
            return SeqRecord(None, features=[feature] * 100)

        featureAdder = _FeatureAdder()
        featureAdder.WANTED_TYPES = ("site",)
        fig = plt.subplot(111)
        fig.text = MagicMock()
        fig.axis = MagicMock()
        result = featureAdder.add(fig, "title", 0, 300, identity, sequenceFetcher=fetcher)
        fig.text.assert_called_with(
            0.5,
            0.5,
            "Too many features to plot",
            horizontalalignment="center",
            verticalalignment="center",
            transform=ANY,
            fontsize=20,
        )
        fig.axis.assert_called_with([0, 300, -1, 1])
        self.assertTrue(isinstance(result, _FeatureList))
        self.assertEqual(100, len(result))
Exemplo n.º 3
0
    def testNoFeatures(self):
        """
        If the sequence fetcher used by a L{_FeatureAdder} returns no features
        the C{text} and C{axis} methods on the fig must both be called
        correctly and the C{add} method must return C{[]}.
        """
        def fetcher(title, db='database'):
            return SeqRecord(None)

        featureAdder = _FeatureAdder()
        featureAdder.WANTED_TYPES = ('site', )
        fig = plt.subplot(111, label=_randomLabel())
        fig.text = MagicMock()
        fig.axis = MagicMock()
        result = featureAdder.add(fig,
                                  'title',
                                  0,
                                  300,
                                  sequenceFetcher=fetcher)
        fig.text.assert_called_with(0.5,
                                    0.5,
                                    'No features found',
                                    horizontalalignment='center',
                                    verticalalignment='center',
                                    transform=ANY,
                                    fontsize=20)
        fig.axis.assert_called_with([0, 300, -1, 1])
        self.assertEqual([], result)
Exemplo n.º 4
0
 def testNotTooManyFeaturesByDefault(self):
     """
     A new instance of L{_FeatureAdder} must be marked on creation as not
     having too many features to plot.
     """
     featureAdder = _FeatureAdder()
     self.assertFalse(featureAdder.tooManyFeaturesToPlot)
Exemplo n.º 5
0
    def testOneFeatureRaisesNotImplementedError(self):
        """
        If the sequence fetcher used by a L{_FeatureAdder} returns a feature,
        the C{add} method must raise C{NotImplementedError} because the
        C{_displayFeatures} method is not implemented.
        """
        def fetcher(title, db='database'):
            location = FeatureLocation(100, 200)
            subfeature = SeqFeature(type='region',
                                    qualifiers={'a': ['b']},
                                    location=location)
            feature = SeqFeature(type='site',
                                 qualifiers={'a': ['b']},
                                 sub_features=[subfeature],
                                 location=location)
            return SeqRecord(None, features=[feature])

        featureAdder = _FeatureAdder()
        featureAdder.WANTED_TYPES = ('site', )
        fig = plt.subplot(111)
        self.assertRaises(NotImplementedError,
                          featureAdder.add,
                          fig,
                          'title',
                          0,
                          300,
                          sequenceFetcher=fetcher)
Exemplo n.º 6
0
    def testTooManyFeatures(self):
        """
        If the sequence fetcher used by a L{_FeatureAdder} returns too many
        features, the C{text} and C{axis} methods on the figure must be called
        correctly and the C{add} call must return the sequences.
        """
        def fetcher(title, db='database'):
            location = FeatureLocation(100, 200)
            feature = SeqFeature(type='site', qualifiers={'a': ['b']},
                                 location=location)
            return SeqRecord(None, features=[feature] * 100)

        featureAdder = _FeatureAdder()
        featureAdder.WANTED_TYPES = ('site',)
        fig = plt.subplot(111)
        fig.text = MagicMock()
        fig.axis = MagicMock()
        result = featureAdder.add(fig, 'title', 0, 300,
                                  sequenceFetcher=fetcher)
        fig.text.assert_called_with(0.5, 0.5,
                                    'Too many features to plot',
                                    horizontalalignment='center',
                                    verticalalignment='center',
                                    transform=ANY, fontsize=20)
        fig.axis.assert_called_with([0, 300, -1, 1])
        self.assertTrue(isinstance(result, FeatureList))
        self.assertEqual(100, len(result))
Exemplo n.º 7
0
    def testTooManyFeatures(self):
        """
        If the sequence fetcher used by a L{_FeatureAdder} returns too many
        features, the C{text} and C{axis} methods on the figure must be called
        correctly and the C{add} call must return the sequences.
        """
        def fetcher(title, db='database'):
            location = FeatureLocation(100, 200)
            feature = SeqFeature(type='site',
                                 qualifiers={'a': ['b']},
                                 location=location)
            return SeqRecord(None, features=[feature] * 100)

        featureAdder = _FeatureAdder()
        featureAdder.WANTED_TYPES = ('site', )
        fig = plt.subplot(111, label=_randomLabel())
        fig.text = MagicMock()
        fig.axis = MagicMock()
        result = featureAdder.add(fig,
                                  'title',
                                  0,
                                  300,
                                  sequenceFetcher=fetcher)
        fig.text.assert_called_with(0.5,
                                    0.5,
                                    'Too many features to plot',
                                    horizontalalignment='center',
                                    verticalalignment='center',
                                    transform=ANY,
                                    fontsize=20)
        fig.axis.assert_called_with([0, 300, -1, 1])
        self.assertTrue(isinstance(result, FeatureList))
        self.assertEqual(100, len(result))
Exemplo n.º 8
0
 def testYTicks(self):
     """
     A L{_FeatureAdder} must set the title of its figure.
     """
     fetcher = lambda title, db='database': None
     featureAdder = _FeatureAdder()
     fig = plt.subplot(111)
     fig.set_yticks = MagicMock()
     featureAdder.add(fig, 'title', 0, 100, sequenceFetcher=fetcher)
     fig.set_yticks.assert_called_with([])
Exemplo n.º 9
0
 def testTitle(self):
     """
     A L{_FeatureAdder} must set the title of its figure.
     """
     fetcher = lambda title, db="database": None
     featureAdder = _FeatureAdder()
     fig = plt.subplot(111)
     fig.set_title = MagicMock()
     featureAdder.add(fig, "title", 0, 100, identity, sequenceFetcher=fetcher)
     fig.set_title.assert_called_with("Target sequence features", fontsize=16)
Exemplo n.º 10
0
 def testYTicks(self):
     """
     A L{_FeatureAdder} must set the title of its figure.
     """
     fetcher = lambda title, db="database": None
     featureAdder = _FeatureAdder()
     fig = plt.subplot(111)
     fig.set_yticks = MagicMock()
     featureAdder.add(fig, "title", 0, 100, identity, sequenceFetcher=fetcher)
     fig.set_yticks.assert_called_with([])
Exemplo n.º 11
0
 def testTitle(self):
     """
     A L{_FeatureAdder} must set the title of its figure.
     """
     fetcher = lambda title, db='database': None
     featureAdder = _FeatureAdder()
     fig = plt.subplot(111)
     fig.set_title = MagicMock()
     featureAdder.add(fig, 'title', 0, 100, sequenceFetcher=fetcher)
     fig.set_title.assert_called_with('Target sequence features',
                                      fontsize=16)
Exemplo n.º 12
0
    def testYTicks(self):
        """
        A L{_FeatureAdder} must set the title of its figure.
        """
        def fetcher(title, db='database'):
            return None

        featureAdder = _FeatureAdder()
        fig = plt.subplot(111)
        fig.set_yticks = MagicMock()
        featureAdder.add(fig, 'title', 0, 100, sequenceFetcher=fetcher)
        fig.set_yticks.assert_called_with([])
Exemplo n.º 13
0
    def testYTicks(self):
        """
        A L{_FeatureAdder} must set the title of its figure.
        """
        def fetcher(title, db='database'):
            return None

        featureAdder = _FeatureAdder()
        fig = plt.subplot(111, label=_randomLabel())
        fig.set_yticks = MagicMock()
        featureAdder.add(fig, 'title', 0, 100, sequenceFetcher=fetcher)
        fig.set_yticks.assert_called_with([])
Exemplo n.º 14
0
    def testTitle(self):
        """
        A L{_FeatureAdder} must set the title of its figure.
        """
        def fetcher(title, db='database'):
            return None

        featureAdder = _FeatureAdder()
        fig = plt.subplot(111)
        fig.set_title = MagicMock()
        featureAdder.add(fig, 'title', 0, 100, sequenceFetcher=fetcher)
        fig.set_title.assert_called_with('Target sequence features',
                                         fontsize=16)
Exemplo n.º 15
0
 def testOffline(self):
     """
     If the sequence fetcher used by a L{_FeatureAdder} returns C{None},
     the C{add} method of the L{_FeatureAdder} must return C{None}. The
     C{text} and C{axis} methods on the fig must both be called correctly.
     """
     fetcher = lambda title, db="database": None
     featureAdder = _FeatureAdder()
     fig = plt.subplot(111)
     fig.text = MagicMock()
     fig.axis = MagicMock()
     featureAdder.add(fig, "title", 0, 300, identity, sequenceFetcher=fetcher)
     fig.text.assert_called_with(100, 0, "You (or Genbank) appear to be offline.", fontsize=20)
     fig.axis.assert_called_with([0, 300, -1, 1])
Exemplo n.º 16
0
 def testOffline(self):
     """
     If the sequence fetcher used by a L{_FeatureAdder} returns C{None},
     the C{add} method of the L{_FeatureAdder} must return C{None}. The
     C{text} and C{axis} methods on the fig must both be called correctly.
     """
     fetcher = lambda title, db='database': None
     featureAdder = _FeatureAdder()
     fig = plt.subplot(111)
     fig.text = MagicMock()
     fig.axis = MagicMock()
     featureAdder.add(fig, 'title', 0, 300, sequenceFetcher=fetcher)
     fig.text.assert_called_with(100,
                                 0,
                                 'You (or Genbank) appear to be offline.',
                                 fontsize=20)
     fig.axis.assert_called_with([0, 300, -1, 1])
Exemplo n.º 17
0
    def testOneFeatureRaisesNotImplementedError(self):
        """
        If the sequence fetcher used by a L{_FeatureAdder} returns a feature,
        the C{add} method must raise C{NotImplementedError} because the
        C{_displayFeatures} method is not implemented.
        """
        def fetcher(title, db='database'):
            location = FeatureLocation(100, 200)
            feature = SeqFeature(type='site', qualifiers={'a': ['b']},
                                 location=location)
            return SeqRecord(None, features=[feature])

        featureAdder = _FeatureAdder()
        featureAdder.WANTED_TYPES = ('site',)
        fig = plt.subplot(111)
        self.assertRaises(NotImplementedError, featureAdder.add, fig, 'title',
                          0, 300, sequenceFetcher=fetcher)
Exemplo n.º 18
0
    def testOneFeatureRaisesNotImplementedError(self):
        """
        If the sequence fetcher used by a L{_FeatureAdder} returns a feature,
        the C{add} method must raise C{NotImplementedError} because the
        C{_displayFeatures} method is not implemented.
        """

        def fetcher(title, db="database"):
            subfeature = SeqFeature(type="region", qualifiers={"a": ["b"]})
            feature = SeqFeature(type="site", qualifiers={"a": ["b"]}, sub_features=[subfeature])
            return SeqRecord(None, features=[feature])

        featureAdder = _FeatureAdder()
        featureAdder.WANTED_TYPES = ("site",)
        fig = plt.subplot(111)
        self.assertRaises(
            NotImplementedError, featureAdder.add, fig, "title", 0, 300, identity, sequenceFetcher=fetcher
        )
Exemplo n.º 19
0
 def testNoFeatures(self):
     """
     If the sequence fetcher used by a L{_FeatureAdder} returns no features
     the C{text} and C{axis} methods on the fig must both be called
     correctly and the C{add} method must return C{[]}.
     """
     fetcher = lambda title, db='database': SeqRecord(None)
     featureAdder = _FeatureAdder()
     featureAdder.WANTED_TYPES = ('site',)
     fig = plt.subplot(111)
     fig.text = MagicMock()
     fig.axis = MagicMock()
     result = featureAdder.add(fig, 'title', 0, 300,
                               sequenceFetcher=fetcher)
     fig.text.assert_called_with(0.5, 0.5,
                                 'No features found',
                                 horizontalalignment='center',
                                 verticalalignment='center',
                                 transform=ANY, fontsize=20)
     fig.axis.assert_called_with([0, 300, -1, 1])
     self.assertEqual([], result)