Skip to content

Commit

Permalink
reduce parseCIF warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmkrieger committed Nov 8, 2023
1 parent f6baf7c commit bb13bec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
8 changes: 2 additions & 6 deletions prody/proteins/ciffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,8 @@ def _parseMMCIFLines(atomgroup, lines, model, chain, subset,

anisou = None
siguij = None
try:
data = parseSTARSection(lines, "_atom_site_anisotrop")
x = data[0] # check if data has anything in it
except IndexError:
LOGGER.warn("No anisotropic B factors found")
else:
data = parseSTARSection(lines, "_atom_site_anisotrop", report=False)
if len(data) > 0:
anisou = np.zeros((acount, 6),
dtype=float)

Expand Down
40 changes: 20 additions & 20 deletions prody/proteins/cifheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,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')
data2 = parseSTARSection(lines, '_pdbx_struct_oper_list')
data1 = parseSTARSection(lines, '_pdbx_struct_assembly_gen', report=False)
data2 = parseSTARSection(lines, '_pdbx_struct_oper_list', report=False)

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

try:
key = "_pdbx_database_related"
data = parseSTARSection(lines, key)
data = parseSTARSection(lines, key, report=False)
for item in data:
dbref = DBRef()
dbref.accession = item[key + ".db_id"]
Expand Down Expand Up @@ -715,8 +715,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")
items2 = parseSTARSection(lines, "_citation_author")
items1 = parseSTARSection(lines, "_citation", report=False)
items2 = parseSTARSection(lines, "_citation_author", report=False)

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

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

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

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

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

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

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

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

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

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

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

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

dict_ = {}
for molecule in data6:
Expand Down Expand Up @@ -1045,7 +1045,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")
items = parseSTARSection(lines, "_pdbx_nonpoly_scheme", report=False)

for data in items:
resname = data["_pdbx_nonpoly_scheme.mon_id"]
Expand All @@ -1064,7 +1064,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")
items = parseSTARSection(lines, "_pdbx_branch_scheme", report=False)

for data in items:
resname = data["_pdbx_branch_scheme.mon_id"]
Expand All @@ -1080,7 +1080,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")
items = parseSTARSection(lines, "_chem_comp", report=False)

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

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

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

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

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

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

try:
unobs = parseSTARSection(lines, key_unobs)
unobs = parseSTARSection(lines, key_unobs, report=False)
polymers = _getPolymers(lines)
except:
pass
Expand Down
5 changes: 3 additions & 2 deletions prody/proteins/starfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ def parseImagesFromSTAR(particlesSTAR, **kwargs):
return np.array(images), parsed_images_data


def parseSTARSection(lines, key):
def parseSTARSection(lines, key, report=True):
"""Parse a section of data from *lines* from a STAR file
corresponding to a *key* (part before the dot).
This can be a loop or data block.
Expand Down Expand Up @@ -1077,7 +1077,8 @@ def parseSTARSection(lines, key):
else:
data = [loop_dict["data"]]
else:
LOGGER.warn("Could not find {0} in lines.".format(key))
if report:
LOGGER.warn("Could not find {0} in lines.".format(key))
return []

return data

0 comments on commit bb13bec

Please sign in to comment.