def test_get_representatives(self): """get_representatives should return the representatives as list of Sequence.""" result = """>1: 5 ABABABA >3: 1 BABA >4: 1 ABABAA >8: 2 BABBA """ seqs = self.data.iteritems mapping = self.mapping test_result = list(get_representatives(mapping, seqs())) test_result_as_fasta = "".join(map(lambda a: a.to_fasta(), test_result)) self.assertEqual(test_result_as_fasta, result) # another example mapping = {'1': ('a', 'b', 'c'), '2': ('d', 'e', 'f')} seqs = [('1', "ACGT"), ('2', "TAGC"), ('a', "TTTTT")] observed = list(get_representatives(mapping, seqs)) expected = [ BiologicalSequence("ACGT", id="1"), BiologicalSequence("TAGC", id='2') ] self.assertEqual(observed, expected)
def test_get_representatives(self): """get_representatives should return the representatives as list of Sequence.""" result= """>1: 5 ABABABA >3: 1 BABA >4: 1 ABABAA >8: 2 BABBA""" seqs = self.data.iteritems mapping = self.mapping test_result = list(get_representatives(mapping, seqs())) test_result_as_fasta = "\n".join(map(lambda a: a.toFasta(),test_result)) self.assertEqual(test_result_as_fasta, result) #another example mapping = {'1': ('a','b','c'), '2': ('d','e','f')} seqs = [('1',"ACGT"), ('2', "TAGC"), ('a',"TTTTT")] observed = list(get_representatives(mapping, seqs)) expected = [Sequence(name = ">1", seq="ACGT"), Sequence(name='2', seq="TAGC")] self.assertEqual(observed, expected)
def print_rep_seqs(mapping, seqs, out_fp): """Print the cluster seeds of a mapping to out_fp. mapping: a cluster mapping seqs: a list of seqs contained in the mapping out_fp: output directory """ out_fh = open(out_fp + "/prefix_dereplicated.fasta", "w") for s in (get_representatives(mapping, seqs.iteritems())): out_fh.write(s.toFasta() + "\n") out_fh.close()
def print_rep_seqs(mapping, seqs, out_fp): """Print the cluster seeds of a mapping to out_fp. mapping: a cluster mapping seqs: a list of seqs contained in the mapping out_fp: output directory """ out_fh = open(out_fp + "/prefix_dereplicated.fasta", "w") for s in (get_representatives(mapping, seqs.iteritems())): out_fh.write(s.to_fasta()) out_fh.close()