def test_bit_ops(self): """PackedBases xor and bitcount should give correct # differences""" p = PackedBases('UCAGU') q = PackedBases('CAGGA') self.assertEqual((p ^ q).bitcount(), 5) r = PackedBases('CAAG') self.assertEqual((r ^ q).bitcount(), 1)
def test_str(self): """PackedBases str should respect RNA/DNA""" p = PackedBases('UCAGu') self.assertEqual(str(p), 'UCAGU') p.Rna = False self.assertEqual(str(p), 'TCAGT') p.Rna = True self.assertEqual(str(p), 'UCAGU') q = PackedBases('ucagu', Rna=False) self.assertEqual(str(q), 'TCAGT') p = PackedBases('T'*100, Rna=False) self.assertEqual(str(p), 'T'*100) p.Rna = True self.assertEqual(str(p), 'U'*100)
def test_str(self): """PackedBases str should respect RNA/DNA""" p = PackedBases("UCAGu") self.assertEqual(str(p), "UCAGU") p.Rna = False self.assertEqual(str(p), "TCAGT") p.Rna = True self.assertEqual(str(p), "UCAGU") q = PackedBases("ucagu", Rna=False) self.assertEqual(str(q), "TCAGT") p = PackedBases("T" * 100, Rna=False) self.assertEqual(str(p), "T" * 100) p.Rna = True self.assertEqual(str(p), "U" * 100)
def test_init(self): """PackedBases init should allow sequence recovery""" p = PackedBases() self.assertEqual(str(p), '') self.assertEqual(len(p), 0) p = PackedBases('uCaGGCAU') self.assertEqual(len(p), 16) self.assertEqual(str(p), 'UCAGGCAU') p = PackedBases('aaaAaaAaa') self.assertEqual(str(p), 'AAAAAAAAA') self.assertEqual(len(p), 18) for base in 'ucagUCAGtT': p = PackedBases(base) self.assertEqual(len(p), 2) self.assertEqual(str(p), base.upper().replace('T', 'U'))
def __call__(self, mismatches): """Consolidates ModuleInstances in KFinder.ModuleInstances into Modules. - mismatches accounts for the difference between two ModuleInstances in terms of purine vs pyrimidine or strong vs weak bonding. """ #New list to hold consolidated modules consolidated_list = [] #Bind module_dict and module_order locally module_dict = self.KFinder.ModuleDict module_order = self.KFinder.ModuleOrder #Check that dict is not empty if module_dict: #Iterate through modules in order for pattern in module_order: #Create a Bitvector representation of pattern pat_vec = PackedBases(pattern) added = False #Iterate through consolidated_list for curr_module, curr_vec in consolidated_list: #If pat_vec and curr_vec are in the allowed mismatch cutoff if sum(pat_vec ^ curr_vec) <= mismatches: #Add module information to curr_module curr_module.update(module_dict[pattern]) added = True break if not added: #Add new module to consolidated list consolidated_list.append([module_dict[pattern], pat_vec]) #self.Modules should have only the list of modules self.Modules = [i[0] for i in consolidated_list] for mod in self.Modules: mod.Template = str(mod)
def test_str(self): """PackedBases str should respect RNA/DNA""" p = PackedBases('UCAGu') self.assertEqual(str(p), 'UCAGU') p.Rna = False self.assertEqual(str(p), 'TCAGT') p.Rna = True self.assertEqual(str(p), 'UCAGU') q = PackedBases('ucagu', Rna=False) self.assertEqual(str(q), 'TCAGT') p = PackedBases('T' * 100, Rna=False) self.assertEqual(str(p), 'T' * 100) p.Rna = True self.assertEqual(str(p), 'U' * 100)