def testNoFeaturesLength(self): """ If the sequence fetcher returns a record with no features, the L{_FeatureList} instance must have length zero. """ fetcher = lambda title, db="database": SeqRecord(None) featureList = _FeatureList("title", "database", set(), identity, sequenceFetcher=fetcher) self.assertEqual(0, len(featureList))
def testNotOffline(self): """ If the sequence fetcher does not return C{None} we must be marked as being online. """ fetcher = lambda title, db="database": SeqRecord(None) featureList = _FeatureList("title", "database", set(), identity, sequenceFetcher=fetcher) self.assertEqual(False, featureList.offline)
def testOfflineLength(self): """ If the sequence fetcher indicates we're offline, the feature list must have length zero. """ fetcher = lambda title, db="database": None featureList = _FeatureList("title", "database", set(), identity, sequenceFetcher=fetcher) self.assertEqual(0, len(featureList))
def testOffline(self): """ If the sequence fetcher returns C{None} we must be marked as being offline. """ fetcher = lambda title, db="database": None featureList = _FeatureList("title", "database", set(), identity, sequenceFetcher=fetcher) self.assertEqual(True, featureList.offline)
def testNotSubfeature(self): """ If the sequence fetcher returns a record with a feature that is not a subfeature, it must not be marked as a subfeature. """ def fetcher(title, db="database"): feature = SeqFeature(type="site", qualifiers={"a": ["b"]}) return SeqRecord(None, features=[feature]) featureList = _FeatureList("title", "database", set(["site"]), identity, sequenceFetcher=fetcher) self.assertFalse(featureList[0].subfeature)
def testFetcherValueError(self): """ If the sequence fetcher throws a C{ValueError}, the feature list must have length zero and should not be marked as being offline. """ def fetcher(title, db): raise ValueError() featureList = _FeatureList("title", "database", set(), identity, sequenceFetcher=fetcher) self.assertEqual(0, len(featureList)) self.assertEqual(False, featureList.offline)
def testNoQualifiersLength(self): """ If the sequence fetcher returns a record with two features but neither of them has any qualifiers, the L{_FeatureList} instance must still include both features. """ def fetcher(title, db="database"): feature = SeqFeature(type="site") return SeqRecord(None, features=[feature, feature]) featureList = _FeatureList("title", "database", set(["site"]), identity, sequenceFetcher=fetcher) self.assertEqual(2, len(featureList))
def testWantedTypeLength(self): """ If the sequence fetcher returns a record with two features but only one of them has a wanted type ('site'), the L{_FeatureList} instance must have length one. """ def fetcher(title, db="database"): feature1 = SeqFeature(type="region") feature2 = SeqFeature(type="site", qualifiers={"a": ["b"]}) return SeqRecord(None, features=[feature1, feature2]) featureList = _FeatureList("title", "database", set(["site"]), identity, sequenceFetcher=fetcher) self.assertEqual(1, len(featureList))
def testSubfeatures(self): """ If the sequence fetcher returns a record with a feature that has a subfeature, the L{_FeatureList} instance must have length two and the second feature in the list must be a subfeature. """ def fetcher(title, db="database"): subfeature = SeqFeature(type="site", qualifiers={"a": ["b"]}) feature = SeqFeature(type="site", qualifiers={"a": ["b"]}, sub_features=[subfeature]) return SeqRecord(None, features=[feature]) featureList = _FeatureList("title", "database", set(["site"]), identity, sequenceFetcher=fetcher) self.assertEqual(2, len(featureList)) self.assertTrue(featureList[1].subfeature)
def testColors(self): """ If the sequence fetcher returns a record with 3 features, each must be assigned a correct color. """ def fetcher(title, db="database"): feature = SeqFeature(type="site", qualifiers={"a": ["b"]}) return SeqRecord(None, features=[feature] * 3) featureList = _FeatureList("title", "database", set(["site"]), identity, sequenceFetcher=fetcher) colormap = plt.cm.coolwarm colors = [colormap(i) for i in np.linspace(0.0, 0.99, 3)] for i in range(3): self.assertEqual(colors[i], featureList[i].color)
def testSubfeaturesWithoutParentFeature(self): """ If the sequence fetcher returns a record with a feature that has a subfeature, and the subfeature is wanted but the parent feature is not, the L{_FeatureList} instance must have length one and the feature in the list must be a subfeature. """ 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]) featureList = _FeatureList("title", "database", set(["region"]), identity, sequenceFetcher=fetcher) self.assertEqual(1, len(featureList)) self.assertTrue(featureList[0].subfeature)