How to use the snps.utils.gzip_file function in snps

To help you get started, we’ve selected a few snps examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apriha / snps / tests / io / test_reader.py View on Github external
def _setup_gsa_test(resources_dir):
        # reset resource if already loaded
        r = Resources()
        r._resources_dir = resources_dir
        r._gsa_resources = {}

        gzip_file(
            "tests/resources/gsa_rsid_map.txt",
            os.path.join(resources_dir, "gsa_rsid_map.txt.gz"),
        )
        gzip_file(
            "tests/resources/gsa_chrpos_map.txt",
            os.path.join(resources_dir, "gsa_chrpos_map.txt.gz"),
        )
github apriha / snps / tests / io / test_reader.py View on Github external
def _setup_gsa_test(resources_dir):
        # reset resource if already loaded
        r = Resources()
        r._resources_dir = resources_dir
        r._gsa_resources = {}

        gzip_file(
            "tests/resources/gsa_rsid_map.txt",
            os.path.join(resources_dir, "gsa_rsid_map.txt.gz"),
        )
        gzip_file(
            "tests/resources/gsa_chrpos_map.txt",
            os.path.join(resources_dir, "gsa_chrpos_map.txt.gz"),
        )
github apriha / snps / tests / io / test_reader.py View on Github external
with tempfile.TemporaryDirectory() as tmpdir:
            file1 = os.path.join(tmpdir, "ftdna_concat_gzip1.csv")
            file1_gz = "{}.gz".format(file1)
            file2 = os.path.join(tmpdir, "ftdna_concat_gzip2.csv")
            file2_gz = "{}.gz".format(file2)
            path = os.path.join(tmpdir, "ftdna_concat_gzip.csv.gz")

            # write individual files
            with open(file1, "w") as f:
                f.write(s1)
            with open(file2, "w") as f:
                f.write(s2)

            # compress files
            gzip_file(file1, file1_gz)
            gzip_file(file2, file2_gz)

            # concatenate gzips
            with open(file1_gz, "rb") as f:
                data = f.read()
            with open(file2_gz, "rb") as f:
                data += f.read()

            # add extra data
            data += b"extra data"

            # write file with concatenated gzips and extra data
            with open(path, "wb") as f:
                f.write(data)

            self.make_parsing_assertions(
                self.parse_file(path), "FTDNA", False, 37, False, snps_df
github apriha / snps / tests / io / test_reader.py View on Github external
with tempfile.TemporaryDirectory() as tmpdir:
            file1 = os.path.join(tmpdir, "ftdna_concat_gzip1.csv")
            file1_gz = "{}.gz".format(file1)
            file2 = os.path.join(tmpdir, "ftdna_concat_gzip2.csv")
            file2_gz = "{}.gz".format(file2)
            path = os.path.join(tmpdir, "ftdna_concat_gzip.csv.gz")

            # write individual files
            with open(file1, "w") as f:
                f.write(s1)
            with open(file2, "w") as f:
                f.write(s2)

            # compress files
            gzip_file(file1, file1_gz)
            gzip_file(file2, file2_gz)

            # concatenate gzips
            with open(file1_gz, "rb") as f:
                data = f.read()
            with open(file2_gz, "rb") as f:
                data += f.read()

            # add extra data
            data += b"extra data"

            # write file with concatenated gzips and extra data
            with open(path, "wb") as f:
                f.write(data)

            self.make_parsing_assertions(
github apriha / snps / tests / __init__.py View on Github external
def run_parsing_tests(
        self, file, source, phased=False, build=37, build_detected=False, snps_df=None
    ):
        self.make_parsing_assertions(
            self.parse_file(file), source, phased, build, build_detected, snps_df
        )
        self.make_parsing_assertions(
            self.parse_bytes(file), source, phased, build, build_detected, snps_df
        )

        with tempfile.TemporaryDirectory() as tmpdir:
            base = os.path.basename(file)
            dest = os.path.join(tmpdir, "{}.gz".format(base))
            gzip_file(file, dest)
            self.make_parsing_assertions(
                self.parse_file(dest), source, phased, build, build_detected, snps_df
            )
            self.make_parsing_assertions(
                self.parse_bytes(dest), source, phased, build, build_detected, snps_df
            )
            # remove .gz extension
            shutil.move(dest, dest[:-3])
            self.make_parsing_assertions(
                self.parse_file(dest[:-3]),
                source,
                phased,
                build,
                build_detected,
                snps_df,
            )
github apriha / snps / tests / io / test_writer.py View on Github external
def test_save_snps_vcf(self):
        s = SNPs("tests/input/testvcf.vcf")

        r = Resources()
        r._reference_sequences["GRCh37"] = {}

        with tempfile.TemporaryDirectory() as tmpdir:
            dest = os.path.join(tmpdir, "generic.fa.gz")
            gzip_file("tests/input/generic.fa", dest)

            seq = ReferenceSequence(ID="1", path=dest)

            r._reference_sequences["GRCh37"]["1"] = seq

            self.assertEqual(
                os.path.relpath(s.save_snps(vcf=True)), "output/vcf_GRCh37.vcf"
            )

        self.run_parsing_tests_vcf("output/vcf_GRCh37.vcf")