Skip to content
Snippets Groups Projects
Select Git revision
  • 6e60b71df07234c329fcf448ec67e26e5d84d525
  • master default protected
  • develop protected
  • cmake_boost_refactor
  • ubuntu_ci
  • mmtf
  • non-orthogonal-maps
  • no_boost_filesystem
  • data_viewer
  • 2.11.1
  • 2.11.0
  • 2.10.0
  • 2.9.3
  • 2.9.2
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.0
  • 2.6.1
  • 2.6.0
  • 2.6.0-rc4
  • 2.6.0-rc3
  • 2.6.0-rc2
  • 2.6.0-rc
  • 2.5.0
  • 2.5.0-rc2
  • 2.5.0-rc
  • 2.4.0
  • 2.4.0-rc2
29 results

test_clustalw.py

Blame
  • Gabriel Studer's avatar
    Studer Gabriel authored
    This commit doesn't make OpenStructure work with Python 3. The goal of this
    commit was to perform an automated port of the Python code and make it compile.
    The performed steps:
    
    - Edited CMakeLists.txt to search for Python with 3.6 as min version 3.6 is the
      Python version shipped by default with Ubuntu 18.04 LTS
    - Add version 3.6 to cmake_support/FindPython.cmake
    - Adapt setup_boost macro in cmake_support/OST.cmake to prefer versioned
      libraries and not first check for boost_python.so. In the example of
      Ubuntu 18.04, libboost_python.so is specific for Python 2 but
      libboost_python3.so is the one we want.
    - apply the following command: 2to3-2.7 -n -w <OST_DIR>
    - adapt base/pymod/wrap_base.cc, gui/pymod/wrap_gui.cc and
      gui/pymod/export_message_widget.cc as PyString functionalities do not exist
      anymore in the Python 3 interpreter (replaced by PyUnicode)
    - adapt gui/src/python_shell/python_interpreter_worker.hh to resolve issue
      discussed in https://stackoverflow.com/questions/23068700/embedding-python3-in-qt-5
      Long story short: Qt does a typedef for "slots" which causes trouble with
      other headers that are pulled in from the Python interpreter
    6e60b71d
    History
    test_clustalw.py 3.66 KiB
    import sys
    import unittest
    from ost import *
    from ost import settings
    from ost.bindings import clustalw
    
    class TestClustalWBindings(unittest.TestCase):
      
      def setUp(self):
        self.protein = io.LoadEntity("testfiles/testprotein.pdb").Select("cname=A")
    
        self.targetseq = io.LoadSequence("testfiles/test.fasta")
        self.targetseq.AttachView(self.protein)
        self.templseq = io.LoadSequence("testfiles/similar.fasta")
        self.multseq = io.LoadSequenceList("testfiles/multiple.fasta")
        self.pw_alignment = io.LoadAlignment("testfiles/pairwise_aln.fasta")
        self.nopgap_pw_alignment = io.LoadAlignment("testfiles/nopgap_pairwise_aln.fasta")
        self.mult_alignment = io.LoadAlignment("testfiles/multiple_aln.fasta")
    
        self.strseq1 = self.targetseq.GetGaplessString()
        self.strseq2 = self.templseq.GetGaplessString()
    
        self.seq1 = io.LoadSequence("testfiles/seq1.fasta")
        self.seq2 = io.LoadSequence("testfiles/seq2.fasta")
        self.seq1_seq2_alignment = io.LoadAlignment("testfiles/seq1_seq2_aln.fasta")
        self.seq1_seq2_alignment_options_changed = io.LoadAlignment("testfiles/seq1_seq2_aln_options_changed.fasta")
    
      def testPairwiseClustalW(self):
        aln=clustalw.ClustalW(self.targetseq, self.templseq)
        assert self.pw_alignment.ToString(80) == aln.ToString(80), \
               "Pairwise alignment differs from precomputed one"
      
      def testNoPGapPariwiseClustalW(self):
        aln=clustalw.ClustalW(self.targetseq, self.templseq, nopgap=True)
        assert self.nopgap_pw_alignment.ToString(80) == aln.ToString(80), \
               "NoPGap pairwise alignment differs from precomputed one"
    
      def testAttachedViewClustalW(self):
        aln=clustalw.ClustalW(self.targetseq, self.templseq)
        assert aln.FindSequence("testseq").HasAttachedView(), \
               "Aligned sequence doesn't have an attached view"
        
      def testMultipleClustalW(self):
        aln=clustalw.ClustalW(self.multseq)
        assert self.mult_alignment.ToString(80) == aln.ToString(80), \
               "Multiple alignment differs from precomputed one"
    
      def testStringClustalW(self):
        aln=clustalw.ClustalW(self.strseq1, self.strseq2)
        aln.SetSequenceName(0,self.targetseq.GetName())
        aln.SetSequenceName(1,self.templseq.GetName())
        assert self.pw_alignment.ToString(80) == aln.ToString(80), \
               "Pairwise alignment using two strings differs from precomputed one \n%s \n%s" \
               %(self.pw_alignment.ToString(80),aln.ToString(80))
    
      def testPairwiseClustalWChangedOptions(self):
        # five residues removed two positions before the end of seq2
        aln=clustalw.ClustalW(self.seq1,self.seq2)
        assert self.seq1_seq2_alignment.ToString(80) == aln.ToString(80), \
               "Pairwise alignment with default gap penalties differs from precomputed one"
        aln=clustalw.ClustalW(self.seq1,self.seq2,clustalw_option_string="-GAPOPEN=2 -GAPEXT=0")
        assert self.seq1_seq2_alignment_options_changed.ToString(80) == aln.ToString(80), \
               "Pairwise alignment with modified gap penalties differs from precomputed one"
    
      def testUniqueIdentifier(self):
        # common case
        seq1 = seq.CreateSequence('heelloo', 'AWESOME')
        seq2 = seq.CreateSequence('heelloo', 'AWESOME')
        self.assertRaises(ValueError, clustalw.ClustalW, seq1, seq2)
        # nasty case with spaces
        seq2 = seq.CreateSequence('heelloo dear', 'AWESOME')
        self.assertRaises(ValueError, clustalw.ClustalW, seq1, seq2)
    
    if __name__ == "__main__":
      # test if clustalw package is available on system, otherwise ignore tests
      try:
        clustalw_path=settings.Locate(('clustalw', 'clustalw2'))
      except(settings.FileNotFound):
        print("Could not find clustalw executable: ignoring unit tests")
        sys.exit(0)
      from ost import testutils
      testutils.RunTests()