Skip to content

Commit

Permalink
accommodate edge case of 1 contigs db/pan genome with colormap
Browse files Browse the repository at this point in the history
  • Loading branch information
semiller10 committed Sep 18, 2024
1 parent 438ac47 commit e420286
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
20 changes: 16 additions & 4 deletions anvio/keggmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,15 @@ def map_contigs_databases_kos(
# Sample the colormap for colors representing each possible number of contigs
# databases. Lower color values correspond to smaller numbers of databases.
if sampling == 'in_order':
sample_points = range(len(contigs_dbs))
if len(contigs_dbs) == 1:
sample_points = range(1, 2)
else:
sample_points = range(len(contigs_dbs))
elif sampling == 'even':
sample_points = np.linspace(0, 1, len(contigs_dbs))
if len(contigs_dbs) == 1:
sample_points = np.linspace(1, 1, 1)
else:
sample_points = np.linspace(0, 1, len(contigs_dbs))
else:
raise AssertionError

Expand Down Expand Up @@ -1055,9 +1061,15 @@ def map_pan_database_kos(
# Sample the colormap for colors representing each possible number of genomes. Lower
# color values correspond to smaller numbers of databases.
if sampling == 'in_order':
sample_points = range(len(genome_names))
if len(genome_names) == 1:
sample_points = range(1, 2)
else:
sample_points = range(len(genome_names))
elif sampling == 'even':
sample_points = np.linspace(0, 1, len(genome_names))
if len(genome_names) == 1:
sample_points = np.linspace(1, 1, 1)
else:
sample_points = np.linspace(0, 1, len(genome_names))
else:
raise AssertionError

Expand Down
22 changes: 17 additions & 5 deletions bin/anvi-draw-kegg-pathways
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,24 @@ def main() -> None:

mapper = Mapper(kegg_dir=args.kegg_dir, overwrite_output=args.overwrite_output_destinations)

if args.contigs_dbs is not None and len(args.contigs_dbs) == 1 and args.ko is True:
if (
args.contigs_dbs is not None and
len(args.contigs_dbs) == 1 and
args.colormap is None and
args.ko is True
):
map_single_contigs_db_ko_data(args, mapper)
elif args.contigs_dbs is not None and len(args.contigs_dbs) > 1 and args.ko is True:
elif (
args.contigs_dbs is not None and
args.ko is True
):
map_multiple_contigs_dbs_ko_data(args, mapper)

if args.pan_db is not None and args.genomes_storage is not None and args.ko is True:
if (
args.pan_db is not None and
args.genomes_storage is not None and
args.ko is True
):
map_pan_db_ko_data(args, mapper)

def get_args() -> Namespace:
Expand Down Expand Up @@ -223,7 +235,7 @@ def consolidate_contigs_dbs(args: Namespace) -> None:
args.contigs_dbs += external_genomes_table['contigs_db_path'].tolist()

def map_single_contigs_db_ko_data(args: Namespace, mapper: Mapper) -> None:
"""Draw KO data from a single contigs database source."""
"""Draw KO data from a single contigs database source in the absence of a colormap."""
map_contigs_database_kos = mapper.map_contigs_database_kos

if args.set_color is None or args.set_color is True:
Expand All @@ -242,7 +254,7 @@ def map_single_contigs_db_ko_data(args: Namespace, mapper: Mapper) -> None:
)

def map_multiple_contigs_dbs_ko_data(args: Namespace, mapper: Mapper) -> None:
"""Draw KO data from multiple contigs database sources."""
"""Draw KO data from contigs database sources."""
map_contigs_databases_kos = mapper.map_contigs_databases_kos

if args.draw_individual_files is None:
Expand Down

0 comments on commit e420286

Please sign in to comment.