You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mmCIF issue parsing multine text and line-end comments #1441
I've just encountered a possible issue using Bio.PDB.MMCIF2Dict to parse a more-complex-than-usual CIF file. This was tested on the most recent development version of biopython.
Multiline text strings don't preserve newlines
The CIF format uses a pair of semicolons in column 1 to delimit multiline blocks of text. The current parser merges each line in the block into one:
fromBio.PDB.MMCIF2DictimportMMCIF2Dict>>>MMCIF2Dict(io.StringIO("""\ 2 data_test 3 _test 4 ; 5 This should be 6 parsed as 7 multiline text. 8 ; 9 """))["_test"]
'This should beparsed asmultiline text.'
According to the CIF spec (section 17 and 20), this should be parsed as
I agree with the first point and the fix you propose.
Re comments, the CIF spec has a few things to say:
A comment in a CIF begins with an unquoted character "#" and extends to the end of the current line
at number 21 as you point out. But also, in the formal grammar section (number 45):
A "comment" is defined to be initiated with the character # followed by any sequence of characters (which include <SP> or <HT>). The only characters not allowed are those in the production <eol>, which <eol> terminates a comment. A comment is recognized only at the beginning of a line or after blanks, i.e. only after space, tab or <eol> [...]
This sounds more thorough and says in-line comments are not allowed. However, it would require a change on line 97 of the MMCIF2Dict.py file from
Hi @jgreener64, thanks for the comment. I read "... after blanks, i.e. only after space, tab or <eol>..." as allowing comments after other tokens as long as they are separated by whitespace. That is,
foo # ignore this
↑ comment after whitespace
is legal. The mmCIF dictionary (5.2MiB text file) seems to use line-end comments like #V5 to indicate the version of the spec in which fields were introduced. The current parser fails when parsing that dictionary.
Either way, it looks like a fairly easy change. If we want to support comments at the end of lines, I think it would just be a case of adding
Okay I hadn't spotted that ambiguity but I think your reading is correct. We should certainly be able to parse the mmCIF dictionary. Your suggestion looks good.
Activity
peterjc commentedon Nov 6, 2017
Probably @jgreener64, @JoaoRodrigues or @lennax is best placed to comment on this...
jgreener64 commentedon Nov 6, 2017
Hey @StefansM, nice one for finding this stuff.
I agree with the first point and the fix you propose.
Re comments, the CIF spec has a few things to say:
at number 21 as you point out. But also, in the formal grammar section (number 45):
This sounds more thorough and says in-line comments are not allowed. However, it would require a change on line 97 of the
MMCIF2Dict.pyfile fromto
to fit the spec. Let me know what you think.
StefansM commentedon Nov 7, 2017
Hi @jgreener64, thanks for the comment. I read "... after blanks, i.e. only after space, tab or <eol>..." as allowing comments after other tokens as long as they are separated by whitespace. That is,
is legal. The mmCIF dictionary (5.2MiB text file) seems to use line-end comments like
#V5to indicate the version of the spec in which fields were introduced. The current parser fails when parsing that dictionary.Either way, it looks like a fairly easy change. If we want to support comments at the end of lines, I think it would just be a case of adding
to line 86 of
MMCIF2Dict.jgreener64 commentedon Nov 7, 2017
Okay I hadn't spotted that ambiguity but I think your reading is correct. We should certainly be able to parse the mmCIF dictionary. Your suggestion looks good.
peterjc commentedon Nov 28, 2017
Oh yeah, thanks for closing this issue now that #1445 was merged.