Skip to content

Commit c769a24

Browse files
committed
Fix #296: add 'available' CLI action listing supported species/releases
Iterates Species._latin_names_to_species and prints each species (with synonyms) and the Ensembl release range for every reference assembly it supports. Read-only, no I/O. Bump version to 2.6.12.
1 parent bdd38de commit c769a24

3 files changed

Lines changed: 48 additions & 3 deletions

File tree

pyensembl/shell.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,16 @@
147147
"delete-all-files",
148148
"delete-index-files",
149149
"list",
150+
"available",
150151
),
151152
help=(
152153
'"install" will download and index any data that is not '
153154
'currently downloaded or indexed. "delete-all-files" will delete all data '
154155
'associated with a genome annotation. "delete-index-files" deletes '
155156
"all files other than the original GTF and FASTA files for a genome. "
156-
'"list" will show you all installed Ensembl genomes.'
157+
'"list" will show you all installed Ensembl genomes. '
158+
'"available" prints every species and the Ensembl release ranges '
159+
"supported by pyensembl."
157160
),
158161
)
159162

@@ -249,6 +252,25 @@ def collect_selected_genomes(args):
249252
return all_combinations_of_ensembl_genomes(args)
250253

251254

255+
def format_available_species():
256+
"""
257+
Build the multi-line string printed by the "available" action: every
258+
registered species followed by its supported Ensembl release ranges,
259+
grouped by reference assembly.
260+
"""
261+
lines = []
262+
for latin_name in sorted(Species._latin_names_to_species):
263+
species = Species._latin_names_to_species[latin_name]
264+
if species.synonyms:
265+
synonyms = ",".join(species.synonyms)
266+
lines.append("* %s (%s):" % (latin_name, synonyms))
267+
else:
268+
lines.append("* %s:" % latin_name)
269+
for assembly, (start, end) in species.reference_assemblies.items():
270+
lines.append(" * %s: (%d, %d)" % (assembly, start, end))
271+
return "\n".join(lines)
272+
273+
252274
def run():
253275
args = parser.parse_args()
254276
if args.action == "list":
@@ -261,6 +283,8 @@ def run():
261283
filepaths = genome.required_local_files()
262284
directories = {os.path.split(path)[0] for path in filepaths}
263285
print("-- %s: %s" % (genome, ", ".join(directories)))
286+
elif args.action == "available":
287+
print(format_available_species())
264288
else:
265289
genomes = collect_selected_genomes(args)
266290

pyensembl/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "2.6.11"
1+
__version__ = "2.6.12"
22

33
def print_version():
44
print(f"v{__version__}")

tests/test_shell.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from pyensembl.shell import parser, all_combinations_of_ensembl_genomes
1+
from pyensembl.shell import (
2+
all_combinations_of_ensembl_genomes,
3+
format_available_species,
4+
parser,
5+
)
26
from .common import eq_
37

48

@@ -9,3 +13,20 @@ def test_genome_selection_grch38():
913
genome = genomes[0]
1014
eq_(genome.species.latin_name, "homo_sapiens")
1115
eq_(genome.release, 100)
16+
17+
18+
def test_available_action_parses():
19+
args = parser.parse_args(["available"])
20+
eq_(args.action, "available")
21+
22+
23+
def test_format_available_species_includes_human_and_assemblies():
24+
output = format_available_species()
25+
# human is registered with common name "human" and three reference assemblies
26+
assert "homo_sapiens" in output
27+
assert "human" in output
28+
assert "GRCh38" in output
29+
assert "GRCh37" in output
30+
# mouse should also appear
31+
assert "mus_musculus" in output
32+
assert "GRCm38" in output

0 commit comments

Comments
 (0)