Source code for conkit.io.tests.test_ccmpred

"""Testing facility for conkit.io.CCMpredIO"""

__author__ = "Felix Simkovic"
__date__ = "14 Sep 2016"

import os
import sys
import unittest

from conkit.core.contact import Contact
from conkit.core.contactfile import ContactFile
from conkit.core.contactmap import ContactMap
from conkit.core.sequence import Sequence
from conkit.io.ccmpred import CCMpredParser
from conkit.io.tests.helpers import ParserTestCase


[docs]class TestCCMpredParser(ParserTestCase):
[docs] def test_read_1(self): content = """0.00000000000000000000e+00 9.05865192413330078125e-01 4.48399752378463745117e-01 3.83993983268737792969e-02 7.80840754508972167969e-01 5.15280842781066894531e-01 2.66545146703720092773e-01 4.99921828508377075195e-01 4.54095661640167236328e-01 7.60651350021362304688e-01 9.05863702297210693359e-01 0.00000000000000000000e+00 7.22257912158966064453e-01 1.90076664090156555176e-01 1.08203485608100891113e-01 1.23369038105010986328e-01 5.28753221035003662109e-01 3.98827701807022094727e-01 7.34628140926361083984e-01 5.52688777446746826172e-01 4.48399752378463745117e-01 7.22256183624267578125e-01 0.00000000000000000000e+00 1.39001503586769104004e-01 8.06087076663970947266e-01 4.15808916091918945312e-01 3.66488158702850341797e-01 5.48547744750976562500e-01 3.75738739967346191406e-01 6.22575163841247558594e-01 3.83996069431304931641e-02 1.90076768398284912109e-01 1.39001443982124328613e-01 0.00000000000000000000e+00 3.90003859996795654297e-01 2.16557279229164123535e-01 4.70980733633041381836e-01 7.48713970184326171875e-01 3.39133590459823608398e-01 3.63562434911727905273e-01 7.80841588973999023438e-01 1.08203165233135223389e-01 8.06088566780090332031e-01 3.90004277229309082031e-01 0.00000000000000000000e+00 1.00000000000000000000e+00 4.70447808504104614258e-01 2.48236447572708129883e-01 1.31565973162651062012e-01 2.77379095554351806641e-01 5.15280425548553466797e-01 1.23368613421916961670e-01 4.15808051824569702148e-01 2.16556847095489501953e-01 9.99999344348907470703e-01 0.00000000000000000000e+00 4.25846457481384277344e-01 2.21113219857215881348e-01 9.12295103073120117188e-01 5.38769721984863281250e-01 2.66544729471206665039e-01 5.28752684593200683594e-01 3.66489529609680175781e-01 4.70980644226074218750e-01 4.70447897911071777344e-01 4.25846666097640991211e-01 0.00000000000000000000e+00 3.21736276149749755859e-01 5.99321126937866210938e-02 5.63172221183776855469e-01 4.99920457601547241211e-01 3.98826628923416137695e-01 5.48546612262725830078e-01 7.48714208602905273438e-01 2.48236656188964843750e-01 2.21113741397857666016e-01 3.21736931800842285156e-01 0.00000000000000000000e+00 6.80750489234924316406e-01 0.00000000000000000000e+00 4.54095035791397094727e-01 7.34628796577453613281e-01 3.75739067792892456055e-01 3.39132964611053466797e-01 1.31566718220710754395e-01 9.12294447422027587891e-01 5.99323771893978118896e-02 6.80750906467437744141e-01 0.00000000000000000000e+00 3.14438492059707641602e-01 7.60651111602783203125e-01 5.52687942981719970703e-01 6.22575819492340087891e-01 3.63562554121017456055e-01 2.77379721403121948242e-01 5.38770556449890136719e-01 5.63172996044158935547e-01 1.05407856665351573611e-07 3.14439445734024047852e-01 0.00000000000000000000e+00 """ f_name = self.tempfile(content=content) with open(f_name, "r") as f_in: contact_file = CCMpredParser().read(f_in) contact_map1 = contact_file.top_map self.assertEqual(1, len(contact_file)) self.assertEqual(55, len(contact_map1)) self.assertEqual( sorted([1] * 10 + [2] * 9 + [3] * 8 + [4] * 7 + [5] * 6 + [6] * 5 + [7] * 4 + [8] * 3 + [9] * 2 + [10] * 1), sorted([c.res1_seq for c in contact_map1]), ) self.assertEqual( [ 1.0, 0.9122951030731201, 0.9058651924133301, 0.806087076663971, 0.7808407545089722, 0.7606513500213623, 0.7487139701843262, 0.7346281409263611, 0.7222579121589661, 0.6807504892349243, 0.6225751638412476, 0.5631722211837769, 0.5526887774467468, 0.5485477447509766, 0.5387697219848633, 0.5287532210350037, 0.5152808427810669, 0.4999218285083771, 0.4709807336330414, 0.4704478085041046, 0.45409566164016724, 0.44839975237846375, 0.4258464574813843, 0.41580891609191895, 0.3988277018070221, 0.39000385999679565, 0.3757387399673462, 0.36648815870285034, 0.3635624349117279, 0.3391335904598236, 0.32173627614974976, 0.31443849205970764, 0.2773790955543518, 0.2665451467037201, 0.24823644757270813, 0.22111321985721588, 0.21655727922916412, 0.19007666409015656, 0.1390015035867691, 0.13156597316265106, 0.12336903810501099, 0.10820348560810089, 0.05993211269378662, 0.03839939832687378, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ], [c.raw_score for c in contact_map1], )
[docs] def test_write_1(self): contact_file = ContactFile("test") contact_map = ContactMap("1") contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence("1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD") f_name = self.tempfile() # Not sure if bug in Python3 numpy or intended purpose [Implemented: 21.11.2016] mode = "wb" if sys.version_info.major == 3 else "w" with open(f_name, mode) as f_out: CCMpredParser().write(f_out, contact_file) content = [ "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t6.999999999999999556e-01\t6.999999999999999556e-01\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t9.000000000000000222e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t4.000000000000000222e-01", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t9.000000000000000222e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "6.999999999999999556e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "6.999999999999999556e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t4.000000000000000222e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", ] with open(f_name, "r") as f_in: output = f_in.read().splitlines() self.assertEqual(content, output)
[docs] def test_write_2(self): contact_file = ContactFile("test") contact_map = ContactMap("1") contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence("1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD") f_name = self.tempfile() # Not sure if bug in Python3 numpy or intended purpose [Implemented: 21.11.2016] with open(f_name, "w") as f_out: if sys.version_info.major == 3: with self.assertRaises(TypeError): CCMpredParser().write(f_out, contact_file) else: self.assertTrue(True)
if __name__ == "__main__": unittest.main(verbosity=2)