-
Notifications
You must be signed in to change notification settings - Fork 13
/
sigProfilerPlotting.py
11228 lines (10577 loc) · 399 KB
/
sigProfilerPlotting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# Author: Erik Bergstrom
# Contact: ebergstr@eng.ucsd.edu
import argparse
import copy
import errno
import io
import itertools
import logging
import os
import pickle
import re
import string
import sys
import warnings
from bdb import set_trace
from collections import OrderedDict
import matplotlib
import matplotlib.font_manager
import matplotlib.lines as lines
import matplotlib.patches as mplpatches
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib.transforms as transforms
import numpy as np
import pandas as pd
import sklearn
from matplotlib.backends.backend_pdf import PdfPages
from matplotlib.ticker import LinearLocator
from PIL import Image
from sklearn.preprocessing import LabelEncoder
import sigProfilerPlotting as spplt
matplotlib.use("Agg")
MUTTYPE = "MutationType"
INDEX_VALS = ["MutationType", "index", "Mutation Types", "classification"]
SPP_PATH = spplt.__path__[0]
SPP_TEMPLATES = os.path.join(SPP_PATH, "templates/")
SPP_FONTS = os.path.join(SPP_PATH, "fonts/")
SPP_REFERENCE = os.path.join(SPP_PATH, "reference_formats/")
_FONTS_LOADED = False
logging.getLogger("matplotlib.font_manager").disabled = False
warnings.filterwarnings("ignore")
type_dict = {
"96": "SBS96.txt",
"sbs": "SBS96.txt",
"sbs96": "SBS96.txt",
"288": "SBS288.txt",
"sbs288": "SBS288.txt",
"sbs1536": "SBS1536.txt",
"1536": "SBS1536.txt",
"sbs6144": "SBS6144.txt",
"6144": "SBS6144.txt",
"78": "DBS78.txt",
"dbs": "DBS78.txt",
"dbs78": "DBS78.txt",
"dinuc": "DBS78.txt",
"83": "ID83.txt",
"id": "ID83.txt",
"id83": "ID83.txt",
"cnv48": "CNV48.txt",
"48": "CNV48.txt",
"sv32": "SV32.txt",
"32": "SV32.txt",
}
# Loads fonts required for plotting
def load_custom_fonts():
global _FONTS_LOADED
if not _FONTS_LOADED:
for font_file in os.listdir(SPP_FONTS):
if font_file.endswith(".ttf"):
try:
font_path = os.path.join(SPP_FONTS, font_file)
matplotlib.font_manager.fontManager.addfont(font_path)
except:
print("ERROR loading font: " + font_file)
_FONTS_LOADED = True
# Note that plt.close(), plt.clf(), and plt.cla() would not close memory
# Referenced the following post for the function below:
# https://stackoverflow.com/questions/28757348/how-to-clear-memory-completely-of-all-matplotlib-plots
def clear_plotting_memory():
usedbackend = matplotlib.get_backend()
matplotlib.use(usedbackend)
allfignums = matplotlib.pyplot.get_fignums()
for i in allfignums:
fig = matplotlib.pyplot.figure(i)
fig.clear()
matplotlib.pyplot.close(fig)
# Saves figures to files, unless savefig_format is "PIL_Image", in which case
# the figures are saved to a dictionary of buffers
def output_results(savefig_format, output_path, project, figs, context_type, dpi=100):
if savefig_format.lower() == "pdf":
pp = PdfPages(output_path + context_type + "_plots_" + project + ".pdf")
for fig in figs:
if context_type in ("CNV_48", "SV_32"):
figs[fig].savefig(pp, format="pdf", bbox_inches="tight")
else:
figs[fig].savefig(pp, format="pdf")
pp.close()
clear_plotting_memory()
elif savefig_format.lower() == "png":
for fig in figs:
if context_type in ("CNV_48", "SV_32"):
figs[fig].savefig(
output_path + context_type + "_plots_" + fig + ".png",
dpi=dpi,
bbox_inches="tight",
)
else:
figs[fig].savefig(
output_path + context_type + "_plots_" + fig + ".png", dpi=dpi
)
clear_plotting_memory()
elif savefig_format.lower() == "pil_image":
image_list = {}
for fig in figs:
tmp_buffer = io.BytesIO()
if context_type in ("CNV_48", "SV_32"):
figs[fig].savefig(
tmp_buffer, format="png", bbox_inches="tight", dpi=dpi
)
else:
figs[fig].savefig(tmp_buffer, format="png", dpi=dpi)
# convert tmp_buffer to a PIL and close buffer
tmp_buffer.seek(0)
tmp_image = Image.open(tmp_buffer)
# add the image to the image list for return
image_list[fig] = tmp_image
clear_plotting_memory()
return image_list
else:
raise ValueError("ERROR: savefig_format must be 'pdf', 'png', or 'PIL_Image'.")
return None
# Get corresponding reference index from our reference_format folder
def get_context_reference(plot_type):
ref_index = []
if plot_type.lower() in type_dict:
SPP_TYPE = type_dict[plot_type.lower()]
else:
raise ValueError(
"ERROR: SigProfilerPlotting is currently not supporting this input plot_type."
)
ref_index = pd.read_csv(SPP_REFERENCE + SPP_TYPE, sep="\t", header=None)
ref_index = ref_index.iloc[:, 0].tolist()
return ref_index
def process_input(matrix_path, plot_type):
# input data is a DataFrame
if isinstance(matrix_path, pd.DataFrame):
# copy dataframe with deepcopy
data = matrix_path.copy()
# index is a non-standard value
if data.index.name not in INDEX_VALS:
if MUTTYPE in data.columns:
data = data.set_index(MUTTYPE, drop=True)
# the first column is non-MUTTYPE and non-integer
elif not data.iloc[:, 0].apply(lambda x: isinstance(x, int)).all():
data.rename(columns={data.columns[0]: MUTTYPE}, inplace=True)
data = data.set_index(data.columns[0], drop=True)
else:
data = data.reset_index()
data.rename(columns={data.columns[0]: MUTTYPE}, inplace=True)
data = data.set_index(MUTTYPE, drop=True)
else:
# Note: set the index to MUTTYPE for consistency with the rest of the code
data.index.name = MUTTYPE
# input data is a file path
elif isinstance(matrix_path, str):
data = pd.read_csv(matrix_path, sep="\t", index_col=0)
data = data.dropna(axis=1, how="all")
data.index.name = MUTTYPE
# input data is a numpy array
elif isinstance(matrix_path, np.ndarray):
# Note: ndarray does not have index or column names and is not recommended
data = pd.DataFrame(matrix_path)
# add index of mutation type to the dataframe
if plot_type.lower() in type_dict:
data.index = get_context_reference(plot_type)
else:
raise ValueError(
"ERROR: matrix_path requires pd.DataFrame, path to file, or np.ndarray, not "
+ f"{type(matrix_path)}."
)
if data.isnull().values.any():
raise ValueError("ERROR: matrix_path contains Nans.")
def order_input_context(plot_type, input_data):
if plot_type.lower() in type_dict:
if data.shape[0] != len(get_context_reference(plot_type)):
raise ValueError(
"Input matrix file should have "
+ str(len(get_context_reference(plot_type)))
+ " rows"
)
else:
ref_format = get_context_reference(plot_type)
reindexed_data = input_data.reindex(ref_format)
else:
# If a non-standard context is used, no sort is applied
reindexed_data = input_data
return reindexed_data
return order_input_context(plot_type, data)
def get_default_96labels():
first = ["A", "C", "G", "T"]
inner_bracket = [[x] * 16 for x in ["C>A", "C>G", "C>T", "T>A", "T>C", "T>G"]]
inner_bracket = [item for sublist in inner_bracket for item in sublist]
outter_bracket = [x for x in list(itertools.product(first, first))]
result = [
outter_bracket[f % 16][0]
+ "["
+ inner_bracket[f]
+ "]"
+ outter_bracket[f % 16][1]
for f in range(0, 96)
]
return result
def make_pickle_file(context="SBS96", return_plot_template=False, volume=None):
if volume is None:
volume = SPP_TEMPLATES
path = os.path.join(volume, context + ".pkl")
# if the pickle file already exists, return the template
if os.path.exists(path):
return pickle.load(open(path, "rb"))
# check if the template directory exists, create if not
if not os.path.exists(volume):
os.mkdir(volume)
if context == "SBS96":
plot_custom_text = False
sig_probs = False
pcawg = False
# total_count = sum(sum(nuc.values()) for nuc in mutations[sample].values())
# , extent=[-5, 80, -5, 30])
plt.rcParams["axes.linewidth"] = 2
plot1 = plt.figure(figsize=(43.93, 9.92))
plt.rc("axes", edgecolor="lightgray")
panel1 = plt.axes([0.04, 0.09, 0.95, 0.77])
seq96 = [
"A[C>A]A",
"A[C>A]C",
"A[C>A]G",
"A[C>A]T",
"C[C>A]A",
"C[C>A]C",
"C[C>A]G",
"C[C>A]T",
"G[C>A]A",
"G[C>A]C",
"G[C>A]G",
"G[C>A]T",
"T[C>A]A",
"T[C>A]C",
"T[C>A]G",
"T[C>A]T",
"A[C>G]A",
"A[C>G]C",
"A[C>G]G",
"A[C>G]T",
"C[C>G]A",
"C[C>G]C",
"C[C>G]G",
"C[C>G]T",
"G[C>G]A",
"G[C>G]C",
"G[C>G]G",
"G[C>G]T",
"T[C>G]A",
"T[C>G]C",
"T[C>G]G",
"T[C>G]T",
"A[C>T]A",
"A[C>T]C",
"A[C>T]G",
"A[C>T]T",
"C[C>T]A",
"C[C>T]C",
"C[C>T]G",
"C[C>T]T",
"G[C>T]A",
"G[C>T]C",
"G[C>T]G",
"G[C>T]T",
"T[C>T]A",
"T[C>T]C",
"T[C>T]G",
"T[C>T]T",
"A[T>A]A",
"A[T>A]C",
"A[T>A]G",
"A[T>A]T",
"C[T>A]A",
"C[T>A]C",
"C[T>A]G",
"C[T>A]T",
"G[T>A]A",
"G[T>A]C",
"G[T>A]G",
"G[T>A]T",
"T[T>A]A",
"T[T>A]C",
"T[T>A]G",
"T[T>A]T",
"A[T>C]A",
"A[T>C]C",
"A[T>C]G",
"A[T>C]T",
"C[T>C]A",
"C[T>C]C",
"C[T>C]G",
"C[T>C]T",
"G[T>C]A",
"G[T>C]C",
"G[T>C]G",
"G[T>C]T",
"T[T>C]A",
"T[T>C]C",
"T[T>C]G",
"T[T>C]T",
"A[T>G]A",
"A[T>G]C",
"A[T>G]G",
"A[T>G]T",
"C[T>G]A",
"C[T>G]C",
"C[T>G]G",
"C[T>G]T",
"G[T>G]A",
"G[T>G]C",
"G[T>G]G",
"G[T>G]T",
"T[T>G]A",
"T[T>G]C",
"T[T>G]G",
"T[T>G]T",
]
xlabels = []
x = 0.4
ymax = 0
colors = [
[3 / 256, 189 / 256, 239 / 256],
[1 / 256, 1 / 256, 1 / 256],
[228 / 256, 41 / 256, 38 / 256],
[203 / 256, 202 / 256, 202 / 256],
[162 / 256, 207 / 256, 99 / 256],
[236 / 256, 199 / 256, 197 / 256],
]
xlabels = [seq[0] + seq[2] + seq[6] for seq in seq96]
i = 0
x = 0.043
y3 = 0.87
y = int(ymax * 1.25)
y2 = y + 2
for i in range(0, 6, 1):
panel1.add_patch(
plt.Rectangle(
(x, y3),
0.15,
0.05,
facecolor=colors[i],
clip_on=False,
transform=plt.gcf().transFigure,
)
)
x += 0.159
yText = y3 + 0.06
plt.text(
0.1,
yText,
"C>A",
fontsize=55,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.255,
yText,
"C>G",
fontsize=55,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.415,
yText,
"C>T",
fontsize=55,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.575,
yText,
"T>A",
fontsize=55,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.735,
yText,
"T>C",
fontsize=55,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.89,
yText,
"T>G",
fontsize=55,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
if y <= 4:
y += 4
while y % 4 != 0:
y += 1
# ytick_offest = int(y/4)
y = ymax / 1.025
ytick_offest = float(y / 3)
labs = np.arange(0.375, 96.375, 1)
panel1.set_xlim([0, 96])
# panel1.set_ylim([0, y])
panel1.set_xticks(labs)
# panel1.set_yticks(ylabs)
count = 0
m = 0
for i in range(0, 96, 1):
plt.text(
i / 101 + 0.0415,
0.02,
xlabels[i][0],
fontsize=30,
color="gray",
rotation="vertical",
verticalalignment="center",
fontname="Courier New",
transform=plt.gcf().transFigure,
)
plt.text(
i / 101 + 0.0415,
0.044,
xlabels[i][1],
fontsize=30,
color=colors[m],
rotation="vertical",
verticalalignment="center",
fontname="Courier New",
fontweight="bold",
transform=plt.gcf().transFigure,
)
plt.text(
i / 101 + 0.0415,
0.071,
xlabels[i][2],
fontsize=30,
color="gray",
rotation="vertical",
verticalalignment="center",
fontname="Courier New",
transform=plt.gcf().transFigure,
)
count += 1
if count == 16:
count = 0
m += 1
plt.gca().yaxis.grid(True)
plt.gca().grid(which="major", axis="y", color=[0.93, 0.93, 0.93], zorder=1)
panel1.set_xlabel("")
panel1.set_ylabel("")
panel1.tick_params(
axis="both",
which="both",
bottom=False,
labelbottom=False,
left=True,
labelleft=True,
right=True,
labelright=False,
top=False,
labeltop=False,
direction="in",
length=25,
colors="lightgray",
width=2,
)
[i.set_color("black") for i in plt.gca().get_yticklabels()]
if return_plot_template == False:
pickle.dump(plot1, open(path, "wb"))
else:
pickle.dump(plot1, open(path, "wb"))
return plot1
elif context == "SBS288":
plot_custom_text = False
sig_probs = False
pcawg = False
plt.rcParams["axes.linewidth"] = 2
plot1 = plt.figure(figsize=(43.93, 9.92))
plt.rc("axes", edgecolor="lightgray")
panel1 = plt.axes([0.04, 0.09, 0.7, 0.77])
panel2 = plt.axes([0.77, 0.09, 0.21, 0.77])
xlabels = []
x = 0.4
ymax = 0
colors = [
[3 / 256, 189 / 256, 239 / 256],
[1 / 256, 1 / 256, 1 / 256],
[228 / 256, 41 / 256, 38 / 256],
[203 / 256, 202 / 256, 202 / 256],
[162 / 256, 207 / 256, 99 / 256],
[236 / 256, 199 / 256, 197 / 256],
]
i = 0
result = get_default_96labels()
xlabels = [seq[0] + seq[2] + seq[6] for seq in result]
x = 0.043
y3 = 0.87
y = int(ymax * 1.25)
y2 = y + 2
for i in range(0, 6, 1):
panel1.add_patch(
plt.Rectangle(
(x, y3),
0.11,
0.05,
facecolor=colors[i],
clip_on=False,
transform=plt.gcf().transFigure,
)
)
x += 0.117
yText = y3 + 0.06
plt.text(
0.082,
yText,
"C>A",
fontsize=55,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.1975,
yText,
"C>G",
fontsize=55,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.315,
yText,
"C>T",
fontsize=55,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.43,
yText,
"T>A",
fontsize=55,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.55,
yText,
"T>C",
fontsize=55,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.665,
yText,
"T>G",
fontsize=55,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
if y <= 4:
y += 4
while y % 4 != 0:
y += 1
y = ymax / 1.025
ytick_offest = float(y / 3)
font_label_size = 30
labs = np.arange(0.375, 96.375, 1)
panel1.set_xlim([0, 96])
panel1.set_ylim([0, y])
panel1.set_xticks(labs)
count = 0
m = 0
for i in range(0, 96, 1):
plt.text(
i / 137 + 0.04,
0.02,
xlabels[i][0],
fontsize=25,
color="gray",
rotation="vertical",
verticalalignment="center",
fontname="Courier New",
transform=plt.gcf().transFigure,
)
plt.text(
i / 137 + 0.04,
0.044,
xlabels[i][1],
fontsize=25,
color=colors[m],
rotation="vertical",
verticalalignment="center",
fontname="Courier New",
fontweight="bold",
transform=plt.gcf().transFigure,
)
plt.text(
i / 137 + 0.04,
0.071,
xlabels[i][2],
fontsize=25,
color="gray",
rotation="vertical",
verticalalignment="center",
fontname="Courier New",
transform=plt.gcf().transFigure,
)
count += 1
if count == 16:
count = 0
m += 1
panel1.yaxis.grid(True)
panel1.grid(which="major", axis="y", color=[0.93, 0.93, 0.93], zorder=1)
panel1.set_xlabel("")
panel1.set_ylabel("")
panel1.tick_params(
axis="both",
which="both",
bottom=False,
labelbottom=False,
left=True,
labelleft=True,
right=True,
labelright=False,
top=False,
labeltop=False,
direction="in",
length=25,
colors="lightgray",
width=2,
)
[i.set_color("black") for i in panel1.get_yticklabels()]
yp2 = 28
labels = []
y2max = 0
tsbColors = [
[1 / 256, 70 / 256, 102 / 256],
[228 / 256, 41 / 256, 38 / 256],
"green",
]
y = int(y2max * 1.1)
if y <= 4:
y += 4
while y % 4 != 0:
y += 1
ytick_offest = int(y / 4)
panel2.spines["right"].set_visible(False)
panel2.spines["top"].set_visible(False)
labels.reverse()
panel2.set_yticks([3, 7, 11, 15, 19, 23, 27])
panel2.set_yticklabels(labels, fontsize=30, fontname="Arial", weight="bold")
panel2.set_xticklabels(xlabels, fontsize=30)
handles, labels = panel2.get_legend_handles_labels()
panel2.legend(handles[:3], labels[:3], loc="best", prop={"size": 30})
if return_plot_template == False:
pickle.dump(plot1, open(path, "wb"))
else:
pickle.dump(plot1, open(path, "wb"))
return plot1
elif context == "DBS78":
plot_custom_text = False
pcawg = False
sig_probs = False
plt.rcParams["axes.linewidth"] = 4
plot1 = plt.figure(figsize=(43.93, 9.92))
plt.rc("axes", edgecolor="grey")
panel1 = plt.axes([0.04, 0.09, 0.95, 0.77])
xlabels = []
x = 0.4
ymax = 0
colors = [
[3 / 256, 189 / 256, 239 / 256],
[3 / 256, 102 / 256, 204 / 256],
[162 / 256, 207 / 256, 99 / 256],
[1 / 256, 102 / 256, 1 / 256],
[255 / 256, 153 / 256, 153 / 256],
[228 / 256, 41 / 256, 38 / 256],
[255 / 256, 178 / 256, 102 / 256],
[255 / 256, 128 / 256, 1 / 256],
[204 / 256, 153 / 256, 255 / 256],
[76 / 256, 1 / 256, 153 / 256],
]
x = 0.043
y3 = 0.87
y = int(ymax * 1.25)
y2 = y + 2
i = 0
panel1.add_patch(
plt.Rectangle(
(0.043, y3),
0.101,
0.05,
facecolor=colors[0],
clip_on=False,
transform=plt.gcf().transFigure,
)
)
panel1.add_patch(
plt.Rectangle(
(0.151, y3),
0.067,
0.05,
facecolor=colors[1],
clip_on=False,
transform=plt.gcf().transFigure,
)
)
panel1.add_patch(
plt.Rectangle(
(0.225, y3),
0.102,
0.05,
facecolor=colors[2],
clip_on=False,
transform=plt.gcf().transFigure,
)
)
panel1.add_patch(
plt.Rectangle(
(0.334, y3),
0.067,
0.05,
facecolor=colors[3],
clip_on=False,
transform=plt.gcf().transFigure,
)
)
panel1.add_patch(
plt.Rectangle(
(0.408, y3),
0.102,
0.05,
facecolor=colors[4],
clip_on=False,
transform=plt.gcf().transFigure,
)
)
panel1.add_patch(
plt.Rectangle(
(0.517, y3),
0.067,
0.05,
facecolor=colors[5],
clip_on=False,
transform=plt.gcf().transFigure,
)
)
panel1.add_patch(
plt.Rectangle(
(0.591, y3),
0.067,
0.05,
facecolor=colors[6],
clip_on=False,
transform=plt.gcf().transFigure,
)
)
panel1.add_patch(
plt.Rectangle(
(0.665, y3),
0.102,
0.05,
facecolor=colors[7],
clip_on=False,
transform=plt.gcf().transFigure,
)
)
panel1.add_patch(
plt.Rectangle(
(0.774, y3),
0.102,
0.05,
facecolor=colors[8],
clip_on=False,
transform=plt.gcf().transFigure,
)
)
panel1.add_patch(
plt.Rectangle(
(0.883, y3),
0.102,
0.05,
facecolor=colors[9],
clip_on=False,
transform=plt.gcf().transFigure,
)
)
yText = y3 + 0.06
plt.text(
0.07,
yText,
"AC>NN",
fontsize=40,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.163,
yText,
"AT>NN",
fontsize=40,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.255,
yText,
"CC>NN",
fontsize=40,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.345,
yText,
"CG>NN",
fontsize=40,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.435,
yText,
"CT>NN",
fontsize=40,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.527,
yText,
"GC>NN",
fontsize=40,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.6,
yText,
"TA>NN",
fontsize=40,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.69,
yText,
"TC>NN",
fontsize=40,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.8,
yText,
"TG>NN",
fontsize=40,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
plt.text(
0.915,
yText,
"TT>NN",
fontsize=40,
fontweight="bold",
fontname="Arial",
transform=plt.gcf().transFigure,
)
if y <= 4:
y += 4
while y % 4 != 0:
y += 1
ytick_offest = int(y / 4)
labs = np.arange(0.44, 78.44, 1)
panel1.set_xlim([0, 78])
panel1.set_ylim([0, y])
panel1.set_xticks(labs)
panel1.set_xticklabels(
xlabels,
rotation="vertical",
fontsize=30,
color="grey",
fontname="Courier New",
verticalalignment="top",
fontweight="bold",
)
plt.gca().yaxis.grid(True)
plt.gca().grid(which="major", axis="y", color=[0.93, 0.93, 0.93], zorder=1)
panel1.set_xlabel("")
panel1.set_ylabel("")
panel1.tick_params(
axis="both",
which="both",
bottom=False,
labelbottom=True,
left=True,