Skip to content

Commit

Permalink
add report as argument for ciffile and cifheader
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmkrieger committed Nov 8, 2023
1 parent bb13bec commit df2ff6b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
9 changes: 7 additions & 2 deletions prody/proteins/ciffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,15 @@ def parseMMCIFStream(stream, **kwargs):


def _parseMMCIFLines(atomgroup, lines, model, chain, subset,
altloc_torf, segment, unite_chains):
altloc_torf, segment, unite_chains,
report=False):
"""Returns an AtomGroup. See also :func:`.parsePDBStream()`.
:arg lines: mmCIF lines
:arg report: whether to report warnings about not finding data
default True
:type report: bool
"""

if subset is not None:
Expand Down Expand Up @@ -508,7 +513,7 @@ def _parseMMCIFLines(atomgroup, lines, model, chain, subset,

anisou = None
siguij = None
data = parseSTARSection(lines, "_atom_site_anisotrop", report=False)
data = parseSTARSection(lines, "_atom_site_anisotrop", report=report)
if len(data) > 0:
anisou = np.zeros((acount, 6),
dtype=float)
Expand Down
51 changes: 29 additions & 22 deletions prody/proteins/cifheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,16 @@ def parseCIFHeader(pdb, *keys):
return header


def getCIFHeaderDict(stream, *keys):
def getCIFHeaderDict(stream, *keys, **kwargs):
"""Returns header data in a dictionary. *stream* may be a list of PDB lines
or a stream."""
or a stream.
:arg report: whether to report warnings about not finding data
default True
:type report: bool
"""

report = kwargs.get('report', False)

try:
lines = stream.readlines()
Expand Down Expand Up @@ -178,8 +185,8 @@ def _getBiomoltrans(lines):
# 2 blocks are needed for this:
# _pdbx_struct_assembly_gen: what to apply to which chains
# _pdbx_struct_oper_list: everything else
data1 = parseSTARSection(lines, '_pdbx_struct_assembly_gen', report=False)
data2 = parseSTARSection(lines, '_pdbx_struct_oper_list', report=False)
data1 = parseSTARSection(lines, '_pdbx_struct_assembly_gen', report=report)
data2 = parseSTARSection(lines, '_pdbx_struct_oper_list', report=report)

# extracting the data
for n, item1 in enumerate(data1):
Expand Down Expand Up @@ -225,7 +232,7 @@ def _getRelatedEntries(lines):

try:
key = "_pdbx_database_related"
data = parseSTARSection(lines, key, report=False)
data = parseSTARSection(lines, key, report=report)
for item in data:
dbref = DBRef()
dbref.accession = item[key + ".db_id"]
Expand Down Expand Up @@ -715,8 +722,8 @@ def _getReference(lines):

# JRNL double block. Blocks 6 and 7 as copied from COMPND
# Block 1 has most info. Block 2 has author info
items1 = parseSTARSection(lines, "_citation", report=False)
items2 = parseSTARSection(lines, "_citation_author", report=False)
items1 = parseSTARSection(lines, "_citation", report=report)
items2 = parseSTARSection(lines, "_citation_author", report=report)

for row in items1:
for k, value in row.items():
Expand Down Expand Up @@ -767,7 +774,7 @@ def _getPolymers(lines):
entities = defaultdict(list)

# SEQRES block
items1 = parseSTARSection(lines, '_entity_poly', report=False)
items1 = parseSTARSection(lines, '_entity_poly', report=report)

for item in items1:
chains = item['_entity_poly.pdbx_strand_id']
Expand All @@ -781,7 +788,7 @@ def _getPolymers(lines):
'_entity_poly.pdbx_seq_one_letter_code_can'].replace(';', '').split())

# DBREF block 1
items2 = parseSTARSection(lines, '_struct_ref', report=False)
items2 = parseSTARSection(lines, '_struct_ref', report=report)

for item in items2:
entity = item["_struct_ref.id"]
Expand All @@ -798,7 +805,7 @@ def _getPolymers(lines):
poly.dbrefs.append(dbref)

# DBREF block 2
items3 = parseSTARSection(lines, "_struct_ref_seq", report=False)
items3 = parseSTARSection(lines, "_struct_ref_seq", report=report)

for i, item in enumerate(items3):
i += 1
Expand Down Expand Up @@ -884,7 +891,7 @@ def _getPolymers(lines):
last = temp

# MODRES block
data4 = parseSTARSection(lines, "_pdbx_struct_mod_residue", report=False)
data4 = parseSTARSection(lines, "_pdbx_struct_mod_residue", report=report)

for data in data4:
ch = data["_pdbx_struct_mod_residue.label_asym_id"]
Expand All @@ -904,7 +911,7 @@ def _getPolymers(lines):
data["_pdbx_struct_mod_residue.details"]))

# SEQADV block
data5 = parseSTARSection(lines, "_struct_ref_seq_dif", report=False)
data5 = parseSTARSection(lines, "_struct_ref_seq_dif", report=report)

for i, data in enumerate(data5):
ch = data["_struct_ref_seq_dif.pdbx_pdb_strand_id"]
Expand Down Expand Up @@ -964,8 +971,8 @@ def _getPolymers(lines):

# COMPND double block.
# Block 6 has most info. Block 7 has synonyms
data6 = parseSTARSection(lines, "_entity", report=False)
data7 = parseSTARSection(lines, "_entity_name_com", report=False)
data6 = parseSTARSection(lines, "_entity", report=report)
data7 = parseSTARSection(lines, "_entity_name_com", report=report)

dict_ = {}
for molecule in data6:
Expand Down Expand Up @@ -1045,7 +1052,7 @@ def _getChemicals(lines):
# 1st block we need is has info about location in structure

# this instance only includes single sugars not branched structures
items = parseSTARSection(lines, "_pdbx_nonpoly_scheme", report=False)
items = parseSTARSection(lines, "_pdbx_nonpoly_scheme", report=report)

for data in items:
resname = data["_pdbx_nonpoly_scheme.mon_id"]
Expand All @@ -1064,7 +1071,7 @@ def _getChemicals(lines):
chemicals[chem.resname].append(chem)

# next we get the equivalent one for branched sugars part
items = parseSTARSection(lines, "_pdbx_branch_scheme", report=False)
items = parseSTARSection(lines, "_pdbx_branch_scheme", report=report)

for data in items:
resname = data["_pdbx_branch_scheme.mon_id"]
Expand All @@ -1080,7 +1087,7 @@ def _getChemicals(lines):
chemicals[chem.resname].append(chem)

# 2nd block to get has general info e.g. name and formula
items = parseSTARSection(lines, "_chem_comp", report=False)
items = parseSTARSection(lines, "_chem_comp", report=report)

for data in items:
resname = data["_chem_comp.id"]
Expand Down Expand Up @@ -1155,7 +1162,7 @@ def _getTitle(lines):
title = ''

try:
data = parseSTARSection(lines, "_struct", report=False)
data = parseSTARSection(lines, "_struct", report=report)
for item in data:
title += item['_struct.title'].upper()
except:
Expand All @@ -1172,7 +1179,7 @@ def _getAuthors(lines):
authors = []

try:
data = parseSTARSection(lines, "_audit_author", report=False)
data = parseSTARSection(lines, "_audit_author", report=report)
for item in data:
author = ''.join(item['_audit_author.name'].split(', ')[::-1])
authors.append(author.upper())
Expand All @@ -1192,7 +1199,7 @@ def _getSplit(lines):
key = "_pdbx_database_related"

try:
data, _ = parseSTARSection(lines, key, report=False)
data, _ = parseSTARSection(lines, key, report=report)
for item in data:
if item[key + '.content_type'] == 'split':
split.append(item[key + '.db_id'])
Expand Down Expand Up @@ -1227,7 +1234,7 @@ def _getOther(lines, key=None):
data = []

try:
data = parseSTARSection(lines, key, report=False)
data = parseSTARSection(lines, key, report=report)
except:
pass

Expand All @@ -1242,7 +1249,7 @@ def _getUnobservedSeq(lines):
key_unobs = '_pdbx_unobs_or_zero_occ_residues'

try:
unobs = parseSTARSection(lines, key_unobs, report=False)
unobs = parseSTARSection(lines, key_unobs, report=report)
polymers = _getPolymers(lines)
except:
pass
Expand Down
7 changes: 6 additions & 1 deletion prody/proteins/starfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,12 @@ def parseSTARSection(lines, key, report=True):
corresponding to a *key* (part before the dot).
This can be a loop or data block.
Returns data encapulated in a list and the associated fields."""
Returns data encapulated in a list and the associated fields.
:arg report: whether to report warnings about not finding data
default True
:type report: bool
"""

if not isinstance(key, str):
raise TypeError("key should be a string")
Expand Down

0 comments on commit df2ff6b

Please sign in to comment.