Skip to content

Commit 4f85bc5

Browse files
committed
rever reformatting
1 parent 6416a39 commit 4f85bc5

16 files changed

+238
-261
lines changed

fgpyo/fasta/builder.py

+5-16
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def samtools_dict(*args: Any) -> None:
4949
def samtools_faidx(*args: Any) -> None:
5050
pass
5151

52+
5253
else:
5354
from pysam import dict as samtools_dict
5455
from pysam import faidx as samtools_faidx
@@ -91,10 +92,7 @@ class ContigBuilder:
9192
"""
9293

9394
def __init__(
94-
self,
95-
name: str,
96-
assembly: str,
97-
species: str,
95+
self, name: str, assembly: str, species: str,
9896
):
9997
self.name = name
10098
self.assembly = assembly
@@ -146,10 +144,7 @@ class FastaBuilder:
146144
"""
147145

148146
def __init__(
149-
self,
150-
assembly: str = "testassembly",
151-
species: str = "testspecies",
152-
line_length: int = 80,
147+
self, assembly: str = "testassembly", species: str = "testspecies", line_length: int = 80,
153148
):
154149
self.assembly: str = assembly
155150
self.species: str = species
@@ -161,10 +156,7 @@ def __getitem__(self, key: str) -> ContigBuilder:
161156
return self.__contig_builders[key]
162157

163158
def add(
164-
self,
165-
name: str,
166-
assembly: Optional[str] = None,
167-
species: Optional[str] = None,
159+
self, name: str, assembly: Optional[str] = None, species: Optional[str] = None,
168160
) -> ContigBuilder:
169161
"""
170162
Creates and returns a new ContigBuilder for a contig with the provided name.
@@ -189,10 +181,7 @@ def add(
189181
self.__contig_builders[name] = builder
190182
return builder
191183

192-
def to_file(
193-
self,
194-
path: Path,
195-
) -> None:
184+
def to_file(self, path: Path,) -> None:
196185
"""
197186
Writes out the set of accumulated contigs to a FASTA file at the `path` given.
198187
Also generates the accompanying fasta index file (`.fa.fai`) and sequence

fgpyo/fasta/tests/test_builder.py

+4-18
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,10 @@ def test_bases_length_from_ContigBuilder_add_default() -> None:
2525

2626

2727
@pytest.mark.parametrize(
28-
"name, bases, times, length_bases",
29-
[
30-
("chr1", "AAA", 3, 9),
31-
("chr2", "TTT", 10, 30),
32-
],
28+
"name, bases, times, length_bases", [("chr1", "AAA", 3, 9), ("chr2", "TTT", 10, 30),],
3329
)
3430
def test_bases_length_from_ContigBuilder_add(
35-
name: str,
36-
bases: str,
37-
times: int,
38-
length_bases: int,
31+
name: str, bases: str, times: int, length_bases: int,
3932
) -> None:
4033
"""Checks that the number of bases in each contig is correct"""
4134
builder = FastaBuilder()
@@ -60,17 +53,10 @@ def test_contig_dict_is_not_accessable() -> None:
6053

6154
@pytest.mark.parametrize(
6255
"name, bases, times, expected",
63-
[
64-
("chr3", "AAA a", 3, ("AAAA" * 3)),
65-
("chr2", "TT T gT", 10, ("TTTGT" * 10)),
66-
],
56+
[("chr3", "AAA a", 3, ("AAAA" * 3)), ("chr2", "TT T gT", 10, ("TTTGT" * 10)),],
6757
)
6858
def test_bases_string_from_ContigBuilder_add(
69-
name: str,
70-
bases: str,
71-
times: int,
72-
expected: str,
73-
tmp_path: Path,
59+
name: str, bases: str, times: int, expected: str, tmp_path: Path,
7460
) -> None:
7561
"""
7662
Reads bases back from fasta and checks that extra spaces are removed and bases are uppercase

fgpyo/io/tests/test_io.py

+5-22
Original file line numberDiff line numberDiff line change
@@ -84,33 +84,19 @@ def test_assert_path_is_writeable_pass() -> None:
8484

8585

8686
@pytest.mark.parametrize(
87-
"suffix, expected",
88-
[
89-
(".gz", io.TextIOWrapper),
90-
(".fa", io.TextIOWrapper),
91-
],
87+
"suffix, expected", [(".gz", io.TextIOWrapper), (".fa", io.TextIOWrapper),],
9288
)
93-
def test_reader(
94-
suffix: str,
95-
expected: Any,
96-
) -> None:
89+
def test_reader(suffix: str, expected: Any,) -> None:
9790
"""Tests fgpyo.io.to_reader"""
9891
with NamedTemp(suffix=suffix, mode="r", delete=True) as read_file:
9992
with fio.to_reader(path=Path(read_file.name)) as reader:
10093
assert isinstance(reader, expected)
10194

10295

10396
@pytest.mark.parametrize(
104-
"suffix, expected",
105-
[
106-
(".gz", io.TextIOWrapper),
107-
(".fa", io.TextIOWrapper),
108-
],
97+
"suffix, expected", [(".gz", io.TextIOWrapper), (".fa", io.TextIOWrapper),],
10998
)
110-
def test_writer(
111-
suffix: str,
112-
expected: Any,
113-
) -> None:
99+
def test_writer(suffix: str, expected: Any,) -> None:
114100
"""Tests fgpyo.io.to_writer()"""
115101
with NamedTemp(suffix=suffix, mode="w", delete=True) as write_file:
116102
with fio.to_writer(path=Path(write_file.name)) as writer:
@@ -121,10 +107,7 @@ def test_writer(
121107
"suffix, list_to_write",
122108
[(".txt", ["Test with a flat file", 10]), (".gz", ["Test with a gzip file", 10])],
123109
)
124-
def test_read_and_write_lines(
125-
suffix: str,
126-
list_to_write: List[Any],
127-
) -> None:
110+
def test_read_and_write_lines(suffix: str, list_to_write: List[Any],) -> None:
128111
"""Test fgpyo.fio.read_lines and write_lines"""
129112
with NamedTemp(suffix=suffix, mode="w", delete=True) as read_file:
130113
fio.write_lines(path=Path(read_file.name), lines_to_write=list_to_write)

fgpyo/sam/__init__.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -863,11 +863,7 @@ def all_recs(self) -> Iterator[AlignedSegment]:
863863
for rec in recs:
864864
yield rec
865865

866-
def write_to(
867-
self,
868-
writer: SamFile,
869-
primary_only: bool = False,
870-
) -> None:
866+
def write_to(self, writer: SamFile, primary_only: bool = False,) -> None:
871867
"""Write the records associated with the template to file.
872868
873869
Args:
@@ -883,11 +879,7 @@ def write_to(
883879
for rec in rec_iter:
884880
writer.write(rec)
885881

886-
def set_tag(
887-
self,
888-
tag: str,
889-
value: Union[str, int, float, None],
890-
) -> None:
882+
def set_tag(self, tag: str, value: Union[str, int, float, None],) -> None:
891883
"""Add a tag to all records associated with the template.
892884
893885
Setting a tag to `None` will remove the tag.

fgpyo/sam/tests/test_sam.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ def test_sam_file_open_writing(
154154

155155

156156
def test_sam_file_open_writing_header_keyword(
157-
expected_records: List[pysam.AlignedSegment],
158-
header_dict: AlignmentHeader,
159-
tmp_path: Path,
157+
expected_records: List[pysam.AlignedSegment], header_dict: AlignmentHeader, tmp_path: Path,
160158
) -> None:
161159
# Use SamWriter
162160
# use header as a keyword argument

fgpyo/sam/tests/test_template_iterator.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ def test_to_templates() -> None:
7373
assert len(list(template2.all_recs())) == 2
7474

7575

76-
def test_write_template(
77-
tmp_path: Path,
78-
) -> None:
76+
def test_write_template(tmp_path: Path,) -> None:
7977
builder = SamBuilder()
8078
template = Template.build(
8179
[

fgpyo/tests/test_read_structure.py

+5-37
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,9 @@ def _S(off: int, len: int) -> ReadSegment:
3131
("1M", (_M(0, 1),)),
3232
("1S", (_S(0, 1),)),
3333
("101T", (_T(0, 101),)),
34-
(
35-
"5B101T",
36-
(
37-
_B(0, 5),
38-
_T(5, 101),
39-
),
40-
),
34+
("5B101T", (_B(0, 5), _T(5, 101),),),
4135
("123456789T", (_T(0, 123456789),)),
42-
(
43-
"10T10B10B10S10M",
44-
(
45-
_T(0, 10),
46-
_B(10, 10),
47-
_B(20, 10),
48-
_S(30, 10),
49-
_M(40, 10),
50-
),
51-
),
36+
("10T10B10B10S10M", (_T(0, 10), _B(10, 10), _B(20, 10), _S(30, 10), _M(40, 10),),),
5237
],
5338
)
5439
def test_read_structure_from_string(string: str, segments: Tuple[ReadSegment, ...]) -> None:
@@ -58,24 +43,8 @@ def test_read_structure_from_string(string: str, segments: Tuple[ReadSegment, ..
5843
@pytest.mark.parametrize(
5944
"string,segments",
6045
[
61-
(
62-
"75T 8B 8B 75T",
63-
(
64-
_T(0, 75),
65-
_B(75, 8),
66-
_B(83, 8),
67-
_T(91, 75),
68-
),
69-
),
70-
(
71-
" 75T 8B 8B 75T ",
72-
(
73-
_T(0, 75),
74-
_B(75, 8),
75-
_B(83, 8),
76-
_T(91, 75),
77-
),
78-
),
46+
("75T 8B 8B 75T", (_T(0, 75), _B(75, 8), _B(83, 8), _T(91, 75),),),
47+
(" 75T 8B 8B 75T ", (_T(0, 75), _B(75, 8), _B(83, 8), _T(91, 75),),),
7948
],
8049
)
8150
def test_read_structure_from_string_with_whitespace(
@@ -98,8 +67,7 @@ def test_read_structure_variable_once_and_only_once_last_segment_ok(
9867

9968

10069
@pytest.mark.parametrize(
101-
"string",
102-
["++M", "5M++T", "5M70+T", "+M+T", "+M70T"],
70+
"string", ["++M", "5M++T", "5M70+T", "+M+T", "+M70T"],
10371
)
10472
def test_read_structure_variable_once_and_only_once_last_segment_exception(string: str) -> None:
10573
with pytest.raises(Exception):

fgpyo/util/inspect.py

+7-32
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ def split_at_given_level(
6868

6969

7070
def _get_parser(
71-
cls: Type,
72-
type_: TypeAlias,
73-
parsers: Optional[Dict[type, Callable[[str], Any]]] = None,
71+
cls: Type, type_: TypeAlias, parsers: Optional[Dict[type, Callable[[str], Any]]] = None,
7472
) -> partial:
7573
"""Attempts to find a parser for a provided type.
7674
@@ -114,11 +112,7 @@ def get_parser() -> partial:
114112
assert (
115113
len(subtypes) == 1
116114
), "Lists are allowed only one subtype per PEP specification!"
117-
subtype_parser = _get_parser(
118-
cls,
119-
subtypes[0],
120-
parsers,
121-
)
115+
subtype_parser = _get_parser(cls, subtypes[0], parsers,)
122116
return functools.partial(
123117
lambda s: list(
124118
[]
@@ -134,11 +128,7 @@ def get_parser() -> partial:
134128
assert (
135129
len(subtypes) == 1
136130
), "Sets are allowed only one subtype per PEP specification!"
137-
subtype_parser = _get_parser(
138-
cls,
139-
subtypes[0],
140-
parsers,
141-
)
131+
subtype_parser = _get_parser(cls, subtypes[0], parsers,)
142132
return functools.partial(
143133
lambda s: set(
144134
set({})
@@ -151,12 +141,7 @@ def get_parser() -> partial:
151141
)
152142
elif typing.get_origin(type_) == tuple:
153143
subtype_parsers = [
154-
_get_parser(
155-
cls,
156-
subtype,
157-
parsers,
158-
)
159-
for subtype in typing.get_args(type_)
144+
_get_parser(cls, subtype, parsers,) for subtype in typing.get_args(type_)
160145
]
161146

162147
def tuple_parse(tuple_string: str) -> Tuple[Any, ...]:
@@ -185,16 +170,8 @@ def tuple_parse(tuple_string: str) -> Tuple[Any, ...]:
185170
len(subtypes) == 2
186171
), "Dict object must have exactly 2 subtypes per PEP specification!"
187172
(key_parser, val_parser) = (
188-
_get_parser(
189-
cls,
190-
subtypes[0],
191-
parsers,
192-
),
193-
_get_parser(
194-
cls,
195-
subtypes[1],
196-
parsers,
197-
),
173+
_get_parser(cls, subtypes[0], parsers,),
174+
_get_parser(cls, subtypes[1], parsers,),
198175
)
199176

200177
def dict_parse(dict_string: str) -> Dict[Any, Any]:
@@ -254,9 +231,7 @@ def dict_parse(dict_string: str) -> Dict[Any, Any]:
254231

255232

256233
def attr_from(
257-
cls: Type,
258-
kwargs: Dict[str, str],
259-
parsers: Optional[Dict[type, Callable[[str], Any]]] = None,
234+
cls: Type, kwargs: Dict[str, str], parsers: Optional[Dict[type, Callable[[str], Any]]] = None,
260235
) -> Any:
261236
"""Builds an attr class from key-word arguments
262237

fgpyo/util/logging.py

+4-15
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ def __exit__(
125125
return False
126126

127127
def record(
128-
self,
129-
reference_name: Optional[str] = None,
130-
position: Optional[int] = None,
128+
self, reference_name: Optional[str] = None, position: Optional[int] = None,
131129
) -> bool:
132130
"""Record an item at a given genomic coordinate.
133131
Args:
@@ -147,10 +145,7 @@ def record(
147145
else:
148146
return False
149147

150-
def record_alignment(
151-
self,
152-
rec: AlignedSegment,
153-
) -> bool:
148+
def record_alignment(self, rec: AlignedSegment,) -> bool:
154149
"""Correctly record pysam.AlignedSegments (zero-based coordinates).
155150
156151
Args:
@@ -164,11 +159,7 @@ def record_alignment(
164159
else:
165160
return self.record(rec.reference_name, rec.reference_start + 1)
166161

167-
def _log(
168-
self,
169-
refname: Optional[str] = None,
170-
position: Optional[int] = None,
171-
) -> None:
162+
def _log(self, refname: Optional[str] = None, position: Optional[int] = None,) -> None:
172163
"""Helper method to print the log message.
173164
174165
Args:
@@ -187,9 +178,7 @@ def _log(
187178

188179
self.printer(f"{self.verb} {self.count:,d} {self.noun}: {coordinate}")
189180

190-
def log_last(
191-
self,
192-
) -> bool:
181+
def log_last(self,) -> bool:
193182
"""Force logging the last record, for example when progress has completed."""
194183
if self._count_mod_unit != 0:
195184
self._log(refname=self._last_reference_name, position=self._last_position)

fgpyo/util/tests/test_logging.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ def test_progress_logger_as_context_manager() -> None:
4343

4444

4545
@pytest.mark.parametrize(
46-
"record",
47-
[
48-
(r1_mapped_named),
49-
(r2_unmapped_named),
50-
(r2_unmapped_un_named),
51-
],
46+
"record", [(r1_mapped_named), (r2_unmapped_named), (r2_unmapped_un_named),],
5247
)
5348
def test_record_alignment_mapped_record(record: pysam.AlignedSegment) -> None:
5449
# Define instance of ProgressLogger

0 commit comments

Comments
 (0)