Permalink
Browse files

Finish turning test_SeqUtils.py into unittest based test

  • Loading branch information...
peterjc committed Jan 7, 2013
1 parent cc90569 commit 132f8d7c03496033cd3a277865eb1a9a1dedfdc2
Showing with 51 additions and 51 deletions.
  1. +0 −30 Tests/output/test_SeqUtils
  2. +51 −21 Tests/test_SeqUtils.py
View
@@ -1,30 +0,0 @@
-test_SeqUtils
-gi|1348912|gb|G26680|G26680 has GC% of 42.2
-gi|1348917|gb|G26685|G26685 has GC% of 38.0
-gi|1592936|gb|G29385|G29385 has GC% of 41.0
-
-Codon Adaption Index (CAI)
-Example CAI 0.09978 using E. coli (default)
-Example CAI 0.67213 using Yersinia pestis biovar Microtus str. 91001
-
-Example 1, length 110, QSALTQPASV...
- u_crc32 = 2994980265
- crc64 = CRC-44CAAD88706CC153
- gcg = 9729
- seguid = BpBeDdcNUYNsdk46JoJdw7Pd3BI
- simple_LCC = 1.03
- windowed_LCC = 0.00, 1.00, 0.96, 0.96, 0.96, 0.65, 0.43, 0.35, 0.35, 0.35, 0.35, 0.53, 0.59, 0.26
-Example 2, length 110, QSALTQPASV...
- u_crc32 = 802105214
- crc64 = CRC-44CAAD88706CC153
- gcg = 9647
- seguid = X5XEaayob1nZLOc7eVT9qyczarY
- simple_LCC = 1.07
- windowed_LCC = 0.00, 1.00, 0.96, 0.96, 0.96, 0.65, 0.43, 0.35, 0.35, 0.35, 0.35, 0.53, 0.59, 0.26
-Example 3, length 32, ATGCGTATCG...
- u_crc32 = 817679856
- crc64 = CRC-6234FF451DC6DFC6
- gcg = 7959
- seguid = 8WCUbVjBgiRmM10gfR7XJNjbwnE
- simple_LCC = 1.98
- windowed_LCC = 0.00, 2.00, 1.99, 1.99, 2.00, 1.99, 1.97, 1.99, 1.99, 1.99, 1.96, 1.96, 1.96, 1.96
View
@@ -57,7 +57,14 @@ def test_quick_fasta_reader(self):
for tuple_record, seq_record in zip(tuple_records, seq_records):
self.assertEqual(tuple_record, (seq_record.description, str(seq_record.seq)))
- def test_codon_usage(self):
+ def test_codon_usage_ecoli(self):
+ """Test Codon Adaptation Index (CAI) using default E. coli data."""
+ CAI = CodonAdaptationIndex()
+ self.assertEqual("%0.5f" % CAI.cai_for_gene("ATGCGTATCGATCGCGATACGATTAGGCGGATG"),
+ "0.09978")
+
+ def test_codon_usage_custom(self):
+ """Test Codon Adaptation Index (CAI) using FASTA file for background."""
#We need a FASTA file of CDS sequences to count the codon usage...
dna_fasta_filename = "fasta.tmp"
dna_genbank_filename = "GenBank/NC_005816.gb"
@@ -87,10 +94,11 @@ def test_codon_usage(self):
# Note - this needs a FASTA file which containing non-ambiguous DNA coding
# sequences - which should each be a whole number of codons.
CAI.generate_index(dna_fasta_filename)
- print "Example CAI %0.5f using %s" \
- % (CAI.cai_for_gene("ATGCGTATCGATCGCGATACGATTAGGCGGATG"),
- record.annotations["source"])
-
+ # Now check codon usage index (CAI) using this species
+ self.assertEqual(record.annotations["source"],
+ "Yersinia pestis biovar Microtus str. 91001")
+ self.assertEqual("%0.5f" % CAI.cai_for_gene("ATGCGTATCGATCGCGATACGATTAGGCGGATG"),
+ "0.67213")
os.remove(dna_fasta_filename)
def test_crc_checksum_collision(self):
@@ -101,22 +109,44 @@ def test_crc_checksum_collision(self):
self.assertNotEqual(gcg(self.str_light_chain_one), gcg(self.str_light_chain_two))
self.assertNotEqual(seguid(self.str_light_chain_one), seguid(self.str_light_chain_two))
- def test_checksum(self):
- #Print some output, which the test harness will check
- examples = [self.str_light_chain_one, self.str_light_chain_two,
- "ATGCGTATCGATCGCGATACGATTAGGCGGAT"]
-
- for i, seq_str in enumerate(examples):
- print "Example %i, length %i, %s..." % (i+1, len(seq_str), seq_str[:10])
-
- for checksum in [u_crc32, crc64, gcg, seguid, simple_LCC, windowed_LCC]:
- #First using a string:
- value = checksum(seq_str)
- print " %s = %s" % (checksum.__name__, value)
- #Secondly check it works with a Seq object
- self.assertEqual(value, checksum(Seq(seq_str, single_letter_alphabet)))
- #Finally check it works with a MutableSeq object
- self.assertEqual(value, checksum(MutableSeq(seq_str, single_letter_alphabet)))
+ def seq_checksums(self, seq_str, exp_crc32, exp_crc64, exp_gcg, exp_seguid,
+ exp_simple_LCC, exp_window_LCC):
+ for s in [seq_str,
+ Seq(seq_str, single_letter_alphabet),
+ MutableSeq(seq_str, single_letter_alphabet)]:
+ self.assertEqual(exp_crc32, u_crc32(s))
+ self.assertEqual(exp_crc64, crc64(s))
+ self.assertEqual(exp_gcg, gcg(s))
+ self.assertEqual(exp_seguid, seguid(s))
+ self.assertEqual(exp_simple_LCC, simple_LCC(s))
+ self.assertEqual(exp_window_LCC, windowed_LCC(s))
+
+ def test_checksum1(self):
+ self.seq_checksums(self.str_light_chain_one,
+ 2994980265,
+ "CRC-44CAAD88706CC153",
+ 9729,
+ "BpBeDdcNUYNsdk46JoJdw7Pd3BI",
+ "1.03",
+ "0.00, 1.00, 0.96, 0.96, 0.96, 0.65, 0.43, 0.35, 0.35, 0.35, 0.35, 0.53, 0.59, 0.26")
+
+ def test_checksum2(self):
+ self.seq_checksums(self.str_light_chain_two,
+ 802105214,
+ "CRC-44CAAD88706CC153",
+ 9647,
+ "X5XEaayob1nZLOc7eVT9qyczarY",
+ "1.07",
+ "0.00, 1.00, 0.96, 0.96, 0.96, 0.65, 0.43, 0.35, 0.35, 0.35, 0.35, 0.53, 0.59, 0.26")
+
+ def test_checksum3(self):
+ self.seq_checksums("ATGCGTATCGATCGCGATACGATTAGGCGGAT",
+ 817679856,
+ "CRC-6234FF451DC6DFC6",
+ 7959,
+ "8WCUbVjBgiRmM10gfR7XJNjbwnE",
+ "1.98",
+ "0.00, 2.00, 1.99, 1.99, 2.00, 1.99, 1.97, 1.99, 1.99, 1.99, 1.96, 1.96, 1.96, 1.96")
def test_GC(self):
seq = "ACGGGCTACCGTATAGGCAAGAGATGATGCCC"

1 comment on commit 132f8d7

@cbrueffer

This comment has been minimized.

Show comment
Hide comment
@cbrueffer

cbrueffer Jan 18, 2013

Member

Thanks for cleaning this up! I'm back from vacation, so will start looking at some other loose ends soon.

Member

cbrueffer commented on 132f8d7 Jan 18, 2013

Thanks for cleaning this up! I'm back from vacation, so will start looking at some other loose ends soon.

Please sign in to comment.