def _parse(self): tmp_ct = [] defline = ">" for line in open(self.ct_path): if line.startswith('#'): defline += line.strip() + '|' else: tmp_ct.append(line) defline = defline.replace('\n', '').replace('#', '') # just one entry per file result = ct_parser(tmp_ct)[0] sequence = result[0] # IMPORTANT! # ct_parser starts numbering of base pairs from 0, not from 1, as # elsewhere in nucleic.secstruc. To make things consistent, here # we'll add 1 to each index in base pairs list! result_1 = [(pair[0] + 1, pair[1] + 1) for pair in result[1]] pairs = BasePairs(result_1) if self._is_valid_sequence(sequence): sequence = Sequence(sequence.upper()).seq_without_modifications # Second check, because ModeRNA might also mix a bit at this stage # including for exampel X in sequences without modifications! if self._is_valid_sequence(sequence): try: vienna = pairs.toVienna(len(sequence)) except PseudoknotTokensError: vienna = None finally: return defline, sequence, vienna, pairs return None, None, None, None
def test_gap_structure2_model(self): """ Should create model with no gaps. Template: 1H3E B (whole structure) Target: 1WZ2 C (whole structure) """ t = load_template('test_data/gaps/1h3e_B.pdb', 'B') print examine_structure(t) print t['16'] a = load_alignment('test_data/gaps/structure2_alignment.fasta') print a m = create_model(t, a) os.system('mkdir -p test_data/gaps/structure2_candidates1') old_candidates = os.listdir('test_data/gaps/structure2_candidates1') for x in old_candidates: if x.startswith('model'): os.remove('test_data/gaps/structure2_candidates1/' + x) print m write_model( m, 'test_data/gaps/structure2_candidates1/model_structure2.pdb') self.assertEqual( m.get_sequence(), Sequence( 'GCGGGGGUUGCCGAGCCUGGUCAAAGGCGGGGGACUCAAGAUCCCCUCCCGUA.GGGUUCCGGGGUUCGAAUCCCCGCCCCCGCACCA' ))
def test_gap3_model(self): """ Should create model with no gaps. Template: 1QF6 B (fragment) Target: 1B23 R (fragment) """ t = load_template('test_data/gaps/gap3_template.pdb', 'B') a = load_alignment('test_data/gaps/gap3_alignment.fasta') m = create_model(t, a) os.system('mkdir -p test_data/gaps/gap3_candidates') old_candidates = os.listdir('test_data/gaps/gap3_candidates') for x in old_candidates: if x.startswith('model'): os.remove('test_data/gaps/gap3_candidates/' + x) write_model(m, 'test_data/gaps/gap3_candidates/model3.pdb') self.assertEqual(m.get_sequence(), Sequence('CUAGUC'))
def test_gap1_model(self): """ Should create model with no gaps. Template: 1B23 (fragment) Target: 1EHZ (fragment) """ t = load_template('test_data/gaps/gap1_template.pdb', 'B') a = load_alignment('test_data/gaps/gap1_alignment.fasta') m = create_model(t, a) os.system('mkdir -p test_data/gaps/gap1_candidates') old_candidates = os.listdir('test_data/gaps/gap1_candidates') for x in old_candidates: if x.startswith('model'): os.remove('test_data/gaps/gap1_candidates/' + x) m.write_pdb_file('test_data/gaps/gap1_candidates/model1.pdb') self.assertEqual(m.get_sequence(), Sequence('AGDDGGG'))
def test_gap7_model(self): """ Should create model with no gaps. Template: 2CV2 D (fragment) Target: 1WZ2 C (fragment) """ t = load_template('test_data/gaps/gap7_template.pdb', 'D') a = load_alignment('test_data/gaps/gap7_alignment.fasta') m = create_model(t, a) os.system('mkdir -p test_data/gaps/gap7_candidates1') old_candidates = os.listdir('test_data/gaps/gap7_candidates1') for x in old_candidates: if x.startswith('model'): os.remove('test_data/gaps/gap7_candidates1/' + x) write_model(m, 'test_data/gaps/gap7_candidates1/model7.pdb') self.assertEqual(m.get_sequence(), Sequence('AGCCUGGUCAAA'))
def test_gap6_model(self): """ Should create model with no gaps. Template: 2V0G B (fragment) Target: 1GTS B (fragment) """ # Template has letters in original numeration. t = load_template('test_data/gaps/gap6_template.pdb', 'B') a = load_alignment('test_data/gaps/gap6_alignment.fasta') m = create_model(t, a) os.system('mkdir -p test_data/gaps/gap6_candidates') old_candidates = os.listdir('test_data/gaps/gap6_candidates') for x in old_candidates: if x.startswith('model'): os.remove('test_data/gaps/gap6_candidates/' + x) write_model(m, 'test_data/gaps/gap6_candidates/model6.pdb') self.assertEqual(m.get_sequence(), Sequence('UUCCGA'))
def test_gap5_model(self): """ Should create model with no gaps. Template: 1WZ2 C (fragment) Target: 1B23 R (fragment) """ # Won't find gap automaticly. t = load_template('test_data/gaps/gap5_template.pdb', 'C') a = load_alignment('test_data/gaps/gap5_alignment.fasta') m = create_model(t, a) os.system('mkdir -p test_data/gaps/gap5_candidates') old_candidates = os.listdir('test_data/gaps/gap5_candidates') for x in old_candidates: if x.startswith('model'): os.remove('test_data/gaps/gap5_candidates/' + x) write_model(m, 'test_data/gaps/gap5_candidates/model5.pdb') self.assertEqual(m.get_sequence(), Sequence('GUCUAGU'))
def test_gap_structure1_model(self): """ Should create model with no gaps. Template: 1H4S T (whole structure) Target: 1EHZ A (whole structure) """ t = load_template('test_data/gaps/1h4s_T.pdb', 'T') a = load_alignment('test_data/gaps/structure1_alignment.fasta') m = create_model(t, a) os.system('mkdir -p test_data/gaps/structure1_candidates1') old_candidates = os.listdir('test_data/gaps/structure1_candidates1') for x in old_candidates: if x.startswith('model'): os.remove('test_data/gaps/structure1_candidates1/' + x) write_model( m, 'test_data/gaps/structure1_candidates1/model_structure1.pdb') self.assertEqual( m.get_sequence(), Sequence( 'GCGGAUUUALCUCAGDDGGGAGAGCRCCAGABU#AAYAP?UGGAG7UC?UGUGTPCG"UCCACAGAAUUCGCACCA' ))