Mercurial > repos > greg > draw_features
changeset 7:c5555f1c8f49 draft
Uploaded
author | greg |
---|---|
date | Thu, 23 Mar 2023 17:20:23 +0000 |
parents | d5a5d145cfce |
children | 67520145696f |
files | draw_features.py |
diffstat | 1 files changed, 13 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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: