Skip to content

Commit

Permalink
Automatically remove redundant commas
Browse files Browse the repository at this point in the history
Used this hack from psf/black#1288

$ pip install black==19.3b0 && black . && pip install black==19.10b && black .

I then manually reverted changes to a handful of explicit data
structures where the magic trailing comma should be retained
(indicates to black not to squash into one line).

Doing this dramatically improves the changes from trying black
version 21.7b0 (right now just four minor changes).
  • Loading branch information
peterjc committed Aug 27, 2021
1 parent 9bd28ed commit 8bdb61e
Show file tree
Hide file tree
Showing 50 changed files with 107 additions and 209 deletions.
2 changes: 1 addition & 1 deletion Bio/AlignIO/MsfIO.py
Expand Up @@ -316,7 +316,7 @@ def __next__(self):
)

records = (
SeqRecord(Seq(s), id=i, name=i, description=i, annotations={"weight": w},)
SeqRecord(Seq(s), id=i, name=i, description=i, annotations={"weight": w})
for (i, s, w) in zip(ids, seqs, weights)
)

Expand Down
5 changes: 1 addition & 4 deletions Bio/AlignIO/StockholmIO.py
Expand Up @@ -231,10 +231,7 @@ def _write_record(self, record):
seq_name = seq_name.replace(" ", "_")

if "start" in record.annotations and "end" in record.annotations:
suffix = "/%s-%s" % (
record.annotations["start"],
record.annotations["end"],
)
suffix = "/%s-%s" % (record.annotations["start"], record.annotations["end"])
if seq_name[-len(suffix) :] != suffix:
seq_name = "%s/%s-%s" % (
seq_name,
Expand Down
2 changes: 1 addition & 1 deletion Bio/Blast/Record.py
Expand Up @@ -252,7 +252,7 @@ def __str__(self):
else:
lines.append(
"Query:%8s %s...%s %s"
% (self.query_start, self.query[:45], self.query[-3:], self.query_end,)
% (self.query_start, self.query[:45], self.query[-3:], self.query_end)
)
lines.append(" %s...%s" % (self.match[:45], self.match[-3:]))
lines.append(
Expand Down
2 changes: 1 addition & 1 deletion Bio/GenBank/Scanner.py
Expand Up @@ -529,7 +529,7 @@ def parse_records(self, handle, do_features=True):
yield record

def parse_cds_features(
self, handle, alphabet=None, tags2id=("protein_id", "locus_tag", "product"),
self, handle, alphabet=None, tags2id=("protein_id", "locus_tag", "product")
):
"""Parse CDS features, return SeqRecord object iterator.
Expand Down
6 changes: 3 additions & 3 deletions Bio/Nexus/Nexus.py
Expand Up @@ -416,7 +416,7 @@ def combine(matrices):
combined.matrix[t] += Seq(
str(m.matrix[t])
.replace(m.gap, combined.gap)
.replace(m.missing, combined.missing),
.replace(m.missing, combined.missing)
)
# replace date of missing taxa with symbol for missing data
for t in combined_only:
Expand All @@ -425,7 +425,7 @@ def combine(matrices):
combined.matrix[t] = Seq(combined.missing * combined.nchar) + Seq(
str(m.matrix[t])
.replace(m.gap, combined.gap)
.replace(m.missing, combined.missing),
.replace(m.missing, combined.missing)
)
combined.taxlabels.extend(m_only) # new taxon list
for cn, cs in m.charsets.items(): # adjust character sets for new matrix
Expand Down Expand Up @@ -1052,7 +1052,7 @@ def _matrix(self, options):
# Reformat sequence for non-standard datatypes
if self.datatype != "standard":
iupac_seq = Seq(
_replace_parenthesized_ambigs(chars, self.rev_ambiguous_values),
_replace_parenthesized_ambigs(chars, self.rev_ambiguous_values)
)
# first taxon has the reference sequence if matchhar is used
if taxcount == 1:
Expand Down
22 changes: 4 additions & 18 deletions Bio/PDB/internal_coords.py
Expand Up @@ -84,17 +84,7 @@
from Bio.PDB.ic_data import ic_data_sidechain_extras, residue_atom_bond_state

# for type checking only
from typing import (
List,
Dict,
Set,
TextIO,
Union,
Tuple,
cast,
TYPE_CHECKING,
Optional,
)
from typing import List, Dict, Set, TextIO, Union, Tuple, cast, TYPE_CHECKING, Optional

if TYPE_CHECKING:
from Bio.PDB.Residue import Residue
Expand Down Expand Up @@ -606,7 +596,7 @@ def init_atom_coords(self) -> None:
a4shift[udFwd] = self.hedraIC[self.dH2ndx, 0][mdFwd] # len12

self.a4_pre_rotation[:, 2][self.dAtoms_needs_update] = numpy.add(
self.a4_pre_rotation[:, 2][self.dAtoms_needs_update], a4shift,
self.a4_pre_rotation[:, 2][self.dAtoms_needs_update], a4shift
) # so a2 at origin

# build rz rotation matrix for dihedral angle
Expand Down Expand Up @@ -1649,7 +1639,7 @@ def clear_transforms(self):
d.rcst = None

def assemble(
self, resetLocation: bool = False, verbose: bool = False,
self, resetLocation: bool = False, verbose: bool = False
) -> Union[Dict["AtomKey", numpy.array], Dict[HKT, numpy.array], None]:
"""Compute atom coordinates for this residue from internal coordinates.
Expand Down Expand Up @@ -2841,11 +2831,7 @@ def __init__(self, *args: Union[List["AtomKey"], HKT], **kwargs: str) -> None:

if "len12" in kwargs:
self.lal = numpy.array(
(
float(kwargs["len12"]),
float(kwargs["angle"]),
float(kwargs["len23"]),
)
(float(kwargs["len12"]), float(kwargs["angle"]), float(kwargs["len23"]))
)
else:
self.lal = numpy.zeros(3)
Expand Down
4 changes: 2 additions & 2 deletions Bio/SeqIO/FastaIO.py
Expand Up @@ -203,7 +203,7 @@ def iterate(self, handle):
# Should we use SeqRecord default for no ID?
first_word = ""
yield SeqRecord(
Seq(sequence), id=first_word, name=first_word, description=title,
Seq(sequence), id=first_word, name=first_word, description=title
)


Expand Down Expand Up @@ -239,7 +239,7 @@ def iterate(self, handle):
# Should we use SeqRecord default for no ID?
first_word = ""
yield SeqRecord(
Seq(sequence), id=first_word, name=first_word, description=title,
Seq(sequence), id=first_word, name=first_word, description=title
)


Expand Down
2 changes: 1 addition & 1 deletion Bio/SeqIO/PirIO.py
Expand Up @@ -171,7 +171,7 @@ def iterate(self, handle):

# Return the record and then continue...
record = SeqRecord(
Seq(seq[:-1]), id=identifier, name=identifier, description=description,
Seq(seq[:-1]), id=identifier, name=identifier, description=description
)
record.annotations["PIR-type"] = pir_type
if _pir_mol_type[pir_type]:
Expand Down
2 changes: 1 addition & 1 deletion Bio/SeqIO/SffIO.py
Expand Up @@ -1044,7 +1044,7 @@ def iterate(self, handle):
# the index_offset so we can skip extra handle.tell() calls:
index_offset = 0
yield _sff_read_seq_record(
handle, number_of_flows_per_read, flow_chars, key_sequence, trim,
handle, number_of_flows_per_read, flow_chars, key_sequence, trim
)
_check_eof(handle, index_offset, index_length)

Expand Down
2 changes: 1 addition & 1 deletion Bio/SeqIO/_index.py
Expand Up @@ -141,7 +141,7 @@ def get(self, offset):
handle = self._handle
handle.seek(offset)
return SeqIO.SffIO._sff_read_seq_record(
handle, self._flows_per_read, self._flow_chars, self._key_sequence,
handle, self._flows_per_read, self._flow_chars, self._key_sequence
)

def get_raw(self, offset):
Expand Down
4 changes: 2 additions & 2 deletions Bio/codonalign/__init__.py
Expand Up @@ -246,7 +246,7 @@ def _get_aa_regex(codon_table, stop="*", unknown="X"):


def _check_corr(
pro, nucl, gap_char, codon_table, complete_protein=False, anchor_len=10,
pro, nucl, gap_char, codon_table, complete_protein=False, anchor_len=10
):
"""Check if the nucleotide can be translated into the protein (PRIVATE).
Expand Down Expand Up @@ -571,7 +571,7 @@ def get_aa_from_codonre(re_aa):


def _get_codon_rec(
pro, nucl, span_mode, gap_char, codon_table, complete_protein=False, max_score=10,
pro, nucl, span_mode, gap_char, codon_table, complete_protein=False, max_score=10
):
"""Generate codon alignment based on regular re match (PRIVATE).
Expand Down
2 changes: 1 addition & 1 deletion Bio/codonalign/codonalignment.py
Expand Up @@ -65,7 +65,7 @@ def __str__(self):
rows = len(self._records)
lines = [
"CodonAlignment with %i rows and %i columns (%i codons)"
% (rows, self.get_alignment_length(), self.get_aln_length(),)
% (rows, self.get_alignment_length(), self.get_aln_length())
]

if rows <= 60:
Expand Down
4 changes: 1 addition & 3 deletions Bio/codonalign/codonseq.py
Expand Up @@ -276,9 +276,7 @@ def _get_codon_list(codonseq):
return codon_lst


def cal_dn_ds(
codon_seq1, codon_seq2, method="NG86", codon_table=None, k=1, cfreq=None,
):
def cal_dn_ds(codon_seq1, codon_seq2, method="NG86", codon_table=None, k=1, cfreq=None):
"""Calculate dN and dS of the given two sequences.
Available methods:
Expand Down
2 changes: 1 addition & 1 deletion BioSQL/BioSeq.py
Expand Up @@ -321,7 +321,7 @@ def _retrieve_annotations(adaptor, primary_id, taxon_id):

def _retrieve_alphabet(adaptor, primary_id):
results = adaptor.execute_and_fetchall(
"SELECT alphabet FROM biosequence WHERE bioentry_id = %s", (primary_id,),
"SELECT alphabet FROM biosequence WHERE bioentry_id = %s", (primary_id,)
)
assert len(results) == 1
alphabets = results[0]
Expand Down
2 changes: 1 addition & 1 deletion Scripts/PDB/hsexpo.py
Expand Up @@ -43,7 +43,7 @@
default="HSEb",
)
ap.add_argument(
"-o", "--out", dest="outfile", help="output to PDB file (B factor=exposure)",
"-o", "--out", dest="outfile", help="output to PDB file (B factor=exposure)"
)
ap.add_argument(
"-r",
Expand Down
7 changes: 1 addition & 6 deletions Tests/common_BioSQL.py
Expand Up @@ -495,12 +495,7 @@ def test_convert(self):
def test_addition(self):
"""Check can add Seq objects from BioSQL together."""
test_seq = self.item.seq
for other in [
Seq("ACGT"),
MutableSeq("ACGT"),
"ACGT",
test_seq,
]:
for other in [Seq("ACGT"), MutableSeq("ACGT"), "ACGT", test_seq]:
test = test_seq + other
self.assertEqual(test, str(test_seq) + str(other))
self.assertIsInstance(test, Seq)
Expand Down
5 changes: 1 addition & 4 deletions Tests/pairwise2_testCases.py
Expand Up @@ -855,10 +855,7 @@ def test_clean_alignments(self):
("ACCGT", "AC-G-", 3.0, 0, 4),
("ACCGT", "A-CG-", 3.0, 0, 4),
]
expected = [
("ACCGT", "AC-G-", 3.0, 0, 4),
("ACCGT", "A-CG-", 3.0, 0, 4),
]
expected = [("ACCGT", "AC-G-", 3.0, 0, 4), ("ACCGT", "A-CG-", 3.0, 0, 4)]
result = pairwise2._clean_alignments(alns)
self.assertEqual(expected, result)

Expand Down
2 changes: 1 addition & 1 deletion Tests/test_AlignIO.py
Expand Up @@ -451,7 +451,7 @@ def test_reading_alignments_nexus2(self):
self.check_alignment_rows(
alignment,
[
("Aegotheles", "AAAAAGGCATTGTGGTGGGAAT",),
("Aegotheles", "AAAAAGGCATTGTGGTGGGAAT"),
("Aerodramus", "?????????TTGTGGTGGGAAT"),
],
)
Expand Down
12 changes: 4 additions & 8 deletions Tests/test_Align_emboss.py
Expand Up @@ -960,21 +960,17 @@ def test_local_water2(self):
repr(alignment.sequences[0].seq),
"Seq({78: 'CGTTTGAGTCTGGGATG'}, length=95)",
)
self.assertEqual(
alignment.sequences[0].seq[78:95], "CGTTTGAGTCTGGGATG",
)
self.assertEqual(
alignment.sequences[1].seq[0:18], "CGTTTGAGTACTGGGATG",
)
self.assertEqual(alignment.sequences[0].seq[78:95], "CGTTTGAGTCTGGGATG")
self.assertEqual(alignment.sequences[1].seq[0:18], "CGTTTGAGTACTGGGATG")
self.assertTrue(
numpy.array_equal(
alignment.coordinates, numpy.array([[78, 87, 87, 95], [0, 9, 10, 18]]),
alignment.coordinates, numpy.array([[78, 87, 87, 95], [0, 9, 10, 18]])
)
)
self.assertEqual(alignment[0], "CGTTTGAGT-CTGGGATG")
self.assertEqual(alignment[1], "CGTTTGAGTACTGGGATG")
self.assertEqual(
alignment.column_annotations["emboss_consensus"], "||||||||| ||||||||",
alignment.column_annotations["emboss_consensus"], "||||||||| ||||||||"
)


Expand Down
6 changes: 1 addition & 5 deletions Tests/test_BioSQL_sqlite3.py
Expand Up @@ -16,11 +16,7 @@
from common_BioSQL import * # noqa: F403

# Import these explicitly to avoid flake8 F405 below:
from common_BioSQL import (
load_biosql_ini,
check_config,
temp_db_filename,
)
from common_BioSQL import load_biosql_ini, check_config, temp_db_filename

# Constants for the database driver
DBDRIVER = "sqlite3"
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_CAPS.py
Expand Up @@ -20,7 +20,7 @@ def createAlignment(sequences):
(
SeqRecord(Seq(s), id="sequence%i" % (i + 1))
for (i, s) in enumerate(sequences)
),
)
)


Expand Down
6 changes: 3 additions & 3 deletions Tests/test_Emboss.py
Expand Up @@ -305,7 +305,7 @@ def test_ig(self):
# NOTE - EMBOSS considers "genbank" to be for nucleotides only,
# and will turn "X" into "N" for GenBank output.
self.check_SeqIO_to_EMBOSS(
"IntelliGenetics/VIF_mase-pro.txt", "ig", skip_formats=["genbank", "embl"],
"IntelliGenetics/VIF_mase-pro.txt", "ig", skip_formats=["genbank", "embl"]
)
# TODO - What does a % in an ig sequence mean?
# e.g. "IntelliGenetics/vpu_nucaligned.txt"
Expand Down Expand Up @@ -457,13 +457,13 @@ def pairwise_alignment_check(self, query_seq, targets, alignments, local=True):
# Local alignment
self.assertIn(str(alignment[0].seq).replace("-", ""), query_seq)
self.assertIn(
str(alignment[1].seq).replace("-", "").upper(), target.seq.upper(),
str(alignment[1].seq).replace("-", "").upper(), target.seq.upper()
)
else:
# Global alignment
self.assertEqual(query_seq, str(alignment[0].seq).replace("-", ""))
self.assertEqual(
target.seq.upper(), str(alignment[1].seq).replace("-", "").upper(),
target.seq.upper(), str(alignment[1].seq).replace("-", "").upper()
)
return True

Expand Down
12 changes: 5 additions & 7 deletions Tests/test_Entrez.py
Expand Up @@ -144,7 +144,7 @@ def test_construct_cgi_ecitmatch(self):
self.assertEqual(get_base_url(parsed), URL_HEAD + "ecitmatch.cgi")
query.pop("bdata") # TODO
self.assertDictEqual(
query, {"retmode": ["xml"], "db": [variables["db"]], **QUERY_DEFAULTS},
query, {"retmode": ["xml"], "db": [variables["db"]], **QUERY_DEFAULTS}
)

def test_construct_cgi_einfo(self):
Expand All @@ -170,7 +170,7 @@ def test_construct_cgi_epost1(self):

self.assertEqual(result_url, URL_HEAD + "epost.fcgi") # Params in POST data
self.assertDictEqual(
query, {"db": [variables["db"]], "id": [variables["id"]], **QUERY_DEFAULTS},
query, {"db": [variables["db"]], "id": [variables["id"]], **QUERY_DEFAULTS}
)

def test_construct_cgi_epost2(self):
Expand All @@ -185,9 +185,7 @@ def test_construct_cgi_epost2(self):
self.assertEqual(result_url, URL_HEAD + "epost.fcgi") # Params in POST data
# Compare IDs up to reordering:
self.assertCountEqual(query.pop("id"), variables["id"])
self.assertDictEqual(
query, {"db": [variables["db"]], **QUERY_DEFAULTS},
)
self.assertDictEqual(query, {"db": [variables["db"]], **QUERY_DEFAULTS})

def test_construct_cgi_elink1(self):
variables = {
Expand Down Expand Up @@ -320,10 +318,10 @@ def test_custom_directory(self):

# Confirm that the two temp directories are named what we want.
self.assertEqual(
handler.local_dtd_dir, os.path.join(tmpdir, "Bio", "Entrez", "DTDs"),
handler.local_dtd_dir, os.path.join(tmpdir, "Bio", "Entrez", "DTDs")
)
self.assertEqual(
handler.local_xsd_dir, os.path.join(tmpdir, "Bio", "Entrez", "XSDs"),
handler.local_xsd_dir, os.path.join(tmpdir, "Bio", "Entrez", "XSDs")
)

# And that they were created.
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_GenBank.py
Expand Up @@ -7512,7 +7512,7 @@ def test_implicit_orign_wrap_extract_and_translate(self):
"MPYKTQGCLGKGATPTPSSRGI*",
)
self.assertEqual(
seq_features[2].extract(seq_record).seq.translate(), "MPRLEGVGVAPFPRQPWVL*",
seq_features[2].extract(seq_record).seq.translate(), "MPRLEGVGVAPFPRQPWVL*"
)

def test_fuzzy_origin_wrap(self):
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_GenomeDiagram.py
Expand Up @@ -303,7 +303,7 @@ def test_slicing(self):

self.assertEqual(
gd[4:16],
[(5, 15), (10, 20),], # noqa 231
[(5, 15), (10, 20)], # noqa 231
"Unable to insert and retrieve points correctly",
)

Expand Down
4 changes: 1 addition & 3 deletions Tests/test_HMMGeneral.py
Expand Up @@ -122,9 +122,7 @@ def test_set_equal_probabilities(self):
self.mm_builder.allow_transition("2", "1", 0.95)
self.mm_builder.set_equal_probabilities()

self.assertEqual(
self.mm_builder.initial_prob, {"1": 0.5, "2": 0.5},
)
self.assertEqual(self.mm_builder.initial_prob, {"1": 0.5, "2": 0.5})
self.assertEqual(
self.mm_builder.transition_prob, {("1", "2"): 0.5, ("2", "1"): 0.5}
)
Expand Down

0 comments on commit 8bdb61e

Please sign in to comment.