Exemplo n.º 1
0
    def test_empty_input_succeed(self):
        novoalign = tools.novoalign.NovoalignTool()
        novoalign.install()

        # make the input fasta empty
        inFasta = util.file.mkstempfname('.input.fasta')
        util.file.touch(inFasta)
        novoalign.index_fasta(inFasta)

        inBam = os.path.join(util.file.get_test_input_path(), 'empty.bam')

        outFasta = util.file.mkstempfname('.refined.fasta')

        # run refine_assembly
        args = [
            inFasta, inBam, outFasta, "--chr_names", 'G5012.3',
            "--min_coverage", '3', "--novo_params",
            "-r Random -l 30 -g 40 -x 20 -t 502 -c {}".format(_CPUS)
        ]
        args = assembly.parser_refine_assembly(
            argparse.ArgumentParser()).parse_args(args)
        print(args)
        args.func_main(args)

        # the expected output is an empty fasta file
        self.assertTrue(os.path.isfile(outFasta))
        self.assertTrue(os.path.getsize(outFasta) == 0)
Exemplo n.º 2
0
    def test_ref_assisted_assembly(self):
        novoalign = tools.novoalign.NovoalignTool()
        novoalign.install()

        # prep inputs
        orig_ref = os.path.join(util.file.get_test_input_path(), 'ebov-makona.fasta')
        refGenome = util.file.mkstempfname('.ref.fasta')
        shutil.copyfile(orig_ref, refGenome)
        novoalign.index_fasta(refGenome)
        inBam = os.path.join(util.file.get_test_input_path(), 'G5012.3.testreads.bam')
        outFasta = util.file.mkstempfname('.refined.fasta')

        # run refine_assembly
        args = [refGenome, inBam, outFasta, "--chr_names", 'G5012.3', "--min_coverage", '3', "--novo_params",
                "-r Random -l 30 -g 40 -x 20 -t 502"]
        args = assembly.parser_refine_assembly().parse_args(args)
        args.func_main(args)
        self.assertTrue(os.path.isfile(outFasta))
        self.assertTrue(os.path.getsize(outFasta) > 1000)

        # check assembly quality
        with open(outFasta, 'rt') as inf:
            seq = Bio.SeqIO.read(inf, 'fasta')
            self.assertGreater(len(seq), 17000)
            self.assertGreater(assembly.unambig_count(seq.seq), len(seq) * 0.95)
    def test_aligned_empty_input_bam_assembly(self):
        mm2 = tools.minimap2.Minimap2()
        samtools = tools.samtools.SamtoolsTool()
        with util.file.tempfname('.ref.fasta') as inFasta:
            with util.file.tempfname('.bam') as inBam:
                with util.file.tempfname('.refined.fasta') as outFasta:
                    with util.file.tempfname('.vcf.gz') as outVcf:
                        shutil.copyfile(
                            os.path.join(util.file.get_test_input_path(),
                                         'ebov-makona.fasta'), inFasta)
                        mm2.align_bam(os.path.join(
                            util.file.get_test_input_path(), 'empty.bam'),
                                      inFasta,
                                      inBam,
                                      options=['-x', 'sr'])
                        samtools.index(inBam)

                        # run refine_assembly
                        args = [
                            inFasta, inBam, outFasta,
                            "--already_realigned_bam", inBam, '--outVcf',
                            outVcf
                        ]
                        args = assembly.parser_refine_assembly(
                            argparse.ArgumentParser()).parse_args(args)
                        args.func_main(args)

                        # the expected output is an empty fasta file
                        self.assertTrue(os.path.isfile(outFasta))
                        self.assertTrue(os.path.getsize(outFasta) == 0)
                        self.assertTrue(os.path.isfile(outVcf))
                        self.assertTrue(os.path.getsize(outVcf) > 0)
Exemplo n.º 4
0
    def test_empty_input_bam_assembly(self):
        novoalign = tools.novoalign.NovoalignTool()
        novoalign.install()

        # prep inputs
        orig_ref = os.path.join(util.file.get_test_input_path(),
                                'ebov-makona.fasta')
        inFasta = util.file.mkstempfname('.ref.fasta')
        shutil.copyfile(orig_ref, inFasta)
        novoalign.index_fasta(inFasta)

        inBam = os.path.join(util.file.get_test_input_path(), 'empty.bam')

        outFasta = util.file.mkstempfname('.refined.fasta')

        # run refine_assembly
        args = [
            inFasta, inBam, outFasta, "--chr_names", 'G5012.3',
            "--min_coverage", '3', "--novo_params",
            "-r Random -l 30 -g 40 -x 20 -t 502"
        ]
        args = assembly.parser_refine_assembly(
            argparse.ArgumentParser()).parse_args(args)
        args.func_main(args)

        # the expected output is an empty fasta file
        self.assertTrue(os.path.isfile(outFasta))
        self.assertTrue(os.path.getsize(outFasta) == 0)
Exemplo n.º 5
0
    def test_ref_assisted_assembly(self):
        novoalign = tools.novoalign.NovoalignTool()
        novoalign.install()

        # prep inputs
        orig_ref = os.path.join(util.file.get_test_input_path(), 'ebov-makona.fasta')
        refGenome = util.file.mkstempfname('.ref.fasta')
        shutil.copyfile(orig_ref, refGenome)
        novoalign.index_fasta(refGenome)
        inBam = os.path.join(util.file.get_test_input_path(), 'G5012.3.testreads.bam')
        outFasta = util.file.mkstempfname('.refined.fasta')

        # run refine_assembly
        args = [refGenome, inBam, outFasta, "--chr_names", 'G5012.3', "--min_coverage", '3', "--novo_params",
                "-r Random -l 30 -g 40 -x 20 -t 502"]
        args = assembly.parser_refine_assembly().parse_args(args)
        args.func_main(args)
        self.assertTrue(os.path.isfile(outFasta))
        self.assertTrue(os.path.getsize(outFasta) > 1000)

        # check assembly quality
        with open(outFasta, 'rt') as inf:
            seq = Bio.SeqIO.read(inf, 'fasta')
            self.assertGreater(len(seq), 17000)
            self.assertGreater(assembly.unambig_count(seq.seq), len(seq) * 0.95)
Exemplo n.º 6
0
    def test_empty_input_fasta_assembly(self):
        novoalign = tools.novoalign.NovoalignTool()
        novoalign.install()

        # make the input fasta empty
        inFasta = util.file.mkstempfname('.input.fasta')
        util.file.touch(inFasta)
        novoalign.index_fasta(inFasta)

        inBam = os.path.join(util.file.get_test_input_path(), 'G5012.3.testreads.bam')

        outFasta = util.file.mkstempfname('.refined.fasta')

        # run refine_assembly
        args = [inFasta, inBam, outFasta, "--chr_names", 'G5012.3', "--min_coverage", '3', "--novo_params",
                "-r Random -l 30 -g 40 -x 20 -t 502 -c {}".format(_CPUS)]
        args = assembly.parser_refine_assembly(argparse.ArgumentParser()).parse_args(args)
        args.func_main(args)

        # the expected output is an empty fasta file
        self.assertTrue(os.path.isfile(outFasta))
        self.assertTrue(os.path.getsize(outFasta) == 0)
Exemplo n.º 7
0
    def test_empty_input_bam_assembly(self):
        novoalign = tools.novoalign.NovoalignTool()
        novoalign.install()

        # prep inputs
        orig_ref = os.path.join(util.file.get_test_input_path(), 'ebov-makona.fasta')
        inFasta = util.file.mkstempfname('.ref.fasta')
        shutil.copyfile(orig_ref, inFasta)
        novoalign.index_fasta(inFasta)

        inBam = os.path.join(util.file.get_test_input_path(), 'empty.bam')
        
        outFasta = util.file.mkstempfname('.refined.fasta')

        # run refine_assembly
        args = [inFasta, inBam, outFasta, "--chr_names", 'G5012.3', "--min_coverage", '3', "--novo_params",
                "-r Random -l 30 -g 40 -x 20 -t 502"]
        args = assembly.parser_refine_assembly(argparse.ArgumentParser()).parse_args(args)
        args.func_main(args)

        # the expected output is an empty fasta file
        self.assertTrue(os.path.isfile(outFasta))
        self.assertTrue(os.path.getsize(outFasta) == 0)