Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to v1.4.1 #65

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pygenomeviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pygenomeviz.genomeviz import GenomeViz

__version__ = "1.4.0"
__version__ = "1.4.1"

__all__ = [
"GenomeViz",
Expand Down
6 changes: 3 additions & 3 deletions src/pygenomeviz/align/coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def parse_pmauve_file(
align_coords : list[AlignCoord]
Align coord list
"""
with open(bbone_file) as f:
with open(bbone_file, encoding="utf-8") as f:
reader = csv.reader(f, delimiter="\t")
header_row = next(reader)
genome_num = int(len(header_row) / 2)
Expand Down Expand Up @@ -316,7 +316,7 @@ def write(
elif isinstance(outfile, io.BytesIO):
outfile.write(bytes(contents, encoding="utf-8"))
else:
with open(outfile, "w") as f:
with open(outfile, "w", encoding="utf-8") as f:
f.write(contents)

@staticmethod
Expand All @@ -334,7 +334,7 @@ def read(align_coords_file: str | Path) -> list[AlignCoord]:
Alignment coords
"""
align_coords = []
with open(align_coords_file) as f:
with open(align_coords_file, encoding="utf-8") as f:
reader = csv.reader(f, delimiter="\t")
next(reader)
for row in reader:
Expand Down
4 changes: 2 additions & 2 deletions src/pygenomeviz/align/tool/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def run_cmd(
# Write stdout result if stdout_file is set
if stdout_file:
logger.info(f"> Save cmd stdout results to '{stdout_file}'")
with open(stdout_file, "w") as f:
with open(stdout_file, "w", encoding="utf-8") as f:
f.write(cmd_res.stdout)
else:
logger.error("Failed to run command below!!")
Expand Down Expand Up @@ -183,7 +183,7 @@ def _parse_input_gbk_and_fasta_seqs(
if isinstance(seq, Path):
suffix = seq.suffix
if suffix == ".gz" and len(seq.suffixes) >= 2:
suffix = seq.suffixes[-2].join("")
suffix = "".join(seq.suffixes[-2])
if suffix in gbk_suffixes:
parse_seqs.append(Genbank(seq))
elif suffix in fasta_suffixes:
Expand Down
2 changes: 1 addition & 1 deletion src/pygenomeviz/align/tool/mmseqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _parse_coords_file(
"""
align_coords = []
dup_check_list = []
with open(rbh_result_file) as f:
with open(rbh_result_file, encoding="utf-8") as f:
reader = csv.reader(f, delimiter="\t")
for row in reader:
# Query [e.g. `GENE000001_NC_XXXXXX.X|name|8205_8559_1|`]
Expand Down
2 changes: 1 addition & 1 deletion src/pygenomeviz/genomeviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def savefig_html(
elif isinstance(html_outfile, io.BytesIO):
html_outfile.write(bytes(viewer_html, encoding="utf-8"))
else:
with open(html_outfile, "w") as f:
with open(html_outfile, "w", encoding="utf-8") as f:
f.write(viewer_html)

############################################################
Expand Down
12 changes: 7 additions & 5 deletions src/pygenomeviz/parser/fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def write_genome_fasta(self, outfile: str | Path) -> None:
outfile : str | Path
Output genome fasta file
"""
with open(outfile, "w") as f:
with open(outfile, "w", encoding="utf-8") as f:
for seqid, seq in self.get_seqid2seq().items():
f.write(f">{seqid}\n{seq}\n")

Expand All @@ -142,14 +142,16 @@ def _parse_fasta_file(self, fasta_file: str | Path) -> list[SeqRecord]:
SeqRecord list
"""
if Path(fasta_file).suffix == ".gz":
with gzip.open(fasta_file, mode="rt") as f:
with gzip.open(fasta_file, mode="rt", encoding="utf-8") as f:
return list(SeqIO.parse(f, "fasta"))
elif Path(fasta_file).suffix == ".bz2":
with bz2.open(fasta_file, mode="rt") as f:
with bz2.open(fasta_file, mode="rt", encoding="utf-8") as f:
return list(SeqIO.parse(f, "fasta"))
elif Path(fasta_file).suffix == ".zip":
with zipfile.ZipFile(fasta_file) as zip:
with zip.open(zip.namelist()[0]) as f:
return list(SeqIO.parse(TextIOWrapper(f), "fasta"))
io = TextIOWrapper(f, encoding="utf-8")
return list(SeqIO.parse(io, "fasta"))
else:
return list(SeqIO.parse(fasta_file, "fasta"))
with open(fasta_file, encoding="utf-8") as f:
return list(SeqIO.parse(f, "fasta"))
16 changes: 10 additions & 6 deletions src/pygenomeviz/parser/genbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def write_genome_fasta(self, outfile: str | Path) -> None:
outfile : str | Path
Output genome fasta file
"""
with open(outfile, "w") as f:
with open(outfile, "w", encoding="utf-8") as f:
for seqid, seq in self.get_seqid2seq().items():
f.write(f">{seqid}\n{seq}\n")

Expand All @@ -391,19 +391,23 @@ def _parse_gbk_source(
list[SeqRecord]
Genbank SeqRecords
"""
# Parse compressed file
# Parse file
if isinstance(gbk_source, (str, Path)):
if Path(gbk_source).suffix == ".gz":
with gzip.open(gbk_source, mode="rt") as f:
with gzip.open(gbk_source, mode="rt", encoding="utf-8") as f:
return list(SeqIO.parse(f, "genbank"))
elif Path(gbk_source).suffix == ".bz2":
with bz2.open(gbk_source, mode="rt") as f:
with bz2.open(gbk_source, mode="rt", encoding="utf-8") as f:
return list(SeqIO.parse(f, "genbank"))
elif Path(gbk_source).suffix == ".zip":
with zipfile.ZipFile(gbk_source) as zip:
with zip.open(zip.namelist()[0]) as f:
return list(SeqIO.parse(TextIOWrapper(f), "genbank"))
# Parse no compressed file or TextIOWrapper
io = TextIOWrapper(f, encoding="utf-8")
return list(SeqIO.parse(io, "genbank"))
else:
with open(gbk_source, encoding="utf-8") as f:
return list(SeqIO.parse(f, "genbank"))
# Parse TextIOWrapper
return list(SeqIO.parse(gbk_source, "genbank"))

def _is_straddle_feature(self, feature: SeqFeature) -> bool:
Expand Down
8 changes: 4 additions & 4 deletions src/pygenomeviz/parser/gff.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,18 @@ def _parse_gff(
"""
gff_file = Path(gff_file)
if gff_file.suffix == ".gz":
with gzip.open(gff_file, mode="rt") as f:
with gzip.open(gff_file, mode="rt", encoding="utf-8") as f:
gff_records, start, end = self._parse_gff_textio(f, target_seqid)
elif gff_file.suffix == ".bz2":
with bz2.open(gff_file, mode="rt") as f:
with bz2.open(gff_file, mode="rt", encoding="utf-8") as f:
gff_records, start, end = self._parse_gff_textio(f, target_seqid)
elif gff_file.suffix == ".zip":
with zipfile.ZipFile(gff_file) as zip:
with zip.open(zip.namelist()[0]) as f:
io = TextIOWrapper(f)
io = TextIOWrapper(f, encoding="utf-8")
gff_records, start, end = self._parse_gff_textio(io, target_seqid)
else:
with open(gff_file) as f:
with open(gff_file, encoding="utf-8") as f:
gff_records, start, end = self._parse_gff_textio(f, target_seqid)

return gff_records, start, end
Expand Down
2 changes: 1 addition & 1 deletion src/pygenomeviz/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def fetch_genbank_by_accid(
)
if gbk_outfile is not None:
gbk_text = gbk_fetch_data.read()
with open(gbk_outfile, "w") as f:
with open(gbk_outfile, "w", encoding="utf-8") as f:
f.write(gbk_text)
gbk_fetch_data = StringIO(gbk_text)

Expand Down
4 changes: 2 additions & 2 deletions src/pygenomeviz/viewer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _concat_target_files_contents(files: list[Path], target_ext: str) -> str:
contents = "\n"
target_files = [file for file in files if file.suffix == target_ext]
for target_file in target_files:
with open(target_file) as f:
with open(target_file, encoding="utf-8") as f:
contents += f.read() + "\n"
return contents

Expand Down Expand Up @@ -70,7 +70,7 @@ def setup_viewer_html(
err_msg = "Failed to save HTML viewer. Check if target figure is generated by 'gv.plotfig(fast_render=False)' method call." # noqa: E501
raise ValueError(err_msg)
# Read template html file
with open(TEMPLATE_HTML_FILE) as f:
with open(TEMPLATE_HTML_FILE, encoding="utf-8") as f:
viewer_html = f.read()
# Replace template strings
return (
Expand Down
2 changes: 1 addition & 1 deletion tests/parser/test_fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
def test_fasta_property(tmp_path: Path):
"""Test Fasta instance properties"""
fasta_file = tmp_path / "test.fa"
with open(fasta_file, "w") as f:
with open(fasta_file, "w", encoding="utf-8") as f:
f.write(fasta_txt)
fasta = Fasta(fasta_file)

Expand Down
2 changes: 1 addition & 1 deletion tests/parser/test_genbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_genbank_write_genome_fasta(multi_record_gbk_file: Path, tmp_path: Path)
assert outfile.exists()

# Check number of genome fasta
with open(outfile) as f:
with open(outfile, encoding="utf-8") as f:
lines = f.read().splitlines()
fasta_count = len([line for line in lines if line.startswith(">")])
assert fasta_count == 8
Expand Down