Exemple #1
0
 def test_mask_vcf_removes_matching_sites(self, vcf_file, out_file):
     """mask_vcf should remove the given sites from the VCF file"""
     mask.mask_vcf([4, 5], vcf_file, out_file)
     with open(out_file) as after, open(vcf_file) as before:
         assert len(after.readlines()) == len(
             before.readlines()) - 1, "Too many lines removed!"
         assert "SEQ\t5" not in after.read(), "Correct sites not removed!"
Exemple #2
0
 def test_mask_vcf_bails_on_no_chrom(self, tmpdir):
     """mask_vcf should pull a sys.exit() if get_chrom_name returns None"""
     bad_vcf = str(tmpdir / "bad.vcf")
     with open(bad_vcf, "w") as fh:
         fh.write("#")
     with pytest.raises(SystemExit) as err:
         mask.mask_vcf([], bad_vcf, "")
Exemple #3
0
    def test_mask_vcf_cleanup_flag(self, vcf_file, mp_context):
        """mask_vcf should respect the cleanup flag"""
        tmp_mask_file = vcf_file + "_maskTemp"
        mp_context.setattr(mask, "run_shell_command", lambda *a, **k: None)
        mp_context.setattr(mask, "get_chrom_name", lambda f: "SEQ")

        mask.mask_vcf([], vcf_file, "", cleanup=True)
        assert not os.path.isfile(
            tmp_mask_file), "Temporary mask not cleaned up"

        mask.mask_vcf([], vcf_file, "", cleanup=False)
        assert os.path.isfile(
            tmp_mask_file), "Temporary mask cleaned up as expected"
Exemple #4
0
    def test_mask_vcf_handles_gz(self, vcf_file, mp_context):
        """mask_vcf should recognize when the in or out files are .gz and call out accordingly"""
        def test_shell(call, raise_errors=True):
            assert "--gzvcf" in call
            assert "| gzip -c" in call

        mp_context.setattr(mask, "run_shell_command", test_shell)
        mp_context.setattr(mask, "get_chrom_name", lambda f: "SEQ")
        # Still worth using the fixture here because writing the mask file uses this path
        # Using it for both entries in case god forbid someone starts assuming that path
        # valid earlier than it currently is.
        in_file = vcf_file + ".gz"
        mask.mask_vcf([1, 5], in_file, in_file)
Exemple #5
0
    def test_mask_vcf_creates_maskfile(self, vcf_file, mp_context):
        """mask_vcf should create a 1-indexed mask file from the 0-indexed list of sites"""
        mask_file = vcf_file + "_maskTemp"

        def shell_has_maskfile(call, **kwargs):
            assert mask_file in call

        mp_context.setattr(mask, "get_chrom_name", lambda f: "SEQ")
        mp_context.setattr(mask, "run_shell_command", shell_has_maskfile)
        mask.mask_vcf([1, 5], vcf_file, vcf_file, cleanup=False)
        assert os.path.isfile(mask_file), "Mask file was not written!"
        with open(mask_file) as fh:
            assert fh.read() == "SEQ	2\nSEQ	6", "Incorrect mask file written!"