Skip to content

Commit

Permalink
Guard aligned list/dicts from formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
padix-key committed Jul 2, 2024
1 parent d51cb42 commit fcc8963
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 116 deletions.
10 changes: 6 additions & 4 deletions src/biotite/database/entrez/dbnames.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
__all__ = ["get_database_name"]


# fmt: off
_db_names = {
"BioProject" : "bioproject",
"BioSample" : "biosample",
Expand Down Expand Up @@ -45,26 +46,27 @@
"UniGene" : "unigene",
"UniSTS" : "unists"
}
# fmt: on


def get_database_name(database):
"""
Map a common NCBI Entrez database name to an E-utility database
name.
Parameters
----------
database : str
Entrez database name.
Returns
-------
name : str
E-utility database name.
Examples
--------
>>> print(get_database_name("Nucleotide"))
nuccore
"""
Expand Down
2 changes: 2 additions & 0 deletions src/biotite/structure/bonds.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ def _invert_index(IndexType[:] index_v, uint32 length):



# fmt: off
_DEFAULT_DISTANCE_RANGE = {
# Taken from Allen et al.
# min - 2*std max + 2*std
Expand Down Expand Up @@ -1376,6 +1377,7 @@ _DEFAULT_DISTANCE_RANGE = {
("SE", "SE") : (2.340 - 2*0.024, 2.340 + 2*0.024),
("SI", "SE") : (2.359 - 2*0.012, 2.359 + 2*0.012),
}
# fmt: on

def connect_via_distances(atoms, dict distance_range=None, bint inter_residue=True,
default_bond_type=BondType.ANY, bint periodic=False):
Expand Down
12 changes: 7 additions & 5 deletions src/biotite/structure/info/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
from .ccd import get_ccd


non_hetero_residues = set([
"ALA","ARG","ASN","ASP","CYS","GLN","GLU","GLY","HIS",
"ILE","LEU","LYS","MET","PHE","PRO","PYL","SER","THR",
"TRP","TYR","VAL", "SEC",
# fmt: off
NON_HETERO_RESIDUES = set([
"ALA", "ARG", "ASN", "ASP", "CYS", "GLN", "GLU", "GLY", "HIS",
"ILE", "LEU", "LYS", "MET", "PHE", "PRO", "PYL", "SER", "THR",
"TRP", "TYR", "VAL", "SEC",
"A", "DA", "G", "DG", "C", "DC", "U", "DT",
])
# fmt: on


def residue(res_name):
Expand Down Expand Up @@ -78,5 +80,5 @@ def residue(res_name):
raise KeyError(
f"No atom information found for residue '{res_name}' in CCD"
)
component.hetero[:] = res_name not in non_hetero_residues
component.hetero[:] = res_name not in NON_HETERO_RESIDUES
return component
28 changes: 15 additions & 13 deletions src/biotite/structure/info/radii.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .bonds import bonds_in_residue


# fmt: off
# Contains tuples for the different ProtOr groups:
# Tuple contains: element, valency, H count
_PROTOR_RADII = {
Expand All @@ -35,28 +36,29 @@
_SINGLE_RADII = {
"H": 1.20,
"HE": 1.40,

"C": 1.70,
"N": 1.55,
"O": 1.52,
"F": 1.47,
"NE": 1.54,

"SI": 2.10,
"P": 1.80,
"S": 1.80,
"CL": 1.75,
"AR": 1.88,

"AS": 1.85,
"SE": 1.90,
"BR": 1.85,
"KR": 2.02,

"TE": 2.06,
"I": 1.98,
"XE": 2.16,
}
# fmt: on

# A dictionary that caches radii for each residue
_protor_radii = {}
Expand All @@ -82,7 +84,7 @@ def vdw_radius_protor(res_name, atom_name):
to.
atom_name : str
The name of the non-hydrogen atom.
Returns
-------
The Van-der-Waals radius of the given atom.
Expand All @@ -91,12 +93,12 @@ def vdw_radius_protor(res_name, atom_name):
See also
--------
vdw_radius_single
References
----------
.. footbibliography::
Examples
--------
Expand Down Expand Up @@ -173,21 +175,21 @@ def vdw_radius_single(element):
----------
element : str
The chemical element of the atoms.
Returns
-------
The Van-der-Waals radius of the atom.
If the radius is unknown for the element, `None` is returned.
See also
--------
vdw_radius_protor
References
----------
.. footbibliography::
Examples
--------
Expand Down
105 changes: 59 additions & 46 deletions tests/application/test_msa.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,43 @@ def sequences():
]]


@pytest.mark.parametrize("app_cls, exp_ali, exp_order",
[(MuscleApp,
"BIQT-ITE\n"
"TITANITE\n"
"BISM-ITE\n"
"-IQL-ITE",
[1, 2, 0, 3]),
(Muscle5App,
"BI-QTITE\n"
"TITANITE\n"
"BI-SMITE\n"
"-I-QLITE",
[0, 3, 1, 2]),
(MafftApp,
"-BIQTITE\n"
"TITANITE\n"
"-BISMITE\n"
"--IQLITE",
[0, 3, 2, 1]),
(ClustalOmegaApp,
"-BIQTITE\n"
"TITANITE\n"
"-BISMITE\n"
"--IQLITE",
[1, 2, 0, 3])]
)
@pytest.mark.parametrize(
"app_cls, exp_ali, exp_order",
[
(
MuscleApp,
"BIQT-ITE\n"
"TITANITE\n"
"BISM-ITE\n"
"-IQL-ITE",
[1, 2, 0, 3]
),
(
Muscle5App,
"BI-QTITE\n"
"TITANITE\n"
"BI-SMITE\n"
"-I-QLITE",
[0, 3, 1, 2]
),
(
MafftApp,
"-BIQTITE\n"
"TITANITE\n"
"-BISMITE\n"
"--IQLITE",
[0, 3, 2, 1]
),
(
ClustalOmegaApp,
"-BIQTITE\n"
"TITANITE\n"
"-BISMITE\n"
"--IQLITE",
[1, 2, 0, 3]
)
]
) # fmt: skip
def test_msa(sequences, app_cls, exp_ali, exp_order):
"""
Test MSA software on short toy sequences with known alignment
Expand Down Expand Up @@ -120,11 +131,11 @@ def test_additional_options(sequences):

app1 = ClustalOmegaApp(sequences)
app1.start()

app2 = ClustalOmegaApp(sequences)
app2.add_additional_options(["--full"])
app2.start()

app1.join()
app2.join()
assert "--full" not in app1.get_command()
Expand All @@ -137,7 +148,7 @@ def test_custom_substitution_matrix(sequences, app_cls):
bin_path = BIN_PATH[app_cls]
if is_not_installed(bin_path):
pytest.skip(f"'{bin_path}' is not installed")

alph = seq.ProteinSequence.alphabet
# Strong identity matrix
score_matrix = np.identity(len(alph)) * 1000
Expand All @@ -147,7 +158,7 @@ def test_custom_substitution_matrix(sequences, app_cls):
"TITANITE\n"
"BI-SMITE\n"
"-I-QLITE"
)
) # fmt: skip
try:
app = app_cls(sequences, matrix=matrix)
except VersionError:
Expand All @@ -165,12 +176,12 @@ def test_custom_sequence_type(app_cls):
bin_path = BIN_PATH[app_cls]
if is_not_installed(bin_path):
pytest.skip(f"'{bin_path}' is not installed")

alph = seq.Alphabet(("foo", "bar", 42))
sequences = [seq.GeneralSequence(alph, sequence) for sequence in [
["foo", "bar", 42, "foo", "foo", 42, 42],
["foo", 42, "foo", "bar", "foo", 42, 42],
]]
]] # fmt: skip
exp_trace = [
[ 0, 0],
[ 1, -1],
Expand Down Expand Up @@ -206,12 +217,12 @@ def test_invalid_sequence_type_no_matrix(app_cls):
bin_path = BIN_PATH[app_cls]
if is_not_installed(bin_path):
pytest.skip(f"'{bin_path}' is not installed")

alph = seq.Alphabet(("foo", "bar", 42))
sequences = [seq.GeneralSequence(alph, sequence) for sequence in [
["foo", "bar", 42, "foo", "foo", 42, 42],
["foo", 42, "foo", "bar", "foo", 42, 42],
]]
]] # fmt: skip
with pytest.raises(TypeError):
try:
app_cls(sequences)
Expand All @@ -228,7 +239,7 @@ def test_invalid_sequence_type_unsuitable_alphabet(app_cls):
bin_path = BIN_PATH[app_cls]
if is_not_installed(bin_path):
pytest.skip(f"'{bin_path}' is not installed")

alph = seq.Alphabet(range(50))
sequences = [seq.GeneralSequence(alph, sequence) for sequence in [
[1,2,3],
Expand All @@ -249,7 +260,7 @@ def test_invalid_muscle_version(sequences):
bin_path = BIN_PATH[MuscleApp]
if is_not_installed(bin_path):
pytest.skip(f"'{bin_path}' is not installed")

if is_not_installed("muscle"):
pytest.skip(f"'muscle' is not installed")

Expand All @@ -262,13 +273,13 @@ def test_clustalo_matrix(sequences):
bin_path = BIN_PATH[ClustalOmegaApp]
if is_not_installed(bin_path):
pytest.skip(f"'{bin_path}' is not installed")

ref_matrix = [
[0, 1, 2, 3],
[1, 0, 1, 2],
[2, 1, 0, 1],
[3, 2, 1, 0]
]
] # fmt: skip
app = ClustalOmegaApp(sequences)
app.full_matrix_calculation()
app.set_distance_matrix(np.array(ref_matrix))
Expand All @@ -282,7 +293,7 @@ def test_clustalo_tree(sequences):
bin_path = BIN_PATH[ClustalOmegaApp]
if is_not_installed(bin_path):
pytest.skip(f"'{bin_path}' is not installed")

leaves = [phylo.TreeNode(index=i) for i in range(len(sequences))]
inter1 = phylo.TreeNode([leaves[0], leaves[1]], [1.0, 1.0])
inter2 = phylo.TreeNode([leaves[2], leaves[3]], [2.5, 2.5])
Expand All @@ -305,7 +316,7 @@ def test_mafft_tree(sequences):
bin_path = BIN_PATH[MafftApp]
if is_not_installed(bin_path):
pytest.skip(f"'{bin_path}' is not installed")

app = MafftApp(sequences)
app.start()
app.join()
Expand All @@ -317,7 +328,7 @@ def test_muscle_tree(sequences):
bin_path = BIN_PATH[MuscleApp]
if is_not_installed(bin_path):
pytest.skip(f"'{bin_path}' is not installed")

try:
app = MuscleApp(sequences)
except VersionError:
Expand All @@ -334,7 +345,7 @@ def test_muscle5_options(sequences):
bin_path = BIN_PATH[Muscle5App]
if is_not_installed(bin_path):
pytest.skip(f"'{bin_path}' is not installed")

try:
app = Muscle5App(sequences)
except VersionError:
Expand All @@ -350,7 +361,9 @@ def test_muscle5_options(sequences):
assert "-threads" in app.get_command()

app.join()
assert str(app.get_alignment()) == "BI-QTITE\n" \
"TITANITE\n" \
"BI-SMITE\n" \
"-I-QLITE"
assert str(app.get_alignment()) == (
"BI-QTITE\n" \
"TITANITE\n" \
"BI-SMITE\n" \
"-I-QLITE"
) # fmt: skip
Loading

0 comments on commit fcc8963

Please sign in to comment.