annotate commons/core/seq/test/TestClusterConsensusCollection.py @ 31:0ab839023fe4

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 14:33:21 -0400
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 import unittest
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 import os
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 from commons.core.seq.ClusterConsensusCollection import ClusterConsensusCollection
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 from commons.core.seq.Bioseq import Bioseq
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 from commons.core.seq.BioseqDB import BioseqDB
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 class TestClusterConsensusCollection(unittest.TestCase):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 def setUp(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 self._clusterSequencesFileName = "clusterSequences.fa"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 self._ClusterConsensusCollection = ClusterConsensusCollection(self._clusterSequencesFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 self._createClusterConsensusFile()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 def tearDown(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 os.remove(self._clusterSequencesFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 def test_fillCollection(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 expClusterConsensusCollection = ClusterConsensusCollection(self._clusterSequencesFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 expClusterConsensusCollection._clusterFileName = self._clusterSequencesFileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 bioseq1 = Bioseq("seq1", "ACCAAAGACACTAGAATAACAAGATGCGTAACGCCATACGATTTTTTGGCACACTATTTT")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 bioseq2 = Bioseq("seq2", "ACCAAAGACACTAGAATAACAAGATGCGTAACGCCATACGATTTTTTGGCACACTATTTT")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 bioseq3 = Bioseq("seq3", "ACCAAAGACACTAGAATAACAAGATGCGTAACGCCATACGATTTTTTGGCACACTATTTT")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 iBioseqDB1 = BioseqDB()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 iBioseqDB2 = BioseqDB()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 iBioseqDB1.setData([bioseq1, bioseq2])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 iBioseqDB2.setData([bioseq3])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 expClusterConsensusCollection._lClusterConsensus = [iBioseqDB1, iBioseqDB2]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 self._ClusterConsensusCollection.fillCollection()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 self.assertEqual(expClusterConsensusCollection, self._ClusterConsensusCollection)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 def test_getNumClusterForAConsensus_for_seq2(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 self._ClusterConsensusCollection.fillCollection()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 expClusterNumber = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 obsClusterNumber = self._ClusterConsensusCollection.getNumClusterForAConsensus ("seq2")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 self.assertEqual(expClusterNumber, obsClusterNumber)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 def test_getNumClusterForAConsensus_for_seq3(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 self._ClusterConsensusCollection.fillCollection()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 expClusterNumber = 2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 obsClusterNumber = self._ClusterConsensusCollection.getNumClusterForAConsensus ("seq3")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 self.assertEqual(expClusterNumber, obsClusterNumber)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 def test_getNumConsensusInCluster_1(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 self._ClusterConsensusCollection.fillCollection()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 expConsensusNumber = 2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 obsConsensusNumber = self._ClusterConsensusCollection.getNumConsensusInCluster (1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 self.assertEqual(expConsensusNumber, obsConsensusNumber)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 def test_getNumConsensusInCluster_2(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 self._ClusterConsensusCollection.fillCollection()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 expConsensusNumber = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 obsConsensusNumber = self._ClusterConsensusCollection.getNumConsensusInCluster (2)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 self.assertEqual(expConsensusNumber, obsConsensusNumber)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 def _createClusterConsensusFile(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 fCluster = open(self._clusterSequencesFileName, "w")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 fCluster.write(">BlastclustCluster1Mb1 seq1\n")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 fCluster.write("ACCAAAGACACTAGAATAACAAGATGCGTAACGCCATACGATTTTTTGGCACACTATTTT\n")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 fCluster.write(">BlastclustCluster1Mb2 seq2\n")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 fCluster.write("ACCAAAGACACTAGAATAACAAGATGCGTAACGCCATACGATTTTTTGGCACACTATTTT\n")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 fCluster.write(">BlasterGrouperCluster3Mb1 seq3\n")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 fCluster.write("ACCAAAGACACTAGAATAACAAGATGCGTAACGCCATACGATTTTTTGGCACACTATTTT\n")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 fCluster.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 if __name__ == "__main__":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 unittest.main()