File size: 2,234 Bytes
6d3b444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Unit tests for sequence validation functions.
"""
import unittest
from Bio.SeqUtils.ProtParam import ProteinAnalysis
from modules.validate_sequences import SequenceValidator

class TestSequenceValidator(unittest.TestCase):
    def setUp(self):
        # Test sequences with known properties
        self.test_sequences = {
            "acidic": "DDDEEEDDEE",  # Should have low pI
            "basic": "KKRRKKKRKR",   # Should have high pI
            "neutral": "GGGAAAGGG",   # Should have middle pI
            "mixed": "DEDKRKDEKR"     # Should have intermediate pI
        }
    
    def test_pi_calculation(self):
        """Test that pI calculations match BioPython's results."""
        for name, seq in self.test_sequences.items():
            validator = SequenceValidator(seq)
            our_properties = validator.calculate_properties()
            our_pi = our_properties["pI"]
            biopython_analysis = ProteinAnalysis(seq)
            biopython_pi = biopython_analysis.isoelectric_point()
            
            print(f"\nTesting {name} sequence:")
            print(f"Sequence: {seq}")
            print(f"Our pI: {our_pi}")
            print(f"BioPython pI: {biopython_pi}")
            print(f"Charge at pH 7: {validator.charge_at_ph(7.0)}")
            print(f"BioPython charge at pH 7: {biopython_analysis.charge_at_pH(7.0)}")
            
            self.assertAlmostEqual(
                our_pi, 
                biopython_pi, 
                places=1,
                msg=f"pI calculation failed for {name} sequence"
            )
    
    def test_gravy_calculation(self):
        """Test GRAVY calculations."""
        hydrophobic = "ILVAAA"  # Should have positive GRAVY
        hydrophilic = "RKDENN"  # Should have negative GRAVY
        
        validator_hydrophobic = SequenceValidator(hydrophobic)
        validator_hydrophilic = SequenceValidator(hydrophilic)
        
        gravy_hydrophobic = validator_hydrophobic.calculate_properties()["GRAVY"]
        gravy_hydrophilic = validator_hydrophilic.calculate_properties()["GRAVY"]
        
        self.assertGreater(gravy_hydrophobic, 0)
        self.assertLess(gravy_hydrophilic, 0)

if __name__ == '__main__':
    unittest.main()