Mercurial > repos > greg > draw_features
comparison draw_features.py @ 7:c5555f1c8f49 draft
Uploaded
| author | greg | 
|---|---|
| date | Thu, 23 Mar 2023 17:20:23 +0000 | 
| parents | 7d47800ee5ac | 
| children | 67520145696f | 
   comparison
  equal
  deleted
  inserted
  replaced
| 6:d5a5d145cfce | 7:c5555f1c8f49 | 
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python | 
| 2 | 2 | 
| 3 import argparse | 3 import argparse | 
| 4 import os | 4 import os | 
| 5 import random | |
| 5 | 6 | 
| 7 import matplotlib.pyplot as pyplot | |
| 6 import pandas | 8 import pandas | 
| 7 import matplotlib.pyplot as pyplot | |
| 8 from Bio import SeqIO | 9 from Bio import SeqIO | 
| 9 from dna_features_viewer import GraphicFeature, GraphicRecord | 10 from dna_features_viewer import GraphicFeature, GraphicRecord | 
| 10 | 11 | 
| 11 | 12 | 
| 12 AMR_COLOR = '#FED976' | 13 AMR_COLOR = '#FED976' | 
| 13 INC_GROUPS_COLOR = '#0570B0' | 14 INC_GROUPS_COLOR = '#0570B0' | 
| 14 FEATURE_COLORS = [AMR_COLOR, INC_GROUPS_COLOR] | 15 FEATURE_COLORS = [AMR_COLOR, INC_GROUPS_COLOR] | 
| 15 FIGURE_WIDTH = 13 | 16 FIGURE_WIDTH = 13 | 
| 17 | |
| 18 | |
| 19 def get_random_color(): | |
| 20 number_of_colors = 16 | |
| 21 colors = ['#%s' % ' '.join([random.choice('0123456789ABCDEF') for j in range(6)]) for i in range(number_of_colors)] | |
| 22 return random.choice(colors) | |
| 16 | 23 | 
| 17 | 24 | 
| 18 def draw_features(feature_hits_files, contigs, output_dir): | 25 def draw_features(feature_hits_files, contigs, output_dir): | 
| 19 ofh = open('process_log', 'w') | 26 ofh = open('process_log', 'w') | 
| 20 # Read feature_hits_files. | 27 # Read feature_hits_files. | 
| 49 # No features. | 56 # No features. | 
| 50 continue | 57 continue | 
| 51 features_to_plot = [] | 58 features_to_plot = [] | 
| 52 for i in range(contig_features.shape[0]): | 59 for i in range(contig_features.shape[0]): | 
| 53 i = contig_features.iloc[i, :] | 60 i = contig_features.iloc[i, :] | 
| 54 features_to_plot += [GraphicFeature(start=i[1], end=i[2], label=i[3], strand=1 * i[5], color=FEATURE_COLORS[feature_number])] | 61 if feature_number <= len(FEATURE_COLORS): | 
| 62 color = FEATURE_COLORS[feature_number] | |
| 63 else: | |
| 64 color = get_random_color() | |
| 65 features_to_plot += [GraphicFeature(start=i[1], end=i[2], label=i[3], strand=1 * i[5], color=color)] | |
| 55 feature_sets_to_plot[feature_name] = features_to_plot | 66 feature_sets_to_plot[feature_name] = features_to_plot | 
| 56 ofh.write("Number of features to plot: %d\n" % len(feature_sets_to_plot)) | 67 ofh.write("Number of features to plot: %d\n" % len(feature_sets_to_plot)) | 
| 57 if len(feature_sets_to_plot) == 0: | 68 if len(feature_sets_to_plot) == 0: | 
| 58 # No features. | 69 # No features. | 
| 59 continue | 70 continue | 
