biotite 1.5.0__cp314-cp314-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.
- biotite/__init__.py +18 -0
- biotite/application/__init__.py +69 -0
- biotite/application/application.py +276 -0
- biotite/application/autodock/__init__.py +12 -0
- biotite/application/autodock/app.py +500 -0
- biotite/application/blast/__init__.py +14 -0
- biotite/application/blast/alignment.py +92 -0
- biotite/application/blast/webapp.py +428 -0
- biotite/application/clustalo/__init__.py +12 -0
- biotite/application/clustalo/app.py +223 -0
- biotite/application/dssp/__init__.py +12 -0
- biotite/application/dssp/app.py +216 -0
- biotite/application/localapp.py +342 -0
- biotite/application/mafft/__init__.py +12 -0
- biotite/application/mafft/app.py +116 -0
- biotite/application/msaapp.py +363 -0
- biotite/application/muscle/__init__.py +13 -0
- biotite/application/muscle/app3.py +227 -0
- biotite/application/muscle/app5.py +163 -0
- biotite/application/sra/__init__.py +18 -0
- biotite/application/sra/app.py +447 -0
- biotite/application/tantan/__init__.py +12 -0
- biotite/application/tantan/app.py +199 -0
- biotite/application/util.py +77 -0
- biotite/application/viennarna/__init__.py +18 -0
- biotite/application/viennarna/rnaalifold.py +310 -0
- biotite/application/viennarna/rnafold.py +254 -0
- biotite/application/viennarna/rnaplot.py +208 -0
- biotite/application/viennarna/util.py +77 -0
- biotite/application/webapp.py +76 -0
- biotite/copyable.py +71 -0
- biotite/database/__init__.py +23 -0
- biotite/database/afdb/__init__.py +12 -0
- biotite/database/afdb/download.py +197 -0
- biotite/database/entrez/__init__.py +15 -0
- biotite/database/entrez/check.py +60 -0
- biotite/database/entrez/dbnames.py +101 -0
- biotite/database/entrez/download.py +228 -0
- biotite/database/entrez/key.py +44 -0
- biotite/database/entrez/query.py +263 -0
- biotite/database/error.py +16 -0
- biotite/database/pubchem/__init__.py +21 -0
- biotite/database/pubchem/download.py +258 -0
- biotite/database/pubchem/error.py +30 -0
- biotite/database/pubchem/query.py +819 -0
- biotite/database/pubchem/throttle.py +98 -0
- biotite/database/rcsb/__init__.py +13 -0
- biotite/database/rcsb/download.py +161 -0
- biotite/database/rcsb/query.py +963 -0
- biotite/database/uniprot/__init__.py +13 -0
- biotite/database/uniprot/check.py +40 -0
- biotite/database/uniprot/download.py +126 -0
- biotite/database/uniprot/query.py +292 -0
- biotite/file.py +244 -0
- biotite/interface/__init__.py +19 -0
- biotite/interface/openmm/__init__.py +20 -0
- biotite/interface/openmm/state.py +93 -0
- biotite/interface/openmm/system.py +227 -0
- biotite/interface/pymol/__init__.py +201 -0
- biotite/interface/pymol/cgo.py +346 -0
- biotite/interface/pymol/convert.py +185 -0
- biotite/interface/pymol/display.py +267 -0
- biotite/interface/pymol/object.py +1228 -0
- biotite/interface/pymol/shapes.py +178 -0
- biotite/interface/pymol/startup.py +169 -0
- biotite/interface/rdkit/__init__.py +19 -0
- biotite/interface/rdkit/mol.py +490 -0
- biotite/interface/version.py +94 -0
- biotite/interface/warning.py +19 -0
- biotite/sequence/__init__.py +84 -0
- biotite/sequence/align/__init__.py +199 -0
- biotite/sequence/align/alignment.py +702 -0
- biotite/sequence/align/banded.cpython-314-darwin.so +0 -0
- biotite/sequence/align/banded.pyx +652 -0
- biotite/sequence/align/buckets.py +71 -0
- biotite/sequence/align/cigar.py +425 -0
- biotite/sequence/align/kmeralphabet.cpython-314-darwin.so +0 -0
- biotite/sequence/align/kmeralphabet.pyx +595 -0
- biotite/sequence/align/kmersimilarity.cpython-314-darwin.so +0 -0
- biotite/sequence/align/kmersimilarity.pyx +233 -0
- biotite/sequence/align/kmertable.cpython-314-darwin.so +0 -0
- biotite/sequence/align/kmertable.pyx +3411 -0
- biotite/sequence/align/localgapped.cpython-314-darwin.so +0 -0
- biotite/sequence/align/localgapped.pyx +892 -0
- biotite/sequence/align/localungapped.cpython-314-darwin.so +0 -0
- biotite/sequence/align/localungapped.pyx +279 -0
- biotite/sequence/align/matrix.py +631 -0
- biotite/sequence/align/matrix_data/3Di.mat +24 -0
- biotite/sequence/align/matrix_data/BLOSUM100.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM30.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM35.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM40.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM45.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM50.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM50_13p.mat +25 -0
- biotite/sequence/align/matrix_data/BLOSUM50_14.3.mat +25 -0
- biotite/sequence/align/matrix_data/BLOSUM50_5.0.mat +25 -0
- biotite/sequence/align/matrix_data/BLOSUM55.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM60.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM62.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM62_13p.mat +25 -0
- biotite/sequence/align/matrix_data/BLOSUM62_14.3.mat +25 -0
- biotite/sequence/align/matrix_data/BLOSUM62_5.0.mat +25 -0
- biotite/sequence/align/matrix_data/BLOSUM65.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM70.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM75.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM80.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM85.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUM90.mat +31 -0
- biotite/sequence/align/matrix_data/BLOSUMN.mat +31 -0
- biotite/sequence/align/matrix_data/CorBLOSUM49_5.0.mat +25 -0
- biotite/sequence/align/matrix_data/CorBLOSUM57_13p.mat +25 -0
- biotite/sequence/align/matrix_data/CorBLOSUM57_14.3.mat +25 -0
- biotite/sequence/align/matrix_data/CorBLOSUM61_5.0.mat +25 -0
- biotite/sequence/align/matrix_data/CorBLOSUM66_13p.mat +25 -0
- biotite/sequence/align/matrix_data/CorBLOSUM67_14.3.mat +25 -0
- biotite/sequence/align/matrix_data/DAYHOFF.mat +32 -0
- biotite/sequence/align/matrix_data/GONNET.mat +26 -0
- biotite/sequence/align/matrix_data/IDENTITY.mat +25 -0
- biotite/sequence/align/matrix_data/MATCH.mat +25 -0
- biotite/sequence/align/matrix_data/NUC.mat +25 -0
- biotite/sequence/align/matrix_data/PAM10.mat +34 -0
- biotite/sequence/align/matrix_data/PAM100.mat +34 -0
- biotite/sequence/align/matrix_data/PAM110.mat +34 -0
- biotite/sequence/align/matrix_data/PAM120.mat +34 -0
- biotite/sequence/align/matrix_data/PAM130.mat +34 -0
- biotite/sequence/align/matrix_data/PAM140.mat +34 -0
- biotite/sequence/align/matrix_data/PAM150.mat +34 -0
- biotite/sequence/align/matrix_data/PAM160.mat +34 -0
- biotite/sequence/align/matrix_data/PAM170.mat +34 -0
- biotite/sequence/align/matrix_data/PAM180.mat +34 -0
- biotite/sequence/align/matrix_data/PAM190.mat +34 -0
- biotite/sequence/align/matrix_data/PAM20.mat +34 -0
- biotite/sequence/align/matrix_data/PAM200.mat +34 -0
- biotite/sequence/align/matrix_data/PAM210.mat +34 -0
- biotite/sequence/align/matrix_data/PAM220.mat +34 -0
- biotite/sequence/align/matrix_data/PAM230.mat +34 -0
- biotite/sequence/align/matrix_data/PAM240.mat +34 -0
- biotite/sequence/align/matrix_data/PAM250.mat +34 -0
- biotite/sequence/align/matrix_data/PAM260.mat +34 -0
- biotite/sequence/align/matrix_data/PAM270.mat +34 -0
- biotite/sequence/align/matrix_data/PAM280.mat +34 -0
- biotite/sequence/align/matrix_data/PAM290.mat +34 -0
- biotite/sequence/align/matrix_data/PAM30.mat +34 -0
- biotite/sequence/align/matrix_data/PAM300.mat +34 -0
- biotite/sequence/align/matrix_data/PAM310.mat +34 -0
- biotite/sequence/align/matrix_data/PAM320.mat +34 -0
- biotite/sequence/align/matrix_data/PAM330.mat +34 -0
- biotite/sequence/align/matrix_data/PAM340.mat +34 -0
- biotite/sequence/align/matrix_data/PAM350.mat +34 -0
- biotite/sequence/align/matrix_data/PAM360.mat +34 -0
- biotite/sequence/align/matrix_data/PAM370.mat +34 -0
- biotite/sequence/align/matrix_data/PAM380.mat +34 -0
- biotite/sequence/align/matrix_data/PAM390.mat +34 -0
- biotite/sequence/align/matrix_data/PAM40.mat +34 -0
- biotite/sequence/align/matrix_data/PAM400.mat +34 -0
- biotite/sequence/align/matrix_data/PAM410.mat +34 -0
- biotite/sequence/align/matrix_data/PAM420.mat +34 -0
- biotite/sequence/align/matrix_data/PAM430.mat +34 -0
- biotite/sequence/align/matrix_data/PAM440.mat +34 -0
- biotite/sequence/align/matrix_data/PAM450.mat +34 -0
- biotite/sequence/align/matrix_data/PAM460.mat +34 -0
- biotite/sequence/align/matrix_data/PAM470.mat +34 -0
- biotite/sequence/align/matrix_data/PAM480.mat +34 -0
- biotite/sequence/align/matrix_data/PAM490.mat +34 -0
- biotite/sequence/align/matrix_data/PAM50.mat +34 -0
- biotite/sequence/align/matrix_data/PAM500.mat +34 -0
- biotite/sequence/align/matrix_data/PAM60.mat +34 -0
- biotite/sequence/align/matrix_data/PAM70.mat +34 -0
- biotite/sequence/align/matrix_data/PAM80.mat +34 -0
- biotite/sequence/align/matrix_data/PAM90.mat +34 -0
- biotite/sequence/align/matrix_data/PB.license +21 -0
- biotite/sequence/align/matrix_data/PB.mat +18 -0
- biotite/sequence/align/matrix_data/RBLOSUM52_5.0.mat +25 -0
- biotite/sequence/align/matrix_data/RBLOSUM59_13p.mat +25 -0
- biotite/sequence/align/matrix_data/RBLOSUM59_14.3.mat +25 -0
- biotite/sequence/align/matrix_data/RBLOSUM64_5.0.mat +25 -0
- biotite/sequence/align/matrix_data/RBLOSUM69_13p.mat +25 -0
- biotite/sequence/align/matrix_data/RBLOSUM69_14.3.mat +25 -0
- biotite/sequence/align/multiple.cpython-314-darwin.so +0 -0
- biotite/sequence/align/multiple.pyx +619 -0
- biotite/sequence/align/pairwise.cpython-314-darwin.so +0 -0
- biotite/sequence/align/pairwise.pyx +585 -0
- biotite/sequence/align/permutation.cpython-314-darwin.so +0 -0
- biotite/sequence/align/permutation.pyx +313 -0
- biotite/sequence/align/primes.txt +821 -0
- biotite/sequence/align/selector.cpython-314-darwin.so +0 -0
- biotite/sequence/align/selector.pyx +954 -0
- biotite/sequence/align/statistics.py +264 -0
- biotite/sequence/align/tracetable.cpython-314-darwin.so +0 -0
- biotite/sequence/align/tracetable.pxd +64 -0
- biotite/sequence/align/tracetable.pyx +370 -0
- biotite/sequence/alphabet.py +555 -0
- biotite/sequence/annotation.py +836 -0
- biotite/sequence/codec.cpython-314-darwin.so +0 -0
- biotite/sequence/codec.pyx +155 -0
- biotite/sequence/codon.py +476 -0
- biotite/sequence/codon_tables.txt +202 -0
- biotite/sequence/graphics/__init__.py +33 -0
- biotite/sequence/graphics/alignment.py +1101 -0
- biotite/sequence/graphics/color_schemes/3di_flower.json +48 -0
- biotite/sequence/graphics/color_schemes/autumn.json +51 -0
- biotite/sequence/graphics/color_schemes/blossom.json +51 -0
- biotite/sequence/graphics/color_schemes/clustalx_dna.json +11 -0
- biotite/sequence/graphics/color_schemes/clustalx_protein.json +28 -0
- biotite/sequence/graphics/color_schemes/flower.json +51 -0
- biotite/sequence/graphics/color_schemes/jalview_buried.json +31 -0
- biotite/sequence/graphics/color_schemes/jalview_hydrophobicity.json +31 -0
- biotite/sequence/graphics/color_schemes/jalview_prop_helix.json +31 -0
- biotite/sequence/graphics/color_schemes/jalview_prop_strand.json +31 -0
- biotite/sequence/graphics/color_schemes/jalview_prop_turn.json +31 -0
- biotite/sequence/graphics/color_schemes/jalview_taylor.json +28 -0
- biotite/sequence/graphics/color_schemes/jalview_zappo.json +28 -0
- biotite/sequence/graphics/color_schemes/ocean.json +51 -0
- biotite/sequence/graphics/color_schemes/pb_flower.json +40 -0
- biotite/sequence/graphics/color_schemes/rainbow_dna.json +11 -0
- biotite/sequence/graphics/color_schemes/rainbow_protein.json +30 -0
- biotite/sequence/graphics/color_schemes/spring.json +51 -0
- biotite/sequence/graphics/color_schemes/sunset.json +51 -0
- biotite/sequence/graphics/color_schemes/wither.json +51 -0
- biotite/sequence/graphics/colorschemes.py +170 -0
- biotite/sequence/graphics/dendrogram.py +231 -0
- biotite/sequence/graphics/features.py +544 -0
- biotite/sequence/graphics/logo.py +102 -0
- biotite/sequence/graphics/plasmid.py +712 -0
- biotite/sequence/io/__init__.py +12 -0
- biotite/sequence/io/fasta/__init__.py +22 -0
- biotite/sequence/io/fasta/convert.py +283 -0
- biotite/sequence/io/fasta/file.py +265 -0
- biotite/sequence/io/fastq/__init__.py +19 -0
- biotite/sequence/io/fastq/convert.py +117 -0
- biotite/sequence/io/fastq/file.py +507 -0
- biotite/sequence/io/genbank/__init__.py +17 -0
- biotite/sequence/io/genbank/annotation.py +269 -0
- biotite/sequence/io/genbank/file.py +573 -0
- biotite/sequence/io/genbank/metadata.py +336 -0
- biotite/sequence/io/genbank/sequence.py +173 -0
- biotite/sequence/io/general.py +201 -0
- biotite/sequence/io/gff/__init__.py +26 -0
- biotite/sequence/io/gff/convert.py +128 -0
- biotite/sequence/io/gff/file.py +449 -0
- biotite/sequence/phylo/__init__.py +36 -0
- biotite/sequence/phylo/nj.cpython-314-darwin.so +0 -0
- biotite/sequence/phylo/nj.pyx +221 -0
- biotite/sequence/phylo/tree.cpython-314-darwin.so +0 -0
- biotite/sequence/phylo/tree.pyx +1169 -0
- biotite/sequence/phylo/upgma.cpython-314-darwin.so +0 -0
- biotite/sequence/phylo/upgma.pyx +164 -0
- biotite/sequence/profile.py +561 -0
- biotite/sequence/search.py +117 -0
- biotite/sequence/seqtypes.py +720 -0
- biotite/sequence/sequence.py +373 -0
- biotite/setup_ccd.py +197 -0
- biotite/structure/__init__.py +135 -0
- biotite/structure/alphabet/__init__.py +25 -0
- biotite/structure/alphabet/encoder.py +332 -0
- biotite/structure/alphabet/encoder_weights_3di.kerasify +0 -0
- biotite/structure/alphabet/i3d.py +109 -0
- biotite/structure/alphabet/layers.py +86 -0
- biotite/structure/alphabet/pb.license +21 -0
- biotite/structure/alphabet/pb.py +170 -0
- biotite/structure/alphabet/unkerasify.py +128 -0
- biotite/structure/atoms.py +1562 -0
- biotite/structure/basepairs.py +1403 -0
- biotite/structure/bonds.cpython-314-darwin.so +0 -0
- biotite/structure/bonds.pyx +2036 -0
- biotite/structure/box.py +724 -0
- biotite/structure/celllist.cpython-314-darwin.so +0 -0
- biotite/structure/celllist.pyx +864 -0
- biotite/structure/chains.py +310 -0
- biotite/structure/charges.cpython-314-darwin.so +0 -0
- biotite/structure/charges.pyx +520 -0
- biotite/structure/compare.py +683 -0
- biotite/structure/density.py +109 -0
- biotite/structure/dotbracket.py +213 -0
- biotite/structure/error.py +39 -0
- biotite/structure/filter.py +591 -0
- biotite/structure/geometry.py +817 -0
- biotite/structure/graphics/__init__.py +13 -0
- biotite/structure/graphics/atoms.py +243 -0
- biotite/structure/graphics/rna.py +298 -0
- biotite/structure/hbond.py +425 -0
- biotite/structure/info/__init__.py +24 -0
- biotite/structure/info/atom_masses.json +121 -0
- biotite/structure/info/atoms.py +98 -0
- biotite/structure/info/bonds.py +149 -0
- biotite/structure/info/ccd.py +200 -0
- biotite/structure/info/components.bcif +0 -0
- biotite/structure/info/groups.py +128 -0
- biotite/structure/info/masses.py +121 -0
- biotite/structure/info/misc.py +137 -0
- biotite/structure/info/radii.py +267 -0
- biotite/structure/info/standardize.py +185 -0
- biotite/structure/integrity.py +213 -0
- biotite/structure/io/__init__.py +29 -0
- biotite/structure/io/dcd/__init__.py +13 -0
- biotite/structure/io/dcd/file.py +67 -0
- biotite/structure/io/general.py +243 -0
- biotite/structure/io/gro/__init__.py +14 -0
- biotite/structure/io/gro/file.py +343 -0
- biotite/structure/io/mol/__init__.py +20 -0
- biotite/structure/io/mol/convert.py +112 -0
- biotite/structure/io/mol/ctab.py +420 -0
- biotite/structure/io/mol/header.py +120 -0
- biotite/structure/io/mol/mol.py +149 -0
- biotite/structure/io/mol/sdf.py +940 -0
- biotite/structure/io/netcdf/__init__.py +13 -0
- biotite/structure/io/netcdf/file.py +64 -0
- biotite/structure/io/pdb/__init__.py +20 -0
- biotite/structure/io/pdb/convert.py +389 -0
- biotite/structure/io/pdb/file.py +1380 -0
- biotite/structure/io/pdb/hybrid36.cpython-314-darwin.so +0 -0
- biotite/structure/io/pdb/hybrid36.pyx +242 -0
- biotite/structure/io/pdbqt/__init__.py +15 -0
- biotite/structure/io/pdbqt/convert.py +113 -0
- biotite/structure/io/pdbqt/file.py +688 -0
- biotite/structure/io/pdbx/__init__.py +23 -0
- biotite/structure/io/pdbx/bcif.py +674 -0
- biotite/structure/io/pdbx/cif.py +1091 -0
- biotite/structure/io/pdbx/component.py +251 -0
- biotite/structure/io/pdbx/compress.py +362 -0
- biotite/structure/io/pdbx/convert.py +2113 -0
- biotite/structure/io/pdbx/encoding.cpython-314-darwin.so +0 -0
- biotite/structure/io/pdbx/encoding.pyx +1078 -0
- biotite/structure/io/trajfile.py +696 -0
- biotite/structure/io/trr/__init__.py +13 -0
- biotite/structure/io/trr/file.py +43 -0
- biotite/structure/io/util.py +38 -0
- biotite/structure/io/xtc/__init__.py +13 -0
- biotite/structure/io/xtc/file.py +43 -0
- biotite/structure/mechanics.py +72 -0
- biotite/structure/molecules.py +337 -0
- biotite/structure/pseudoknots.py +622 -0
- biotite/structure/rdf.py +245 -0
- biotite/structure/repair.py +302 -0
- biotite/structure/residues.py +716 -0
- biotite/structure/rings.py +451 -0
- biotite/structure/sasa.cpython-314-darwin.so +0 -0
- biotite/structure/sasa.pyx +322 -0
- biotite/structure/segments.py +328 -0
- biotite/structure/sequence.py +110 -0
- biotite/structure/spacegroups.json +1567 -0
- biotite/structure/spacegroups.license +26 -0
- biotite/structure/sse.py +306 -0
- biotite/structure/superimpose.py +511 -0
- biotite/structure/tm.py +581 -0
- biotite/structure/transform.py +736 -0
- biotite/structure/util.py +160 -0
- biotite/version.py +34 -0
- biotite/visualize.py +375 -0
- biotite-1.5.0.dist-info/METADATA +162 -0
- biotite-1.5.0.dist-info/RECORD +354 -0
- biotite-1.5.0.dist-info/WHEEL +6 -0
- biotite-1.5.0.dist-info/licenses/LICENSE.rst +30 -0
|
@@ -0,0 +1,1101 @@
|
|
|
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
|
+
def __init__(
|
|
397
|
+
self, axes, fl_score, color_symbols=False, font_size=None, font_param=None
|
|
398
|
+
):
|
|
399
|
+
super().__init__(axes, color_symbols, font_size, font_param)
|
|
400
|
+
self.fl_score = fl_score
|
|
401
|
+
self._cmap = self._generate_colormap(colors["dimorange"], self._color_symbols)
|
|
402
|
+
|
|
403
|
+
def get_color(self, alignment, column_i, seq_i):
|
|
404
|
+
index1 = alignment.trace[column_i, seq_i]
|
|
405
|
+
if index1 == -1:
|
|
406
|
+
spot_signal = 0
|
|
407
|
+
else:
|
|
408
|
+
spot_signal = self._get_signal(self.fl_score, column_i, seq_i)
|
|
409
|
+
return self._cmap(spot_signal)
|
|
410
|
+
|
|
411
|
+
def _get_signal(self, fl_score, column_i, seq_i):
|
|
412
|
+
if fl_score is None:
|
|
413
|
+
signal = 0.0
|
|
414
|
+
else:
|
|
415
|
+
signal = fl_score[column_i, seq_i]
|
|
416
|
+
return signal
|
|
417
|
+
|
|
418
|
+
def get_cmap(self):
|
|
419
|
+
return self._cmap
|
|
420
|
+
|
|
421
|
+
def plot_symbol(self, bbox, alignment, column_i, seq_i):
|
|
422
|
+
from matplotlib.patches import Rectangle
|
|
423
|
+
|
|
424
|
+
trace = alignment.trace
|
|
425
|
+
|
|
426
|
+
if trace[column_i, seq_i] != -1:
|
|
427
|
+
key1 = alignment.sequences[1][trace[column_i, 1]]
|
|
428
|
+
key2 = alignment.sequences[0][trace[column_i, 0]]
|
|
429
|
+
if key1 == key2:
|
|
430
|
+
if seq_i == 1:
|
|
431
|
+
symbol = "*"
|
|
432
|
+
else:
|
|
433
|
+
symbol = alignment.sequences[seq_i][trace[column_i, seq_i]]
|
|
434
|
+
else:
|
|
435
|
+
symbol = alignment.sequences[seq_i][trace[column_i, seq_i]]
|
|
436
|
+
else:
|
|
437
|
+
symbol = "-"
|
|
438
|
+
color = self.get_color(alignment, column_i, seq_i)
|
|
439
|
+
box = Rectangle(bbox.p0, bbox.width, bbox.height)
|
|
440
|
+
self.axes.add_patch(box)
|
|
441
|
+
text = self.axes.text(
|
|
442
|
+
bbox.x0 + bbox.width / 2,
|
|
443
|
+
bbox.y0 + bbox.height / 2,
|
|
444
|
+
symbol,
|
|
445
|
+
color="black",
|
|
446
|
+
ha="center",
|
|
447
|
+
va="center",
|
|
448
|
+
size=self._font_size,
|
|
449
|
+
**self._font_param,
|
|
450
|
+
)
|
|
451
|
+
text.set_clip_on(True)
|
|
452
|
+
|
|
453
|
+
if self._color_symbols:
|
|
454
|
+
box.set_color("None")
|
|
455
|
+
text.set_color(color)
|
|
456
|
+
else:
|
|
457
|
+
box.set_color(color)
|
|
458
|
+
|
|
459
|
+
@staticmethod
|
|
460
|
+
def _generate_colormap(color, to_black):
|
|
461
|
+
from matplotlib.colors import ListedColormap, to_rgb
|
|
462
|
+
|
|
463
|
+
color = to_rgb(color)
|
|
464
|
+
if to_black:
|
|
465
|
+
cmap_val = np.stack(
|
|
466
|
+
[
|
|
467
|
+
np.interp(np.linspace(0, 1, 100), [0, 1], [color[i], 0])
|
|
468
|
+
for i in range(len(color))
|
|
469
|
+
]
|
|
470
|
+
).transpose()
|
|
471
|
+
else:
|
|
472
|
+
cmap_val = np.stack(
|
|
473
|
+
[
|
|
474
|
+
np.interp(np.linspace(0, 1, 100), [0, 1], [1, color[i]])
|
|
475
|
+
for i in range(len(color))
|
|
476
|
+
]
|
|
477
|
+
).transpose()
|
|
478
|
+
return ListedColormap(cmap_val)
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def plot_alignment(
|
|
482
|
+
axes,
|
|
483
|
+
alignment,
|
|
484
|
+
symbol_plotter,
|
|
485
|
+
symbols_per_line=50,
|
|
486
|
+
show_numbers=False,
|
|
487
|
+
number_size=None,
|
|
488
|
+
number_functions=None,
|
|
489
|
+
labels=None,
|
|
490
|
+
label_size=None,
|
|
491
|
+
show_line_position=False,
|
|
492
|
+
spacing=1,
|
|
493
|
+
symbol_spacing=None,
|
|
494
|
+
):
|
|
495
|
+
"""
|
|
496
|
+
Plot a pairwise or multiple sequence alignment.
|
|
497
|
+
|
|
498
|
+
The output is similar to a string representation of an
|
|
499
|
+
:class:`Alignment`, but with enhanced styling, symbol coloring and
|
|
500
|
+
optional sequence labels and sequence position numbering.
|
|
501
|
+
How each symbol of the alignment is drawn is determined by the
|
|
502
|
+
given :class:`SymbolPlotter` object.
|
|
503
|
+
|
|
504
|
+
Parameters
|
|
505
|
+
----------
|
|
506
|
+
axes : Axes
|
|
507
|
+
A *Matplotlib* axes, that is used as plotting area.
|
|
508
|
+
alignment : Alignment
|
|
509
|
+
The pairwise or multiple sequence alignment to be plotted.
|
|
510
|
+
symbol_plotter : SymbolPlotter
|
|
511
|
+
Defines how the symbols in the alignment are drawn.
|
|
512
|
+
symbols_per_line : int, optional
|
|
513
|
+
The amount of alignment columns that are diplayed per line.
|
|
514
|
+
show_numbers : bool, optional
|
|
515
|
+
If true, the sequence position of the symbols in the last
|
|
516
|
+
alignment column of a line is shown on the right side of the
|
|
517
|
+
plot.
|
|
518
|
+
If the last symbol is a gap, the position of the last actual
|
|
519
|
+
symbol before this gap is taken.
|
|
520
|
+
If the first symbol did not occur up to this point,
|
|
521
|
+
no number is shown for this line.
|
|
522
|
+
By default the first symbol of a sequence has the position 1,
|
|
523
|
+
but this behavior can be changed using the `number_functions`
|
|
524
|
+
parameter.
|
|
525
|
+
number_size : float, optional
|
|
526
|
+
The font size of the position numbers.
|
|
527
|
+
number_functions : list of [(None or Callable(int -> int)], optional
|
|
528
|
+
By default the position of the first symbol in a sequence is 1,
|
|
529
|
+
i.e. the sequence position is the sequence index incremented by
|
|
530
|
+
1.
|
|
531
|
+
The behavior can be changed with this parameter:
|
|
532
|
+
If supplied, the length of the list must match the number of
|
|
533
|
+
sequences in the alignment.
|
|
534
|
+
Every entry is a function that maps a sequence index (*int*) to
|
|
535
|
+
a sequence position (*int*) for the respective sequence.
|
|
536
|
+
A ``None`` entry means, that the default numbering is applied
|
|
537
|
+
for the sequence.
|
|
538
|
+
labels : list of str, optional
|
|
539
|
+
The sequence labels.
|
|
540
|
+
Must be the same size and order as the sequences in the
|
|
541
|
+
alignment.
|
|
542
|
+
label_size : float, optional
|
|
543
|
+
Font size of the labels.
|
|
544
|
+
show_line_position : bool, optional
|
|
545
|
+
If true the position within a line is plotted below the
|
|
546
|
+
alignment.
|
|
547
|
+
spacing : float, optional
|
|
548
|
+
The spacing between the alignment lines. 1.0 means that the size
|
|
549
|
+
is equal to the size of a symbol box.
|
|
550
|
+
symbol_spacing : int, optional
|
|
551
|
+
A space is placed between each number of elements desired
|
|
552
|
+
by variable.
|
|
553
|
+
|
|
554
|
+
Notes
|
|
555
|
+
-----
|
|
556
|
+
The labels are placed on the Y-axis of the `axes` and the numbers
|
|
557
|
+
are placed on the Y-axis of the `axes` twin.
|
|
558
|
+
The position within a line is placed on the X-axis of the `axes`.
|
|
559
|
+
Further modification of these can be performed using the usual
|
|
560
|
+
*Matplotlib* API.
|
|
561
|
+
"""
|
|
562
|
+
from matplotlib.transforms import Bbox
|
|
563
|
+
|
|
564
|
+
if number_functions is None:
|
|
565
|
+
number_functions = [lambda x: x + 1] * len(alignment.sequences)
|
|
566
|
+
else:
|
|
567
|
+
if len(number_functions) != len(alignment.sequences):
|
|
568
|
+
raise ValueError(
|
|
569
|
+
f"The amount of renumbering functions is "
|
|
570
|
+
f"{len(number_functions)} but the amount if sequences in the "
|
|
571
|
+
f"alignment is {len(alignment.sequences)}"
|
|
572
|
+
)
|
|
573
|
+
for i, func in enumerate(number_functions):
|
|
574
|
+
if func is None:
|
|
575
|
+
number_functions[i] = lambda x: x + 1
|
|
576
|
+
|
|
577
|
+
seq_num = alignment.trace.shape[1]
|
|
578
|
+
seq_len = alignment.trace.shape[0]
|
|
579
|
+
line_count = seq_len // symbols_per_line
|
|
580
|
+
# Only extend line count by 1 if there is a remainder
|
|
581
|
+
# (remaining symbols)
|
|
582
|
+
if seq_len % symbols_per_line != 0:
|
|
583
|
+
line_count += 1
|
|
584
|
+
|
|
585
|
+
if symbol_spacing:
|
|
586
|
+
spacing_ratio = symbols_per_line / symbol_spacing
|
|
587
|
+
if spacing_ratio % 1 != 0:
|
|
588
|
+
raise ValueError("symbols_per_line not multiple of symbol_spacing")
|
|
589
|
+
# Initializing symbols_to_print to print symbols_per_line
|
|
590
|
+
# symbols on one line + spacing between symbols
|
|
591
|
+
symbols_to_print = int(spacing_ratio) + symbols_per_line - 1
|
|
592
|
+
else:
|
|
593
|
+
symbols_to_print = symbols_per_line
|
|
594
|
+
|
|
595
|
+
### Draw symbols ###
|
|
596
|
+
x = 0
|
|
597
|
+
y = 0
|
|
598
|
+
y_start = 0
|
|
599
|
+
line_pos = 0
|
|
600
|
+
for i in range(seq_len):
|
|
601
|
+
y = y_start
|
|
602
|
+
for j in range(seq_num):
|
|
603
|
+
bbox = Bbox([[x, y], [x + 1, y + 1]])
|
|
604
|
+
symbol_plotter.plot_symbol(bbox, alignment, i, j)
|
|
605
|
+
y += 1
|
|
606
|
+
line_pos += 1
|
|
607
|
+
if line_pos >= symbols_to_print:
|
|
608
|
+
line_pos = 0
|
|
609
|
+
x = 0
|
|
610
|
+
y_start += seq_num + spacing
|
|
611
|
+
else:
|
|
612
|
+
x += 1
|
|
613
|
+
if symbol_spacing and (i + 1) % symbol_spacing == 0:
|
|
614
|
+
line_pos += 1
|
|
615
|
+
x += 1
|
|
616
|
+
|
|
617
|
+
### Draw labels ###
|
|
618
|
+
ticks = []
|
|
619
|
+
tick_labels = []
|
|
620
|
+
if labels is not None:
|
|
621
|
+
# Labels at center height of each line of symbols -> 0.5
|
|
622
|
+
y = 0.5
|
|
623
|
+
for i in range(line_count):
|
|
624
|
+
for j in range(seq_num):
|
|
625
|
+
ticks.append(y)
|
|
626
|
+
tick_labels.append(labels[j])
|
|
627
|
+
y += 1
|
|
628
|
+
y += spacing
|
|
629
|
+
axes.set_yticks(ticks)
|
|
630
|
+
axes.set_yticklabels(tick_labels)
|
|
631
|
+
|
|
632
|
+
### Draw numbers ###
|
|
633
|
+
# Create twin to allow different tick labels on right side
|
|
634
|
+
number_axes = axes.twinx()
|
|
635
|
+
ticks = []
|
|
636
|
+
tick_labels = []
|
|
637
|
+
if show_numbers:
|
|
638
|
+
# Numbers at center height of each line of symbols -> 0.5
|
|
639
|
+
y = 0.5
|
|
640
|
+
for i in range(line_count):
|
|
641
|
+
for j in range(seq_num):
|
|
642
|
+
if i == line_count - 1:
|
|
643
|
+
# Last line -> get number of last column in trace
|
|
644
|
+
trace_pos = len(alignment.trace) - 1
|
|
645
|
+
else:
|
|
646
|
+
trace_pos = (i + 1) * symbols_per_line - 1
|
|
647
|
+
seq_index = _get_last_valid_index(alignment, trace_pos, j)
|
|
648
|
+
# if -1 -> terminal gap
|
|
649
|
+
# -> skip number for this sequence in this line
|
|
650
|
+
if seq_index != -1:
|
|
651
|
+
# Convert sequence index to position
|
|
652
|
+
# (default index + 1)
|
|
653
|
+
number = number_functions[j](seq_index)
|
|
654
|
+
ticks.append(y)
|
|
655
|
+
tick_labels.append(str(number))
|
|
656
|
+
y += 1
|
|
657
|
+
y += spacing
|
|
658
|
+
number_axes.set_yticks(ticks)
|
|
659
|
+
number_axes.set_yticklabels(tick_labels)
|
|
660
|
+
|
|
661
|
+
axes.set_xlim(0, symbols_to_print)
|
|
662
|
+
# Y-axis starts from top
|
|
663
|
+
lim = seq_num * line_count + spacing * (line_count - 1)
|
|
664
|
+
axes.set_ylim(lim, 0)
|
|
665
|
+
number_axes.set_ylim(lim, 0)
|
|
666
|
+
axes.set_frame_on(False)
|
|
667
|
+
number_axes.set_frame_on(False)
|
|
668
|
+
# Remove ticks and set label and number size
|
|
669
|
+
axes.yaxis.set_tick_params(left=False, right=False, labelsize=label_size)
|
|
670
|
+
number_axes.yaxis.set_tick_params(left=False, right=False, labelsize=number_size)
|
|
671
|
+
|
|
672
|
+
if show_line_position:
|
|
673
|
+
axes.xaxis.set_tick_params(
|
|
674
|
+
top=False, bottom=True, labeltop=False, labelbottom=True
|
|
675
|
+
)
|
|
676
|
+
else:
|
|
677
|
+
axes.xaxis.set_tick_params(
|
|
678
|
+
top=False, bottom=False, labeltop=False, labelbottom=False
|
|
679
|
+
)
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
def plot_alignment_similarity_based(
|
|
683
|
+
axes,
|
|
684
|
+
alignment,
|
|
685
|
+
symbols_per_line=50,
|
|
686
|
+
show_numbers=False,
|
|
687
|
+
number_size=None,
|
|
688
|
+
number_functions=None,
|
|
689
|
+
labels=None,
|
|
690
|
+
label_size=None,
|
|
691
|
+
show_line_position=False,
|
|
692
|
+
spacing=1,
|
|
693
|
+
color=None,
|
|
694
|
+
cmap=None,
|
|
695
|
+
matrix=None,
|
|
696
|
+
color_symbols=False,
|
|
697
|
+
symbol_spacing=None,
|
|
698
|
+
symbol_size=None,
|
|
699
|
+
symbol_param=None,
|
|
700
|
+
):
|
|
701
|
+
r"""
|
|
702
|
+
Plot a pairwise or multiple sequence alignment highlighting
|
|
703
|
+
the similarity per alignment column.
|
|
704
|
+
|
|
705
|
+
This function works like :func:`plot_alignment()` with a
|
|
706
|
+
:class:`SymbolPlotter`, that colors the symbols based on the
|
|
707
|
+
similarity with the other symbols in the same column.
|
|
708
|
+
The color intensity (or colormap value, respectively) of a symbol
|
|
709
|
+
scales with similarity of the respective symbol to the other symbols
|
|
710
|
+
in the same alignment column.
|
|
711
|
+
|
|
712
|
+
Parameters
|
|
713
|
+
----------
|
|
714
|
+
axes : Axes
|
|
715
|
+
A *Matplotlib* axes, that is used as plotting area.
|
|
716
|
+
alignment : Alignment
|
|
717
|
+
The pairwise or multiple sequence alignment to be plotted.
|
|
718
|
+
The alphabet of each sequence in the alignment must be the same.
|
|
719
|
+
symbols_per_line : int, optional
|
|
720
|
+
The amount of alignment columns that are diplayed per line.
|
|
721
|
+
show_numbers : bool, optional
|
|
722
|
+
If true, the sequence position of the symbols in the last
|
|
723
|
+
alignment column of a line is shown on the right side of the
|
|
724
|
+
plot.
|
|
725
|
+
If the last symbol is a gap, the position of the last actual
|
|
726
|
+
symbol before this gap is taken.
|
|
727
|
+
If the first symbol did not occur up to this point,
|
|
728
|
+
no number is shown for this line.
|
|
729
|
+
By default the first symbol of a sequence has the position 1,
|
|
730
|
+
but this behavior can be changed using the `number_functions`
|
|
731
|
+
parameter.
|
|
732
|
+
number_size : float, optional
|
|
733
|
+
The font size of the position numbers.
|
|
734
|
+
number_functions : list of [(None or Callable(int -> int)], optional
|
|
735
|
+
By default the position of the first symbol in a sequence is 1,
|
|
736
|
+
i.e. the sequence position is the sequence index incremented by
|
|
737
|
+
1.
|
|
738
|
+
The behavior can be changed with this parameter:
|
|
739
|
+
If supplied, the length of the list must match the number of
|
|
740
|
+
sequences in the alignment.
|
|
741
|
+
Every entry is a function that maps a sequence index (*int*) to
|
|
742
|
+
a sequence position (*int*) for the respective sequence.
|
|
743
|
+
A `None` entry means, that the default numbering is applied
|
|
744
|
+
for the sequence.
|
|
745
|
+
labels : list of str, optional
|
|
746
|
+
The sequence labels.
|
|
747
|
+
Must be the same size and order as the sequences in the
|
|
748
|
+
alignment.
|
|
749
|
+
label_size : float, optional
|
|
750
|
+
Font size of the labels.
|
|
751
|
+
show_line_position : bool, optional
|
|
752
|
+
If true the position within a line is plotted below the
|
|
753
|
+
alignment.
|
|
754
|
+
spacing : float, optional
|
|
755
|
+
The spacing between the alignment lines. 1.0 means that the size
|
|
756
|
+
is equal to the size of a symbol box.
|
|
757
|
+
color : tuple or str, optional
|
|
758
|
+
A *Matplotlib* compatible color.
|
|
759
|
+
If this parameter is given, the box color in an interpolated
|
|
760
|
+
value between white and the given color,
|
|
761
|
+
or, if `color_symbols` is set to true, between the given color
|
|
762
|
+
and black.
|
|
763
|
+
The interpolation percentage is given by the average normalized
|
|
764
|
+
similarity.
|
|
765
|
+
cmap : Colormap or str, optional
|
|
766
|
+
The boxes (or symbols, if `color_symbols` is set) are
|
|
767
|
+
colored based on the normalized similarity value on the
|
|
768
|
+
given *Matplotlib* Colormap.
|
|
769
|
+
matrix : SubstitutionMatrix
|
|
770
|
+
The substitution matrix used to determine the similarity
|
|
771
|
+
of two symbols. By default an identity matrix is used, i.e.
|
|
772
|
+
only match and mismatch is distinguished.
|
|
773
|
+
color_symbols : bool, optional
|
|
774
|
+
If true, the symbols themselves are colored.
|
|
775
|
+
If false, the symbols are black, and the boxes behind the
|
|
776
|
+
symbols are colored.
|
|
777
|
+
symbol_spacing : int, optional
|
|
778
|
+
A space is placed between each number of elements desired
|
|
779
|
+
by variable.
|
|
780
|
+
symbol_size : float, optional
|
|
781
|
+
Font size of the sequence symbols.
|
|
782
|
+
symbol_param : dict
|
|
783
|
+
Additional parameters that is given to the
|
|
784
|
+
:class:`matplotlib.Text` instance of each symbol.
|
|
785
|
+
|
|
786
|
+
See Also
|
|
787
|
+
--------
|
|
788
|
+
plot_alignment : Analogous functionality with a customizable :class:`SymbolPlotter`.
|
|
789
|
+
LetterSimilarityPlotter : The :class:`SymbolPlotter` used in this function.
|
|
790
|
+
|
|
791
|
+
Notes
|
|
792
|
+
-----
|
|
793
|
+
For determination of the color, a measure called
|
|
794
|
+
*average normalized similarity* is used.
|
|
795
|
+
|
|
796
|
+
The *normalized similarity* of one symbol *a* to another symbol *b*
|
|
797
|
+
(both in aphabet *X*) is defined as
|
|
798
|
+
|
|
799
|
+
.. 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))}
|
|
800
|
+
|
|
801
|
+
.. math:: a,b,x \in X
|
|
802
|
+
|
|
803
|
+
where *S(x,y)* is the similarity score of the two symbols
|
|
804
|
+
*x* and *y* described in the substitution matrix.
|
|
805
|
+
The similarity *S(x,-)* is always 0.
|
|
806
|
+
As the normalization is conducted only with respect to *a*,
|
|
807
|
+
the *normalized similarity* is not commutative.
|
|
808
|
+
|
|
809
|
+
The *average normalized similarity* of a symbol *a* is
|
|
810
|
+
determined by averaging the normalized similarity over each
|
|
811
|
+
symbol *b*\ :sub:`i` in the same alignment column.
|
|
812
|
+
|
|
813
|
+
.. 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]
|
|
814
|
+
|
|
815
|
+
The normalized similarity of *a* to itself is subtracted,
|
|
816
|
+
because *a* does also occur in *b*\ :sub:`i`.
|
|
817
|
+
"""
|
|
818
|
+
symbol_plotter = LetterSimilarityPlotter(
|
|
819
|
+
axes,
|
|
820
|
+
matrix=matrix,
|
|
821
|
+
font_size=symbol_size,
|
|
822
|
+
font_param=symbol_param,
|
|
823
|
+
color_symbols=color_symbols,
|
|
824
|
+
)
|
|
825
|
+
if color is not None or cmap is not None:
|
|
826
|
+
symbol_plotter.set_color(color=color, cmap=cmap)
|
|
827
|
+
plot_alignment(
|
|
828
|
+
axes=axes,
|
|
829
|
+
alignment=alignment,
|
|
830
|
+
symbol_plotter=symbol_plotter,
|
|
831
|
+
symbols_per_line=symbols_per_line,
|
|
832
|
+
show_numbers=show_numbers,
|
|
833
|
+
number_size=number_size,
|
|
834
|
+
number_functions=number_functions,
|
|
835
|
+
labels=labels,
|
|
836
|
+
label_size=label_size,
|
|
837
|
+
show_line_position=show_line_position,
|
|
838
|
+
spacing=spacing,
|
|
839
|
+
symbol_spacing=symbol_spacing,
|
|
840
|
+
)
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
def plot_alignment_type_based(
|
|
844
|
+
axes,
|
|
845
|
+
alignment,
|
|
846
|
+
symbols_per_line=50,
|
|
847
|
+
show_numbers=False,
|
|
848
|
+
number_size=None,
|
|
849
|
+
number_functions=None,
|
|
850
|
+
labels=None,
|
|
851
|
+
label_size=None,
|
|
852
|
+
show_line_position=False,
|
|
853
|
+
spacing=1,
|
|
854
|
+
color_scheme=None,
|
|
855
|
+
color_symbols=False,
|
|
856
|
+
symbol_size=None,
|
|
857
|
+
symbol_param=None,
|
|
858
|
+
symbol_spacing=None,
|
|
859
|
+
):
|
|
860
|
+
"""
|
|
861
|
+
Plot a pairwise or multiple sequence alignment coloring each symbol
|
|
862
|
+
based on the symbol type.
|
|
863
|
+
|
|
864
|
+
This function works like :func:`plot_alignment()` with a
|
|
865
|
+
:class:`SymbolPlotter`, that colors the symbols based on a color
|
|
866
|
+
scheme.
|
|
867
|
+
The color intensity (or colormap value, respectively) of a symbol
|
|
868
|
+
scales with similarity of the respective symbol to the other symbols
|
|
869
|
+
in the same alignment column.
|
|
870
|
+
|
|
871
|
+
Parameters
|
|
872
|
+
----------
|
|
873
|
+
axes : Axes
|
|
874
|
+
A *Matplotlib* axes, that is used as plotting area.
|
|
875
|
+
alignment : Alignment
|
|
876
|
+
The pairwise or multiple sequence alignment to be plotted.
|
|
877
|
+
The alphabet of each sequence in the alignment must be the same.
|
|
878
|
+
symbols_per_line : int, optional
|
|
879
|
+
The amount of alignment columns that are diplayed per line.
|
|
880
|
+
show_numbers : bool, optional
|
|
881
|
+
If true, the sequence position of the symbols in the last
|
|
882
|
+
alignment column of a line is shown on the right side of the
|
|
883
|
+
plot.
|
|
884
|
+
If the last symbol is a gap, the position of the last actual
|
|
885
|
+
symbol before this gap is taken.
|
|
886
|
+
If the first symbol did not occur up to this point,
|
|
887
|
+
no number is shown for this line.
|
|
888
|
+
By default the first symbol of a sequence has the position 1,
|
|
889
|
+
but this behavior can be changed using the `number_functions`
|
|
890
|
+
parameter.
|
|
891
|
+
number_size : float, optional
|
|
892
|
+
The font size of the position numbers.
|
|
893
|
+
number_functions : list of [(None or Callable(int -> int)], optional
|
|
894
|
+
By default the position of the first symbol in a sequence is 1,
|
|
895
|
+
i.e. the sequence position is the sequence index incremented by
|
|
896
|
+
1.
|
|
897
|
+
The behavior can be changed with this parameter:
|
|
898
|
+
If supplied, the length of the list must match the number of
|
|
899
|
+
sequences in the alignment.
|
|
900
|
+
Every entry is a function that maps a sequence index (*int*) to
|
|
901
|
+
a sequence position (*int*) for the respective sequence.
|
|
902
|
+
A `None` entry means, that the default numbering is applied
|
|
903
|
+
for the sequence.
|
|
904
|
+
labels : list of str, optional
|
|
905
|
+
The sequence labels.
|
|
906
|
+
Must be the same size and order as the sequences in the
|
|
907
|
+
alignment.
|
|
908
|
+
label_size : float, optional
|
|
909
|
+
Font size of the labels.
|
|
910
|
+
show_line_position : bool, optional
|
|
911
|
+
If true the position within a line is plotted below the
|
|
912
|
+
alignment.
|
|
913
|
+
spacing : float, optional
|
|
914
|
+
The spacing between the alignment lines. 1.0 means that the size
|
|
915
|
+
is equal to the size of a symbol box.
|
|
916
|
+
color_scheme : str or list of (tuple or str), optional
|
|
917
|
+
Either a valid color scheme name
|
|
918
|
+
(e.g. ``"flower"``, ``"clustalx"``, ``blossom``, etc.)
|
|
919
|
+
or a list of *Matplotlib* compatible colors.
|
|
920
|
+
The list length must be at least as long as the
|
|
921
|
+
length of the alphabet used by the sequences.
|
|
922
|
+
color_symbols : bool, optional
|
|
923
|
+
If true, the symbols themselves are colored.
|
|
924
|
+
If false, the symbols are black, and the boxes behind the
|
|
925
|
+
symbols are colored.
|
|
926
|
+
symbol_size : float, optional
|
|
927
|
+
Font size of the sequence symbols.
|
|
928
|
+
symbol_param : dict
|
|
929
|
+
Additional parameters that is given to the
|
|
930
|
+
:class:`matplotlib.Text` instance of each symbol.
|
|
931
|
+
symbol_spacing : int, optional
|
|
932
|
+
A space is placed between each number of elements desired
|
|
933
|
+
by variable.
|
|
934
|
+
|
|
935
|
+
See Also
|
|
936
|
+
--------
|
|
937
|
+
plot_alignment : Analogous functionality with a customizable :class:`SymbolPlotter`.
|
|
938
|
+
LetterTypePlotter : The :class:`SymbolPlotter` used in this function.
|
|
939
|
+
"""
|
|
940
|
+
alphabet = alignment.sequences[0].get_alphabet()
|
|
941
|
+
symbol_plotter = LetterTypePlotter(
|
|
942
|
+
axes,
|
|
943
|
+
alphabet,
|
|
944
|
+
font_size=symbol_size,
|
|
945
|
+
font_param=symbol_param,
|
|
946
|
+
color_symbols=color_symbols,
|
|
947
|
+
color_scheme=color_scheme,
|
|
948
|
+
)
|
|
949
|
+
plot_alignment(
|
|
950
|
+
axes=axes,
|
|
951
|
+
alignment=alignment,
|
|
952
|
+
symbol_plotter=symbol_plotter,
|
|
953
|
+
symbols_per_line=symbols_per_line,
|
|
954
|
+
show_numbers=show_numbers,
|
|
955
|
+
number_size=number_size,
|
|
956
|
+
number_functions=number_functions,
|
|
957
|
+
labels=labels,
|
|
958
|
+
label_size=label_size,
|
|
959
|
+
show_line_position=show_line_position,
|
|
960
|
+
spacing=spacing,
|
|
961
|
+
symbol_spacing=symbol_spacing,
|
|
962
|
+
)
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
def plot_alignment_array(
|
|
966
|
+
axes,
|
|
967
|
+
alignment,
|
|
968
|
+
fl_score,
|
|
969
|
+
symbols_per_line=50,
|
|
970
|
+
show_numbers=False,
|
|
971
|
+
number_size=None,
|
|
972
|
+
number_functions=None,
|
|
973
|
+
labels=None,
|
|
974
|
+
label_size=None,
|
|
975
|
+
show_line_position=False,
|
|
976
|
+
spacing=1,
|
|
977
|
+
color=None,
|
|
978
|
+
cmap=None,
|
|
979
|
+
symbol_spacing=None,
|
|
980
|
+
symbol_size=None,
|
|
981
|
+
symbol_param=None,
|
|
982
|
+
):
|
|
983
|
+
"""
|
|
984
|
+
Plot a pairwise sequence alignment using an :class:`ArrayPlotter`
|
|
985
|
+
instance.
|
|
986
|
+
|
|
987
|
+
Highlights sequence recognition regions at the positions of the respective
|
|
988
|
+
score residue per alignment column.
|
|
989
|
+
|
|
990
|
+
Parameters
|
|
991
|
+
----------
|
|
992
|
+
axes : Axes
|
|
993
|
+
A Matplotlib axes, that is used as plotting area.
|
|
994
|
+
alignment : Alignment
|
|
995
|
+
The pairwise sequence alignment to be plotted.
|
|
996
|
+
fl_score : ndarray
|
|
997
|
+
The array to map fluorescence values to score residues.
|
|
998
|
+
By default the normalized score is 1 for maximum recognition
|
|
999
|
+
and 0 for non-recognition (no color).
|
|
1000
|
+
symbols_per_line : int, optional
|
|
1001
|
+
The amount of alignment columns that are displayed per line.
|
|
1002
|
+
show_numbers : bool, optional
|
|
1003
|
+
If true, the sequence position of the symbols in the last
|
|
1004
|
+
alignment column of a line is shown on the right side of the
|
|
1005
|
+
plot.
|
|
1006
|
+
If the last symbol is a gap, the position of the last actual
|
|
1007
|
+
symbol before this gap is taken.
|
|
1008
|
+
If the first symbol did not occur up to this point,
|
|
1009
|
+
no number is shown for this line.
|
|
1010
|
+
By default the first symbol of a sequence has the position 1,
|
|
1011
|
+
but this behavior can be changed using the `number_functions`
|
|
1012
|
+
parameter.
|
|
1013
|
+
number_size : float, optional
|
|
1014
|
+
The font size of the position numbers.
|
|
1015
|
+
number_functions : list of [(None or Callable(int -> int)], optional
|
|
1016
|
+
By default the position of the first symbol in a sequence is 1,
|
|
1017
|
+
i.e. the sequence position is the sequence index incremented by
|
|
1018
|
+
1.
|
|
1019
|
+
The behavior can be changed with this parameter:
|
|
1020
|
+
If supplied, the length of the list must match the number of
|
|
1021
|
+
sequences in the alignment.
|
|
1022
|
+
Every entry is a function that maps a sequence index (*int*) to
|
|
1023
|
+
a sequence position (*int*) for the respective sequence.
|
|
1024
|
+
A `None` entry means, that the default numbering is applied
|
|
1025
|
+
for the sequence.
|
|
1026
|
+
labels : list of str, optional
|
|
1027
|
+
The sequence labels.
|
|
1028
|
+
Must be the same size and order as the sequences in the
|
|
1029
|
+
alignment.
|
|
1030
|
+
label_size : float, optional
|
|
1031
|
+
Font size of the labels.
|
|
1032
|
+
show_line_position : bool, optional
|
|
1033
|
+
If true the position within a line is plotted below the
|
|
1034
|
+
alignment.
|
|
1035
|
+
spacing : float, optional
|
|
1036
|
+
The spacing between the alignment lines. 1.0 means that the size
|
|
1037
|
+
is equal to the size of a symbol box.
|
|
1038
|
+
color : tuple or str, optional
|
|
1039
|
+
A *Matplotlib* compatible color.
|
|
1040
|
+
cmap : Colormap or str, optional
|
|
1041
|
+
The boxes are
|
|
1042
|
+
colored based on the normalized intensity value on the
|
|
1043
|
+
given *Matplotlib* Colormap.
|
|
1044
|
+
symbol_spacing : int, optional
|
|
1045
|
+
A space is placed between each number of elements desired
|
|
1046
|
+
by variable.
|
|
1047
|
+
symbol_size : float, optional
|
|
1048
|
+
Font size of the sequence symbols.
|
|
1049
|
+
symbol_param : dict
|
|
1050
|
+
Additional parameters that is given to the
|
|
1051
|
+
:class:`matplotlib.Text` instance of each symbol.
|
|
1052
|
+
|
|
1053
|
+
Notes
|
|
1054
|
+
-----
|
|
1055
|
+
A '*' represents a sequence match on the alignment
|
|
1056
|
+
A '-' represents a sequence gap on the alignment
|
|
1057
|
+
"""
|
|
1058
|
+
symbol_plotter = ArrayPlotter(
|
|
1059
|
+
axes,
|
|
1060
|
+
fl_score=fl_score,
|
|
1061
|
+
font_size=symbol_size,
|
|
1062
|
+
font_param=symbol_param,
|
|
1063
|
+
)
|
|
1064
|
+
|
|
1065
|
+
plot_alignment(
|
|
1066
|
+
axes=axes,
|
|
1067
|
+
alignment=alignment,
|
|
1068
|
+
symbol_plotter=symbol_plotter,
|
|
1069
|
+
symbols_per_line=symbols_per_line,
|
|
1070
|
+
show_numbers=show_numbers,
|
|
1071
|
+
number_size=number_size,
|
|
1072
|
+
number_functions=number_functions,
|
|
1073
|
+
labels=labels,
|
|
1074
|
+
label_size=label_size,
|
|
1075
|
+
show_line_position=show_line_position,
|
|
1076
|
+
spacing=spacing,
|
|
1077
|
+
symbol_spacing=symbol_spacing,
|
|
1078
|
+
)
|
|
1079
|
+
|
|
1080
|
+
|
|
1081
|
+
def _get_last_valid_index(alignment, column_i, seq_i):
|
|
1082
|
+
"""
|
|
1083
|
+
Find the last trace value that belongs to a valid sequence index
|
|
1084
|
+
(no gap -> no -1) up to the specified column.
|
|
1085
|
+
"""
|
|
1086
|
+
index_found = False
|
|
1087
|
+
while not index_found:
|
|
1088
|
+
if column_i == -1:
|
|
1089
|
+
# Iterated from column_i back to beyond the beginning
|
|
1090
|
+
# and no index has been found
|
|
1091
|
+
# -> Terminal gap
|
|
1092
|
+
# -> First symbol of sequence has not occured yet
|
|
1093
|
+
# -> return -1
|
|
1094
|
+
index = -1
|
|
1095
|
+
index_found = True
|
|
1096
|
+
else:
|
|
1097
|
+
index = alignment.trace[column_i, seq_i]
|
|
1098
|
+
if index != -1:
|
|
1099
|
+
index_found = True
|
|
1100
|
+
column_i -= 1
|
|
1101
|
+
return index
|