Back to index

python-biopython  1.60
test_CAPS.py
Go to the documentation of this file.
00001 import unittest
00002 
00003 from Bio import CAPS
00004 from Bio.Restriction import EcoRI, AluI
00005 from Bio import Alphabet
00006 from Bio.Seq import Seq
00007 from Bio.SeqRecord import SeqRecord
00008 from Bio.Align import MultipleSeqAlignment
00009 
00010 def createAlignment(sequences, alphabet):
00011     """Create an Alignment object from a list of sequences"""
00012     return MultipleSeqAlignment((SeqRecord(Seq(s,alphabet), id="sequence%i"%(i+1)) \
00013                                  for (i,s) in enumerate(sequences)),
00014                                 alphabet)
00015     
00016 class TestCAPS(unittest.TestCase):
00017 
00018     def test_trivial(self):
00019         enzymes = [EcoRI]
00020         alignment = ["gaattc",
00021                      "gaactc",
00022                     ]
00023         align = createAlignment(alignment, Alphabet.generic_dna)
00024         map = CAPS.CAPSMap(align, enzymes)
00025 
00026         self.assertEqual(len(map.dcuts), 1)
00027         self.assertEqual(map.dcuts[0].enzyme, EcoRI)
00028         self.assertEqual(map.dcuts[0].start, 1)
00029         self.assertEqual(map.dcuts[0].cuts_in, [0])
00030         self.assertEqual(map.dcuts[0].blocked_in, [1])
00031 
00032 
00033     def test(self):
00034         alignment = [
00035 """\
00036 AAAagaattcTAGATATACCAAACCAGAGAAAACAAATACATAATCGGAGAAATACAGAT
00037 AGAGAGCGAGAGAGATCGACGGCGAAGCTCTTTACCCGGAAACCATTGAAATCGGACGGT
00038 TTAGTGAAAATGGAGGATCAAGTagAtTTTGGGTTCCGTCCGAACGACGAGGAGCTCGTT
00039 GGTCACTATCTCCGTAACAAAATCGAAGGAAACACTAGCCGCGACGTTGAAGTAGCCATC
00040 AGCGAGGTCAACATCTGTAGCTACGATCCTTGGAACTTGCGCTGTAAGTTCCGAATTTTC
00041 """,
00042 """\
00043 AAAagaTttcTAGATATACCAAACCAGAGAAAACAAATACATAATCGGAGAAATACAGAT
00044 AGAGAGCGAGAGAGATCGACGGCGAAGCTCTTTACCCGGAAACCATTGAAATCGGACGGT
00045 TTAGTGAAAATGGAGGATCAAGTagctTTTGGGTTCCGTCCGAACGACGAGGAGCTCGTT
00046 GGTCACTATCTCCGTAACAAAATCGAAGGAAACACTAGCCGCGACGTTGAAGTAGCCATC
00047 AGCGAGGTCAACATCTGTAGCTACGATCCTTGGAACTTGCGCTGTAAGTTCCGAATTTTC
00048 """,
00049 """\
00050 AAAagaTttcTAGATATACCAAACCAGAGAAAACAAATACATAATCGGAGAAATACAGAT
00051 AGAGAGCGAGAGAGATCGACGGCGAAGCTCTTTACCCGGAAACCATTGAAATCGGACGGT
00052 TTAGTGAAAATGGAGGATCAAGTagctTTTGGGTTCCGTCCGAACGACGAGGAGCTCGTT
00053 GGTCACTATCTCCGTAACAAAATCGAAGGAAACACTAGCCGCGACGTTGAAGTAGCCATC
00054 AGCGAGGTCAACATCTGTAGCTACGATCCTTGGAACTTGCGCTGTAAGTTCCGAATTTTC
00055 """,
00056                     ]
00057         enzymes = [EcoRI, AluI]
00058         align = createAlignment(alignment, Alphabet.generic_dna)
00059         map = CAPS.CAPSMap(align, enzymes)
00060 
00061         self.assertEqual(len(map.dcuts), 2)
00062         self.assertEqual(map.dcuts[0].enzyme, EcoRI)
00063         self.assertEqual(map.dcuts[0].start, 5)
00064         self.assertEqual(map.dcuts[0].cuts_in, [0])
00065         self.assertEqual(map.dcuts[0].blocked_in, [1,2])
00066         self.assertEqual(map.dcuts[1].enzyme, AluI)
00067         self.assertEqual(map.dcuts[1].start, 144)
00068         self.assertEqual(map.dcuts[1].cuts_in, [1,2])
00069         self.assertEqual(map.dcuts[1].blocked_in, [0])
00070 
00071 
00072     def testNoCAPS(self):
00073         alignment = ["aaaaaaaaaaaaaaaaaaaa",
00074                      "aaaaaaaaaaaaaaaaaaaa",
00075                     ]
00076         enzymes = []
00077         align = createAlignment(alignment, Alphabet.generic_nucleotide)
00078         map = CAPS.CAPSMap(align, enzymes)
00079         self.assertEqual(map.dcuts, [])
00080 
00081 
00082     def test_uneven(self):
00083         alignment = ["aaaaaaaaaaaaaa",
00084                      "aaaaaaaaaaaaaa", #we'll change this below
00085                      "aaaaaaaaaaaaaa",
00086                     ]
00087         align = createAlignment(alignment, Alphabet.generic_nucleotide)
00088         align[1].seq = align[1].seq[:8] #evil
00089         self.assertRaises(CAPS.AlignmentHasDifferentLengthsError,
00090                           CAPS.CAPSMap,
00091                           align)
00092 
00093  
00094 
00095 if __name__ == "__main__":
00096     runner = unittest.TextTestRunner(verbosity = 2)
00097     unittest.main(testRunner=runner)