Exemplo n.º 1
0
class Test(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.thisd = os.path.abspath(os.path.dirname(__file__))
        cls.ample_share = constants.SHARE_DIR
        cls.testfiles_dir = os.path.join(cls.ample_share, 'testfiles')
        cls.tests_dir = tempfile.gettempdir()

    @unittest.skipUnless(test_funcs.found_exe("gesamt" + ample_util.EXE_EXT), "gesamt exec missing")
    def test_gesamt(self):
        gesamt_exe = ample_util.find_exe("gesamt" + ample_util.EXE_EXT)
        pdb_list = ['1ujbA.pdb', '2a6pA.pdb', '3c7tA.pdb']
        models = [os.path.join(self.ample_share, 'examples', 'homologs', 'input', pdb) for pdb in pdb_list]
        work_dir = os.path.join(self.tests_dir, "gesamt_test")
        alignment_file = align_gesamt(models, gesamt_exe=gesamt_exe, work_dir=work_dir)
        self.assertTrue(os.path.isfile(alignment_file))
        # TODO: fix this error on Windows...not sure how this arises
        try:
            shutil.rmtree(work_dir)
        except WindowsError:
            pass

    @unittest.skipUnless(test_funcs.found_exe("mustang" + ample_util.EXE_EXT), "mustang exec missing")
    def test_mustang(self):
        mustang_exe = ample_util.find_exe("mustang" + ample_util.EXE_EXT)
        pdb_list = ['1ujbA.pdb', '2a6pA.pdb', '3c7tA.pdb']
        models = [os.path.join(self.ample_share, 'examples', 'homologs', 'input', pdb) for pdb in pdb_list]
        work_dir = os.path.join(self.tests_dir, "mustang_test")
        alignment_file = align_mustang(models, mustang_exe=mustang_exe, work_dir=work_dir)
        self.assertTrue(os.path.isfile(alignment_file))
        shutil.rmtree(work_dir)
Exemplo n.º 2
0
"""Test functions for python.shelxe"""

import os
import unittest
from ample import constants
from ample.util import ample_util
from ample.util import shelxe
from ample.testing import test_funcs


@unittest.skipUnless(test_funcs.found_exe("shelxe" + ample_util.EXE_EXT),
                     "shelxe exec missing")
class Test(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.thisd = os.path.abspath(os.path.dirname(__file__))
        cls.ample_share = constants.SHARE_DIR
        cls.testfiles_dir = os.path.join(cls.ample_share, 'testfiles')

    def test_shelxe_1BYZ(self):
        shelxe_exe = ample_util.find_exe('shelxe' + ample_util.EXE_EXT)
        pdb = os.path.join(self.testfiles_dir, "1BYZ.pdb")
        mtz = os.path.join(self.testfiles_dir, "1BYZ-cad.mtz")
        mrPdb = os.path.join(
            self.testfiles_dir,
            "1BYZ_phaser_loc0_ALL_poly_ala_trunc_0.486615_rad_1_UNMOD.1.pdb")
        mrinfo = shelxe.MRinfo(shelxe_exe, pdb, mtz)
        mrinfo.analyse(mrPdb)

        self.assertEqual(mrinfo.originShift, [0.326, 0.19, 0.275])
        # Need MRBUMP to be updated
Exemplo n.º 3
0
import glob
import os
import shutil
import unittest
from ample import constants
from ample.testing import test_funcs
from ample.util import ample_util, fast_protein_cluster


@unittest.skip("fast_protein_cluster deprecated")
@unittest.skipUnless(
    test_funcs.found_exe("fast_protein_cluster" + ample_util.EXE_EXT), "fast_protein_cluster exec missing"
)
class Test(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.thisd = os.path.abspath(os.path.dirname(__file__))
        cls.ample_share = constants.SHARE_DIR
        cls.testfiles_dir = os.path.join(cls.ample_share, 'testfiles')
        cls.fpc_exe = ample_util.find_exe("fast_protein_cluster" + ample_util.EXE_EXT)

    def test_fpc_kmeans_rmsd(self):
        os.chdir(self.thisd)  # Need as otherwise tests that happen in other directories change os.cwd()
        mdir = os.path.join(self.testfiles_dir, "models")
        models = glob.glob(mdir + os.sep + "*.pdb")

        wdir = 'fpc_test'
        if not os.path.isdir(wdir):
            os.mkdir(wdir)
        fpc = fast_protein_cluster.FPC()
        num_clusters = 3
Exemplo n.º 4
0
class Test_1(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.thisd = os.path.abspath(os.path.dirname(__file__))
        cls.ample_share = constants.SHARE_DIR
        cls.testfiles_dir = os.path.join(cls.ample_share, 'testfiles')

    def test_radius_cctbx(self):
        # Test we can reproduce the original thresholds
        radius = 8
        clusterer = subcluster.CctbxClusterer()
        # Only select a few as is very slow
        pdb_list = [
            os.path.join(self.testfiles_dir, "models", pdb) for pdb in [
                '1_S_00000001.pdb', '1_S_00000002.pdb', '1_S_00000003.pdb',
                '1_S_00000004.pdb'
            ]
        ]
        clusterer.generate_distance_matrix(pdb_list)
        cluster_files1 = [
            os.path.basename(x) for x in clusterer.cluster_by_radius(radius)
        ]
        ref = ['1_S_00000002.pdb', '1_S_00000004.pdb']
        self.assertItemsEqual(ref, cluster_files1)

    @unittest.skipUnless(test_funcs.found_exe("gesamt" + ample_util.EXE_EXT),
                         "gesamt exec missing")
    def test_gesamt_matrix_generic(self):
        # Test we can reproduce the original thresholds
        gesamt_exe = ample_util.find_exe("gesamt" + ample_util.EXE_EXT)
        clusterer = subcluster.GesamtClusterer(executable=gesamt_exe)
        pdb_list = glob.glob(
            os.path.join(self.testfiles_dir, "models", '*.pdb'))
        clusterer._generate_distance_matrix_generic(pdb_list, purge_all=True)
        # Test two files manually
        index1 = 2
        index2 = 25
        f1 = pdb_list[index1]
        f2 = pdb_list[index2]
        # Run gesamt to get the score between the two
        logfile = 'gesamt.log'
        ample_util.run_command([gesamt_exe, f1, f2], logfile=logfile)
        qscore = None
        with open(logfile) as f:
            for l in f.readlines():
                if l.startswith(' Q-score'):
                    qscore = float(l.split()[2])

        self.assertIsNotNone(qscore, "No q-score found")
        # read score matrix
        matrix = []
        with open(subcluster.SCORE_MATRIX_NAME) as f:
            for l in f.readlines():
                if not l.strip(): continue
                fields = l.split()
                matrix.append(
                    (int(fields[0]), int(fields[1]), float(fields[2])))
        # Make sure the score matches
        for l in matrix:
            if l[0] == index1 and l[1] == index2:
                # Gesamt log and out file formats have different precisions
                self.assertAlmostEqual(
                    l[2], qscore, 3,
                    "Q-scores differ: {0} - {1}".format(l[2], qscore))
        os.unlink(logfile)
        os.unlink(subcluster.SCORE_MATRIX_NAME)
        os.unlink(subcluster.FILE_LIST_NAME)
        return

    @unittest.skipUnless(test_funcs.found_exe("gesamt" + ample_util.EXE_EXT),
                         "gesamt exec missing")
    def test_radius_gesamt(self):
        # Test we can reproduce the original thresholds
        gesamt_exe = ample_util.find_exe("gesamt" + ample_util.EXE_EXT)
        clusterer = subcluster.GesamtClusterer(executable=gesamt_exe)
        pdb_list = glob.glob(
            os.path.join(self.testfiles_dir, "models", '*.pdb'))

        radius = 4
        clusterer.generate_distance_matrix(pdb_list)
        cluster_files1 = [
            os.path.basename(x) for x in clusterer.cluster_by_radius(radius)
        ]
        ref = [
            '1_S_00000002.pdb', '1_S_00000004.pdb', '1_S_00000005.pdb',
            '2_S_00000001.pdb', '2_S_00000005.pdb', '3_S_00000003.pdb',
            '3_S_00000004.pdb', '3_S_00000006.pdb', '4_S_00000002.pdb',
            '4_S_00000005.pdb', '5_S_00000004.pdb', '5_S_00000005.pdb'
        ]
        self.assertItemsEqual(ref, cluster_files1)
        #clusterer.dump_pdb_matrix('foo')
        return

    def test_radius_lsqkab(self):
        # Test we can reproduce the original thresholds
        clusterer = subcluster.LsqkabClusterer()
        pdb_list = glob.glob(
            os.path.join(self.testfiles_dir, "models", '*.pdb'))
        clusterer.generate_distance_matrix(pdb_list)
        clusterer.dump_pdb_matrix('lsqkab.matrix')
        os.unlink('lsqkab.matrix')
        return

    @unittest.skipUnless(
        test_funcs.found_exe("maxcluster" + ample_util.EXE_EXT),
        "maxcluster exec missing")
    def test_radius_maxcluster(self):
        # Test we can reproduce the original thresholds
        maxcluster_exe = ample_util.find_exe('maxcluster' + ample_util.EXE_EXT)
        radius = 4
        clusterer = subcluster.MaxClusterer(maxcluster_exe)
        pdb_list = glob.glob(
            os.path.join(self.testfiles_dir, "models", '*.pdb'))
        clusterer.generate_distance_matrix(pdb_list)
        cluster_files1 = [
            os.path.basename(x) for x in clusterer.cluster_by_radius(radius)
        ]
        ref = [
            '4_S_00000003.pdb', '2_S_00000005.pdb', '2_S_00000001.pdb',
            '3_S_00000006.pdb', '5_S_00000005.pdb', '3_S_00000003.pdb',
            '1_S_00000004.pdb', '4_S_00000005.pdb', '3_S_00000004.pdb',
            '1_S_00000002.pdb', '5_S_00000004.pdb', '4_S_00000002.pdb',
            '1_S_00000005.pdb'
        ]
        self.assertItemsEqual(ref, cluster_files1)
        os.unlink('files.list')
        os.unlink('maxcluster.log')

    @unittest.skipUnless(
        test_funcs.found_exe("maxcluster" + ample_util.EXE_EXT),
        "maxcluster exec missing")
    def test_cluster_score(self):
        maxcluster_exe = ample_util.find_exe('maxcluster' + ample_util.EXE_EXT)
        radius = 4
        clusterer = subcluster.MaxClusterer(maxcluster_exe)
        pdb_list = glob.glob(
            os.path.join(self.testfiles_dir, "models", '*.pdb'))

        clusterer.generate_distance_matrix(pdb_list)
        clusterer.cluster_by_radius(radius)
        variance = clusterer.cluster_score
        ref = 4.748
        self.assertLessEqual(
            abs(ref - variance), 0.001,
            "Incorrect variance: {0} -> {1}".format(variance, ref))
Exemplo n.º 5
0
"""Test functions for python.shelxe"""

import os
import unittest
from ample import constants
from ample.util import ample_util
from ample.util import shelxe
from ample.testing import test_funcs

@unittest.skipUnless(test_funcs.found_exe("shelxe" + ample_util.EXE_EXT),  "shelxe exec missing")
class Test(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.thisd =  os.path.abspath( os.path.dirname( __file__ ) )
        cls.ample_share = constants.SHARE_DIR
        cls.testfiles_dir = os.path.join(cls.ample_share,'testfiles')

    def test_shelxe_1BYZ(self):
        shelxe_exe = ample_util.find_exe('shelxe' + ample_util.EXE_EXT)
        pdb = os.path.join(self.testfiles_dir, "1BYZ.pdb")
        mtz = os.path.join(self.testfiles_dir, "1BYZ-cad.mtz")
        mrPdb = os.path.join(self.testfiles_dir,
                            "1BYZ_phaser_loc0_ALL_poly_ala_trunc_0.486615_rad_1_UNMOD.1.pdb")
        mrinfo = shelxe.MRinfo(shelxe_exe, pdb, mtz)
        mrinfo.analyse(mrPdb, cleanup=True)

        self.assertEqual(mrinfo.originShift,[0.326, 0.19, 0.275])
        # Need MRBUMP to be updated
        #self.assertEqual(mrinfo.MPE,78.5)
        self.assertEqual(mrinfo.wMPE,74.5)
Exemplo n.º 6
0
import glob
import os
import shutil
import sys
import tempfile
import unittest

from ample import constants
from ample.util import ample_util
from ample.util import pdb_edit
from ample.util import theseus
from ample.testing import test_funcs


@unittest.skipUnless(test_funcs.found_exe("theseus" + ample_util.EXE_EXT),
                     "theseus not found")
class Test(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.ample_share = constants.SHARE_DIR
        cls.testfiles_dir = os.path.join(cls.ample_share, 'testfiles')
        cls.tests_dir = tempfile.gettempdir()
        cls.theseus_exe = ample_util.find_exe("theseus" + ample_util.EXE_EXT)

    def test_align_models(self):
        ## BUG - hlfsimko
        # CAUSES PROBLEMS ON MAC BECAUSE OF SYM LINK IN root on Mac OS X
        tests_dir = os.environ["HOMEPATH"] if sys.platform.startswith("win") \
                        else os.environ["HOME"]
        work_dir = os.path.join(tests_dir, 'theseus_align')
        models = glob.glob(os.path.join(self.testfiles_dir, 'models', '*.pdb'))
Exemplo n.º 7
0
import glob
import os
import shutil
import tempfile
import unittest

from ample import constants
from ample.testing import test_funcs
from ample.util import ample_util
from ample.util import spicker

@unittest.skip("unreliable test cases")
@unittest.skipUnless(test_funcs.found_exe("spicker" + ample_util.EXE_EXT), "spicker exec missing")
class Test(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.thisd =  os.path.abspath( os.path.dirname( __file__ ) )
        cls.ample_share = constants.SHARE_DIR
        cls.testfiles_dir = os.path.join(cls.ample_share, 'testfiles')
        cls.tests_dir = tempfile.gettempdir()
        cls.spicker_exe = ample_util.find_exe('spicker' + ample_util.EXE_EXT)
    
    def test_spicker(self):
        mdir = os.path.join(self.testfiles_dir, "models")
        models = glob.glob(mdir + os.sep + "*.pdb")
        work_dir = os.path.join(self.tests_dir, "spicker")
        if os.path.isdir(work_dir): shutil.rmtree(work_dir)
        os.mkdir(work_dir)
        spickerer = spicker.Spickerer(spicker_exe=self.spicker_exe)
Exemplo n.º 8
0
import glob
import os
import shutil
import unittest
from ample import constants
from ample.testing import test_funcs
from ample.util import ample_util
from ample.util import fast_protein_cluster

@unittest.skip("fast_protein_cluster deprecated")
@unittest.skipUnless(test_funcs.found_exe("fast_protein_cluster" + ample_util.EXE_EXT), "fast_protein_cluster exec missing")
class Test(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.thisd =  os.path.abspath( os.path.dirname( __file__ ) )
        cls.ample_share = constants.SHARE_DIR
        cls.testfiles_dir = os.path.join(cls.ample_share,'testfiles')
        cls.fpc_exe = ample_util.find_exe("fast_protein_cluster" + ample_util.EXE_EXT)   
    
    def test_fpc_kmeans_rmsd(self):
        os.chdir(self.thisd) # Need as otherwise tests that happen in other directories change os.cwd()
        mdir=os.path.join(self.testfiles_dir,"models")
        models=glob.glob(mdir+os.sep+"*.pdb")
        
        wdir='fpc_test'
        if not os.path.isdir(wdir): os.mkdir(wdir)
        fpc=fast_protein_cluster.FPC()
        num_clusters=3
        score_type='rmsd'
Exemplo n.º 9
0
"""Test functions for util.tm_util"""

import unittest
from ample.testing import test_funcs
from ample.util import ample_util, tm_util

@unittest.skipUnless(test_funcs.found_exe("TMscore" + ample_util.EXE_EXT), "TMscore exec missing")
class TestTM(unittest.TestCase):

    def test_gaps_1(self):
        gaps = tm_util.TMscore("TMscore", wdir=".")._find_gaps("AAAA---AA--AA")
        ref_gaps = [False, False, False, False, True, True, True, False, False, True, True, False, False]
        self.assertEqual(ref_gaps, gaps)

    def test_gaps_2(self):
        gaps = tm_util.TMscore("TMscore", wdir=".")._find_gaps("---AA--AA")
        ref_gaps = [True, True, True, False, False, True, True, False, False]
        self.assertEqual(ref_gaps, gaps)

    def test_gaps_3(self):
        gaps = tm_util.TMscore("TMscore", wdir=".")._find_gaps("-AAA--")
        ref_gaps = [True, False, False, False, True, True]
        self.assertEqual(ref_gaps, gaps)

if __name__ == "__main__":
    unittest.main()
Exemplo n.º 10
0
    @unittest.skipUnless(test_funcs.found_exe("maxcluster" + ample_util.EXE_EXT), "maxcluster exec missing")
    def test_cluster_score(self):
        maxcluster_exe = ample_util.find_exe('maxcluster' + ample_util.EXE_EXT)
        radius = 4
        clusterer = subcluster.MaxClusterer(maxcluster_exe)
        pdb_list = glob.glob(os.path.join(self.testfiles_dir, "models",'*.pdb'))

        clusterer.generate_distance_matrix(pdb_list)
        clusterer.cluster_by_radius(radius)
        variance = clusterer.cluster_score
        ref = 4.748
        self.assertLessEqual(abs(ref-variance), 0.001, "Incorrect variance: {0} -> {1}".format(variance, ref))


@unittest.skipUnless(test_funcs.found_exe("fast_protein_cluster" + ample_util.EXE_EXT), "fast_protein_cluster exec missing")
class Test_2(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.thisd =  os.path.abspath( os.path.dirname( __file__ ))
        cls.ample_share = constants.SHARE_DIR
        cls.testfiles_dir = os.path.join(cls.ample_share, 'testfiles')
        cls.fpc_exe = ample_util.find_exe("fast_protein_cluster" + ample_util.EXE_EXT)

    def test_indices_fpc(self):
        # Test we can reproduce the original thresholds
        radius = 4
        clusterer = subcluster.FpcClusterer(self.fpc_exe)
        pdb_list = glob.glob(os.path.join(self.testfiles_dir, "models",'*.pdb'))
        clusterer.generate_distance_matrix(pdb_list)