Skip to content
Snippets Groups Projects
Commit 0288eced authored by Studer Gabriel's avatar Studer Gabriel
Browse files

restore backwards compatibility in BuildRawModel function

As of 3.1.0, BuildRawModel only accepts a list of strings as chain
names if the alignments have been passed as AlignmentList. This
commit restores the behaviour that we can also pass a string where
each chain gets named according to the single letters in that string.
parent 75732ac3
No related branches found
No related tags found
No related merge requests found
......@@ -77,8 +77,11 @@ def BuildRawModel(aln, chain_names = None, include_ligands = False,
If *aln* is of type :class:`ost.seq.AlignmentHandle`,
*chain_names* is expected to be a :class:`str`.
If *aln* is of type :class:`ost.seq.AlignmentList`,
chain_names is expected to be a :class:`list` of
:class:`str` of same size as *aln*.
*chain_names* is expected to be a :class:`list` of
:class:`str` of same size as *aln* or a :class:`str`.
For the latter case, chains will consecutively named
according to characters in *chain_names*.
:type chain_names: :class:`str` / :class:`list`
:param spdbv_style: True, if we need a model in the old SPDBV style.
......@@ -130,9 +133,15 @@ def BuildRawModel(aln, chain_names = None, include_ligands = False,
raise RuntimeError('Number of alns and chain_names must be '\
'consistent')
name_list = chain_names
elif isinstance(chain_names, str):
if len(chain_names) < len(aln_list):
raise RuntimeError('If you provide a string as chain_names, '\
'it must be at least as long as the '\
'AlignmentList in aln.')
name_list = [n for n in chain_names[:len(aln_list)]]
else:
raise RuntimeError('chain_names must be list if aln is of type '\
'ost.seq.AlignmentList')
raise RuntimeError('chain_names must be list of str or str if aln '\
'is of type ost.seq.AlignmentList')
else:
raise RuntimeError('aln must be of type ost.seq.AlignmentHandle or '\
'ost.seq.AlignmentList')
......
......@@ -76,24 +76,28 @@ class ModellingTests(unittest.TestCase):
result = modelling.BuildRawModel(aln_lst, ['cheese', 'steak'])
self.assertEqual(result.model.chains[0].GetName(), 'cheese')
self.assertEqual(result.model.chains[1].GetName(), 'steak')
result = modelling.BuildRawModel(aln_lst, 'ch')
self.assertEqual(result.model.chains[0].GetName(), 'c')
self.assertEqual(result.model.chains[1].GetName(), 'h')
result = modelling.BuildRawModel(aln_lst, 'cheese')
self.assertEqual(result.model.chains[0].GetName(), 'c')
self.assertEqual(result.model.chains[1].GetName(), 'h')
# we only accept a string as chain_names if aln is AlignmentHandle
self.assertRaises(RuntimeError, modelling.BuildRawModel, aln, 1)
self.assertRaises(RuntimeError, modelling.BuildRawModel, aln, ['A'])
# we only accept a list as chain_names if aln is AlignmentList
# we only accept a list or str as chain_names if aln is AlignmentList
self.assertRaises(RuntimeError, modelling.BuildRawModel, aln_lst, 1)
self.assertRaises(RuntimeError, modelling.BuildRawModel, aln_lst, 'A')
# size also matters...
self.assertRaises(RuntimeError, modelling.BuildRawModel, aln_lst, ['A'])
self.assertRaises(RuntimeError, modelling.BuildRawModel, aln_lst, 'A')
# increase size of aln_list => at some point we should run out of
# default chain_names
aln_lst = 100*[aln]
self.assertRaises(RuntimeError, modelling.BuildRawModel, aln_lst)
def testModeledSequence(self):
# test if the model has the sequence we want.
tpl = io.LoadPDB('data/gly.pdb')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment