Пример #1
0
    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))
Пример #2
0
    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
    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
    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
    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)
Пример #6
0
    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
    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
    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)
Пример #9
0
    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])
Пример #10
0
    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])
Пример #11
0
    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)
Пример #12
0
    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)
Пример #13
0
    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)
Пример #14
0
    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
    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)
Пример #16
0
    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
    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)