AAindex2
The AAindex2 section currently contains 94 amino acid mutation matrices: 47 symmetric matrices and 19 non-symmetric matrices. The format of the entry is almost the same as that of AAindex1 except that it contains 210 numerical values (20 diagonal and 20 × 19/2 off-diagonal elements) for a symmetric matrix and 400 or more numerical values for a non-symmetric matrix (some matrices include a gap or distinguish two states of cysteine).
Record format
************************************************************************
* *
* Each entry has the following format. *
* *
* H Accession number *
* D Data description *
* R PMID *
* A Author(s) *
* T Title of the article *
* J Journal reference *
* * Comment or missing *
* M rows = ARNDCQEGHILKMFPSTWYV, cols = ARNDCQEGHILKMFPSTWYV *
* AA *
* AR RR *
* AN RN NN *
* AD RD ND DD *
* AC RC NC DC CC *
* AQ RQ NQ DQ CQ QQ *
* AE RE NE DE CE QE EE *
* AG RG NG DG CG QG EG GG *
* AH RH NH DH CH QH EH GH HH *
* AI RI NI DI CI QI EI GI HI II *
* AL RL NL DL CL QL EL GL HL IL LL *
* AK RK NK DK CK QK EK GK HK IK LK KK *
* AM RM NM DM CM QM EM GM HM IM LM KM MM *
* AF RF NF DF CF QF EF GF HF IF LF KF MF FF *
* AP RP NP DP CP QP EP GP HP IP LP KP MP FP PP *
* AS RS NS DS CS QS ES GS HS IS LS KS MS FS PS SS *
* AT RT NT DT CT QT ET GT HT IT LT KT MT FT PT ST TT *
* AW RW NW DW CW QW EW GW HW IW LW KW MW FW PW SW TW WW *
* AY RY NY DY CY QY EY GY HY IY LY KY MY FY PY SY TY WY YY *
* AV RV NV DV CV QV EV GV HV IV LV KV MV FV PV SV TV WV YV VV *
* // *
************************************************************************
- class aaindex.aaindex2.AAIndex2[source]
Bases:
_AAIndexMatrixPython parser for AAindex2: Amino Acid Substitution Matrix Database.
Inherits all parsing, search, and lookup functionality from _AAIndexMatrix. Stores the 94 known 20x20 substitution matrices from AAindex2 (http://www.genome.jp/aaindex/).
References
- [1]: Kawashima, S. and Kanehisa, M.; AAindex: amino acid index database.
Nucleic Acids Res. 28, 374 (2000).
- __getitem__(record_code: str) Map
Return a record by accession number wrapped in a Map (dot-notation dict).
- Parameters:
record_code – AAindex accession number (case-insensitive, leading/trailing whitespace is stripped).
- Returns:
Record data as a Map, accessible via dict or dot notation.
- Raises:
TypeError – If record_code is not a string.
ValueError – If record_code is not found in the database.
- amino_acids() list[str]
Return sorted list of the 20 canonical amino acid single-letter codes.
Derived from the row_order field of the first record in the database. Result is cached after the first call.
- Returns:
Sorted list of single-letter amino acid codes.
- get(record_code: str, aa1: str, aa2: str) float | None
Return the pairwise matrix score for two amino acids from a given record.
For symmetric (lower-triangular) records, get(code, aa1, aa2) == get(code, aa2, aa1). For non-symmetric records, order matters: get(code, aa1, aa2) may differ from get(code, aa2, aa1). Returns None when the amino acid pair has an NA value in the source data or when the amino acid letter is not present in this record’s matrix.
- Parameters:
record_code – AAindex accession number.
aa1 – Single-letter code for the first amino acid (row).
aa2 – Single-letter code for the second amino acid (column).
- Returns:
Pairwise score as float, or None if data is not available.
- Raises:
TypeError – If aa1 or aa2 are not strings.
ValueError – If record_code is not found in the database.
- num_records() int
Return the total number of records in the database.
- Returns:
Number of records as int.
- parse_aaindex() dict
Deprecated: use _parse_aaindex() instead.
Deprecated since version This: method is an internal implementation detail and will be removed in a future version.
- plot_heatmap(record_code: str) Any
Plot the pairwise amino acid matrix for a record as a heatmap.
Requires
matplotlibto be installed. NA values (None) in the matrix are rendered as white / masked cells.- Parameters:
record_code – AAindex accession number.
- Returns:
matplotlib.axes.Axescontaining the heatmap. The figure can be displayed withplt.show()or saved withplt.savefig().- Raises:
ImportError – If
matplotlibis not installed.ValueError – If record_code is not found in the database.
Example
>>> ax = aaindex2.plot_heatmap('ALTS910101') >>> import matplotlib.pyplot as plt; plt.show()
- record_codes() list[str]
Return sorted list of all accession numbers in the database.
- Returns:
Sorted list of accession number strings.
- record_names() list[str]
Return a list of description strings for all records.
- Returns:
List of description strings in database insertion order.
- search(query: str | list[str]) dict
Search records by keyword(s) across all text fields.
Searches description, accession code, PMID, references, and notes. Matching is case-insensitive. Results are returned sorted by accession number.
- Parameters:
query – Keyword string or list of keyword strings.
- Returns:
Dict of matching records keyed by accession number, sorted alphabetically. Returns an empty dict if no records match.
- Raises:
TypeError – If query is not a str or list.
- search_fuzzy(query: str, n: int = 10, cutoff: float = 0.0) dict
Search records using fuzzy matching with ranked results.
Scores each record by how closely query matches any of its text fields (description, accession code, PMID, references, notes) using
difflib.SequenceMatcher. Results are returned in descending score order (most relevant first) with no external dependencies.- Parameters:
query – Search string.
n – Maximum number of results to return. Defaults to
10.cutoff – Minimum similarity score in [0, 1] to include a record. Defaults to
0.0(all records scored, top n returned).
- Returns:
Dict of matching records keyed by accession number, ordered by descending similarity score.
- Raises:
TypeError – If query is not a str.
ValueError – If n < 1 or cutoff is outside [0, 1].
- to_dataframe(record_code: str | None = None) Any
Export pairwise matrix scores as a pandas DataFrame.
Requires
pandasto be installed. If pandas is not available a clearImportErroris raised rather than a silent failure.When record_code is given the returned DataFrame is the full 20×20 (or N×N) matrix for that record, with row and column labels from
row_orderandcol_order. When record_code isNonea MultiIndex DataFrame is returned with index levels(accession, row_aa)and column labels fromcol_order.- Parameters:
record_code – If given, export only that record’s matrix. If
None(default), export all records.- Returns:
pandas.DataFramerepresenting the requested matrix data.- Raises:
ImportError – If
pandasis not installed.ValueError – If record_code is not found in the database.
- to_dict(record_code: str | None = None) dict
Export one record or the full database as a plain Python dict.
- Parameters:
record_code – If given, export only that record keyed by its accession number. If
None(default), export the entire database.- Returns:
Dict containing the requested records.
- Raises:
ValueError – If record_code is not found in the database.
- to_json(record_code: str | None = None, indent: int = 4) str
Serialise one record or the full database to a JSON string.
- Parameters:
record_code – If given, serialise only that record. If
None(default), serialise the entire database.indent – JSON indentation level. Defaults to
4.
- Returns:
JSON-formatted string.
- Raises:
ValueError – If record_code is not found in the database.
- values(record_code: str) dict
Return the full 20x20 matrix dict for a given record.
Shortcut to avoid accessing the whole record when only the matrix is needed. Consistent with AAIndex1.values() which returns amino acid values.
- Parameters:
record_code – AAindex accession number.
- Returns:
Nested dict of pairwise scores keyed by single-letter amino acid codes.
- Raises:
ValueError – If record_code is not found in the database.
References
[1] Kawashima, S. and Kanehisa, M.; AAindex: amino acid index database. Nucleic Acids Res. 28, 374 (2000).