<commit_before>"""Test functions for python.ample_sequence"""

import os
import unittest
from ample.python import ample_sequence

class Test(unittest.TestCase):
    
    @classmethod
    def setUpClass(cls):
        """
        Set up paths. Need to do this with setUpClass, as otherwise the __file__
        variable is updated whenever the cwd is changed in a test and the next test
        gets the wrong paths.
        """
        cls.thisd =  os.path.abspath( os.path.dirname( __file__ ) )
        paths = cls.thisd.split( os.sep )
        cls.ample_dir = os.sep.join( paths[ : -2 ] )
        cls.tests_dir=os.path.join(cls.ample_dir,"tests")
        cls.testfiles_dir = os.path.join(cls.tests_dir,'testfiles')
        return

    def test_add(self):
        s1 = ample_sequence.Sequence(pdb=os.path.join(self.testfiles_dir,'1GU8.pdb'))
        s2 = ample_sequence.Sequence(fasta=os.path.join(self.testfiles_dir,'2uui.fasta'))
        s1 += s2
        
        self.assertTrue(len(s1.sequences),2)
        self.assertTrue(len(s1.resseqs),2)
        self.assertTrue(len(s1.headers),2)
        self.assertTrue(len(s1.pdbs),2)
        self.assertTrue(len(s1.chains),2)
        self.assertTrue(len(s1.fasta_files),2)
        
        # Test write for the hell of it
        #out_fasta = 'seq_add.fasta'
        #s1.write_fasta(out_fasta)
        #os.unlink(out_fasta)
        return

    def test_addPdbData(self):
        fasta1 = os.path.join(self.testfiles_dir,'1ujb_2a6pA_3c7tA.afasta')
        pdbin1 = os.path.join(self.ample_dir, 'examples', 'homologs','1ujb.pdb')
        pdbin2 = os.path.join(self.ample_dir, 'examples', 'homologs','2a6pA.pdb')
        pdbin3 = os.path.join(self.ample_dir, 'examples', 'homologs','3c7tA.pdb')
        s1 = ample_sequence.Sequence(fasta=fasta1)
        s1.add_pdb_data(pdbin1)
        s1.add_pdb_data(pdbin2)
        s1.add_pdb_data(pdbin3)
        
        self.assertEqual(s1.pdbs[0], os.path.basename(pdbin1))
        self.assertEqual(s1.chains[0],'A')
        self.assertEqual(s1.pdbs[1], os.path.basename(pdbin2))
        self.assertEqual(s1.chains[1],'A')
        self.assertEqual(s1.pdbs[2], os.path.basename(pdbin3))
        self.assertEqual(s1.chains[2],'A')
        
        p1r = [None, None, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 
               None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, <commit_msg>changed name; see revno 1955<commit_after>"""Test functions for python.ample_sequence"""

import os
import unittest
from ample.python import ample_sequence

class Test(unittest.TestCase):
    
    @classmethod
    def setUpClass(cls):
        """
        Set up paths. Need to do this with setUpClass, as otherwise the __file__
        variable is updated whenever the cwd is changed in a test and the next test
        gets the wrong paths.
        """
        cls.thisd =  os.path.abspath( os.path.dirname( __file__ ) )
        paths = cls.thisd.split( os.sep )
        cls.ample_dir = os.sep.join( paths[ : -2 ] )
        cls.tests_dir=os.path.join(cls.ample_dir,"tests")
        cls.testfiles_dir = os.path.join(cls.tests_dir,'testfiles')
        return

    def test_add(self):
        s1 = ample_sequence.Sequence(pdb=os.path.join(self.testfiles_dir,'1GU8.pdb'))
        s2 = ample_sequence.Sequence(fasta=os.path.join(self.testfiles_dir,'2uui.fasta'))
        s1 += s2
        
        self.assertTrue(len(s1.sequences),2)
        self.assertTrue(len(s1.resseqs),2)
        self.assertTrue(len(s1.headers),2)
        self.assertTrue(len(s1.pdbs),2)
        self.assertTrue(len(s1.chains),2)
        self.assertTrue(len(s1.fasta_files),2)
        
        # Test write for the hell of it
        #out_fasta = 'seq_add.fasta'
        #s1.write_fasta(out_fasta)
        #os.unlink(out_fasta)
        return

    def test_addPdbData(self):
        fasta1 = os.path.join(self.testfiles_dir,'1ujb_2a6pA_3c7tA.afasta')
        pdbin1 = os.path.join(self.ample_dir, 'examples', 'homologs','1ujbA.pdb')
        pdbin2 = os.path.join(self.ample_dir, 'examples', 'homologs','2a6pA.pdb')
        pdbin3 = os.path.join(self.ample_dir, 'examples', 'homologs','3c7tA.pdb')
        s1 = ample_sequence.Sequence(fasta=fasta1)
        s1.add_pdb_data(pdbin1)
        s1.add_pdb_data(pdbin2)
        s1.add_pdb_data(pdbin3)
        
        self.assertEqual(s1.pdbs[0], os.path.basename(pdbin1))
        self.assertEqual(s1.chains[0],'A')
        self.assertEqual(s1.pdbs[1], os.path.basename(pdbin2))
        self.assertEqual(s1.chains[1],'A')
        self.assertEqual(s1.pdbs[2], os.path.basename(pdbin3))
        self.assertEqual(s1.chains[2],'A')
        
        p1r = [None, None, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 
               None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 
{'fraction_non_alphanumeric': 0.14173680183626625, 'fraction_numerical': 0.045906656465187455, 'mean_word_length': 2.7217081850533806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7468750', 'n_tokens_mistral': 2105, 'n_tokens_neox': 1946, 'n_words': 386}