Skip to content

Commit

Permalink
fixed bug that led to crash if no genes with mutations where found in…
Browse files Browse the repository at this point in the history
… gff3
  • Loading branch information
jonas-fuchs committed Oct 23, 2023
1 parent b8eac47 commit e64640b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions virheat/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def main(sysargs=sys.argv[1:]):
# define relative locations of all items in the plot
n_samples = len(frequency_array)
n_mutations = len(frequency_array[0])
if n_mutations == 0:
sys.exit("\033[31m\033[1mERROR:\033[0m Frequency array seems to be empty. There is nothing to plot.")
if n_samples < 4:
genome_y_location = 2
else:
Expand Down Expand Up @@ -159,11 +161,12 @@ def main(sysargs=sys.argv[1:]):
plotting.create_heatmap(ax, frequency_array, cmap_cells)
mutation_set = plotting.create_genome_vis(ax, genome_y_location, n_mutations, unique_mutations, genome_end)
if args.gff3_path is not None:
# distinct colors for the genes
cmap_genes = plt.get_cmap('tab20', len(genes_with_mutations))
colors_genes = [cmap_genes(i) for i in range(len(genes_with_mutations))]
# plot gene track
plotting.create_gene_vis(ax, genes_with_mutations, n_mutations, y_size, n_tracks, genome_end, min_y_location, genome_y_location, colors_genes)
if genes_with_mutations:
# distinct colors for the genes
cmap_genes = plt.get_cmap('tab20', len(genes_with_mutations))
colors_genes = [cmap_genes(i) for i in range(len(genes_with_mutations))]
# plot gene track
plotting.create_gene_vis(ax, genes_with_mutations, n_mutations, y_size, n_tracks, genome_end, min_y_location, genome_y_location, colors_genes)
plotting.create_axis(ax, n_mutations, min_y_location, n_samples, file_names, genome_end, genome_y_location, unique_mutations, reference_name)
plotting.create_colorbar(args.threshold, cmap_cells, min_y_location, n_samples, ax)
plotting.create_mutation_legend(mutation_set, min_y_location, n_samples)
Expand Down
3 changes: 2 additions & 1 deletion virheat/scripts/data_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ def create_track_dict(unique_mutations, gff3_info, annotation_type):
gff3_info[type][annotation]["stop"])
)
if not genes_with_mutations:
sys.exit("none of the given annotation types were found in gff3.")
print("\033[31m\033[1mWARNING:\033[0m either the annotation types were not found in gff3 or no genes with mutations.")
return {}, 0

# create a dict and sort
gene_dict = {element[0]: [element[1:4]] for element in genes_with_mutations}
Expand Down

0 comments on commit e64640b

Please sign in to comment.