Beispiel #1
0
def run(options):
    remover = contam_remover.ContamRemover(
        options.metadata_tsv,
        options.bam_in,
        options.counts_out,
        options.reads_out_1,
        options.reads_out_2,
        contam_out_1=options.contam_out_1,
        contam_out_2=options.contam_out_2,
        no_match_out_1=options.no_match_out_1,
        no_match_out_2=options.no_match_out_2,
        done_file=options.done_file,
    )
    remover.run()
    def test_run_no_match_not_wanted(self):
        """test run when no_match_are_wanted=False"""
        metadata_file = os.path.join(data_dir, "run.metadata.tsv")
        samfile = os.path.join(data_dir, "run.sam")
        outprefix = "tmp.contam_remover.test_run"
        counts_file = outprefix + ".counts.tsv"
        reads1 = outprefix + ".wanted_1.fq"
        reads2 = outprefix + ".wanted_2.fq"
        no_match1 = outprefix + ".no_match_1.fq"
        no_match2 = outprefix + ".no_match_2.fq"
        contam_1 = outprefix + ".contam_1.fq"
        contam_2 = outprefix + ".contam_2.fq"
        done_file = outprefix + ".done"
        if os.path.exists(done_file):
            os.unlink(done_file)
        cremover = contam_remover.ContamRemover(
            metadata_file,
            samfile,
            counts_file,
            reads1,
            reads2,
            contam_out_1=contam_1,
            contam_out_2=contam_2,
            no_match_out_1=no_match1,
            no_match_out_2=no_match2,
            done_file=done_file,
        )

        cremover.run()
        for read_type in "contam", "no_match", "wanted":
            for i in 1, 2:
                got_file = outprefix + "." + read_type + "_" + str(i) + ".fq"
                self.assertTrue(os.path.exists(got_file))
                expected_file = os.path.join(
                    data_dir,
                    "run.no_match_not_wanted." + read_type + "_" + str(i) +
                    ".fq",
                )
                self.assertTrue(
                    filecmp.cmp(expected_file, got_file, shallow=False))
                os.unlink(got_file)

        expected_counts_file = os.path.join(data_dir,
                                            "run.expected_counts.tsv")
        self.assertTrue(
            filecmp.cmp(expected_counts_file, counts_file, shallow=False))
        os.unlink(counts_file)
        self.assertTrue(os.path.exists(done_file))
        os.unlink(done_file)
    def test_run_no_match_not_wanted(self):
        '''test run when no_match_are_wanted=False'''
        metadata_file = os.path.join(data_dir, 'run.metadata.tsv')
        samfile = os.path.join(data_dir, 'run.sam')
        outprefix = 'tmp.contam_remover.test_run'
        counts_file = outprefix + '.counts.tsv'
        reads1 = outprefix + '.wanted_1.fq'
        reads2 = outprefix + '.wanted_2.fq'
        no_match1 = outprefix + '.no_match_1.fq'
        no_match2 = outprefix + '.no_match_2.fq'
        contam_1 = outprefix + '.contam_1.fq'
        contam_2 = outprefix + '.contam_2.fq'
        done_file = outprefix + '.done'
        if os.path.exists(done_file):
            os.unlink(done_file)
        cremover = contam_remover.ContamRemover(metadata_file,
                                                samfile,
                                                counts_file,
                                                reads1,
                                                reads2,
                                                contam_out_1=contam_1,
                                                contam_out_2=contam_2,
                                                no_match_out_1=no_match1,
                                                no_match_out_2=no_match2,
                                                done_file=done_file)

        cremover.run()
        for read_type in 'contam', 'no_match', 'wanted':
            for i in 1, 2:
                got_file = outprefix + '.' + read_type + '_' + str(i) + '.fq'
                self.assertTrue(os.path.exists(got_file))
                expected_file = os.path.join(
                    data_dir, 'run.no_match_not_wanted.' + read_type + '_' +
                    str(i) + '.fq')
                self.assertTrue(
                    filecmp.cmp(expected_file, got_file, shallow=False))
                os.unlink(got_file)

        expected_counts_file = os.path.join(data_dir,
                                            'run.expected_counts.tsv')
        self.assertTrue(
            filecmp.cmp(expected_counts_file, counts_file, shallow=False))
        os.unlink(counts_file)
        self.assertTrue(os.path.exists(done_file))
        os.unlink(done_file)