示例#1
0
文件: __init__.py 项目: khasinski/csb
    def testDuplicateEntryError(self):
        c = Clans()
        e = ClansEntry(name='a', seq='A', coords=(1., 1., 1.))
        c.add_entry(e)
        c.add_entry(e)
        original_length = len(c)

        self.assertRaises(DuplicateEntryError, c._update_index)
        self.assertEqual(original_length, len(c))
    def testDuplicateEntryError(self):
        c = Clans()
        e = ClansEntry(name='a', seq='A', coords=(1., 1., 1.))
        c.add_entry(e)
        c.add_entry(e)
        original_length = len(c)

        self.assertRaises(DuplicateEntryError, c._update_index)
        self.assertEqual(original_length, len(c))
示例#3
0
文件: __init__.py 项目: khasinski/csb
    def testClansEntryAddingAndSorting(self):
        c = Clans()

        names = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        shuffled_names = ['g', 'f', 'b', 'd', 'e', 'c', 'a']

        for name in shuffled_names:
            c.add_entry(ClansEntry(name=name))

        c.sort()

        for i, e in enumerate(c):
            self.assertEqual(e.name, names[i])
示例#4
0
文件: __init__.py 项目: khasinski/csb
    def testClansEntrySortingWithCustomKeyFunction(self):
        c = Clans()

        sequences = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        shuffled_sequences = ['g', 'f', 'b', 'd', 'e', 'c', 'a']

        for i, sequence in enumerate(sequences):
            c.add_entry(ClansEntry(name=str(i), seq=shuffled_sequences[i]))

        custom_key_function = lambda e: e.seq  # sort by sequence instead of name
        c.sort(key=custom_key_function)

        for i, e in enumerate(c):
            self.assertEqual(e.seq, sequences[i])
示例#5
0
文件: __init__.py 项目: khasinski/csb
    def testRemovingClansEntries(self):
        c = Clans()

        sg = ClansSeqgroup()
        c.add_group(sg)

        e = ClansEntry()
        c.add_entry(e)

        sg.add(e)
        sg.remove(e)
        self.assertEqual(len(sg), 0)
        self.assertEqual(len(e.groups), 0)
        self.assertRaises(TypeError, sg.remove, 23)
        self.assertRaises(ValueError, sg.remove, e)
    def testClansInit(self):
        '''
        Test creating an empty L{Clans} instance.
        '''

        c = Clans()

        param_names = [
            'attfactor', 'attvalpow', 'avgfoldchange', 'blastpath',
            'cluster2d', 'colors', 'complexatt', 'cooling', 'currcool',
            'dampening', 'dotsize', 'formatdbpath', 'groupsize', 'maxmove',
            'minattract', 'ovalsize', 'pval', 'repfactor', 'repvalpow',
            'showinfo', 'usefoldchange', 'usescval', 'zoom'
        ]

        for param_name in param_names:
            self.assertTrue(hasattr(c.params, param_name))

        self.assertEqual(c.filename, None)
        self.assertEqual(c.rotmtx.shape, (3, 3))
        self.assertEqual(len(c.entries), 0)
        self.assertEqual(len(c.seqgroups), 0)

        self.assertTrue(isinstance(c.entries, ClansEntryCollection))
        self.assertTrue(isinstance(c.seqgroups, ClansSeqgroupCollection))
示例#7
0
文件: __init__.py 项目: khasinski/csb
    def testAddingAndRemovingSeqgroups(self):
        c = Clans()

        names = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        for i, name in enumerate(names):
            c.add_group(ClansSeqgroup(name=name))
            self.assertEqual(len(c.seqgroups), i + 1)

        removed = 0
        while len(c.seqgroups) != 0:
            c.remove_group(c.seqgroups[-1])
            removed += 1

        self.assertEqual(removed, len(names))
        self.assertEqual(len(c.seqgroups), 0)

        testGroup = ClansSeqgroup()
        self.assertRaises(TypeError, testGroup.add, 23)
        self.assertRaises(TypeError, testGroup.remove, 23)
示例#8
0
文件: __init__.py 项目: khasinski/csb
    def testAddingClansEntries(self):
        c = Clans()

        sg = ClansSeqgroup()
        c.add_group(sg)

        e = ClansEntry()
        c.add_entry(e)

        ## add entry to seqgroup
        sg.add(e)
        self.assertEqual(len(sg), 1)
        self.assertEqual(len(e.groups), 1)

        ## adding the same entry is forbidden
        self.assertRaises(ValueError, sg.add, e)

        ## adding s.th. else than a ClansEntry
        self.assertRaises(TypeError, sg.add, 23)
    def testClansEntryAddingAndSorting(self):
        c = Clans()

        names = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        shuffled_names = ['g', 'f', 'b', 'd', 'e', 'c', 'a']

        for name in shuffled_names:
            c.add_entry(ClansEntry(name=name))

        c.sort()

        for i, e in enumerate(c):
            self.assertEqual(e.name, names[i])
    def testClansEntrySortingWithCustomKeyFunction(self):
        c = Clans()

        sequences = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        shuffled_sequences = ['g', 'f', 'b', 'd', 'e', 'c', 'a']

        for i, sequence in enumerate(sequences):
            c.add_entry(ClansEntry(name=str(i), seq=shuffled_sequences[i]))

        custom_key_function = lambda e: e.seq  # sort by sequence instead of name
        c.sort(key=custom_key_function)

        for i, e in enumerate(c):
            self.assertEqual(e.seq, sequences[i])
    def testRemovingClansEntries(self):
        c = Clans()

        sg = ClansSeqgroup()
        c.add_group(sg)

        e = ClansEntry()
        c.add_entry(e)

        sg.add(e)
        sg.remove(e)
        self.assertEqual(len(sg), 0)
        self.assertEqual(len(e.groups), 0)
        self.assertRaises(TypeError, sg.remove, 23)
        self.assertRaises(ValueError, sg.remove, e)
    def testGetEntry(self):
        c = Clans()

        ## get non-existant entry from empty clans instance
        self.assertRaises(ValueError, c.get_entry, 'a')

        names = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        entries = [ClansEntry(name=name) for name in names]
        [c.add_entry(e) for e in entries]

        ## check whether entries fetched by name match those created
        for i, name in enumerate(names):
            self.assertEqual(c.get_entry(name), entries[i])

        ## check pedantic flag for duplicate name='a' entries
        c.add_entry(ClansEntry(name='a'))

        self.assertTrue(c.get_entry('a', False).name == 'a')

        self.assertRaises(DuplicateEntryNameError, c.get_entry, 'a', True)
    def testAddingClansEntries(self):
        c = Clans()

        sg = ClansSeqgroup()
        c.add_group(sg)

        e = ClansEntry()
        c.add_entry(e)

        ## add entry to seqgroup
        sg.add(e)
        self.assertEqual(len(sg), 1)
        self.assertEqual(len(e.groups), 1)

        ## adding the same entry is forbidden
        self.assertRaises(ValueError, sg.add, e)

        ## adding s.th. else than a ClansEntry
        self.assertRaises(TypeError, sg.add, 23)
    def testAddingAndRemovingSeqgroups(self):
        c = Clans()

        names = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        for i, name in enumerate(names):
            c.add_group(ClansSeqgroup(name=name))
            self.assertEqual(len(c.seqgroups), i + 1)

        removed = 0
        while len(c.seqgroups) != 0:
            c.remove_group(c.seqgroups[-1])
            removed += 1

        self.assertEqual(removed, len(names))
        self.assertEqual(len(c.seqgroups), 0)

        testGroup = ClansSeqgroup()
        self.assertRaises(TypeError, testGroup.add, 23)
        self.assertRaises(TypeError, testGroup.remove, 23)
示例#15
0
文件: __init__.py 项目: khasinski/csb
    def testGetEntry(self):
        c = Clans()

        ## get non-existant entry from empty clans instance
        self.assertRaises(ValueError, c.get_entry, 'a')

        names = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        entries = [ClansEntry(name=name) for name in names]
        [c.add_entry(e) for e in entries]

        ## check whether entries fetched by name match those created
        for i, name in enumerate(names):
            self.assertEqual(c.get_entry(name), entries[i])

        ## check pedantic flag for duplicate name='a' entries
        c.add_entry(ClansEntry(name='a'))

        self.assertTrue(c.get_entry('a', False).name == 'a')

        self.assertRaises(DuplicateEntryNameError, c.get_entry, 'a', True)
    def testAppendingSeqgroupsFromOtherInstance(self):
        source = Clans()
        source_entry1 = ClansEntry(name='X', seq='S')
        source_entry2 = ClansEntry(name='A', seq='S')
        source.add_entry(source_entry1)
        source.add_entry(source_entry2)

        seqgroup_names_to_transfer = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        for i, name in enumerate(seqgroup_names_to_transfer):
            sg = ClansSeqgroup(name=name)
            sg.add(source_entry1)
            source.add_group(sg)

        seqgroup_names_to_omit = ['x', 'y', 'z']
        for i, name in enumerate(seqgroup_names_to_omit):
            sg = ClansSeqgroup(name=name)
            sg.add(source_entry2)
            source.add_group(sg)

        target = Clans()

        # different seq is tolerated, only name identity is checked
        target_entry = ClansEntry(name='X', seq='Q')
        target.add_entry(target_entry)
        self.assertEqual(source[0].name, target[0].name)

        target.append_groups_from(source)

        ## each group should have exactly one member
        self.assertEqual(
            len(set([len(group.members) for group in target.seqgroups])), 1)

        ## all groups of seqgroup_names should have been transferred
        self.assertEqual(len(target.seqgroups),
                         len(seqgroup_names_to_transfer))
        self.assertEqual([group.name for group in target.seqgroups],
                         seqgroup_names_to_transfer)

        ## the ones from seqgroup_names_to_omit should not be there
        self.assertEqual(
            len([
                group.name for group in target.seqgroups
                if group.name in seqgroup_names_to_omit
            ]), 0)
示例#17
0
文件: __init__.py 项目: khasinski/csb
    def testAppendingSeqgroupsFromOtherInstance(self):
        source = Clans()
        source_entry1 = ClansEntry(name='X', seq='S')
        source_entry2 = ClansEntry(name='A', seq='S')
        source.add_entry(source_entry1)
        source.add_entry(source_entry2)

        seqgroup_names_to_transfer = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        for i, name in enumerate(seqgroup_names_to_transfer):
            sg = ClansSeqgroup(name=name)
            sg.add(source_entry1)
            source.add_group(sg)

        seqgroup_names_to_omit = ['x', 'y', 'z']
        for i, name in enumerate(seqgroup_names_to_omit):
            sg = ClansSeqgroup(name=name)
            sg.add(source_entry2)
            source.add_group(sg)

        target = Clans()

        # different seq is tolerated, only name identity is checked
        target_entry = ClansEntry(name='X', seq='Q')
        target.add_entry(target_entry)
        self.assertEqual(source[0].name, target[0].name)

        target.append_groups_from(source)

        ## each group should have exactly one member
        self.assertEqual(len(set([len(group.members) for group in target.seqgroups])), 1)

        ## all groups of seqgroup_names should have been transferred
        self.assertEqual(len(target.seqgroups), len(seqgroup_names_to_transfer))
        self.assertEqual([group.name for group in target.seqgroups], seqgroup_names_to_transfer)

        ## the ones from seqgroup_names_to_omit should not be there
        self.assertEqual(len([group.name for group in target.seqgroups
                                 if group.name in seqgroup_names_to_omit]), 0)