コード例 #1
0
 def test_writeToFile(self):
     """FlowgramCollection.writeToFile should write in correct format"""
     a = [
         Flowgram('0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0',
                  Name='a',
                  header_info={
                      'Bases': 'TACCCCTTGG',
                      'Name Length': '14'
                  }),
         Flowgram('1.5 1.0 0.0 0.0 2.5 1.0 2.0 1.0',
                  Name='b',
                  header_info={
                      'Bases': 'TTATTTACCG',
                      'Name Length': '14'
                  })
     ]
     f = FlowgramCollection(a, header_info={'Flow Chars': 'TACG'})
     fn = mktemp(suffix='.sff')
     f.writeToFile(fn)
     result = open(fn, 'U').read()
     self.assertEqual(
         result,
         """Common Header:\n  Flow Chars:\tTACG\n\n>a\n  Name Length:\t14\nBases:\tTACCCCTTGG\nFlowgram:\t0.5\t1.0\t4.0\t0.0\t1.5\t0.0\t0.0\t2.0\n\n>b\n  Name Length:\t14\nBases:\tTTATTTACCG\nFlowgram:\t1.5\t1.0\t0.0\t0.0\t2.5\t1.0\t2.0\t1.0\n"""
     )
     remove(fn)
コード例 #2
0
 def test_getFlow(self):
     """FlowgramCollection.getFlow should return specified flow"""
     a = [('a','0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0'),
          ('b','1.5 1.0 0.0 0.0 2.5 1.0 2.0 1.0'),
          ('c','2.5 0.0 4.0 0.0 0.5 1.0 0.0 1.0')]
     f = FlowgramCollection(a)
     self.assertEqual(f.getFlow('a'), '0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0')
     self.assertRaises(KeyError, f.getFlow, 'd')
コード例 #3
0
 def test_getFlow(self):
     """FlowgramCollection.getFlow should return specified flow"""
     a = [('a','0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0'),
          ('b','1.5 1.0 0.0 0.0 2.5 1.0 2.0 1.0'),
          ('c','2.5 0.0 4.0 0.0 0.5 1.0 0.0 1.0')]
     f = FlowgramCollection(a)
     self.assertEqual(f.getFlow('a'), '0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0')
     self.assertRaises(KeyError, f.getFlow, 'd')
コード例 #4
0
    def test_createCommonHeader(self):
        """create_commor_header should return lines for sff common header"""
        a = [Flowgram('0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0', Name='a',
                      header_info = {'Bases':'TACCCCTTGG','Name Length':'14'}),
             Flowgram('1.5 1.0 0.0 0.0 2.5 1.0 2.0 1.0', Name = 'b',
              header_info = {'Bases':'TTATTTACCG','Name Length':'14'})]
        f = FlowgramCollection(a, header_info = {'Flow Chars':'TACG'})

        self.assertEqual('\n'.join(f.createCommonHeader()),
                         """Common Header:\n  Flow Chars:\tTACG""")
コード例 #5
0
    def test_createCommonHeader(self):
        """create_commor_header should return lines for sff common header"""
        a = [Flowgram('0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0', Name='a',
                      header_info = {'Bases':'TACCCCTTGG','Name Length':'14'}),
             Flowgram('1.5 1.0 0.0 0.0 2.5 1.0 2.0 1.0', Name = 'b',
              header_info = {'Bases':'TTATTTACCG','Name Length':'14'})]
        f = FlowgramCollection(a, header_info = {'Flow Chars':'TACG'})

        self.assertEqual('\n'.join(f.createCommonHeader()),
                         """Common Header:\n  Flow Chars:\tTACG""")
コード例 #6
0
 def test_getFlow(self):
     """FlowgramCollection.getFlow should return specified flow"""
     a = [
         ("a", "0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0"),
         ("b", "1.5 1.0 0.0 0.0 2.5 1.0 2.0 1.0"),
         ("c", "2.5 0.0 4.0 0.0 0.5 1.0 0.0 1.0"),
     ]
     f = FlowgramCollection(a)
     self.assertEqual(f.getFlow("a"), "0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0")
     self.assertRaises(KeyError, f.getFlow, "d")
コード例 #7
0
 def test_writeToFile(self):
     """FlowgramCollection.writeToFile should write in correct format"""
     a = [Flowgram('0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0', Name='a',
                   header_info = {'Bases':'TACCCCTTGG','Name Length':'14'}),
          Flowgram('1.5 1.0 0.0 0.0 2.5 1.0 2.0 1.0', Name = 'b',
           header_info = {'Bases':'TTATTTACCG','Name Length':'14'})]
     f = FlowgramCollection(a, header_info = {'Flow Chars':'TACG'})
     fn = mktemp(suffix='.sff')
     f.writeToFile(fn)
     result = open(fn, 'U').read()
     self.assertEqual(result, """Common Header:\n  Flow Chars:\tTACG\n\n>a\n  Name Length:\t14\nBases:\tTACCCCTTGG\nFlowgram:\t0.5\t1.0\t4.0\t0.0\t1.5\t0.0\t0.0\t2.0\n\n>b\n  Name Length:\t14\nBases:\tTTATTTACCG\nFlowgram:\t1.5\t1.0\t0.0\t0.0\t2.5\t1.0\t2.0\t1.0\n""")
     remove(fn)
コード例 #8
0
ファイル: test_preprocess.py プロジェクト: rob-knight/qiime
   def test_average_flowgrams(self):
       """_average_flowgrams computes an averaged flowgram for each cluster."""

       fc = FlowgramCollection({'a':'1.0 0.0 0.0 1.0 1.0 1.2 1.2 0.8',
                                'b':'1.2 1.0 0.0 0.8 1.2 2.4 1.0 0.0'})

       #return the centroid unmodified if sample_mapping = 1 
       actual = list(_average_flowgrams({'a':'b'}, fc, {'a':['a']}))
       self.assertEqual(actual , [(fc.getFlow('a'), 'a')])
       
       actual = list(_average_flowgrams({'a':'b'}, fc, {'a':['a','b']}))
       self.assertEqual(actual , [(Flowgram(['1.1 0.5 0.0 0.9 1.1 1.8 1.1 0.4']), 'a')])
コード例 #9
0
    def test_createCommonHeader(self):
        """create_commor_header should return lines for sff common header"""
        a = [
            Flowgram(
                "0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0", Name="a", header_info={"Bases": "TACCCCTTGG", "Name Length": "14"}
            ),
            Flowgram(
                "1.5 1.0 0.0 0.0 2.5 1.0 2.0 1.0", Name="b", header_info={"Bases": "TTATTTACCG", "Name Length": "14"}
            ),
        ]
        f = FlowgramCollection(a, header_info={"Flow Chars": "TACG"})

        self.assertEqual("\n".join(f.createCommonHeader()), """Common Header:\n  Flow Chars:\tTACG""")
コード例 #10
0
    def test_average_flowgrams(self):
        """_average_flowgrams computes an averaged flowgram for each cluster."""

        fc = FlowgramCollection({
            'a': '1.0 0.0 0.0 1.0 1.0 1.2 1.2 0.8',
            'b': '1.2 1.0 0.0 0.8 1.2 2.4 1.0 0.0'
        })

        #return the centroid unmodified if sample_mapping = 1
        actual = list(_average_flowgrams({'a': 'b'}, fc, {'a': ['a']}))
        self.assertEqual(actual, [(fc.getFlow('a'), 'a')])

        actual = list(_average_flowgrams({'a': 'b'}, fc, {'a': ['a', 'b']}))
        self.assertEqual(
            actual, [(Flowgram(['1.1 0.5 0.0 0.9 1.1 1.8 1.1 0.4']), 'a')])
コード例 #11
0
 def test_len(self):
     """len(FlowgramCollection) returns length of longest sequence"""
     a = [('a','0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0'),
          ('b','1.5 1.0 0.0 0.0 2.5 1.0 2.0 1.0'),
          ('c','2.5 0.0 4.0 0.0 0.5 1.0 0.0 1.0')]
     f = FlowgramCollection(a)
     self.assertEqual(len(f), 3)
コード例 #12
0
 def test_flows_from_flowCollection(self):
     """flows_from_flowCollection should init from existing collection"""
     c = FlowgramCollection({'a':'0.0 1.1 3.0 1.0','b':'0.5 1.0 4.0 0.0'})
     obs_a, obs_labels, obs_info = flows_from_flowCollection(c)
     self.assertEqual(map(str,obs_a), ['0.0\t1.1\t3.0\t1.0',
                                       '0.5\t1.0\t4.0\t0.0'])
     self.assertEqual(obs_labels, ['a','b'])
     self.assertEqual(obs_info, [None,None])
コード例 #13
0
 def test_str(self):
     """FlowgramCollection __str__ should return sff format"""
     a = [Flowgram('0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0', Name='a',
                   header_info = {'Bases':'TACCCCTTGG','Name Length':'14'}),
          Flowgram('1.5 1.0 0.0 0.0 2.5 1.0 2.0 1.0', Name = 'b',
           header_info = {'Bases':'TTATTTACCG','Name Length':'14'})]
     f = FlowgramCollection(a, header_info = {'Flow Chars':'TACG'})
     
     self.assertEqual(str(f), """Common Header:\n  Flow Chars:\tTACG\n\n>a\n  Name Length:\t14\nBases:\tTACCCCTTGG\nFlowgram:\t0.5\t1.0\t4.0\t0.0\t1.5\t0.0\t0.0\t2.0\n\n>b\n  Name Length:\t14\nBases:\tTTATTTACCG\nFlowgram:\t1.5\t1.0\t0.0\t0.0\t2.5\t1.0\t2.0\t1.0\n""")        
コード例 #14
0
 def test_writeToFile(self):
     """FlowgramCollection.writeToFile should write in correct format"""
     a = [
         Flowgram(
             "0.5 1.0 4.0 0.0 1.5 0.0 0.0 2.0", Name="a", header_info={"Bases": "TACCCCTTGG", "Name Length": "14"}
         ),
         Flowgram(
             "1.5 1.0 0.0 0.0 2.5 1.0 2.0 1.0", Name="b", header_info={"Bases": "TTATTTACCG", "Name Length": "14"}
         ),
     ]
     f = FlowgramCollection(a, header_info={"Flow Chars": "TACG"})
     fn = mktemp(suffix=".sff")
     f.writeToFile(fn)
     result = open(fn, "U").read()
     self.assertEqual(
         result,
         """Common Header:\n  Flow Chars:\tTACG\n\n>a\n  Name Length:\t14\nBases:\tTACCCCTTGG\nFlowgram:\t0.5\t1.0\t4.0\t0.0\t1.5\t0.0\t0.0\t2.0\n\n>b\n  Name Length:\t14\nBases:\tTTATTTACCG\nFlowgram:\t1.5\t1.0\t0.0\t0.0\t2.5\t1.0\t2.0\t1.0\n""",
     )
     remove(fn)
コード例 #15
0
   def test_container(self):
      """FlowgramContainerArray works as expectected"""
      
      fc = FlowgramCollection({'a':'1.0 0.0 0.0 1.0 1.0 1.2 1.2 0.8',
                                'b':'1.2 1.0 0.0 0.8 1.2 2.4 1.0 0.0'})

      f_container = FlowgramContainerArray(header)
      
      for f in fc:
         f_container.add(f)
         
      for f_obs, f_exp in zip(f_container,fc):
         self.assertEqual(str(f_obs), str(f_exp))
コード例 #16
0
   def test_container(self):
      """FlowgramContainerFile works as expected"""

      fc = FlowgramCollection({'a':'1.0 0.0 0.0 1.0 1.0 1.2 1.2 0.8',
                                'b':'1.2 1.0 0.0 0.8 1.2 2.4 1.0 0.0'})

      f_container = FlowgramContainerFile(header)
      
      for f in fc:
         f_container.add(f)
         
      for f_obs, f_exp in zip(f_container,fc):
         self.assertEqual(str(f_obs), str(f_exp))
         
      # adding after iter started raises errror
      self.assertRaises(ValueError, f_container.add,f_obs)
コード例 #17
0
    def test_prefix_filter_flowgrams(self):
        """prefix_filter_flowgrams maps all flowgrams which are exact prefixe."""

        fc = FlowgramCollection({
            'a': '1.0 0.0 0.0 1.0 1.0 1.2 1.2 0.8',
            'b': '1.2 1.0 0.0 0.8 1.2 2.4 1.0 0.0',
            'c': '2.0 0.0 0.0 1.0',
            'd': '1.1 0.3 0.0 1.1'
        })

        expected_squeeze_map = {'a': ['c', 'd'], 'b': []}
        expected_map = {'a': ['d'], 'b': [], 'c': []}

        obs = prefix_filter_flowgrams(fc)
        self.assertEqual(obs, (3, 4, expected_map))

        obs = prefix_filter_flowgrams(fc, squeeze=True)
        self.assertEqual(obs, (2, 4, expected_squeeze_map))