def test_sort_seqs_by_taxonomic_depth_equal_keys(self):
     """Test sorting sequences when keys are all equal."""
     exp = [['1', 3, 4, 'AGGT'], ['3', 3, 4, 'AGGC'], ['2', 3, 4, 'AGGA']]
     obs = sort_seqs_by_taxonomic_depth(self.seq_stats1)
     # Since we were given a dictionary of sequence stats, the order will
     # stay the same as was in the dictionary since we are doing a stable
     # sort. Thus, we can't simply test for equality because the key order
     # in the dictionary is not guaranteed.
     self.assertEqual(obs[0][1:3], exp[0][1:3])
     self.assertEqual(obs[1][1:3], exp[1][1:3])
     self.assertEqual(obs[2][1:3], exp[2][1:3])
Пример #2
0
 def test_sort_seqs_by_taxonomic_depth_equal_keys(self):
     """Test sorting sequences when keys are all equal."""
     exp = [["1", 3, 4, "AGGT"], ["3", 3, 4, "AGGC"], ["2", 3, 4, "AGGA"]]
     obs = sort_seqs_by_taxonomic_depth(self.seq_stats1)
     # Since we were given a dictionary of sequence stats, the order will
     # stay the same as was in the dictionary since we are doing a stable
     # sort. Thus, we can't simply test for equality because the key order
     # in the dictionary is not guaranteed.
     self.assertEqual(obs[0][1:3], exp[0][1:3])
     self.assertEqual(obs[1][1:3], exp[1][1:3])
     self.assertEqual(obs[2][1:3], exp[2][1:3])
Пример #3
0
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    seq_stats = compute_sequence_stats(
        open(opts.input_fasta_fp, 'U').readlines(),
        open(opts.input_taxonomy_map, 'U').readlines(),
        ['Incertae_sedis', 'unidentified'])
    seq_stats_sorted = sort_seqs_by_taxonomic_depth(seq_stats)

    # Write out our sorted sequences.
    out_fasta_f = open(opts.output_fp, 'w')
    for seq in seq_stats_sorted:
        out_fasta_f.write('>' + seq[0] + '\n' + seq[3] + '\n')
    out_fasta_f.close()
Пример #4
0
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    seq_stats = compute_sequence_stats(
            open(opts.input_fasta_fp, 'U').readlines(),
            open(opts.input_taxonomy_map, 'U').readlines(),
            ['Incertae_sedis', 'unidentified'])
    seq_stats_sorted = sort_seqs_by_taxonomic_depth(seq_stats)

    # Write out our sorted sequences.
    out_fasta_f = open(opts.output_fp, 'w')
    for seq in seq_stats_sorted:
        out_fasta_f.write('>' + seq[0] + '\n' + seq[3] + '\n')
    out_fasta_f.close()
Пример #5
0
    def test_sort_seqs_by_taxonomic_depth_mising_seq_in_fasta(self):
        """Test sorting with a sequence that was missing from FASTA file."""
        saved_stdout = sys.stdout
        try:
            out = StringIO()
            sys.stdout = out

            exp = [["2", 3, 7, "AGGAGTC"], ["3", 3, 5, "AGGTA"]]
            obs = sort_seqs_by_taxonomic_depth(self.seq_stats6)
            self.assertEqual(obs, exp)

            output = out.getvalue().strip()
            self.assertEqual(
                output, "Found sequence id '42' in the taxonomy " "mapping file that wasn't in the FASTA file"
            )
        finally:
            sys.stdout = saved_stdout
    def test_sort_seqs_by_taxonomic_depth_mising_seq_in_fasta(self):
        """Test sorting with a sequence that was missing from FASTA file."""
        saved_stdout = sys.stdout
        try:
            out = StringIO()
            sys.stdout = out

            exp = [['2', 3, 7, 'AGGAGTC'], ['3', 3, 5, 'AGGTA']]
            obs = sort_seqs_by_taxonomic_depth(self.seq_stats6)
            self.assertEqual(obs, exp)

            output = out.getvalue().strip()
            self.assertEqual(
                output, "Found sequence id '42' in the taxonomy "
                "mapping file that wasn't in the FASTA file")
        finally:
            sys.stdout = saved_stdout
Пример #7
0
 def test_sort_seqs_by_taxonomic_depth_all_same_tax_depth(self):
     """Test sorting with all taxonomic depths being the same."""
     exp = [["2", 3, 7, "AGGAGTC"], ["3", 3, 5, "AGGTA"], ["1", 3, 4, "AGGT"]]
     obs = sort_seqs_by_taxonomic_depth(self.seq_stats5)
     self.assertEqual(obs, exp)
Пример #8
0
 def test_sort_seqs_by_taxonomic_depth_single_seq(self):
     """Test sorting a single sequence."""
     exp = [["4", 3, 4, "AGGT"]]
     obs = sort_seqs_by_taxonomic_depth(self.seq_stats3)
     self.assertEqual(obs, exp)
Пример #9
0
 def test_sort_seqs_by_taxonomic_depth_unequal_keys(self):
     """Test sorting sequences when keys are all unequal."""
     exp = [["2", 6, 7, "AGGAGTC"], ["3", 5, 1, "A"], ["1", 3, 4, "AGGT"]]
     obs = sort_seqs_by_taxonomic_depth(self.seq_stats2)
     self.assertEqual(obs, exp)
 def test_sort_seqs_by_taxonomic_depth_all_same_tax_depth(self):
     """Test sorting with all taxonomic depths being the same."""
     exp = [['2', 3, 7, 'AGGAGTC'], ['3', 3, 5, 'AGGTA'],
            ['1', 3, 4, 'AGGT']]
     obs = sort_seqs_by_taxonomic_depth(self.seq_stats5)
     self.assertEqual(obs, exp)
 def test_sort_seqs_by_taxonomic_depth_single_seq(self):
     """Test sorting a single sequence."""
     exp = [['4', 3, 4, 'AGGT']]
     obs = sort_seqs_by_taxonomic_depth(self.seq_stats3)
     self.assertEqual(obs, exp)
 def test_sort_seqs_by_taxonomic_depth_unequal_keys(self):
     """Test sorting sequences when keys are all unequal."""
     exp = [['2', 6, 7, 'AGGAGTC'], ['3', 5, 1, 'A'], ['1', 3, 4, 'AGGT']]
     obs = sort_seqs_by_taxonomic_depth(self.seq_stats2)
     self.assertEqual(obs, exp)