# HG changeset patch # User greg # Date 1679592023 0 # Node ID c5555f1c8f49e54443c2e68b12b3d24a832deffe # Parent d5a5d145cfce45a95861750375b765d398e0f74e Uploaded diff -r d5a5d145cfce -r c5555f1c8f49 draw_features.py --- a/draw_features.py Fri Mar 10 18:02:00 2023 +0000 +++ b/draw_features.py Thu Mar 23 17:20:23 2023 +0000 @@ -2,9 +2,10 @@ import argparse import os +import random +import matplotlib.pyplot as pyplot import pandas -import matplotlib.pyplot as pyplot from Bio import SeqIO from dna_features_viewer import GraphicFeature, GraphicRecord @@ -15,6 +16,12 @@ FIGURE_WIDTH = 13 +def get_random_color(): + number_of_colors = 16 + colors = ['#%s' % ' '.join([random.choice('0123456789ABCDEF') for j in range(6)]) for i in range(number_of_colors)] + return random.choice(colors) + + def draw_features(feature_hits_files, contigs, output_dir): ofh = open('process_log', 'w') # Read feature_hits_files. @@ -51,7 +58,11 @@ features_to_plot = [] for i in range(contig_features.shape[0]): i = contig_features.iloc[i, :] - features_to_plot += [GraphicFeature(start=i[1], end=i[2], label=i[3], strand=1 * i[5], color=FEATURE_COLORS[feature_number])] + if feature_number <= len(FEATURE_COLORS): + color = FEATURE_COLORS[feature_number] + else: + color = get_random_color() + features_to_plot += [GraphicFeature(start=i[1], end=i[2], label=i[3], strand=1 * i[5], color=color)] feature_sets_to_plot[feature_name] = features_to_plot ofh.write("Number of features to plot: %d\n" % len(feature_sets_to_plot)) if len(feature_sets_to_plot) == 0: