def test_build_model(self): cmd = "python %smoderna.py -t %s -a %s -o %s > %s" % ( MODULE_PATH + os.sep, MINI_TEMPLATE, MINI_ALIGNMENT_FILE, self.tmp, self.tmp2) os.system(cmd) t = Template(self.tmp) self.assertEqual(t.get_sequence(), Sequence('ACUGUGAYUA[UACCU#PG'))
def test_fill_doublegap(self): """Should insert fragments into correct sites.""" # prepare model t = Template(DOUBLEGAP, 'file', 'A') m = RnaModel() for r in t: m.copy_residue(r) # insert first fragment struc = ModernaStructure('file', FRAGMENT1) f1 = ModernaFragment53(struc, anchor5=m['20'], anchor3=m['24'], \ new_sequence=Sequence('AUA'), keep=keep_first_last) m.insert_fragment(f1) resids = [r.identifier for r in m] expected_resids1 = [ '18', '19', '20', '21', '21A', '23', '24', '27', '28', '29', '30', '31', '32', '33', '34', '35' ] self.assertEqual(resids, expected_resids1) # insert second fragment struc = ModernaStructure('file', FRAGMENT2) f2 = ModernaFragment53(struc, anchor5=m['23'], anchor3=m['28'], \ new_sequence=Sequence('AUUA'), keep=keep_first_last) m.insert_fragment(f2) resids = [r.identifier for r in m] expected_resids2 = [ '18', '19', '20', '21', '21A', '23', '24', '24A', '24B', '27', '28', '29', '30', '31', '32', '33', '34', '35' ] self.assertEqual(resids, expected_resids2)
def setUp(self): self.s = ModernaStructure('file', MINI_TEMPLATE) self.t = Template(MINI_TEMPLATE, 'file') self.m = RnaModel(None, None, 'A', 'file', MINI_TEMPLATE) self.f = ModernaFragment53(self.s, anchor5=self.m['1'], anchor3=self.m['14']) self.struc = PDBParser().get_structure('test_struc', MINI_TEMPLATE)
def load_template(file_path, chain_name='A'): """*load_template(file_path, chain_name='A')* Loads a template structure from a PDB file. Produces a Template object that can be saved in a variable. Each template in ModeRNA has only one chain. By default, the chain with id 'A' is loaded. Another chain id can be specified optionally :Arguments: * path+filename of a PDB structure file * chain id (by default 'A') """ file_path = validate_filename(file_path) t = Template(file_path, 'file', chain_name) log.write_message('Template loaded from %s.\nTemplate sequence:\n%s\n' %(file_path, t.get_sequence().seq_with_modifications)) return t
def test_create_model_with_gaps(self): """Should create the model automatically.""" a = read_alignment(ALIGN_1B23_1QF6) t = Template(RNA_1B23, 'file', 'R') m = RnaModel(t, a) m.apply_alignment() m.insert_all_fragments() self.assertEqual( m.get_sequence().seq_with_modifications.replace('_', ''), 'GCCGAUAUAGCUCAGDDGGDAGAGCAGCGCAUUCGUEAUGCGAAG7UCGUAGGTPCGACUCCUAUUAUCGGCACCA' )
def test_model_with_hydro_template(self): """If the template contains hydrogens, modifications should be added.""" t = Template(RNA_HYDRO, 'file', 'B') a = read_alignment("""> 3tra_A.pdb Z73314.1/2358-2429 UPA > 1qru_B.pdb X55374.1/1-72 CAA """) m = RnaModel(t, a) m.create_model() self.assertEqual(m.get_sequence(), Sequence('UPA'))
def test_number_gap(self): """Builds model with numbering gap in the template.""" a = read_alignment("""> target CCGACCUUCGGCCACCUGACAGUCCUGUGCGGGAAACCGCACAGGACUGUCAACCAGGUAAUAUAACCACCGGGAAACGGUGGUUAUAUUACCUGGUACGCCUUGACGUGGGGGAAACCCCACGUCAAGGCGUGGUGGCCGAAGGUCGG > template CCGACCUUCGGCCACCUGACAGUCCUGUGCGG----CCGCACAGGACUGUCAACCAGGUAAUAUAACCACCGG----CGGUGGUUAUAUUACCUGGUACGCCUUGACGUGGGG----CCCCACGUCAAGGCGUGGUGGCCGAAGGUCGG """) t = Template(JMB_TEMPLATE, 'file') clean_structure(t) m = RnaModel(t, a) m.create_model() self.assertEqual(m.get_sequence().seq_without_breaks, a.target_seq)
def test_model_with_alignment_adjustment(self): """Introduces small corrections on alignment.""" a = read_alignment("""> target ACUGUGAYUA[UACCU#P-G > template with small errors. GCG7A----U.UAGCUCA_G """) t = Template(MINI_TEMPLATE, 'file') match_template_with_alignment(t, a) m = RnaModel(t, a) m.create_model() self.assertEqual(m.get_sequence(), Sequence("ACUGUGAYUA[UACCU#PG"))
def test_doublegap_model(self): """Should create a model filling two gaps""" a = read_alignment('''> target GGGAUAGUUCCAGABU#A > template GGGA-AG--CCAGABU#A ''') t = Template(DOUBLEGAP, 'file', 'A') m = RnaModel(t, a) m.apply_alignment() m.insert_all_fragments() m.fix_backbone() self.assertEqual(m.get_sequence(), Sequence('GGGAUAGUUCCAGABU#A'))
class RnaModelTests(TestCase): def setUp(self): self.a = read_alignment(MINI_ALIGNMENT) self.t = Template(MINI_TEMPLATE, seq=Sequence("GCGGAUUUALCUCAG")) self.m = RnaModel(self.t, self.a) self.seq_before = self.t.get_sequence() self.br = BaseRecognizer() def tearDown(self): self.a = None self.t = None self.m = None self.br = None self.seq_before = None
def test_oppositegap_model(self): """Should create a model with close gaps in the other respective sequence""" a = read_alignment('''> target GGGAGAGCRUUAG-BU#A > template GGGAGAGCR--AGABU#A ''') t = Template(OPPOSITEGAP, 'file', 'A') m = RnaModel(t, a) m.apply_alignment() m.insert_all_fragments() self.assertEqual( m.get_sequence().seq_with_modifications.replace('_', ''), 'GGGAGAGCRUUAGBU#A')
def test_model_with_close_gaps(self): t = Template('test_data/rna_structures/2du3_excerpt.ent', 'file', 'D') a = read_alignment('''> 1qru_B.pdb X55374.1/1-72 GCA-UUCCG > 2du3_D.pdb CUUUA-CCC ''') m = RnaModel() copy_some_residues([t['944'], t['946'], t['947']], m) lc = find_fragment(m, '946', '947', Sequence('U')) insert_fragment(m, lc[0]) lc = find_fragment(m, '944', '946', Sequence('')) insert_fragment(m, lc[0]) return #TODO: remove # generate model m = RnaModel(t, a) m.create_model()
def add_missing_3p(self): """ """ if self.alignment and len(self.recipe.add_fragment_3p) > 0: anchor5 = [r for r in self][-1] ap_list = self.recipe.add_fragment_3p[0] seq = Sequence(''.join( [ap.target_letter.short_abbrev for ap in ap_list])) all_resis = [r for r in Template(SINGLE_STRAND, 'file', 'A')] while len(all_resis) - 1 < len(ap_list): all_resis = self._elongate_strand(all_resis) frag_resis = all_resis[:len(ap_list) + 1] struc = ModernaStructure('residues', frag_resis) frag = ModernaFragment5(struc, anchor5=anchor5, new_sequence=seq, keep=keep_first) self.insert_fragment(frag)
def test_fill_gap_numbering(self): """Should insert fragment with correct numbering.""" t = Template(DOUBLEGAP, 'file', 'A') m = RnaModel() for r in t: m.copy_residue(r) struc = ModernaStructure('file', FRAGMENT1) f1 = ModernaFragment53(struc, anchor5=m['20'], anchor3=m['24'], new_sequence=Sequence('AUA')) m.insert_fragment(f1) resids = [r.identifier for r in m] expected_resids1 = [ '18', '19', '20', '20A', '20B', '20C', '24', '27', '28', '29', '30', '31', '32', '33', '34', '35' ] self.assertEqual(resids, expected_resids1)
def test_insert_modi_chain(self): cmd = "python %smoderna.py -s %s -c D -o %s -m m22G -p 38 > %s"%(MODULE_PATH+os.sep, RNA_HAIRPIN, self.tmp, self.tmp2) os.system(cmd) t = Template(self.tmp, template_chain_name='D') self.assertEqual(t.get_sequence(),Sequence('CUGCCUQUC/RGC'))
def test_insert_modification(self): cmd = "python %smoderna.py -s %s -o %s -m m22G -p 3 > %s"%(MODULE_PATH+os.sep, MINI_TEMPLATE, self.tmp, self.tmp2) os.system(cmd) t = Template(self.tmp) self.assertEqual(t.get_sequence(),Sequence('GCRGAUUUALCUCAG'))
def setUp(self): self.a = read_alignment(MINI_ALIGNMENT) self.t = Template(MINI_TEMPLATE, seq=Sequence("GCGGAUUUALCUCAG")) self.m = RnaModel(self.t, self.a) self.seq_before = self.t.get_sequence() self.br = BaseRecognizer()
def test_gap_optimization_example_2(self): t = Template('test_data/gaps/mini_1h4s_T_gap2.pdb', 'file', 'T') a = read_alignment('test_data/gaps/ali_gap2.fasta') m = RnaModel(t, a) m.create_model()
def test_insert_indel_quality_1(self): """Insert a fragment without strand break""" t = Template('test_data/gaps/mini_1h4s_T_gap2.pdb', 'file', 'T') a = read_alignment('test_data/gaps/ali_gap2.fasta') m = RnaModel(t, a) self.assertEqual(m.get_sequence().seq_with_modifications.find('_'), -1)
def setUp(self): self.a = read_alignment(MINI_ALIGNMENT) self.a2 = read_alignment(MINI_ALIGNMENT_WITH_UNK) self.t = Template(MINI_TEMPLATE, seq=Sequence("GCGGAUUUALCUCAG")) self.m = RnaModel()