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