Skip to content

Commit

Permalink
Merge pull request #47 from fsimkovic/master
Browse files Browse the repository at this point in the history
Some minor fixes and bits
  • Loading branch information
Felix Simkovic committed Jul 27, 2018
2 parents 7679c5b + d2d9919 commit 2ef6efb
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 26 deletions.
10 changes: 5 additions & 5 deletions conkit/core/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ class Contact(_Entity):
The lower and upper distance boundary values of a contact pair in Ångstrom [Default: 0-8Å].
id : str
A unique identifier
true_positive: bool
true_positive : bool
A boolean status for the contact
true_negative: bool
true_negative : bool
A boolean status for the contact
false_positive: bool
false_positive : bool
A boolean status for the contact
false_negative: bool
false_negative : bool
A boolean status for the contact
status_unknown: bool
status_unknown : bool
A boolean status for the contact
lower_bound : int
The lower distance boundary value
Expand Down
6 changes: 5 additions & 1 deletion conkit/io/_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class _ParserCache(object):
"psicov": ["psicov", "metapsicov", "nebcon"],
}

BLINDFOLD = set(['ContactFileParser', 'GenericStructureParser', 'SequenceFileParser'])

def __init__(self):
self._parsers = []

Expand Down Expand Up @@ -129,7 +131,9 @@ def __construct(self):
name = os.path.basename(m).replace(".py", "")
decl.module = "conkit.io." + name
objname = decl.object.lower().replace("parser", "")
if objname in _ParserCache.MASKS:
if decl.object in _ParserCache.BLINDFOLD:
continue
elif objname in _ParserCache.MASKS:
for extra in _ParserCache.MASKS[objname]:
decl_ = copy.copy(decl)
decl_.id = extra
Expand Down
44 changes: 24 additions & 20 deletions conkit/io/bbcontacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"""

__author__ = "Felix Simkovic"
__date__ = "26 Oct 2016"
__version__ = "0.1"
__date__ = "23 Jul 2018"
__version__ = "0.2"

import re

Expand All @@ -42,8 +42,6 @@
from conkit.core.contactmap import ContactMap
from conkit.core.contactfile import ContactFile

RE_COMMENT = re.compile(r'^#+.*$')


class BbcontactsParser(ContactFileParser):
"""Class to parse a Bbcontacts contact file
Expand All @@ -52,7 +50,7 @@ class BbcontactsParser(ContactFileParser):
def __init__(self):
super(BbcontactsParser, self).__init__()

def read(self, f_handle, f_id="bbcontacts"):
def read(self, f_handle, f_id="bbcontacts", del_one_two=False):
"""Read a contact file
Parameters
Expand All @@ -61,6 +59,8 @@ def read(self, f_handle, f_id="bbcontacts"):
Open file handle [read permissions]
f_id : str, optional
Unique contact file identifier
del_one_two : bool
Remove one- & two-strand sheets
Returns
-------
Expand All @@ -72,22 +72,26 @@ def read(self, f_handle, f_id="bbcontacts"):
contact_map = ContactMap("map_1")
contact_file.add(contact_map)

previous = 'first'
for line in f_handle:
line = line.rstrip()

if not line:
continue

elif RE_COMMENT.match(line):
continue

else:
# bbcontacts reverse residue numbering so swap
_, _, _, raw_score, _, _, res2_seq, res1_seq = line.split()
if any(value == "NA" for value in [raw_score, res2_seq, res1_seq]):
continue
contact = Contact(int(res1_seq), int(res2_seq), float(raw_score))
contact_map.add(contact)
line = line.strip()

if line and not line.startswith('#'):
_, _, _, raw_score, _, current, res2_seq, res1_seq = line.split(
)
if del_one_two and previous == 'first' and current == 'last':
contact_map.child_list.pop()
elif any(value == "NA"
for value in [raw_score, res2_seq, res1_seq]):
pass
else:
contact = Contact(
int(res1_seq), int(res2_seq), float(raw_score))
contact_map.add(contact)
previous = current

if del_one_two and previous == 'first' and len(contact_map) > 0:
contact_map.child_list.pop()

contact_file.method = 'Contact map predicted using Bbcontacts'

Expand Down
40 changes: 40 additions & 0 deletions conkit/io/tests/test_bbcontacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,46 @@ def test_read_1(self):
)
os.unlink(f_name)

def test_read_2(self):
content = """#identifier diversity direction viterbiscore indexpred state res1 res2
1EAZ 0.65 Antiparallel 9.860725 1 first 29 24
1EAZ 0.65 Antiparallel 9.860725 1 last 30 23
1EAZ 0.65 Parallel -6.855870 29 first 87 54
"""
f_name = create_tmp_f(content=content)
with open(f_name, 'r') as f_in:
contact_file = BbcontactsParser().read(f_in, del_one_two=True)
contact_map1 = contact_file.top_map
self.assertEqual(1, len(contact_file))
self.assertEqual(0, len(contact_map1))
os.unlink(f_name)

def test_read_3(self):
content = """#identifier diversity direction viterbiscore indexpred state res1 res2
1EAZ 0.65 Antiparallel 9.860725 1 first 29 24
1EAZ 0.65 Antiparallel 9.860725 1 internal 30 23
1EAZ 0.65 Antiparallel 9.860725 1 last 31 22
1EAZ 0.65 Parallel -6.855870 29 first 87 54
1EAZ 0.65 Parallel -6.855870 29 internal 88 55
1EAZ 0.65 Parallel -6.855870 29 last 89 56
1EAZ 0.65 Antiparallel 0.000000 1 first 100 24
1EAZ 0.65 Antiparallel 0.000000 1 last 101 23
1EAZ 0.65 Parallel 0.000000 29 first 100 15
"""
f_name = create_tmp_f(content=content)
with open(f_name, 'r') as f_in:
contact_file = BbcontactsParser().read(f_in, del_one_two=False)
contact_map1 = contact_file.top_map
self.assertEqual(1, len(contact_file))
self.assertEqual(9, len(contact_map1))
self.assertEqual([24, 23, 22, 54, 55, 56, 24, 23, 15], [c.res1_seq for c in contact_map1])
self.assertEqual([29, 30, 31, 87, 88, 89, 100, 101, 100], [c.res2_seq for c in contact_map1])
self.assertEqual(
sorted([9.860725, 9.860725, 9.860725, -6.855870, -6.855870, -6.855870, 0.0, 0.0, 0.0]),
sorted([c.raw_score for c in contact_map1])
)
os.unlink(f_name)


if __name__ == "__main__":
unittest.main(verbosity=2)

0 comments on commit 2ef6efb

Please sign in to comment.