Skip to content

Commit fe02b24

Browse files
committed
Apply black formatting to python-kalign/__init__.py
Brings the file into compliance with the version of black used by the python.yml CI lint job. Purely mechanical reformatting (line wrapping of multi-argument calls); no behaviour change. Verified: pytest tests/python/ still passes 171/171.
1 parent 90d3e74 commit fe02b24

1 file changed

Lines changed: 40 additions & 18 deletions

File tree

python-kalign/__init__.py

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ def align(
313313

314314
# Gap penalty override rule: if any gap penalty is set, use "fast" preset
315315
has_gap_override = (
316-
gap_open is not None or gap_extend is not None
316+
gap_open is not None
317+
or gap_extend is not None
317318
or terminal_gap_extend is not None
318319
)
319320
if has_gap_override:
@@ -323,7 +324,9 @@ def align(
323324

324325
confidence_data = None
325326
result = _core.align_mode(
326-
sequences, effective_mode, seq_type_int,
327+
sequences,
328+
effective_mode,
329+
seq_type_int,
327330
gap_open if gap_open is not None else -1.0,
328331
gap_extend if gap_extend is not None else -1.0,
329332
terminal_gap_extend if terminal_gap_extend is not None else -1.0,
@@ -457,7 +460,8 @@ def align_from_file(
457460
raise ValueError("n_threads must be at least 1")
458461

459462
has_gap_override = (
460-
gap_open is not None or gap_extend is not None
463+
gap_open is not None
464+
or gap_extend is not None
461465
or terminal_gap_extend is not None
462466
)
463467
if has_gap_override:
@@ -466,7 +470,9 @@ def align_from_file(
466470
effective_mode = _resolve_mode_name(mode)
467471

468472
result = _core.align_from_file_mode(
469-
input_file, effective_mode, seq_type_int,
473+
input_file,
474+
effective_mode,
475+
seq_type_int,
470476
gap_open if gap_open is not None else -1.0,
471477
gap_extend if gap_extend is not None else -1.0,
472478
terminal_gap_extend if terminal_gap_extend is not None else -1.0,
@@ -477,8 +483,10 @@ def align_from_file(
477483
col_conf = list(conf["column_confidence"])
478484
res_conf = [list(row) for row in conf["residue_confidence"]]
479485
return AlignedSequences(
480-
names=names, sequences=sequences,
481-
column_confidence=col_conf, residue_confidence=res_conf,
486+
names=names,
487+
sequences=sequences,
488+
column_confidence=col_conf,
489+
residue_confidence=res_conf,
482490
)
483491
else:
484492
names, sequences = result
@@ -512,10 +520,14 @@ def write_alignment(
512520

513521
format_lower = format.lower()
514522
format_map = {
515-
"fasta": "fasta", "fa": "fasta",
516-
"clustal": "clustal", "aln": "clustal",
517-
"stockholm": "stockholm", "sto": "stockholm",
518-
"phylip": "phylip", "phy": "phylip",
523+
"fasta": "fasta",
524+
"fa": "fasta",
525+
"clustal": "clustal",
526+
"aln": "clustal",
527+
"stockholm": "stockholm",
528+
"sto": "stockholm",
529+
"phylip": "phylip",
530+
"phy": "phylip",
519531
}
520532
if format_lower not in format_map:
521533
raise ValueError(
@@ -524,13 +536,16 @@ def write_alignment(
524536
mapped_format = format_map[format_lower]
525537

526538
from . import io as _io
539+
527540
if mapped_format == "fasta":
528541
_io.write_fasta(sequences, output_file, ids=ids)
529542
elif mapped_format == "clustal":
530543
_io.write_clustal(sequences, output_file, ids=ids)
531544
elif mapped_format == "stockholm":
532545
_io.write_stockholm(
533-
sequences, output_file, ids=ids,
546+
sequences,
547+
output_file,
548+
ids=ids,
534549
column_confidence=column_confidence,
535550
residue_confidence=residue_confidence,
536551
)
@@ -651,7 +666,8 @@ def align_file_to_file(
651666
n_threads = get_num_threads()
652667

653668
has_gap_override = (
654-
gap_open is not None or gap_extend is not None
669+
gap_open is not None
670+
or gap_extend is not None
655671
or terminal_gap_extend is not None
656672
)
657673
if has_gap_override:
@@ -660,7 +676,11 @@ def align_file_to_file(
660676
effective_mode = _resolve_mode_name(mode)
661677

662678
_core.align_file_to_file_mode(
663-
input_file, output_file, effective_mode, format, n_threads,
679+
input_file,
680+
output_file,
681+
effective_mode,
682+
format,
683+
n_threads,
664684
seq_type_int,
665685
gap_open if gap_open is not None else -1.0,
666686
gap_extend if gap_extend is not None else -1.0,
@@ -701,6 +721,7 @@ def mask_alignment(
701721
"""
702722
if result.column_confidence is None:
703723
import warnings
724+
704725
warnings.warn(
705726
"No confidence scores available (requires ensemble mode). "
706727
"Returning unmasked alignment."
@@ -712,12 +733,12 @@ def mask_alignment(
712733
for seq in result.sequences:
713734
chars = list(seq)
714735
for col in range(len(chars)):
715-
if col < len(conf) and conf[col] < threshold and chars[col] != '-':
736+
if col < len(conf) and conf[col] < threshold and chars[col] != "-":
716737
if style == "remove":
717-
chars[col] = '-'
738+
chars[col] = "-"
718739
else:
719740
chars[col] = chars[col].lower()
720-
masked_seqs.append(''.join(chars))
741+
masked_seqs.append("".join(chars))
721742

722743
return AlignedSequences(
723744
names=result.names,
@@ -747,6 +768,7 @@ def filter_alignment(
747768
"""
748769
if result.column_confidence is None:
749770
import warnings
771+
750772
warnings.warn(
751773
"No confidence scores available (requires ensemble mode). "
752774
"Returning unfiltered alignment."
@@ -758,7 +780,7 @@ def filter_alignment(
758780

759781
filtered_seqs = []
760782
for seq in result.sequences:
761-
filtered_seqs.append(''.join(seq[col] for col in keep))
783+
filtered_seqs.append("".join(seq[col] for col in keep))
762784

763785
filtered_conf = [conf[col] for col in keep]
764786
filtered_res_conf = None
@@ -824,7 +846,7 @@ def write_confidence(path: str, result: AlignedSequences) -> None:
824846
"""
825847
if result.column_confidence is None:
826848
raise ValueError("No confidence scores available (requires ensemble mode)")
827-
with open(path, 'w') as f:
849+
with open(path, "w") as f:
828850
for val in result.column_confidence:
829851
f.write(f"{val:.4f}\n")
830852

0 commit comments

Comments
 (0)