comparison commons/core/seq/test/TestClusterConsensusCollection.py @ 6:769e306b7933

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