Skip to content

Commit

Permalink
Merge branch 'rel-0.3.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
alpae committed Aug 8, 2024
2 parents 38b2991 + b821557 commit 62ae7cb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion FastOMA/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

__packagename__ = "FastOMA"
__version__ = "0.3.2"
__version__ = "0.3.3"
15 changes: 14 additions & 1 deletion FastOMA/_hog_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def _sorter_key(sh):
"""


def split_hog(hog:HOG, *partitions):
def split_hog(hog:HOG, level_name:str, *partitions):
"""splits a hog into parts based to the partitions provided.
The partitions need to be a lists of Representatives (or simply members)
Expand Down Expand Up @@ -402,4 +402,17 @@ def split_hog(hog:HOG, *partitions):
h = HOG(subhogs, taxnomic_range=hog.taxlevel, rhogid=hog.rhogid, msa=hog.get_msa(), representatives=partitions[p])
hogs.append(h)
return hogs
else:
rep_to_subhog_list = {rep: hog.get_subhog_path(rep.get_id(), max_depth=-1) for part in partitions for rep in part}
for depth in range(max(len(sh) for sh in rep_to_subhog_list.values())):
rep_sets = [set(rep_to_subhog_list[rep][depth] for rep in part if len(rep_to_subhog_list[rep]) > depth) for part in partitions]
if all(s1.isdisjoint(s2) for s1, s2 in itertools.combinations(rep_sets, 2)):
break
depth -= 1
rep_sets = [set(rep_to_subhog_list[rep][depth] for rep in part if len(rep_to_subhog_list[rep]) > depth) for part in partitions]
merged_in = set.union(*(s1.intersection(s2) for s1, s2 in itertools.combinations(rep_sets, 2)))
involved_reps = [(r, h[depth].hogid, h[depth].taxname) for r, h in rep_to_subhog_list.items() if len(h)>depth and h[depth] in merged_in]
logger.warning(f"{hog} should be split in {len(partitions)} partitions at {level_name}. Not implemented yet.")
for rep in involved_reps:
logger.warning(f" - Rep {rep[0]} merged into {rep[1]} at level {rep[2]}")
#raise RuntimeError("this part of the code needs more thinking")
5 changes: 2 additions & 3 deletions FastOMA/_infer_subhog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import collections
import csv
import itertools
from copy import deepcopy
from pathlib import Path
import gzip

Expand Down Expand Up @@ -436,7 +435,7 @@ def infer_genetree_from_msa(self, msa):
return genetree

def infer_rooted_genetree(self, gene_tree: TreeNode):
genetree = deepcopy(gene_tree)
genetree = gene_tree.copy()
if self.conf.gene_rooting_method == "midpoint":
r_outgroup = genetree.get_midpoint_outgroup()
genetree.set_outgroup(r_outgroup) # print("Midpoint rooting is done for gene tree.")
Expand Down Expand Up @@ -588,7 +587,7 @@ def merge_subhogs(self, reconciled_genetree:TreeNode, msa:MultipleSeqAlignment):
if len(subtrees) > 1:
logger.info(f"Representaives of {hogid} are split among {len(subtrees)} candidate subtrees.")
split_parts = [list(n.name for n in sub.iter_leaves() if n.hogid == hogid) for sub in subtrees]
split_hogs = split_hog(self.subhogs[hogid], *split_parts)
split_hogs = split_hog(self.subhogs[hogid], self.node_species_tree.name, *split_parts)
if split_hogs and len(split_hogs) > 1:
# we could split the current hog.
self.subhogs.pop(hogid)
Expand Down
4 changes: 2 additions & 2 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ manifest {
nextflowVersion = ">=22.10.4"
defaultBranch = "main"
doi = "10.1101/2024.01.29.577392"
version = "0.3.2"
version = "0.3.3"
}

params {
container_name = "dessimozlab/fastoma"
container_version = "0.3.2"
container_version = "0.3.3"
omamer_db = "https://omabrowser.org/All/LUCA.h5"
debug_enabled = false
help = false
Expand Down

0 comments on commit 62ae7cb

Please sign in to comment.