From 0cf19e97b75e18dc300a02ffcc8f2f7730e73a63 Mon Sep 17 00:00:00 2001 From: Amine GHOZLANE Date: Thu, 27 Jun 2024 10:06:22 +0200 Subject: [PATCH] Debug missing trees --- meteor/phylogeny.py | 15 +++++++-------- meteor/treebuilder.py | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/meteor/phylogeny.py b/meteor/phylogeny.py index 0baf3c9..2a32e05 100644 --- a/meteor/phylogeny.py +++ b/meteor/phylogeny.py @@ -14,7 +14,7 @@ import re import logging import sys -from dataclasses import dataclass +from dataclasses import dataclass, field from meteor.session import Session, Component from subprocess import check_call, run from time import perf_counter @@ -39,6 +39,7 @@ class Phylogeny(Session): msp_file_list: list[Path] max_gap: float min_info_sites: int + tree_files: list[Path] = field(default_factory=list) def compute_site_info(self, sequences: Iterable[str]) -> list[float]: """Calculate the percentage of "_" at each position @@ -83,9 +84,7 @@ def clean_sites( print(flush=True, file=output) return resultdict, info_sites - def set_tree_config( - self, raxml_ng_version: str, tree_files: list[Path] - ) -> dict: # pragma: no cover + def set_tree_config(self, raxml_ng_version: str) -> dict: # pragma: no cover """Define the census configuration :param cmd: A string of the specific parameters @@ -98,7 +97,7 @@ def set_tree_config( "phylogeny_tool": "raxml-ng", "phylogeny_version": raxml_ng_version, "phylogeny_date": datetime.now().strftime("%Y-%m-%d"), - "tree_files": ",".join([tree.name for tree in tree_files]), + "tree_files": ",".join([tree.name for tree in self.tree_files]), }, } return config @@ -136,7 +135,7 @@ def execute(self) -> None: # Start phylogenies start = perf_counter() - tree_files: list[Path] = [] + self.tree_files: list[Path] = [] msp_count = len(self.msp_file_list) for idx, msp_file in enumerate(self.msp_file_list, start=1): logging.info( @@ -208,12 +207,12 @@ def execute(self) -> None: if tree_file.with_suffix(".tree").exists() or tree_file.with_suffix( ".raxml.bestTree" ): - tree_files.append(tree_file) + self.tree_files.append(tree_file) logging.info("Completed MSP tree %d/%d", idx, msp_count) else: logging.info( "No tree file generated for MSP %s, skipping", msp_file.name ) logging.info("Completed phylogeny in %f seconds", perf_counter() - start) - config = self.set_tree_config(raxml_ng_version, tree_files) + config = self.set_tree_config(raxml_ng_version) self.save_config(config, self.meteor.tree_dir / "census_stage_4.json") diff --git a/meteor/treebuilder.py b/meteor/treebuilder.py index 261c8de..a89745f 100644 --- a/meteor/treebuilder.py +++ b/meteor/treebuilder.py @@ -107,7 +107,7 @@ def execute(self) -> None: ) phylogeny_process.execute() # Analyze tree data - for msp_file in msp_file_list: + for msp_file in phylogeny_process.tree_files: # Check for a .raxml.bestTree file raxml_tree_file = self.meteor.tree_dir / f"{msp_file.stem}.raxml.bestTree" if raxml_tree_file.exists():