biotite 1.1.0__cp313-cp313-macosx_10_13_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of biotite might be problematic. Click here for more details.

Files changed (332) hide show
  1. biotite/__init__.py +18 -0
  2. biotite/application/__init__.py +69 -0
  3. biotite/application/application.py +276 -0
  4. biotite/application/autodock/__init__.py +12 -0
  5. biotite/application/autodock/app.py +500 -0
  6. biotite/application/blast/__init__.py +14 -0
  7. biotite/application/blast/alignment.py +92 -0
  8. biotite/application/blast/webapp.py +428 -0
  9. biotite/application/clustalo/__init__.py +12 -0
  10. biotite/application/clustalo/app.py +223 -0
  11. biotite/application/dssp/__init__.py +12 -0
  12. biotite/application/dssp/app.py +159 -0
  13. biotite/application/localapp.py +342 -0
  14. biotite/application/mafft/__init__.py +12 -0
  15. biotite/application/mafft/app.py +116 -0
  16. biotite/application/msaapp.py +363 -0
  17. biotite/application/muscle/__init__.py +13 -0
  18. biotite/application/muscle/app3.py +227 -0
  19. biotite/application/muscle/app5.py +163 -0
  20. biotite/application/sra/__init__.py +18 -0
  21. biotite/application/sra/app.py +452 -0
  22. biotite/application/tantan/__init__.py +12 -0
  23. biotite/application/tantan/app.py +199 -0
  24. biotite/application/util.py +57 -0
  25. biotite/application/viennarna/__init__.py +18 -0
  26. biotite/application/viennarna/rnaalifold.py +310 -0
  27. biotite/application/viennarna/rnafold.py +254 -0
  28. biotite/application/viennarna/rnaplot.py +206 -0
  29. biotite/application/viennarna/util.py +77 -0
  30. biotite/application/webapp.py +76 -0
  31. biotite/copyable.py +71 -0
  32. biotite/database/__init__.py +23 -0
  33. biotite/database/entrez/__init__.py +15 -0
  34. biotite/database/entrez/check.py +60 -0
  35. biotite/database/entrez/dbnames.py +91 -0
  36. biotite/database/entrez/download.py +229 -0
  37. biotite/database/entrez/key.py +44 -0
  38. biotite/database/entrez/query.py +262 -0
  39. biotite/database/error.py +16 -0
  40. biotite/database/pubchem/__init__.py +21 -0
  41. biotite/database/pubchem/download.py +258 -0
  42. biotite/database/pubchem/error.py +20 -0
  43. biotite/database/pubchem/query.py +830 -0
  44. biotite/database/pubchem/throttle.py +98 -0
  45. biotite/database/rcsb/__init__.py +13 -0
  46. biotite/database/rcsb/download.py +159 -0
  47. biotite/database/rcsb/query.py +964 -0
  48. biotite/database/uniprot/__init__.py +13 -0
  49. biotite/database/uniprot/check.py +40 -0
  50. biotite/database/uniprot/download.py +129 -0
  51. biotite/database/uniprot/query.py +293 -0
  52. biotite/file.py +232 -0
  53. biotite/sequence/__init__.py +84 -0
  54. biotite/sequence/align/__init__.py +203 -0
  55. biotite/sequence/align/alignment.py +680 -0
  56. biotite/sequence/align/banded.cpython-313-darwin.so +0 -0
  57. biotite/sequence/align/banded.pyx +652 -0
  58. biotite/sequence/align/buckets.py +71 -0
  59. biotite/sequence/align/cigar.py +425 -0
  60. biotite/sequence/align/kmeralphabet.cpython-313-darwin.so +0 -0
  61. biotite/sequence/align/kmeralphabet.pyx +595 -0
  62. biotite/sequence/align/kmersimilarity.cpython-313-darwin.so +0 -0
  63. biotite/sequence/align/kmersimilarity.pyx +233 -0
  64. biotite/sequence/align/kmertable.cpython-313-darwin.so +0 -0
  65. biotite/sequence/align/kmertable.pyx +3411 -0
  66. biotite/sequence/align/localgapped.cpython-313-darwin.so +0 -0
  67. biotite/sequence/align/localgapped.pyx +892 -0
  68. biotite/sequence/align/localungapped.cpython-313-darwin.so +0 -0
  69. biotite/sequence/align/localungapped.pyx +279 -0
  70. biotite/sequence/align/matrix.py +622 -0
  71. biotite/sequence/align/matrix_data/3Di.mat +24 -0
  72. biotite/sequence/align/matrix_data/BLOSUM100.mat +31 -0
  73. biotite/sequence/align/matrix_data/BLOSUM30.mat +31 -0
  74. biotite/sequence/align/matrix_data/BLOSUM35.mat +31 -0
  75. biotite/sequence/align/matrix_data/BLOSUM40.mat +31 -0
  76. biotite/sequence/align/matrix_data/BLOSUM45.mat +31 -0
  77. biotite/sequence/align/matrix_data/BLOSUM50.mat +31 -0
  78. biotite/sequence/align/matrix_data/BLOSUM50_13p.mat +25 -0
  79. biotite/sequence/align/matrix_data/BLOSUM50_14.3.mat +25 -0
  80. biotite/sequence/align/matrix_data/BLOSUM50_5.0.mat +25 -0
  81. biotite/sequence/align/matrix_data/BLOSUM55.mat +31 -0
  82. biotite/sequence/align/matrix_data/BLOSUM60.mat +31 -0
  83. biotite/sequence/align/matrix_data/BLOSUM62.mat +31 -0
  84. biotite/sequence/align/matrix_data/BLOSUM62_13p.mat +25 -0
  85. biotite/sequence/align/matrix_data/BLOSUM62_14.3.mat +25 -0
  86. biotite/sequence/align/matrix_data/BLOSUM62_5.0.mat +25 -0
  87. biotite/sequence/align/matrix_data/BLOSUM65.mat +31 -0
  88. biotite/sequence/align/matrix_data/BLOSUM70.mat +31 -0
  89. biotite/sequence/align/matrix_data/BLOSUM75.mat +31 -0
  90. biotite/sequence/align/matrix_data/BLOSUM80.mat +31 -0
  91. biotite/sequence/align/matrix_data/BLOSUM85.mat +31 -0
  92. biotite/sequence/align/matrix_data/BLOSUM90.mat +31 -0
  93. biotite/sequence/align/matrix_data/BLOSUMN.mat +31 -0
  94. biotite/sequence/align/matrix_data/CorBLOSUM49_5.0.mat +25 -0
  95. biotite/sequence/align/matrix_data/CorBLOSUM57_13p.mat +25 -0
  96. biotite/sequence/align/matrix_data/CorBLOSUM57_14.3.mat +25 -0
  97. biotite/sequence/align/matrix_data/CorBLOSUM61_5.0.mat +25 -0
  98. biotite/sequence/align/matrix_data/CorBLOSUM66_13p.mat +25 -0
  99. biotite/sequence/align/matrix_data/CorBLOSUM67_14.3.mat +25 -0
  100. biotite/sequence/align/matrix_data/DAYHOFF.mat +32 -0
  101. biotite/sequence/align/matrix_data/GONNET.mat +26 -0
  102. biotite/sequence/align/matrix_data/IDENTITY.mat +25 -0
  103. biotite/sequence/align/matrix_data/MATCH.mat +25 -0
  104. biotite/sequence/align/matrix_data/NUC.mat +25 -0
  105. biotite/sequence/align/matrix_data/PAM10.mat +34 -0
  106. biotite/sequence/align/matrix_data/PAM100.mat +34 -0
  107. biotite/sequence/align/matrix_data/PAM110.mat +34 -0
  108. biotite/sequence/align/matrix_data/PAM120.mat +34 -0
  109. biotite/sequence/align/matrix_data/PAM130.mat +34 -0
  110. biotite/sequence/align/matrix_data/PAM140.mat +34 -0
  111. biotite/sequence/align/matrix_data/PAM150.mat +34 -0
  112. biotite/sequence/align/matrix_data/PAM160.mat +34 -0
  113. biotite/sequence/align/matrix_data/PAM170.mat +34 -0
  114. biotite/sequence/align/matrix_data/PAM180.mat +34 -0
  115. biotite/sequence/align/matrix_data/PAM190.mat +34 -0
  116. biotite/sequence/align/matrix_data/PAM20.mat +34 -0
  117. biotite/sequence/align/matrix_data/PAM200.mat +34 -0
  118. biotite/sequence/align/matrix_data/PAM210.mat +34 -0
  119. biotite/sequence/align/matrix_data/PAM220.mat +34 -0
  120. biotite/sequence/align/matrix_data/PAM230.mat +34 -0
  121. biotite/sequence/align/matrix_data/PAM240.mat +34 -0
  122. biotite/sequence/align/matrix_data/PAM250.mat +34 -0
  123. biotite/sequence/align/matrix_data/PAM260.mat +34 -0
  124. biotite/sequence/align/matrix_data/PAM270.mat +34 -0
  125. biotite/sequence/align/matrix_data/PAM280.mat +34 -0
  126. biotite/sequence/align/matrix_data/PAM290.mat +34 -0
  127. biotite/sequence/align/matrix_data/PAM30.mat +34 -0
  128. biotite/sequence/align/matrix_data/PAM300.mat +34 -0
  129. biotite/sequence/align/matrix_data/PAM310.mat +34 -0
  130. biotite/sequence/align/matrix_data/PAM320.mat +34 -0
  131. biotite/sequence/align/matrix_data/PAM330.mat +34 -0
  132. biotite/sequence/align/matrix_data/PAM340.mat +34 -0
  133. biotite/sequence/align/matrix_data/PAM350.mat +34 -0
  134. biotite/sequence/align/matrix_data/PAM360.mat +34 -0
  135. biotite/sequence/align/matrix_data/PAM370.mat +34 -0
  136. biotite/sequence/align/matrix_data/PAM380.mat +34 -0
  137. biotite/sequence/align/matrix_data/PAM390.mat +34 -0
  138. biotite/sequence/align/matrix_data/PAM40.mat +34 -0
  139. biotite/sequence/align/matrix_data/PAM400.mat +34 -0
  140. biotite/sequence/align/matrix_data/PAM410.mat +34 -0
  141. biotite/sequence/align/matrix_data/PAM420.mat +34 -0
  142. biotite/sequence/align/matrix_data/PAM430.mat +34 -0
  143. biotite/sequence/align/matrix_data/PAM440.mat +34 -0
  144. biotite/sequence/align/matrix_data/PAM450.mat +34 -0
  145. biotite/sequence/align/matrix_data/PAM460.mat +34 -0
  146. biotite/sequence/align/matrix_data/PAM470.mat +34 -0
  147. biotite/sequence/align/matrix_data/PAM480.mat +34 -0
  148. biotite/sequence/align/matrix_data/PAM490.mat +34 -0
  149. biotite/sequence/align/matrix_data/PAM50.mat +34 -0
  150. biotite/sequence/align/matrix_data/PAM500.mat +34 -0
  151. biotite/sequence/align/matrix_data/PAM60.mat +34 -0
  152. biotite/sequence/align/matrix_data/PAM70.mat +34 -0
  153. biotite/sequence/align/matrix_data/PAM80.mat +34 -0
  154. biotite/sequence/align/matrix_data/PAM90.mat +34 -0
  155. biotite/sequence/align/matrix_data/PB.license +21 -0
  156. biotite/sequence/align/matrix_data/PB.mat +18 -0
  157. biotite/sequence/align/matrix_data/RBLOSUM52_5.0.mat +25 -0
  158. biotite/sequence/align/matrix_data/RBLOSUM59_13p.mat +25 -0
  159. biotite/sequence/align/matrix_data/RBLOSUM59_14.3.mat +25 -0
  160. biotite/sequence/align/matrix_data/RBLOSUM64_5.0.mat +25 -0
  161. biotite/sequence/align/matrix_data/RBLOSUM69_13p.mat +25 -0
  162. biotite/sequence/align/matrix_data/RBLOSUM69_14.3.mat +25 -0
  163. biotite/sequence/align/multiple.cpython-313-darwin.so +0 -0
  164. biotite/sequence/align/multiple.pyx +620 -0
  165. biotite/sequence/align/pairwise.cpython-313-darwin.so +0 -0
  166. biotite/sequence/align/pairwise.pyx +587 -0
  167. biotite/sequence/align/permutation.cpython-313-darwin.so +0 -0
  168. biotite/sequence/align/permutation.pyx +313 -0
  169. biotite/sequence/align/primes.txt +821 -0
  170. biotite/sequence/align/selector.cpython-313-darwin.so +0 -0
  171. biotite/sequence/align/selector.pyx +954 -0
  172. biotite/sequence/align/statistics.py +264 -0
  173. biotite/sequence/align/tracetable.cpython-313-darwin.so +0 -0
  174. biotite/sequence/align/tracetable.pxd +64 -0
  175. biotite/sequence/align/tracetable.pyx +370 -0
  176. biotite/sequence/alphabet.py +555 -0
  177. biotite/sequence/annotation.py +830 -0
  178. biotite/sequence/codec.cpython-313-darwin.so +0 -0
  179. biotite/sequence/codec.pyx +155 -0
  180. biotite/sequence/codon.py +477 -0
  181. biotite/sequence/codon_tables.txt +202 -0
  182. biotite/sequence/graphics/__init__.py +33 -0
  183. biotite/sequence/graphics/alignment.py +1115 -0
  184. biotite/sequence/graphics/color_schemes/3di_flower.json +48 -0
  185. biotite/sequence/graphics/color_schemes/autumn.json +51 -0
  186. biotite/sequence/graphics/color_schemes/blossom.json +51 -0
  187. biotite/sequence/graphics/color_schemes/clustalx_dna.json +11 -0
  188. biotite/sequence/graphics/color_schemes/clustalx_protein.json +28 -0
  189. biotite/sequence/graphics/color_schemes/flower.json +51 -0
  190. biotite/sequence/graphics/color_schemes/jalview_buried.json +31 -0
  191. biotite/sequence/graphics/color_schemes/jalview_hydrophobicity.json +31 -0
  192. biotite/sequence/graphics/color_schemes/jalview_prop_helix.json +31 -0
  193. biotite/sequence/graphics/color_schemes/jalview_prop_strand.json +31 -0
  194. biotite/sequence/graphics/color_schemes/jalview_prop_turn.json +31 -0
  195. biotite/sequence/graphics/color_schemes/jalview_taylor.json +28 -0
  196. biotite/sequence/graphics/color_schemes/jalview_zappo.json +28 -0
  197. biotite/sequence/graphics/color_schemes/ocean.json +51 -0
  198. biotite/sequence/graphics/color_schemes/pb_flower.json +40 -0
  199. biotite/sequence/graphics/color_schemes/rainbow_dna.json +11 -0
  200. biotite/sequence/graphics/color_schemes/rainbow_protein.json +30 -0
  201. biotite/sequence/graphics/color_schemes/spring.json +51 -0
  202. biotite/sequence/graphics/color_schemes/sunset.json +51 -0
  203. biotite/sequence/graphics/color_schemes/wither.json +51 -0
  204. biotite/sequence/graphics/colorschemes.py +170 -0
  205. biotite/sequence/graphics/dendrogram.py +229 -0
  206. biotite/sequence/graphics/features.py +544 -0
  207. biotite/sequence/graphics/logo.py +104 -0
  208. biotite/sequence/graphics/plasmid.py +712 -0
  209. biotite/sequence/io/__init__.py +12 -0
  210. biotite/sequence/io/fasta/__init__.py +22 -0
  211. biotite/sequence/io/fasta/convert.py +284 -0
  212. biotite/sequence/io/fasta/file.py +265 -0
  213. biotite/sequence/io/fastq/__init__.py +19 -0
  214. biotite/sequence/io/fastq/convert.py +117 -0
  215. biotite/sequence/io/fastq/file.py +507 -0
  216. biotite/sequence/io/genbank/__init__.py +17 -0
  217. biotite/sequence/io/genbank/annotation.py +269 -0
  218. biotite/sequence/io/genbank/file.py +573 -0
  219. biotite/sequence/io/genbank/metadata.py +336 -0
  220. biotite/sequence/io/genbank/sequence.py +171 -0
  221. biotite/sequence/io/general.py +201 -0
  222. biotite/sequence/io/gff/__init__.py +26 -0
  223. biotite/sequence/io/gff/convert.py +128 -0
  224. biotite/sequence/io/gff/file.py +450 -0
  225. biotite/sequence/phylo/__init__.py +36 -0
  226. biotite/sequence/phylo/nj.cpython-313-darwin.so +0 -0
  227. biotite/sequence/phylo/nj.pyx +221 -0
  228. biotite/sequence/phylo/tree.cpython-313-darwin.so +0 -0
  229. biotite/sequence/phylo/tree.pyx +1169 -0
  230. biotite/sequence/phylo/upgma.cpython-313-darwin.so +0 -0
  231. biotite/sequence/phylo/upgma.pyx +164 -0
  232. biotite/sequence/profile.py +567 -0
  233. biotite/sequence/search.py +118 -0
  234. biotite/sequence/seqtypes.py +713 -0
  235. biotite/sequence/sequence.py +374 -0
  236. biotite/setup_ccd.py +197 -0
  237. biotite/structure/__init__.py +133 -0
  238. biotite/structure/alphabet/__init__.py +25 -0
  239. biotite/structure/alphabet/encoder.py +332 -0
  240. biotite/structure/alphabet/encoder_weights_3di.kerasify +0 -0
  241. biotite/structure/alphabet/i3d.py +110 -0
  242. biotite/structure/alphabet/layers.py +86 -0
  243. biotite/structure/alphabet/pb.license +21 -0
  244. biotite/structure/alphabet/pb.py +171 -0
  245. biotite/structure/alphabet/unkerasify.py +122 -0
  246. biotite/structure/atoms.py +1554 -0
  247. biotite/structure/basepairs.py +1404 -0
  248. biotite/structure/bonds.cpython-313-darwin.so +0 -0
  249. biotite/structure/bonds.pyx +1972 -0
  250. biotite/structure/box.py +588 -0
  251. biotite/structure/celllist.cpython-313-darwin.so +0 -0
  252. biotite/structure/celllist.pyx +849 -0
  253. biotite/structure/chains.py +314 -0
  254. biotite/structure/charges.cpython-313-darwin.so +0 -0
  255. biotite/structure/charges.pyx +520 -0
  256. biotite/structure/compare.py +274 -0
  257. biotite/structure/density.py +109 -0
  258. biotite/structure/dotbracket.py +214 -0
  259. biotite/structure/error.py +39 -0
  260. biotite/structure/filter.py +590 -0
  261. biotite/structure/geometry.py +655 -0
  262. biotite/structure/graphics/__init__.py +13 -0
  263. biotite/structure/graphics/atoms.py +243 -0
  264. biotite/structure/graphics/rna.py +295 -0
  265. biotite/structure/hbond.py +428 -0
  266. biotite/structure/info/__init__.py +24 -0
  267. biotite/structure/info/atom_masses.json +121 -0
  268. biotite/structure/info/atoms.py +81 -0
  269. biotite/structure/info/bonds.py +149 -0
  270. biotite/structure/info/ccd.py +202 -0
  271. biotite/structure/info/components.bcif +0 -0
  272. biotite/structure/info/groups.py +131 -0
  273. biotite/structure/info/masses.py +121 -0
  274. biotite/structure/info/misc.py +138 -0
  275. biotite/structure/info/radii.py +197 -0
  276. biotite/structure/info/standardize.py +186 -0
  277. biotite/structure/integrity.py +215 -0
  278. biotite/structure/io/__init__.py +29 -0
  279. biotite/structure/io/dcd/__init__.py +13 -0
  280. biotite/structure/io/dcd/file.py +67 -0
  281. biotite/structure/io/general.py +243 -0
  282. biotite/structure/io/gro/__init__.py +14 -0
  283. biotite/structure/io/gro/file.py +344 -0
  284. biotite/structure/io/mol/__init__.py +20 -0
  285. biotite/structure/io/mol/convert.py +112 -0
  286. biotite/structure/io/mol/ctab.py +415 -0
  287. biotite/structure/io/mol/header.py +120 -0
  288. biotite/structure/io/mol/mol.py +149 -0
  289. biotite/structure/io/mol/sdf.py +914 -0
  290. biotite/structure/io/netcdf/__init__.py +13 -0
  291. biotite/structure/io/netcdf/file.py +64 -0
  292. biotite/structure/io/pdb/__init__.py +20 -0
  293. biotite/structure/io/pdb/convert.py +307 -0
  294. biotite/structure/io/pdb/file.py +1290 -0
  295. biotite/structure/io/pdb/hybrid36.cpython-313-darwin.so +0 -0
  296. biotite/structure/io/pdb/hybrid36.pyx +242 -0
  297. biotite/structure/io/pdbqt/__init__.py +15 -0
  298. biotite/structure/io/pdbqt/convert.py +113 -0
  299. biotite/structure/io/pdbqt/file.py +688 -0
  300. biotite/structure/io/pdbx/__init__.py +23 -0
  301. biotite/structure/io/pdbx/bcif.py +656 -0
  302. biotite/structure/io/pdbx/cif.py +1075 -0
  303. biotite/structure/io/pdbx/component.py +245 -0
  304. biotite/structure/io/pdbx/compress.py +321 -0
  305. biotite/structure/io/pdbx/convert.py +1745 -0
  306. biotite/structure/io/pdbx/encoding.cpython-313-darwin.so +0 -0
  307. biotite/structure/io/pdbx/encoding.pyx +1031 -0
  308. biotite/structure/io/trajfile.py +693 -0
  309. biotite/structure/io/trr/__init__.py +13 -0
  310. biotite/structure/io/trr/file.py +43 -0
  311. biotite/structure/io/xtc/__init__.py +13 -0
  312. biotite/structure/io/xtc/file.py +43 -0
  313. biotite/structure/mechanics.py +73 -0
  314. biotite/structure/molecules.py +352 -0
  315. biotite/structure/pseudoknots.py +628 -0
  316. biotite/structure/rdf.py +245 -0
  317. biotite/structure/repair.py +304 -0
  318. biotite/structure/residues.py +572 -0
  319. biotite/structure/sasa.cpython-313-darwin.so +0 -0
  320. biotite/structure/sasa.pyx +322 -0
  321. biotite/structure/segments.py +178 -0
  322. biotite/structure/sequence.py +111 -0
  323. biotite/structure/sse.py +308 -0
  324. biotite/structure/superimpose.py +689 -0
  325. biotite/structure/transform.py +530 -0
  326. biotite/structure/util.py +168 -0
  327. biotite/version.py +16 -0
  328. biotite/visualize.py +265 -0
  329. biotite-1.1.0.dist-info/METADATA +190 -0
  330. biotite-1.1.0.dist-info/RECORD +332 -0
  331. biotite-1.1.0.dist-info/WHEEL +4 -0
  332. biotite-1.1.0.dist-info/licenses/LICENSE.rst +30 -0
@@ -0,0 +1,1115 @@
1
+ # This source code is part of the Biotite package and is distributed
2
+ # under the 3-Clause BSD License. Please see 'LICENSE.rst' for further
3
+ # information.
4
+
5
+ __name__ = "biotite.sequence.graphics"
6
+ __author__ = "Patrick Kunzmann"
7
+ __all__ = [
8
+ "SymbolPlotter",
9
+ "LetterPlotter",
10
+ "LetterSimilarityPlotter",
11
+ "LetterTypePlotter",
12
+ "ArrayPlotter",
13
+ "plot_alignment",
14
+ "plot_alignment_similarity_based",
15
+ "plot_alignment_type_based",
16
+ "plot_alignment_array",
17
+ ]
18
+
19
+ import abc
20
+ import numpy as np
21
+ from biotite.sequence.graphics.colorschemes import get_color_scheme
22
+ from biotite.visualize import colors
23
+
24
+
25
+ class SymbolPlotter(metaclass=abc.ABCMeta):
26
+ """
27
+ Subclasses of this abstract base class define how symbols in
28
+ an alignment are drawn onto an :class:`Axes` object.
29
+
30
+ Subclasses must override the :func:`plot_symbol()` method.
31
+
32
+ Parameters
33
+ ----------
34
+ axes : Axes
35
+ A *Matplotlib* axes, that is used as plotting area.
36
+ """
37
+
38
+ def __init__(self, axes):
39
+ self._axes = axes
40
+
41
+ @property
42
+ def axes(self):
43
+ return self._axes
44
+
45
+ @abc.abstractmethod
46
+ def plot_symbol(self, bbox, alignment, column_i, seq_i):
47
+ """
48
+ Get the color of a symbol at a specified position in the
49
+ alignment.
50
+
51
+ The symbol is specified as position in the alignment's trace
52
+ (``trace[pos_i, seq_i]``).
53
+
54
+ Parameters
55
+ ----------
56
+ bbox : Bbox
57
+ The axes area to plot the symbol in
58
+ alignment : Alignment
59
+ The respective alignment.
60
+ column_i : int
61
+ The position index in the trace.
62
+ seq_i : int
63
+ The sequence index in the trace.
64
+ """
65
+ pass
66
+
67
+
68
+ class LetterPlotter(SymbolPlotter, metaclass=abc.ABCMeta):
69
+ """
70
+ This abstract :class:`SymbolPlotter` is the most widely used one.
71
+ Symbols are visualized as character on a colored background box or
72
+ as colored character, if `color_symbols` is set to true.
73
+
74
+ Subclasses must override the :class:`get_color()` method.
75
+
76
+ Parameters
77
+ ----------
78
+ axes : Axes
79
+ A *Matplotlib* axes, that is used as plotting area.
80
+ color_symbols : bool, optional
81
+ If true, the symbols themselves are colored.
82
+ If false, the symbols are black, and the boxes behind the
83
+ symbols are colored.
84
+ font_size : float, optional
85
+ Font size of the sequence symbols.
86
+ font_param : dict, optional
87
+ Additional parameters that is given to the
88
+ :class:`matplotlib.Text` instance of each symbol.
89
+ """
90
+
91
+ def __init__(self, axes, color_symbols=False, font_size=None, font_param=None):
92
+ super().__init__(axes)
93
+ self._color_symbols = color_symbols
94
+ self._font_size = font_size
95
+ self._font_param = font_param if font_param is not None else {}
96
+
97
+ def plot_symbol(self, bbox, alignment, column_i, seq_i):
98
+ from matplotlib.patches import Rectangle
99
+
100
+ trace = alignment.trace
101
+ if trace[column_i, seq_i] != -1:
102
+ symbol = alignment.sequences[seq_i][trace[column_i, seq_i]]
103
+ else:
104
+ symbol = "-"
105
+ color = self.get_color(alignment, column_i, seq_i)
106
+
107
+ box = Rectangle(bbox.p0, bbox.width, bbox.height)
108
+ self.axes.add_patch(box)
109
+ text = self.axes.text(
110
+ bbox.x0 + bbox.width / 2,
111
+ bbox.y0 + bbox.height / 2,
112
+ symbol,
113
+ color="black",
114
+ ha="center",
115
+ va="center",
116
+ size=self._font_size,
117
+ **self._font_param,
118
+ )
119
+ text.set_clip_on(True)
120
+
121
+ if self._color_symbols:
122
+ box.set_color("None")
123
+ text.set_color(color)
124
+ else:
125
+ box.set_color(color)
126
+
127
+ @abc.abstractmethod
128
+ def get_color(self, alignment, column_i, seq_i):
129
+ """
130
+ Get the color of a symbol at a specified position in the
131
+ alignment.
132
+
133
+ The symbol is specified as position in the alignment's trace
134
+ (``trace[pos_i, seq_i]``).
135
+
136
+ PROTECTED: Override when inheriting.
137
+
138
+ Parameters
139
+ ----------
140
+ alignment : Alignment
141
+ The respective alignment.
142
+ column_i : int
143
+ The position index in the trace.
144
+ seq_i : int
145
+ The sequence index in the trace.
146
+
147
+ Returns
148
+ -------
149
+ color : object
150
+ A *Matplotlib* compatible color used for the background
151
+ or the symbol itself at the specifed position
152
+ """
153
+ pass
154
+
155
+
156
+ class LetterSimilarityPlotter(LetterPlotter):
157
+ r"""
158
+ This :class:`SymbolPlotter` colors the symbols based on the
159
+ similarity with the other symbols in the same column.
160
+
161
+ The color intensity (or colormap value, respectively) of a symbol
162
+ scales with similarity of the respective symbol to the other symbols
163
+ in the same alignment column.
164
+
165
+ Parameters
166
+ ----------
167
+ axes : Axes
168
+ A *Matplotlib* axes, that is used as plotting area.
169
+ matrix : SubstitutionMatrix, optional
170
+ The substitution matrix to use the similarity scores from.
171
+ By default the normalized similarity is 1 for identity and 0
172
+ for non-identity.
173
+ color_symbols : bool, optional
174
+ If true, the symbols themselves are colored.
175
+ If false, the symbols are black, and the boxes behind the
176
+ symbols are colored.
177
+ font_size : float, optional
178
+ Font size of the sequence symbols.
179
+ font_param : dict, optional
180
+ Additional parameters that is given to the
181
+ :class:`matplotlib.Text` instance of each symbol.
182
+
183
+ Notes
184
+ -----
185
+ For determination of the color, this a measure called
186
+ *average normalized similarity* is used.
187
+
188
+ The *normalized similarity* of one symbol *a* to another symbol *b*
189
+ (both in aphabet *X*) is defined as
190
+
191
+ .. math:: S_{norm}(a,b) = \frac{S(a,b) - \min\limits_x(S(a,x))} {\max\limits_x(S(a,x)) - \min\limits_x(S(a,x))}
192
+
193
+ .. math:: a,b,x \in X
194
+
195
+ where *S(x,y)* is the similarity score of the two symbols
196
+ *x* and *y* described in the substitution matrix.
197
+ The similarity *S(x,-)* is always 0.
198
+ As the normalization is conducted only with respect to *a*,
199
+ the *normalized similarity* is not commutative.
200
+
201
+ The *average normalized similarity* of a symbol *a* is
202
+ determined by averaging the normalized similarity over each
203
+ symbol *b*\ :sub:`i` in the same alignment column.
204
+
205
+ .. math:: S_{norm,av}(a) = \frac{1}{n-1} \left[\left(\sum\limits_{i=1}^n S_{norm}(a,b_i)\right) - S_{norm}(a,a)\right]
206
+
207
+ The normalized similarity of *a* to itself is subtracted,
208
+ because *a* does also occur in *b*\ :sub:`i`.
209
+ """
210
+
211
+ def __init__(
212
+ self, axes, matrix=None, color_symbols=False, font_size=None, font_param=None
213
+ ):
214
+ super().__init__(axes, color_symbols, font_size, font_param)
215
+ if matrix is not None:
216
+ self._matrix = matrix.score_matrix()
217
+ else:
218
+ self._matrix = None
219
+ # Default colormap
220
+ self._cmap = self._generate_colormap(colors["dimgreen"], self._color_symbols)
221
+
222
+ def set_color(self, color=None, cmap=None):
223
+ """
224
+ Set the alignemnt colors used for plotting.
225
+
226
+ This function takes either a color or a colormap.
227
+
228
+ Parameters
229
+ ----------
230
+ color : tuple or str, optional
231
+ A *Matplotlib* compatible color.
232
+ If this parameter is given, the box color in an interpolated
233
+ value between white and the given color,
234
+ or, if `color_symbols` is set, between the given color and
235
+ black.
236
+ The interpolation percentage is given by the normalized
237
+ similarity.
238
+ cmap : Colormap, optional
239
+ The boxes (or symbols, if `color_symbols` is set) are
240
+ colored based on the normalized similarity value on the
241
+ given Colormap.
242
+ """
243
+ from matplotlib import cm
244
+
245
+ if color is None and cmap is None:
246
+ raise ValueError("Either color or colormap must be set")
247
+ elif color is not None:
248
+ self._cmap = self._generate_colormap(color, self._color_symbols)
249
+ else:
250
+ # cmap is not None
251
+ if isinstance(cmap, str):
252
+ self._cmap = cm.get_cmap(cmap)
253
+ else:
254
+ # cmap is a colormap
255
+ self._cmap = cmap
256
+
257
+ def get_color(self, alignment, column_i, seq_i):
258
+ # Calculate average normalize similarity
259
+ index1 = alignment.trace[column_i, seq_i]
260
+ if index1 == -1:
261
+ similarity = 0
262
+ else:
263
+ code1 = alignment.sequences[seq_i].code[index1]
264
+ similarities = np.zeros(alignment.trace.shape[1])
265
+ for i in range(alignment.trace.shape[1]):
266
+ index2 = alignment.trace[column_i, i]
267
+ if index2 == -1:
268
+ similarities[i] = 0
269
+ else:
270
+ code2 = alignment.sequences[i].code[index2]
271
+ similarities[i] = self._get_similarity(self._matrix, code1, code2)
272
+ # Delete self-similarity
273
+ similarities = np.delete(similarities, seq_i)
274
+ similarity = np.average(similarities)
275
+ return self._cmap(similarity)
276
+
277
+ def _get_similarity(self, matrix, code1, code2):
278
+ if matrix is None:
279
+ return 1 if code1 == code2 else 0
280
+ else:
281
+ sim = matrix[code1, code2]
282
+ # Normalize (range 0.0 - 1.0)
283
+ min_sim = np.min(matrix[code1])
284
+ max_sim = np.max(matrix[code1])
285
+ sim = (sim - min_sim) / (max_sim - min_sim)
286
+ return sim
287
+
288
+ @staticmethod
289
+ def _generate_colormap(color, to_black):
290
+ from matplotlib.colors import ListedColormap, to_rgb
291
+
292
+ color = to_rgb(color)
293
+ if to_black:
294
+ # From color to black
295
+ cmap_val = np.stack(
296
+ [
297
+ np.interp(np.linspace(0, 1, 100), [0, 1], [color[i], 0])
298
+ for i in range(len(color))
299
+ ]
300
+ ).transpose()
301
+ else:
302
+ # From white to color
303
+ cmap_val = np.stack(
304
+ [
305
+ np.interp(np.linspace(0, 1, 100), [0, 1], [1, color[i]])
306
+ for i in range(len(color))
307
+ ]
308
+ ).transpose()
309
+ return ListedColormap(cmap_val)
310
+
311
+
312
+ class LetterTypePlotter(LetterPlotter):
313
+ """
314
+ This `SymbolPloter` colors each symbol based on the general
315
+ color of that symbol defined by a color scheme.
316
+
317
+ EXPERIMENTAL: Future API changes are probable.
318
+
319
+ Parameters
320
+ ----------
321
+ axes : Axes
322
+ A *Matplotlib* axes, that is used as plotting area.
323
+ alphabet : Alphabet
324
+ The alphabet of the alignment(s) to be plotted
325
+ color_scheme : str or list of (tuple or str), optional
326
+ Either a valid color scheme name
327
+ (e.g. ``"flower"``, ``"clustalx"``, ``blossom``, etc.)
328
+ or a list of *Matplotlib* compatible colors.
329
+ The list length must be at least as long as the
330
+ length of the alphabet used by the sequences.
331
+ color_symbols : bool, optional
332
+ If true, the symbols themselves are colored.
333
+ If false, the symbols are black, and the boxes behind the
334
+ symbols are colored.
335
+ font_size : float, optional
336
+ Font size of the sequence symbols.
337
+ font_param : dict, optional
338
+ Additional parameters that is given to the
339
+ :class:`matplotlib.Text` instance of each symbol.
340
+ """
341
+
342
+ def __init__(
343
+ self,
344
+ axes,
345
+ alphabet,
346
+ color_scheme=None,
347
+ color_symbols=False,
348
+ font_size=None,
349
+ font_param=None,
350
+ ):
351
+ super().__init__(axes, color_symbols, font_size, font_param)
352
+
353
+ if color_scheme is None:
354
+ self._colors = get_color_scheme("flower", alphabet)
355
+ elif isinstance(color_scheme, str):
356
+ self._colors = get_color_scheme(color_scheme, alphabet)
357
+ else:
358
+ self._colors = color_scheme
359
+
360
+ def get_color(self, alignment, column_i, seq_i):
361
+ index = alignment.trace[column_i, seq_i]
362
+ if index == -1:
363
+ # Gaps are white
364
+ return (1, 1, 1)
365
+ code = alignment.sequences[seq_i].code[index]
366
+ return self._colors[code]
367
+
368
+
369
+ class ArrayPlotter(LetterPlotter):
370
+ """
371
+ This :class:`SymbolPlotter` quantitatively decorates sequences alignments, with molecular
372
+ recognition data obtained from e.g. microarrays. Symbols are visualized as characters
373
+ on a colored background box. The color of a given box represents the recognition
374
+ signal. The intensity of the color, is proportional to the strenght of the
375
+ recognition.
376
+
377
+ Parameters
378
+ ----------
379
+ axes : Axes
380
+ A Matplotlib axes, that is used as plotting area.
381
+ fl_score : numpy.ndarray
382
+ The ndarray to store recognition values corresponding to the score residues.
383
+ By default, the normalized score is 1 for maximum recognition
384
+ and 0 for non-recognition (no color).
385
+ color_symbols : bool, optional
386
+ If true, the symbols themselves are colored.
387
+ If false, the symbols are black, and the boxes behind the
388
+ symbols are colored.
389
+ font_size : float, optional
390
+ Font size of the sequence symbols.
391
+ font_param : dict, optional
392
+ Additional parameters that is given to the
393
+ :class:`matplotlib.Text` instance of each symbol.
394
+
395
+ """
396
+
397
+ def __init__(
398
+ self, axes, fl_score, color_symbols=False, font_size=None, font_param=None
399
+ ):
400
+ super().__init__(axes, color_symbols, font_size, font_param)
401
+ self.fl_score = fl_score
402
+ self._cmap = self._generate_colormap(colors["dimorange"], self._color_symbols)
403
+
404
+ def get_color(self, alignment, column_i, seq_i):
405
+ index1 = alignment.trace[column_i, seq_i]
406
+ if index1 == -1:
407
+ spot_signal = 0
408
+ else:
409
+ spot_signal = self._get_signal(self.fl_score, column_i, seq_i)
410
+ return self._cmap(spot_signal)
411
+
412
+ def _get_signal(self, fl_score, column_i, seq_i):
413
+ if fl_score is None:
414
+ signal = 0.0
415
+ else:
416
+ signal = fl_score[column_i, seq_i]
417
+ return signal
418
+
419
+ def get_cmap(self):
420
+ return self._cmap
421
+
422
+ def plot_symbol(self, bbox, alignment, column_i, seq_i):
423
+ from matplotlib.patches import Rectangle
424
+
425
+ trace = alignment.trace
426
+
427
+ if trace[column_i, seq_i] != -1:
428
+ key1 = alignment.sequences[1][trace[column_i, 1]]
429
+ key2 = alignment.sequences[0][trace[column_i, 0]]
430
+ if key1 == key2:
431
+ if seq_i == 1:
432
+ symbol = "*"
433
+ else:
434
+ symbol = alignment.sequences[seq_i][trace[column_i, seq_i]]
435
+ else:
436
+ symbol = alignment.sequences[seq_i][trace[column_i, seq_i]]
437
+ else:
438
+ symbol = "-"
439
+ color = self.get_color(alignment, column_i, seq_i)
440
+ box = Rectangle(bbox.p0, bbox.width, bbox.height)
441
+ self.axes.add_patch(box)
442
+ text = self.axes.text(
443
+ bbox.x0 + bbox.width / 2,
444
+ bbox.y0 + bbox.height / 2,
445
+ symbol,
446
+ color="black",
447
+ ha="center",
448
+ va="center",
449
+ size=self._font_size,
450
+ **self._font_param,
451
+ )
452
+ text.set_clip_on(True)
453
+
454
+ if self._color_symbols:
455
+ box.set_color("None")
456
+ text.set_color(color)
457
+ else:
458
+ box.set_color(color)
459
+
460
+ @staticmethod
461
+ def _generate_colormap(color, to_black):
462
+ from matplotlib.colors import ListedColormap, to_rgb
463
+
464
+ color = to_rgb(color)
465
+ if to_black:
466
+ cmap_val = np.stack(
467
+ [
468
+ np.interp(np.linspace(0, 1, 100), [0, 1], [color[i], 0])
469
+ for i in range(len(color))
470
+ ]
471
+ ).transpose()
472
+ else:
473
+ cmap_val = np.stack(
474
+ [
475
+ np.interp(np.linspace(0, 1, 100), [0, 1], [1, color[i]])
476
+ for i in range(len(color))
477
+ ]
478
+ ).transpose()
479
+ return ListedColormap(cmap_val)
480
+
481
+
482
+ def plot_alignment(
483
+ axes,
484
+ alignment,
485
+ symbol_plotter,
486
+ symbols_per_line=50,
487
+ show_numbers=False,
488
+ number_size=None,
489
+ number_functions=None,
490
+ labels=None,
491
+ label_size=None,
492
+ show_line_position=False,
493
+ spacing=1,
494
+ symbol_spacing=None,
495
+ ):
496
+ """
497
+ Plot a pairwise or multiple sequence alignment.
498
+
499
+ The output is similar to a string representation of an
500
+ :class:`Alignment`, but with enhanced styling, symbol coloring and
501
+ optional sequence labels and sequence position numbering.
502
+ How each symbol of the alignment is drawn is determined by the
503
+ given :class:`SymbolPlotter` object.
504
+
505
+ Parameters
506
+ ----------
507
+ axes : Axes
508
+ A *Matplotlib* axes, that is used as plotting area.
509
+ alignment : Alignment
510
+ The pairwise or multiple sequence alignment to be plotted.
511
+ symbol_plotter : SymbolPlotter
512
+ Defines how the symbols in the alignment are drawn.
513
+ symbols_per_line : int, optional
514
+ The amount of alignment columns that are diplayed per line.
515
+ show_numbers : bool, optional
516
+ If true, the sequence position of the symbols in the last
517
+ alignment column of a line is shown on the right side of the
518
+ plot.
519
+ If the last symbol is a gap, the position of the last actual
520
+ symbol before this gap is taken.
521
+ If the first symbol did not occur up to this point,
522
+ no number is shown for this line.
523
+ By default the first symbol of a sequence has the position 1,
524
+ but this behavior can be changed using the `number_functions`
525
+ parameter.
526
+ number_size : float, optional
527
+ The font size of the position numbers
528
+ number_functions : list of [(None or Callable(int -> int)], optional
529
+ By default the position of the first symbol in a sequence is 1,
530
+ i.e. the sequence position is the sequence index incremented by
531
+ 1.
532
+ The behavior can be changed with this parameter:
533
+ If supplied, the length of the list must match the number of
534
+ sequences in the alignment.
535
+ Every entry is a function that maps a sequence index (*int*) to
536
+ a sequence position (*int*) for the respective sequence.
537
+ A ``None`` entry means, that the default numbering is applied
538
+ for the sequence.
539
+ labels : list of str, optional
540
+ The sequence labels.
541
+ Must be the same size and order as the sequences in the
542
+ alignment.
543
+ label_size : float, optional
544
+ Font size of the labels
545
+ show_line_position : bool, optional
546
+ If true the position within a line is plotted below the
547
+ alignment.
548
+ spacing : float, optional
549
+ The spacing between the alignment lines. 1.0 means that the size
550
+ is equal to the size of a symbol box.
551
+ symbol_spacing : int, optional
552
+ А space is placed between each number of elements desired
553
+ by variable.
554
+
555
+ See also
556
+ --------
557
+ plot_alignment_similarity_based
558
+ plot_alignment_type_based
559
+
560
+ Notes
561
+ -----
562
+ The labels are placed on the Y-axis of the `axes` and the numbers
563
+ are placed on the Y-axis of the `axes` twin.
564
+ The position within a line is placed on the X-axis of the `axes`.
565
+ Further modification of these can be performed using the usual
566
+ *Matplotlib* API.
567
+ """
568
+ from matplotlib.transforms import Bbox
569
+
570
+ if number_functions is None:
571
+ number_functions = [lambda x: x + 1] * len(alignment.sequences)
572
+ else:
573
+ if len(number_functions) != len(alignment.sequences):
574
+ raise ValueError(
575
+ f"The amount of renumbering functions is "
576
+ f"{len(number_functions)} but the amount if sequences in the "
577
+ f"alignment is {len(alignment.sequences)}"
578
+ )
579
+ for i, func in enumerate(number_functions):
580
+ if func is None:
581
+ number_functions[i] = lambda x: x + 1
582
+
583
+ seq_num = alignment.trace.shape[1]
584
+ seq_len = alignment.trace.shape[0]
585
+ line_count = seq_len // symbols_per_line
586
+ # Only extend line count by 1 if there is a remainder
587
+ # (remaining symbols)
588
+ if seq_len % symbols_per_line != 0:
589
+ line_count += 1
590
+
591
+ if symbol_spacing:
592
+ spacing_ratio = symbols_per_line / symbol_spacing
593
+ if spacing_ratio % 1 != 0:
594
+ raise ValueError("symbols_per_line not multiple of symbol_spacing")
595
+ # Initializing symbols_to_print to print symbols_per_line
596
+ # symbols on one line + spacing between symbols
597
+ symbols_to_print = int(spacing_ratio) + symbols_per_line - 1
598
+ else:
599
+ symbols_to_print = symbols_per_line
600
+
601
+ ### Draw symbols ###
602
+ x = 0
603
+ y = 0
604
+ y_start = 0
605
+ line_pos = 0
606
+ for i in range(seq_len):
607
+ y = y_start
608
+ for j in range(seq_num):
609
+ bbox = Bbox([[x, y], [x + 1, y + 1]])
610
+ symbol_plotter.plot_symbol(bbox, alignment, i, j)
611
+ y += 1
612
+ line_pos += 1
613
+ if line_pos >= symbols_to_print:
614
+ line_pos = 0
615
+ x = 0
616
+ y_start += seq_num + spacing
617
+ else:
618
+ x += 1
619
+ if symbol_spacing and (i + 1) % symbol_spacing == 0:
620
+ line_pos += 1
621
+ x += 1
622
+
623
+ ### Draw labels ###
624
+ ticks = []
625
+ tick_labels = []
626
+ if labels is not None:
627
+ # Labels at center height of each line of symbols -> 0.5
628
+ y = 0.5
629
+ for i in range(line_count):
630
+ for j in range(seq_num):
631
+ ticks.append(y)
632
+ tick_labels.append(labels[j])
633
+ y += 1
634
+ y += spacing
635
+ axes.set_yticks(ticks)
636
+ axes.set_yticklabels(tick_labels)
637
+
638
+ ### Draw numbers ###
639
+ # Create twin to allow different tick labels on right side
640
+ number_axes = axes.twinx()
641
+ ticks = []
642
+ tick_labels = []
643
+ if show_numbers:
644
+ # Numbers at center height of each line of symbols -> 0.5
645
+ y = 0.5
646
+ for i in range(line_count):
647
+ for j in range(seq_num):
648
+ if i == line_count - 1:
649
+ # Last line -> get number of last column in trace
650
+ trace_pos = len(alignment.trace) - 1
651
+ else:
652
+ trace_pos = (i + 1) * symbols_per_line - 1
653
+ seq_index = _get_last_valid_index(alignment, trace_pos, j)
654
+ # if -1 -> terminal gap
655
+ # -> skip number for this sequence in this line
656
+ if seq_index != -1:
657
+ # Convert sequence index to position
658
+ # (default index + 1)
659
+ number = number_functions[j](seq_index)
660
+ ticks.append(y)
661
+ tick_labels.append(str(number))
662
+ y += 1
663
+ y += spacing
664
+ number_axes.set_yticks(ticks)
665
+ number_axes.set_yticklabels(tick_labels)
666
+
667
+ axes.set_xlim(0, symbols_to_print)
668
+ # Y-axis starts from top
669
+ lim = seq_num * line_count + spacing * (line_count - 1)
670
+ axes.set_ylim(lim, 0)
671
+ number_axes.set_ylim(lim, 0)
672
+ axes.set_frame_on(False)
673
+ number_axes.set_frame_on(False)
674
+ # Remove ticks and set label and number size
675
+ axes.yaxis.set_tick_params(left=False, right=False, labelsize=label_size)
676
+ number_axes.yaxis.set_tick_params(left=False, right=False, labelsize=number_size)
677
+
678
+ if show_line_position:
679
+ axes.xaxis.set_tick_params(
680
+ top=False, bottom=True, labeltop=False, labelbottom=True
681
+ )
682
+ else:
683
+ axes.xaxis.set_tick_params(
684
+ top=False, bottom=False, labeltop=False, labelbottom=False
685
+ )
686
+
687
+
688
+ def plot_alignment_similarity_based(
689
+ axes,
690
+ alignment,
691
+ symbols_per_line=50,
692
+ show_numbers=False,
693
+ number_size=None,
694
+ number_functions=None,
695
+ labels=None,
696
+ label_size=None,
697
+ show_line_position=False,
698
+ spacing=1,
699
+ color=None,
700
+ cmap=None,
701
+ matrix=None,
702
+ color_symbols=False,
703
+ symbol_spacing=None,
704
+ symbol_size=None,
705
+ symbol_param=None,
706
+ ):
707
+ r"""
708
+ Plot a pairwise or multiple sequence alignment highlighting
709
+ the similarity per alignment column.
710
+
711
+ This function works like :func:`plot_alignment()` with a
712
+ :class:`SymbolPlotter`, that colors the symbols based on the
713
+ similarity with the other symbols in the same column.
714
+ The color intensity (or colormap value, respectively) of a symbol
715
+ scales with similarity of the respective symbol to the other symbols
716
+ in the same alignment column.
717
+
718
+ Parameters
719
+ ----------
720
+ axes : Axes
721
+ A *Matplotlib* axes, that is used as plotting area.
722
+ alignment : Alignment
723
+ The pairwise or multiple sequence alignment to be plotted.
724
+ The alphabet of each sequence in the alignment must be the same.
725
+ symbol_plotter : SymbolPlotter
726
+ Defines how the symbols in the alignment are drawn.
727
+ symbols_per_line : int, optional
728
+ The amount of alignment columns that are diplayed per line.
729
+ show_numbers : bool, optional
730
+ If true, the sequence position of the symbols in the last
731
+ alignment column of a line is shown on the right side of the
732
+ plot.
733
+ If the last symbol is a gap, the position of the last actual
734
+ symbol before this gap is taken.
735
+ If the first symbol did not occur up to this point,
736
+ no number is shown for this line.
737
+ By default the first symbol of a sequence has the position 1,
738
+ but this behavior can be changed using the `number_functions`
739
+ parameter.
740
+ number_size : float, optional
741
+ The font size of the position numbers
742
+ number_functions : list of [(None or Callable(int -> int)], optional
743
+ By default the position of the first symbol in a sequence is 1,
744
+ i.e. the sequence position is the sequence index incremented by
745
+ 1.
746
+ The behavior can be changed with this parameter:
747
+ If supplied, the length of the list must match the number of
748
+ sequences in the alignment.
749
+ Every entry is a function that maps a sequence index (*int*) to
750
+ a sequence position (*int*) for the respective sequence.
751
+ A `None` entry means, that the default numbering is applied
752
+ for the sequence.
753
+ labels : list of str, optional
754
+ The sequence labels.
755
+ Must be the same size and order as the sequences in the
756
+ alignment.
757
+ label_size : float, optional
758
+ Font size of the labels
759
+ show_line_position : bool, optional
760
+ If true the position within a line is plotted below the
761
+ alignment.
762
+ spacing : float, optional
763
+ The spacing between the alignment lines. 1.0 means that the size
764
+ is equal to the size of a symbol box.
765
+ color : tuple or str, optional
766
+ A *Matplotlib* compatible color.
767
+ If this parameter is given, the box color in an interpolated
768
+ value between white and the given color,
769
+ or, if `color_symbols` is set to true, between the given color
770
+ and black.
771
+ The interpolation percentage is given by the average normalized
772
+ similarity.
773
+ cmap : Colormap or str, optional
774
+ The boxes (or symbols, if `color_symbols` is set) are
775
+ colored based on the normalized similarity value on the
776
+ given *Matplotlib* Colormap.
777
+ matrix : SubstitutionMatrix
778
+ The substitution matrix used to determine the similarity
779
+ of two symbols. By default an identity matrix is used, i.e.
780
+ only match and mismatch is distinguished.
781
+ color_symbols : bool, optional
782
+ If true, the symbols themselves are colored.
783
+ If false, the symbols are black, and the boxes behind the
784
+ symbols are colored.
785
+ symbol_size : float, optional
786
+ Font size of the sequence symbols.
787
+ symbol_param : dict
788
+ Additional parameters that is given to the
789
+ :class:`matplotlib.Text` instance of each symbol.
790
+ symbol_spacing : int, optional
791
+ А space is placed between each number of elements desired
792
+ by variable.
793
+
794
+ See also
795
+ --------
796
+ plot_alignment
797
+ LetterSimilarityPlotter
798
+
799
+ Notes
800
+ -----
801
+ For determination of the color, a measure called
802
+ *average normalized similarity* is used.
803
+
804
+ The *normalized similarity* of one symbol *a* to another symbol *b*
805
+ (both in aphabet *X*) is defined as
806
+
807
+ .. math:: S_{norm}(a,b) = \frac{S(a,b) - \min\limits_x(S(a,x))} {\max\limits_x(S(a,x)) - \min\limits_x(S(a,x))}
808
+
809
+ .. math:: a,b,x \in X
810
+
811
+ where *S(x,y)* is the similarity score of the two symbols
812
+ *x* and *y* described in the substitution matrix.
813
+ The similarity *S(x,-)* is always 0.
814
+ As the normalization is conducted only with respect to *a*,
815
+ the *normalized similarity* is not commutative.
816
+
817
+ The *average normalized similarity* of a symbol *a* is
818
+ determined by averaging the normalized similarity over each
819
+ symbol *b*\ :sub:`i` in the same alignment column.
820
+
821
+ .. math:: S_{norm,av}(a) = \frac{1}{n-1} \left[\left(\sum\limits_{i=1}^n S_{norm}(a,b_i)\right) - S_{norm}(a,a)\right]
822
+
823
+ The normalized similarity of *a* to itself is subtracted,
824
+ because *a* does also occur in *b*\ :sub:`i`.
825
+ """
826
+ symbol_plotter = LetterSimilarityPlotter(
827
+ axes,
828
+ matrix=matrix,
829
+ font_size=symbol_size,
830
+ font_param=symbol_param,
831
+ color_symbols=color_symbols,
832
+ )
833
+ if color is not None or cmap is not None:
834
+ symbol_plotter.set_color(color=color, cmap=cmap)
835
+ plot_alignment(
836
+ axes=axes,
837
+ alignment=alignment,
838
+ symbol_plotter=symbol_plotter,
839
+ symbols_per_line=symbols_per_line,
840
+ show_numbers=show_numbers,
841
+ number_size=number_size,
842
+ number_functions=number_functions,
843
+ labels=labels,
844
+ label_size=label_size,
845
+ show_line_position=show_line_position,
846
+ spacing=spacing,
847
+ symbol_spacing=symbol_spacing,
848
+ )
849
+
850
+
851
+ def plot_alignment_type_based(
852
+ axes,
853
+ alignment,
854
+ symbols_per_line=50,
855
+ show_numbers=False,
856
+ number_size=None,
857
+ number_functions=None,
858
+ labels=None,
859
+ label_size=None,
860
+ show_line_position=False,
861
+ spacing=1,
862
+ color_scheme=None,
863
+ color_symbols=False,
864
+ symbol_size=None,
865
+ symbol_param=None,
866
+ symbol_spacing=None,
867
+ ):
868
+ """
869
+ Plot a pairwise or multiple sequence alignment coloring each symbol
870
+ based on the symbol type.
871
+
872
+ This function works like :func:`plot_alignment()` with a
873
+ :class:`SymbolPlotter`, that colors the symbols based on a color
874
+ scheme.
875
+ The color intensity (or colormap value, respectively) of a symbol
876
+ scales with similarity of the respective symbol to the other symbols
877
+ in the same alignment column.
878
+
879
+ Parameters
880
+ ----------
881
+ axes : Axes
882
+ A *Matplotlib* axes, that is used as plotting area.
883
+ alignment : Alignment
884
+ The pairwise or multiple sequence alignment to be plotted.
885
+ The alphabet of each sequence in the alignment must be the same.
886
+ symbol_plotter : SymbolPlotter
887
+ Defines how the symbols in the alignment are drawn.
888
+ symbols_per_line : int, optional
889
+ The amount of alignment columns that are diplayed per line.
890
+ show_numbers : bool, optional
891
+ If true, the sequence position of the symbols in the last
892
+ alignment column of a line is shown on the right side of the
893
+ plot.
894
+ If the last symbol is a gap, the position of the last actual
895
+ symbol before this gap is taken.
896
+ If the first symbol did not occur up to this point,
897
+ no number is shown for this line.
898
+ By default the first symbol of a sequence has the position 1,
899
+ but this behavior can be changed using the `number_functions`
900
+ parameter.
901
+ number_size : float, optional
902
+ The font size of the position numbers
903
+ number_functions : list of [(None or Callable(int -> int)], optional
904
+ By default the position of the first symbol in a sequence is 1,
905
+ i.e. the sequence position is the sequence index incremented by
906
+ 1.
907
+ The behavior can be changed with this parameter:
908
+ If supplied, the length of the list must match the number of
909
+ sequences in the alignment.
910
+ Every entry is a function that maps a sequence index (*int*) to
911
+ a sequence position (*int*) for the respective sequence.
912
+ A `None` entry means, that the default numbering is applied
913
+ for the sequence.
914
+ labels : list of str, optional
915
+ The sequence labels.
916
+ Must be the same size and order as the sequences in the
917
+ alignment.
918
+ label_size : float, optional
919
+ Font size of the labels
920
+ show_line_position : bool, optional
921
+ If true the position within a line is plotted below the
922
+ alignment.
923
+ spacing : float, optional
924
+ The spacing between the alignment lines. 1.0 means that the size
925
+ is equal to the size of a symbol box.
926
+ color_scheme : str or list of (tuple or str), optional
927
+ Either a valid color scheme name
928
+ (e.g. ``"flower"``, ``"clustalx"``, ``blossom``, etc.)
929
+ or a list of *Matplotlib* compatible colors.
930
+ The list length must be at least as long as the
931
+ length of the alphabet used by the sequences.
932
+ color_symbols : bool, optional
933
+ If true, the symbols themselves are colored.
934
+ If false, the symbols are black, and the boxes behind the
935
+ symbols are colored.
936
+ symbol_size : float, optional
937
+ Font size of the sequence symbols.
938
+ symbol_param : dict
939
+ Additional parameters that is given to the
940
+ :class:`matplotlib.Text` instance of each symbol.
941
+ symbol_spacing : int, optional
942
+ А space is placed between each number of elements desired
943
+ by variable.
944
+
945
+ See also
946
+ --------
947
+ plot_alignment
948
+ LetterTypePlotter
949
+ """
950
+ alphabet = alignment.sequences[0].get_alphabet()
951
+ symbol_plotter = LetterTypePlotter(
952
+ axes,
953
+ alphabet,
954
+ font_size=symbol_size,
955
+ font_param=symbol_param,
956
+ color_symbols=color_symbols,
957
+ color_scheme=color_scheme,
958
+ )
959
+ plot_alignment(
960
+ axes=axes,
961
+ alignment=alignment,
962
+ symbol_plotter=symbol_plotter,
963
+ symbols_per_line=symbols_per_line,
964
+ show_numbers=show_numbers,
965
+ number_size=number_size,
966
+ number_functions=number_functions,
967
+ labels=labels,
968
+ label_size=label_size,
969
+ show_line_position=show_line_position,
970
+ spacing=spacing,
971
+ symbol_spacing=symbol_spacing,
972
+ )
973
+
974
+
975
+ def plot_alignment_array(
976
+ axes,
977
+ alignment,
978
+ fl_score,
979
+ symbols_per_line=50,
980
+ show_numbers=False,
981
+ number_size=None,
982
+ number_functions=None,
983
+ labels=None,
984
+ label_size=None,
985
+ show_line_position=False,
986
+ spacing=1,
987
+ color=None,
988
+ cmap=None,
989
+ symbol_spacing=None,
990
+ symbol_size=None,
991
+ symbol_param=None,
992
+ ):
993
+ """
994
+ Plot a pairwise sequence alignment using an :class:`ArrayPlotter`
995
+ instance.
996
+
997
+ Highlights sequence recognition regions at the positions of the respective
998
+ score residue per alignment column.
999
+
1000
+ Parameters
1001
+ ----------
1002
+ axes : Axes
1003
+ A Matplotlib axes, that is used as plotting area.
1004
+ alignment : Alignment
1005
+ The pairwise sequence alignment to be plotted.
1006
+ fl_score : ndarray
1007
+ The array to map fluorescence values to score residues.
1008
+ By default the normalized score is 1 for maximum recognition
1009
+ and 0 for non-recognition (no color).
1010
+ symbol_plotter : SymbolPlotter
1011
+ Instance of ArrayPlotter. Defines how the symbols are drawn
1012
+ in the alignment.
1013
+ symbols_per_line : int, optional
1014
+ The amount of alignment columns that are displayed per line.
1015
+ show_numbers : bool, optional
1016
+ If true, the sequence position of the symbols in the last
1017
+ alignment column of a line is shown on the right side of the
1018
+ plot.
1019
+ If the last symbol is a gap, the position of the last actual
1020
+ symbol before this gap is taken.
1021
+ If the first symbol did not occur up to this point,
1022
+ no number is shown for this line.
1023
+ By default the first symbol of a sequence has the position 1,
1024
+ but this behavior can be changed using the `number_functions`
1025
+ parameter.
1026
+ number_size : float, optional
1027
+ The font size of the position numbers
1028
+ number_functions : list of [(None or Callable(int -> int)], optional
1029
+ By default the position of the first symbol in a sequence is 1,
1030
+ i.e. the sequence position is the sequence index incremented by
1031
+ 1.
1032
+ The behavior can be changed with this parameter:
1033
+ If supplied, the length of the list must match the number of
1034
+ sequences in the alignment.
1035
+ Every entry is a function that maps a sequence index (*int*) to
1036
+ a sequence position (*int*) for the respective sequence.
1037
+ A `None` entry means, that the default numbering is applied
1038
+ for the sequence.
1039
+ labels : list of str, optional
1040
+ The sequence labels.
1041
+ Must be the same size and order as the sequences in the
1042
+ alignment.
1043
+ label_size : float, optional
1044
+ Font size of the labels
1045
+ show_line_position : bool, optional
1046
+ If true the position within a line is plotted below the
1047
+ alignment.
1048
+ spacing : float, optional
1049
+ The spacing between the alignment lines. 1.0 means that the size
1050
+ is equal to the size of a symbol box.
1051
+ color : tuple or str, optional
1052
+ A *Matplotlib* compatible color.
1053
+ cmap : Colormap or str, optional
1054
+ The boxes are
1055
+ colored based on the normalized intensity value on the
1056
+ given *Matplotlib* Colormap.
1057
+ symbol_size : float, optional
1058
+ Font size of the sequence symbols.
1059
+ symbol_param : dict
1060
+ Additional parameters that is given to the
1061
+ :class:`matplotlib.Text` instance of each symbol.
1062
+ symbol_spacing : int, optional
1063
+ A space is placed between each number of elements desired
1064
+ by variable.
1065
+
1066
+ Notes
1067
+ -----
1068
+ A '*' represents a sequence match on the alignment
1069
+ A '-' represents a sequence gap on the alignment
1070
+
1071
+ """
1072
+ symbol_plotter = ArrayPlotter(
1073
+ axes,
1074
+ fl_score=fl_score,
1075
+ font_size=symbol_size,
1076
+ font_param=symbol_param,
1077
+ )
1078
+
1079
+ plot_alignment(
1080
+ axes=axes,
1081
+ alignment=alignment,
1082
+ symbol_plotter=symbol_plotter,
1083
+ symbols_per_line=symbols_per_line,
1084
+ show_numbers=show_numbers,
1085
+ number_size=number_size,
1086
+ number_functions=number_functions,
1087
+ labels=labels,
1088
+ label_size=label_size,
1089
+ show_line_position=show_line_position,
1090
+ spacing=spacing,
1091
+ symbol_spacing=symbol_spacing,
1092
+ )
1093
+
1094
+
1095
+ def _get_last_valid_index(alignment, column_i, seq_i):
1096
+ """
1097
+ Find the last trace value that belongs to a valid sequence index
1098
+ (no gap -> no -1) up to the specified column.
1099
+ """
1100
+ index_found = False
1101
+ while not index_found:
1102
+ if column_i == -1:
1103
+ # Iterated from column_i back to beyond the beginning
1104
+ # and no index has been found
1105
+ # -> Terminal gap
1106
+ # -> First symbol of sequence has not occured yet
1107
+ # -> return -1
1108
+ index = -1
1109
+ index_found = True
1110
+ else:
1111
+ index = alignment.trace[column_i, seq_i]
1112
+ if index != -1:
1113
+ index_found = True
1114
+ column_i -= 1
1115
+ return index