Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_ensemblgenomes_annotation(localname=None):
"""Test Ensembl annotation
This annotation is hosted on ftp.ensemblgenomes.org.
"""
tmp = mkdtemp()
p = genomepy.provider.ProviderBase.create("Ensembl")
for name, version in [("TAIR10", 45)]:
p.download_annotation(name, tmp, localname=localname, version=version)
localname = genomepy.utils.get_localname(name, localname)
gtf = os.path.join(tmp, localname, localname + ".annotation.gtf.gz")
validate_gzipped_gtf(gtf)
bed = os.path.join(tmp, localname, localname + ".annotation.bed.gz")
validate_gzipped_bed(bed)
shutil.rmtree(tmp)
def test_install_annotation_options(
force, localname, annotation=True, genome="ASM14646v1", provider="NCBI"
):
"""Test force and localname with annotations"""
tmp = mkdtemp()
force = False if force == "no-overwrite" else True
localname = None if localname == "original_name" else "My_localname"
# create dummy fasta to skip download_genome step
name = genomepy.utils.get_localname(genome, localname)
path = os.path.join(tmp, name, name + ".fa")
os.mkdir(os.path.dirname(path))
with open(path, "w") as f:
f.write(">Chr1\nAAAACCCCTTTTGGGG\n")
genomepy.install_genome(
genome,
provider,
genome_dir=tmp,
localname=localname,
annotation=annotation,
force=False,
)
gtf = os.path.join(tmp, name, name + ".annotation.gtf.gz")
validate_gzipped_gtf(gtf)
def test_install_genome_options(
force, localname, bgzip, genome="ASM2732v1", provider="NCBI"
):
"""Test force, localname and bgzip"""
tmp = mkdtemp()
force = False if force == "no-overwrite" else True
localname = None if localname == "original_name" else "My_localname"
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)