Esempio n. 1
0
    def test_assign_taxonomy_file_output(self):
        """ assign_taxonomy wrapper writes correct file output when requested
        
            This function tests for sucessful completion of assign_taxonomy
             when writing to file, that the lines in the file roughly look
             correct by verifying how many are written (by zipping with 
             expected), and that each line starts with the correct seq id.
             Actual testing of taxonomy data is performed elsewhere.
        
        """
        output_fp = get_tmp_filename(\
         prefix='RDPAssignTaxonomyTests',suffix='.txt')
        # convert the expected dict to a list of lines to match
        # file output
        expected_file_headers = self.expected_assignments1.keys()
        expected_file_headers.sort()

        actual_return_value = assign_taxonomy(\
         self.test_input1,min_confidence=0.95,output_fp=output_fp)

        actual_file_output = list(open(output_fp))
        actual_file_output.sort()

        # remove the output_fp before running the tests, so if they
        # fail the output file is still cleaned-up
        remove(output_fp)

        # None return value on write to file
        self.assertEqual(actual_return_value, None)

        # check that each line starts with the correct seq_id -- not
        # checking the taxonomies or confidences here as these are variable and
        # tested elsewhere
        for a, e in zip(actual_file_output, expected_file_headers):
            self.assertTrue(a.startswith(e))
    def test_assign_taxonomy_file_output(self):
        """ assign_taxonomy wrapper writes correct file output when requested
        
            This function tests for sucessful completion of assign_taxonomy
             when writing to file, that the lines in the file roughly look
             correct by verifying how many are written (by zipping with 
             expected), and that each line starts with the correct seq id.
             Actual testing of taxonomy data is performed elsewhere.
        
        """
        output_fp = get_tmp_filename(\
         prefix='RDPAssignTaxonomyTests',suffix='.txt')
        # convert the expected dict to a list of lines to match 
        # file output
        expected_file_headers = self.expected_assignments1.keys()
        expected_file_headers.sort()
        
        actual_return_value = assign_taxonomy(\
         self.test_input1,min_confidence=0.95,output_fp=output_fp)
        
        actual_file_output = list(open(output_fp))
        actual_file_output.sort()

        # remove the output_fp before running the tests, so if they
        # fail the output file is still cleaned-up
        remove(output_fp)
        
        # None return value on write to file
        self.assertEqual(actual_return_value,None)
        
        # check that each line starts with the correct seq_id -- not 
        # checking the taxonomies or confidences here as these are variable and
        # tested elsewhere
        for a,e in zip(actual_file_output,expected_file_headers):
            self.assertTrue(a.startswith(e))
Esempio n. 3
0
 def test_assign_taxonomy_short_sequence(self):
     """assign_taxonomy should return Unclassifiable if sequence is too short
     """
     assignments = assign_taxonomy([
         '>MySeq 1',
         'TTCCGGTTGATCCTGCCGGACCCGACTGCTATCCGGA',
     ])
     self.assertEqual(assignments, {'MySeq 1': ('Unassignable', 1.0)})
 def test_assign_taxonomy_short_sequence(self):
     """assign_taxonomy should return Unclassifiable if sequence is too short
     """
     assignments = assign_taxonomy([
         '>MySeq 1',
         'TTCCGGTTGATCCTGCCGGACCCGACTGCTATCCGGA',
         ])
     self.assertEqual(assignments, {'MySeq 1': ('Unassignable', 1.0)})
Esempio n. 5
0
    def test_assign_taxonomy(self):
        """assign_taxonomy wrapper functions as expected 
        
            This test may fail periodicially, but failure should be rare.
        
        """
        # convert the expected dict to a list, so it's easier to
        # handle the order
        expected_assignments = \
         [(k,v[0],v[1]) for k,v in self.expected_assignments1.items()]
        expected_assignments.sort()

        # Because there is some variation in the taxon assignments,
        # I run the test several times (which can be quite slow) and
        # each sequence was classified the same as expected at least once
        taxon_assignment_results = [False] * len(expected_assignments)
        all_assigned_correctly = False
        for i in range(10):
            actual_assignments = assign_taxonomy(self.test_input1)
            # covert actual_assignments to a list so it's easier to handle
            # the order
            actual_assignments = \
             [(k,v[0],v[1]) for k,v in actual_assignments.items()]
            actual_assignments.sort()

            for j in range(len(expected_assignments)):
                a = actual_assignments[j]
                e = expected_assignments[j]
                # same description fields
                self.assertEqual(a[0], e[0])

                # same taxonomic assignment
                r = a[1] == e[1]
                if r and not taxon_assignment_results[j]:
                    taxon_assignment_results[j] = True

                # confidence >= 0.80
                self.assertTrue(a[2] >= 0.80)

            if False not in taxon_assignment_results:
                # all sequences have been correctly assigned at
                # least once -- bail out
                all_assigned_correctly = True
                break

        # make sure all taxonomic results were correct at least once
        self.assertTrue(all_assigned_correctly)
 def test_assign_taxonomy(self):
     """assign_taxonomy wrapper functions as expected 
     
         This test may fail periodicially, but failure should be rare.
     
     """
     # convert the expected dict to a list, so it's easier to 
     # handle the order
     expected_assignments = \
      [(k,v[0],v[1]) for k,v in self.expected_assignments1.items()]
     expected_assignments.sort()
     
     # Because there is some variation in the taxon assignments, 
     # I run the test several times (which can be quite slow) and 
     # each sequence was classified the same as expected at least once
     taxon_assignment_results = [False] * len(expected_assignments)
     all_assigned_correctly = False
     for i in range(10):
         actual_assignments = assign_taxonomy(self.test_input1)
         # covert actual_assignments to a list so it's easier to handle
         # the order
         actual_assignments = \
          [(k,v[0],v[1]) for k,v in actual_assignments.items()]
         actual_assignments.sort()
         
         for j in range(len(expected_assignments)):
             a = actual_assignments[j]
             e = expected_assignments[j]
             # same description fields
             self.assertEqual(a[0],e[0])
             
             # same taxonomic assignment
             r = a[1] == e[1]
             if r and not taxon_assignment_results[j]:
                 taxon_assignment_results[j] = True
             
             # confidence >= 0.80
             self.assertTrue(a[2]>=0.80)
             
         if False not in taxon_assignment_results:
             # all sequences have been correctly assigned at
             # least once -- bail out
             all_assigned_correctly = True
             break
     
     # make sure all taxonomic results were correct at least once
     self.assertTrue(all_assigned_correctly)
Esempio n. 7
0
    def test_assign_taxonomy_alt_confidence(self):
        """assign_taxonomy wrapper functions as expected with alt confidence
        """
        actual_assignments = \
         assign_taxonomy(self.test_input1,min_confidence=0.95)
        # covert actual_assignments to a list so it's easier to handle
        # the order
        actual_assignments = \
             [(k,v[0],v[1]) for k,v in actual_assignments.items()]
        actual_assignments.sort()

        # convert the expected dict to a list, so it's easier to
        # handle the order
        expected_assignments = \
         [(k,v[0],v[1]) for k,v in self.expected_assignments1.items()]
        expected_assignments.sort()

        for a, e in zip(actual_assignments, expected_assignments):
            # same description fields
            self.assertEqual(a[0], e[0])
            # confidence >= 0.95
            self.assertTrue(a[2] >= 0.95)
 def test_assign_taxonomy_alt_confidence(self):
     """assign_taxonomy wrapper functions as expected with alt confidence
     """
     actual_assignments = \
      assign_taxonomy(self.test_input1,min_confidence=0.95)            
     # covert actual_assignments to a list so it's easier to handle
     # the order
     actual_assignments = \
          [(k,v[0],v[1]) for k,v in actual_assignments.items()]
     actual_assignments.sort()
     
     # convert the expected dict to a list, so it's easier to 
     # handle the order
     expected_assignments = \
      [(k,v[0],v[1]) for k,v in self.expected_assignments1.items()]
     expected_assignments.sort()
     
     for a,e in zip(actual_assignments,expected_assignments):
         # same description fields
         self.assertEqual(a[0],e[0])
         # confidence >= 0.95
         self.assertTrue(a[2]>=0.95)