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 1ed71b6
Show file tree
Hide file tree
Showing 50 changed files with 124 additions and 222 deletions.
2 changes: 1 addition & 1 deletion Bio/AlignIO/MsfIO.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 1ed71b6

Please sign in to comment.