Skip to content
Open
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 ms2rescore/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def main(tims=False):
json.loads(
importlib.resources.files(package_data)
.joinpath("config_default_tims.json")
.read_text()
.read_text(encoding="utf-8")
)
)
if cli_args.config_file:
Expand Down
8 changes: 6 additions & 2 deletions ms2rescore/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,14 @@ def parse_configurations(configurations: list[dict | str | Path | Namespace]) ->

# Initialize CascadeConfig with validation schema and defaults
config_schema = json.loads(
importlib.resources.files(package_data).joinpath("config_schema.json").read_text()
importlib.resources.files(package_data)
.joinpath("config_schema.json")
.read_text(encoding="utf-8")
)
config_default = json.loads(
importlib.resources.files(package_data).joinpath("config_default.json").read_text()
importlib.resources.files(package_data)
.joinpath("config_default.json")
.read_text(encoding="utf-8")
)
cascade_conf = CascadeConfig(
validation_schema=config_schema,
Expand Down
4 changes: 2 additions & 2 deletions ms2rescore/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def rescore(configuration: dict, psm_list: PSMList | None = None) -> None:
] # if no intermediate, takes full name

# Write full configuration including defaults to file
with open(output_file_root + ".full-config.json", "w") as f:
with open(output_file_root + ".full-config.json", "w", encoding="utf-8") as f:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to do this for the other output files as well?

json.dump(configuration, f, indent=4)

logger.debug("Using %i of %i available CPUs.", int(config["processes"]), int(cpu_count()))
Expand Down Expand Up @@ -273,7 +273,7 @@ def rescore(configuration: dict, psm_list: PSMList | None = None) -> None:

def _write_feature_names(feature_names, output_file_root):
"""Write feature names to file."""
with open(output_file_root + ".feature_names.tsv", "w") as f:
with open(output_file_root + ".feature_names.tsv", "w", encoding="utf-8") as f:
f.write("feature_generator\tfeature_name\n")
for fgen, fgen_features in feature_names.items():
f.writelines(f"{fgen}\t{feature}\n" for feature in fgen_features)
2 changes: 1 addition & 1 deletion ms2rescore/report/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _read_config(path: Path) -> dict:
logger.info("No configuration file found. Proceeding without it.")
return {"ms2rescore": {}}
try:
return json.loads(path.read_text())
return json.loads(path.read_text(encoding="utf-8"))
except (json.JSONDecodeError, OSError):
logger.warning("Could not read configuration file. Proceeding without it.")
return {"ms2rescore": {}}
4 changes: 3 additions & 1 deletion ms2rescore/report/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
# charts (DeepLC, IM2Deep, MS²PIP) reuse the same color as the feature-generator overview charts.
FEATURE_GENERATOR_COLORS = charts.FEATURE_GENERATOR_COLORS

TEXTS = tomllib.loads(importlib.resources.files(templates).joinpath("texts.toml").read_text())
TEXTS = tomllib.loads(
importlib.resources.files(templates).joinpath("texts.toml").read_text(encoding="utf-8")
)


def generate_report(
Expand Down
2 changes: 1 addition & 1 deletion ms2rescore/report/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def read_feature_names(feature_names_path: Path | None) -> dict:
return feature_names

try:
with open(feature_names_path) as f:
with open(feature_names_path, encoding="utf-8") as f:
reader = DictReader(f, delimiter="\t")
for line in reader:
feature_names[line["feature_generator"]].append(line["feature_name"])
Expand Down
Loading