Пример #1
0
def main():
    option_parser, opts, args =\
        parse_command_line_parameters(**script_info)

    fasta_fp = opts.fasta_fp
    mapping_fp = opts.mapping_fp
    output_dir = opts.output_dir
    truncate_option = opts.truncate_option
    primer_mismatches = int(opts.primer_mismatches)

    create_dir(output_dir)

    if truncate_option not in ['truncate_only', 'truncate_remove']:
        raise ValueError('-z option must be either truncate_only or ' +
                         'truncate_remove')

    try:
        fasta_f = open(fasta_fp, "U")
        fasta_f.close()
    except IOError:
        raise IOError("Unable to open fasta file, please check path/" +
                      "permissions.")
    try:
        mapping_f = open(fasta_fp, "U")
        mapping_f.close()
    except IOError:
        raise IOError("Unable to open mapping file, please check path/" +
                      "permissions.")

    truncate_reverse_primer(fasta_fp, mapping_fp, output_dir, truncate_option,
                            primer_mismatches)
    def test_truncate_reverse_primer(self):
        """ Overall module functionality test """

        truncate_reverse_primer(self.fasta_fp, self.mapping_fp,
                                self.output_dir, truncate_option='truncate_only', primer_mismatches=2)

        output_log_fp = open(join(self.output_dir,
                                  "rev_primer_truncation.log"), "U")

        actual_log_lines = [line.strip() for line in output_log_fp]

        # Because filepaths used are recorded, need the tmp filepaths
        expected_log_lines = ['Details for removal of reverse primers',
                              'Original fasta filepath: %s' % self.fasta_fp,
                              'Total seqs in fasta: 6',
                              'Mapping filepath: %s' % self.mapping_fp,
                              'Truncation option: truncate_only',
                              'Mismatches allowed: 2',
                              'Total seqs written: 5',
                              'SampleIDs not found: 0',
                              'Reverse primers not found: 0']

        self.assertEqual(actual_log_lines, expected_log_lines)

        expected_fna_fp = basename(self.fasta_fp.replace('.fna', '')) +\
            "_rev_primer_truncated.fna"

        fasta_fp = open(join(self.output_dir, expected_fna_fp), "U")

        actual_fasta_output = [line.strip() for line in fasta_fp]

        self.assertEqual(actual_fasta_output,
                         self.expected_truncation_default_settings.strip().split('\n'))
Пример #3
0
def main():
    option_parser, opts, args =\
        parse_command_line_parameters(**script_info)

    fasta_fp = opts.fasta_fp
    mapping_fp = opts.mapping_fp
    output_dir = opts.output_dir
    truncate_option = opts.truncate_option
    primer_mismatches = int(opts.primer_mismatches)

    create_dir(output_dir)

    if truncate_option not in ['truncate_only', 'truncate_remove']:
        raise ValueError('-z option must be either truncate_only or ' +
                         'truncate_remove')

    try:
        fasta_f = open(fasta_fp, "U")
        fasta_f.close()
    except IOError:
        raise IOError("Unable to open fasta file, please check path/" +
                      "permissions.")
    try:
        mapping_f = open(fasta_fp, "U")
        mapping_f.close()
    except IOError:
        raise IOError("Unable to open mapping file, please check path/" +
                      "permissions.")

    truncate_reverse_primer(fasta_fp, mapping_fp, output_dir, truncate_option,
                            primer_mismatches)
Пример #4
0
    def test_truncate_reverse_primer(self):
        """ Overall module functionality test """

        truncate_reverse_primer(self.fasta_fp, self.mapping_fp,
                                self.output_dir, truncate_option='truncate_only', primer_mismatches=2)

        output_log_fp = open(join(self.output_dir,
                                  "rev_primer_truncation.log"), "U")

        actual_log_lines = [line.strip() for line in output_log_fp]

        # Because filepaths used are recorded, need the tmp filepaths
        expected_log_lines = ['Details for removal of reverse primers',
                              'Original fasta filepath: %s' % self.fasta_fp,
                              'Total seqs in fasta: 6',
                              'Mapping filepath: %s' % self.mapping_fp,
                              'Truncation option: truncate_only',
                              'Mismatches allowed: 2',
                              'Total seqs written: 5',
                              'SampleIDs not found: 0',
                              'Reverse primers not found: 0']

        self.assertEqual(actual_log_lines, expected_log_lines)

        expected_fna_fp = basename(self.fasta_fp.replace('.fna', '')) +\
            "_rev_primer_truncated.fna"

        fasta_fp = open(join(self.output_dir, expected_fna_fp), "U")

        actual_fasta_output = [line.strip() for line in fasta_fp]

        self.assertEqual(actual_fasta_output,
                         self.expected_truncation_default_settings.strip().split('\n'))