Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bgzip = False if bgzip == "unzipped" else True
genomepy.install_genome(
genome, provider, genome_dir=tmp, localname=localname, bgzip=bgzip, force=force
)
# force test
ext = ".fa.gz" if bgzip else ".fa"
name = genomepy.utils.get_localname(genome, localname)
path = os.path.join(tmp, name, name + ext)
t0 = os.path.getmtime(path)
# OSX rounds down getmtime to the second
if system() != "Linux":
sleep(1)
genomepy.install_genome(
genome, provider, genome_dir=tmp, localname=localname, bgzip=bgzip, force=force
)
t1 = os.path.getmtime(path)
assert t0 != t1 if force else t0 == t1
shutil.rmtree(tmp)
def test_bad_url():
"""Test URL.
Try to download a non-genome url link.
"""
with pytest.raises(ValueError):
genomepy.install_genome("www.google.com", "url")
def test_ucsc_genome(genome="sacCer3", provider="UCSC"):
"""Test UCSC.
Download S. cerevisiae genome from UCSC and retrieve a specific sequence."""
tmp = mkdtemp()
genomepy.install_genome(genome, provider, genome_dir=tmp)
g = genomepy.Genome(genome, genome_dir=tmp)
seq = g["chrIV"][1337000:1337020]
assert str(seq) == "TTTGGTTGTTCCTCTTCCTT"
def test_bad_url():
"""Test URL.
Try to download a non-genome url link.
"""
with pytest.raises(ValueError):
genomepy.install_genome("www.google.com", "url")
def test_nonexisting_url():
"""Test URL.
Try to download a non-genome url link.
"""
with pytest.raises(ValueError):
genomepy.install_genome("this is not an url", "url")
def test_zipped_genomes(zipped_genomes):
"""Download a gzipped and a tar.gzipped genome"""
genome = "ASM14646v1" if zipped_genomes == ".gz" else "sacCer3"
provider = "NCBI" if zipped_genomes == ".gz" else "UCSC"
tmp = mkdtemp()
genomepy.install_genome(genome, provider, genome_dir=tmp)
shutil.rmtree(tmp)
def test_install_options(bgzip_force, genome="sacCer3"):
"""Test force and bgzip"""
tmp = mkdtemp()
bgzip = False
if bgzip_force[0] == "bgzipped":
bgzip = True
force = False
if bgzip_force[1] == "overwrite":
force = True
genomepy.install_genome(genome, "UCSC", genome_dir=tmp, bgzip=bgzip, force=force)
ext = ".fa.gz" if bgzip else ".fa"
path = os.path.join(tmp, genome, genome + ext)
t0 = os.path.getmtime(path)
genomepy.install_genome(genome, "UCSC", genome_dir=tmp, bgzip=bgzip, force=force)
t1 = os.path.getmtime(path)
if force:
assert t0 != t1
else:
assert t0 == t1
shutil.rmtree(tmp)
def test_ensembl_human():
"""Test Ensembl.
Download human genome from Ensembl and retrieve a
specific sequence.
"""
tmp = mkdtemp()
genomepy.install_genome("GRCh38.p13", "Ensembl", genome_dir=tmp)
g = genomepy.Genome("GRCh38.p13", genome_dir=tmp)
seq = g["6"][166168664:166168679]
assert str(seq) == "CCTCCTCGCTCTCTT"
shutil.rmtree(tmp)
provider,
genomes_dir,
localname,
mask,
regex,
invert_match,
bgzip,
annotation,
only_annotation,
skip_sanitizing,
threads,
force,
**kwargs,
):
"""Install genome NAME from provider PROVIDER in directory GENOME_DIR."""
genomepy.install_genome(
name,
provider,
genomes_dir=genomes_dir,
localname=localname,
mask=mask,
regex=regex,
invert_match=invert_match,
bgzip=bgzip,
annotation=annotation,
only_annotation=only_annotation,
skip_sanitizing=skip_sanitizing,
threads=threads,
force=force,
**kwargs,
)