1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
# Copyright 2022 by Valentin Vareskic (valentin.vareskic@gmail.com).
# All rights reserved. This code is part of the Biopython distribution
# and governed by its license. Please see the LICENSE file that should
# have been included as part of this package.
"""Tests for PDB PSEA."""
import io
import os
import sys
import unittest
from subprocess import getoutput
from Bio import MissingExternalDependencyError
from Bio.PDB import PDBParser
from Bio.PDB.PSEA import PSEA
from Bio.PDB.PSEA import psea
from Bio.PDB.PSEA import psea2HEC
from Bio.PDB.PSEA import run_psea
os.environ["LANG"] = "C"
cmd_output = getoutput("psea -h")
if not cmd_output.startswith("o---"):
raise MissingExternalDependencyError(
"Download and install psea from "
"ftp://ftp.lmcp.jussieu.fr/pub/sincris/software/protein/p-sea/. "
"Make sure that psea is on path"
)
def remove_sea_files():
for file in os.listdir():
if file.endswith(".sea"):
os.remove(file)
class TestPDBPSEA(unittest.TestCase):
def tearDown(self):
remove_sea_files()
def test_run_psea_verbose(self):
captured_ouput = io.StringIO()
sys.stdout = captured_ouput
psae_run = run_psea("PDB/1A8O.pdb", verbose=True)
sys.stdout = sys.__stdout__
self.assertEqual(psae_run, "1A8O.sea")
self.assertTrue(captured_ouput.getvalue())
def test_run_psea_quiet(self):
captured_ouput = io.StringIO()
sys.stdout = captured_ouput
psae_run = run_psea("PDB/1A8O.pdb", verbose=False)
sys.stdout = sys.__stdout__
self.assertEqual(psae_run, "1A8O.sea")
self.assertFalse(captured_ouput.getvalue())
def test_psea(self):
psae_run = psea("PDB/2BEG.pdb")
self.assertEqual(psae_run, "ccccbbbbbbbccccbbbbbbbbbbc")
def test_psea_2HEC(self):
seq = psea("PDB/2BEG.pdb")
psae_run = psea2HEC(seq)
self.assertEqual(
psae_run,
[
"C",
"C",
"C",
"C",
"E",
"E",
"E",
"E",
"E",
"E",
"E",
"C",
"C",
"C",
"C",
"E",
"E",
"E",
"E",
"E",
"E",
"E",
"E",
"E",
"E",
"C",
],
)
class TestPSEA(unittest.TestCase):
def tearDown(self):
remove_sea_files()
def test_get_seq(self):
p = PDBParser()
s = p.get_structure("X", "PDB/2BEG.pdb")
psea_class = PSEA(s[0], "PDB/2BEG.pdb")
self.assertEqual(
psea_class.get_seq(),
[
"C",
"C",
"C",
"C",
"E",
"E",
"E",
"E",
"E",
"E",
"E",
"C",
"C",
"C",
"C",
"E",
"E",
"E",
"E",
"E",
"E",
"E",
"E",
"E",
"E",
"C",
],
)
if __name__ == "__main__":
runner = unittest.TextTestRunner(verbosity=2)
unittest.main(testRunner=runner)
|