Skip to content

Commit

Permalink
Merge pull request #269 from labgem/no_partition_management
Browse files Browse the repository at this point in the history
Print a warning log when partition step fails
  • Loading branch information
jpjarnoux authored Aug 22, 2024
2 parents ea6986d + 7e63c1f commit 9abb654
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions ppanggolin/nem/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,14 @@ def run_partitioning(nem_dir_path: Path, nb_org: int, beta: float = 2.5, free_di
else:
partitions_list[i] = parti[positions_max_prob.pop()]
except OSError:
logging.getLogger("PPanGGOLiN").debug(
"partitioning did not work (the number of genomes used is probably too low), "
"see logs here to obtain more details " + nem_dir_path.as_posix() + "/nem_file_" +
str(kval) + ".log")
logging.getLogger("PPanGGOLiN").warning("Partitioning did not work (the number of genomes used is probably too low), "
f"see logs here to obtain more details {nem_dir_path.as_posix()}")
return {}, None, None # return empty objects

except ValueError:
# return the default partitions_list which correspond to undefined
pass

if not keep_files and no_nem is False:
os.remove(nem_dir_path / f"nem_file_{str(kval)}.uf")
os.remove(nem_dir_path / f"nem_file_{str(kval)}.mf")
os.remove(nem_dir_path / f"nem_file_{str(kval)}.log")
os.remove(nem_dir_path / f"nem_file_{str(kval)}.stderr")
os.remove(nem_dir_path / f"nem_file_init_{str(kval)}.m")
os.remove(nem_dir_path / "nem_file.index")
os.remove(nem_dir_path / "nem_file.dat")
os.remove(nem_dir_path / "nem_file.nei")
os.remove(nem_dir_path / "nem_file.str")

if just_log_likelihood:
return kval, log_likelihood, entropy
else:
Expand Down Expand Up @@ -469,8 +457,15 @@ def partition(pangenome: Pangenome, output: Path = None, beta: float = 2.5, sm_d
check_pangenome_former_partition(pangenome, force)
check_pangenome_info(pangenome, need_annotations=True, need_families=True, need_graph=True, disable_bar=disable_bar)
organisms = set(pangenome.organisms)
tmp_dir = tempfile.TemporaryDirectory(dir=tmpdir)
tmp_path = Path(tmp_dir.name)

if keep_tmp_files:
# Create a temporary directory without auto-cleanup
tmp_dir = tempfile.mkdtemp(dir=tmpdir)
tmp_path = Path(tmp_dir)
else:
# Create a temporary directory with auto-cleanup
tmp_dir = tempfile.TemporaryDirectory(dir=tmpdir)
tmp_path = Path(tmp_dir.name)

if len(organisms) <= 10:
logging.getLogger("PPanGGOLiN").warning(f"The number of selected genomes is too low ({len(organisms)} "
Expand Down

0 comments on commit 9abb654

Please sign in to comment.