Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def list_installed_genomes(genomes_dir=None):
"""
List all available genomes.
Parameters
----------
genomes_dir : str
Directory with installed genomes.
Returns
-------
list with genome names
"""
genomes_dir = get_genomes_dir(genomes_dir, check_exist=False)
return (
[
f
for f in os.listdir(genomes_dir)
if _is_genome_dir(os.path.join(genomes_dir, f))
]
if os.path.exists(genomes_dir)
else []
)
def __init__(self, name, genomes_dir=None):
self.genomes_dir = get_genomes_dir(genomes_dir, check_exist=False)
self.name = self._parse_name(name)
self.filename = self._parse_filename(name)
super(Genome, self).__init__(self.filename)
# file paths
self.genome_file = self.filename
self.genome_dir = os.path.dirname(self.filename)
self.index_file = self.filename + ".fai"
self.sizes_file = self.genome_file + ".sizes"
self.gaps_file = os.path.join(self.genome_dir, self.name + ".gaps.bed")
self.readme_file = os.path.join(self.genome_dir, "README.txt")
# genome attributes
self.sizes = {}
self.gaps = {}
metadata = self._read_metadata()
If set to True, downloaded annotation files whose sequence names do not match
with the (first header fields of) the genome.fa will not be corrected.
kwargs : dict , optional
Provider specific options.
toplevel : bool , optional
Ensembl only: Always download the toplevel genome. Ignores potential primary assembly.
version : int , optional
Ensembl only: Specify release version. Default is latest.
to_annotation : text , optional
URL only: direct link to annotation file.
Required if this is not the same directory as the fasta.
"""
genomes_dir = get_genomes_dir(genomes_dir, check_exist=False)
localname = get_localname(name, localname)
out_dir = os.path.join(genomes_dir, localname)
# Check if genome already exists, or if downloading is forced
genome_found = (
len([f for f in glob_ext_files(out_dir) if f"{localname}.fa" in f]) >= 1
)
if (not genome_found or force) and not only_annotation:
# Download genome from provider
p = ProviderBase.create(provider)
p.download_genome(
name,
genomes_dir,
mask=mask,
regex=regex,
invert_match=invert_match,