Example #1
0
    def test_call_ref_only(self):
        """ReferenceRepSetPicker.__call__ functions with no non-refseqs"""

        fd, tmp_otu_filepath = mkstemp(prefix='ReferenceRepSetPickerTest_',
                                       suffix='.otu')
        close(fd)
        otu_file = open(tmp_otu_filepath, 'w')
        otu_file.write(otus_all_ref)
        otu_file.close()
        self.files_to_remove.append(tmp_otu_filepath)

        exp = {
            'ref1': ('ref1', 'GGGGGGGAAAAAAAAAAAAA'),
            'ref0': ('ref0', 'CCCAAAAAAATTTTTT')
        }

        # passing only reference (not input seqs)
        app = ReferenceRepSetPicker(params={
            'Algorithm': 'first',
            'ChoiceF': first_id
        })
        obs = app(None, tmp_otu_filepath, self.ref_seq_filepath)
        self.assertEqual(obs, exp)

        # passing reference and input seqs
        app = ReferenceRepSetPicker(params={
            'Algorithm': 'first',
            'ChoiceF': first_id
        })
        obs = app(self.tmp_seq_filepath, tmp_otu_filepath,
                  self.ref_seq_filepath)
        self.assertEqual(obs, exp)
Example #2
0
    def test_call_invalid_id(self):
        """ReferenceRepSetPicker.__call__ expected clusters default params"""
        app = ReferenceRepSetPicker(params={
            'Algorithm': 'first',
            'ChoiceF': first_id
        })

        fd, tmp_otu_filepath = mkstemp(prefix='ReferenceRepSetPickerTest_',
                                       suffix='.otu')
        close(fd)
        otu_file = open(tmp_otu_filepath, 'w')
        # replace a valid sequence identifier with an invalid
        # sequence identifier (i.e., one that we don't have a sequence for)
        otu_file.write(otus_w_ref.replace('R27DLI_4812', 'bad_seq_identifier'))
        otu_file.close()
        self.files_to_remove.append(tmp_otu_filepath)

        # returning in dict
        self.assertRaises(KeyError, app, self.tmp_seq_filepath,
                          tmp_otu_filepath, self.ref_seq_filepath)
        # writing to file
        self.assertRaises(KeyError,
                          app,
                          self.tmp_seq_filepath,
                          tmp_otu_filepath,
                          self.ref_seq_filepath,
                          result_path=self.result_filepath)
Example #3
0
    def test_non_ref_otus(self):
        """ReferenceRepSetPicker.__call__ same result as Generic when no ref otus
        """
        exp = {
            '0': ('R27DLI_4812', 'CTGGGCCGTATCTC'),
            '1': ('U1PLI_7889', 'TTGGACCGTG'),
            '2': ('W3Cecum_4858', 'TTGGGCCGTGTCTCAGT'),
            '3': ('R27DLI_3243', 'CTGGACCGTGTCT')
        }
        fd, tmp_otu_filepath = mkstemp(prefix='ReferenceRepSetPickerTest_',
                                       suffix='.otu')
        close(fd)
        otu_file = open(tmp_otu_filepath, 'w')
        otu_file.write(otus)
        otu_file.close()

        self.files_to_remove.append(tmp_otu_filepath)

        app = ReferenceRepSetPicker(params={
            'Algorithm': 'first',
            'ChoiceF': first_id
        })
        obs = app(self.tmp_seq_filepath, tmp_otu_filepath,
                  self.ref_seq_filepath)
        self.assertEqual(obs, exp)
Example #4
0
 def test_call_write_to_file(self):
     """ReferenceRepSetPicker.__call__ otu map correctly written to file"""
     app = ReferenceRepSetPicker(params={'Algorithm':'first', 
         'ChoiceF':first_id})
     app(self.tmp_seq_filepath,
               self.tmp_otu_filepath,
               self.ref_seq_filepath,
               result_path=self.result_filepath)
     exp = rep_seqs_reference_result_file_exp
     self.assertEqual(LoadSeqs(self.result_filepath,aligned=False), 
                      LoadSeqs(data=exp,aligned=False))
Example #5
0
 def test_call_default_params(self):
     """ReferenceRepSetPicker.__call__ expected clusters default params"""
     
     exp = {'0':('R27DLI_4812','CTGGGCCGTATCTC'),\
            'ref1':('ref1','GGGGGGGAAAAAAAAAAAAA'),\
            '2':('W3Cecum_4858','TTGGGCCGTGTCTCAGT'),\
            'ref0':('ref0','CCCAAAAAAATTTTTT'),\
           } 
     app = ReferenceRepSetPicker(params={'Algorithm':'first', 
         'ChoiceF':first_id})
     obs = app(self.tmp_seq_filepath,
               self.tmp_otu_filepath,
               self.ref_seq_filepath)
     self.assertEqual(obs, exp)
Example #6
0
 def test_call_write_to_file(self):
     """ReferenceRepSetPicker.__call__ otu map correctly written to file"""
     app = ReferenceRepSetPicker(params={
         'Algorithm': 'first',
         'ChoiceF': first_id
     })
     app(self.tmp_seq_filepath,
         self.tmp_otu_filepath,
         self.ref_seq_filepath,
         result_path=self.result_filepath)
     with open(self.result_filepath) as f:
         actual = SequenceCollection.from_fasta_records(parse_fasta(f), DNA)
     expected = SequenceCollection.from_fasta_records(
         parse_fasta(rep_seqs_reference_result_file_exp.split('\n')), DNA)
     # we don't care about order in the results
     self.assertEqual(set(actual), set(expected))
Example #7
0
 def test_call_alt_non_ref_picker(self):
     """ReferenceRepSetPicker.__call__ handles alt non-ref picking method"""
     
     exp = {'0':('U1PLI_9526','CTGGGCCGTATCTCAGTCCCAATGTGGCCGGTCG'
                 'GTCTCTCAACCCGGCTACCCATCGCGGGCTAGGTGGGCCGTT'
                 'ACCCCGCCTACTACCTAATGGGCCGCGACCCCATCCCTTGCCGTCTGGGC'
                 'TTTCCCGGGCCCCCCAGGAGGGGGGCGAGGAGTATCCGGTATTAGCCTCGGTT'
                 'TCCCAAGGTTGTCCCGGAGCAAGGGGCAGGTTGGTCACGTGTTACTCACCCGT'
                 'TCGCCACTTCATGTCCGCCCGAGGGCGGTTTCATCG'),\
            'ref1':('ref1','GGGGGGGAAAAAAAAAAAAA'),\
            '2':('W3Cecum_4858','TTGGGCCGTGTCTCAGT'),\
            'ref0':('ref0','CCCAAAAAAATTTTTT'),\
           } 
     app = ReferenceRepSetPicker(params={'Algorithm':'longest', 
         'ChoiceF':longest_id})
     obs = app(self.tmp_seq_filepath,
               self.tmp_otu_filepath,
               self.ref_seq_filepath)
     self.assertEqual(obs, exp)