Skip to content

Commit

Permalink
Merge pull request #9 from gerardet46/orchard
Browse files Browse the repository at this point in the history
Orchard and cache bugs fixed
  • Loading branch information
bielcardona committed Feb 8, 2023
2 parents 54b34f2 + 376eea7 commit 7411bc1
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions phylonetwork/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def _from_mu_data(self, mu_data):
self.nodes[root]['label'] = str(leaf)
return
S = []
mu_data = [list(mu) for mu in mu_data]
mu_data = [list(mu) for mu in mu_data if sum(mu) > 1]
lenmu = len(mu_data[0])
mu_root = max(mu_data)
while mu_data:
Expand All @@ -325,8 +325,7 @@ def _from_mu_data(self, mu_data):
found = True
# reduce p=(i,j)
try:
mu_data.remove(self.delta([p[0], p[1]], lenmu))
mu_data.remove(self.delta([p[0]], lenmu))
mu_data.remove(mu)
except:
pass
for m in mu_data:
Expand All @@ -341,7 +340,7 @@ def _from_mu_data(self, mu_data):
found = True
# reduce p=(i,j)
try:
mu_data.remove(self.delta([0, p[0], p[1]], lenmu))
mu_data.remove(mu)
except:
pass
for m in mu_data:
Expand Down Expand Up @@ -611,7 +610,7 @@ def add_pair(self, pair):
else:
if str(pair[1]) not in self.cached_taxa:
raise Exception(f"Second coordinate of pair ({pair[0]},{pair[1]}) not in taxa")
if str(pair[0]) in self.cached_taxa:
if str(pair[0]) in self.taxa:
# reticulated
l1 = self.node_with_label(str(pair[0]))
l2 = self.node_with_label(str(pair[1]))
Expand Down Expand Up @@ -682,7 +681,7 @@ def add_sequence(self, seq):
for pair in reversed(seq):
self.add_pair(pair)

@cached_property
@clearable_cached_property
def reducible_pairs(self):
"""List of the reducible pairs."""
result = []
Expand All @@ -698,12 +697,12 @@ def reducible_pairs(self):
result.append(x)
return result

@cached_property
@clearable_cached_property
def smallest_pair(self):
"""Returns the smallest reducible pair."""
return None if not self.reducible_pairs else min(self.reducible_pairs)

@cached_property
@clearable_cached_property
def all_sequences_array(self):
"""Returns a list of all the CPS."""
def reduce_recursive(obj):
Expand All @@ -720,17 +719,17 @@ def reduce_recursive(obj):
return red
return reduce_recursive(self)

@cached_property
@clearable_cached_property
def smallest_sequence_array(self):
"""Returns the smallest reducible sequence, if any."""
return min(self.all_sequences_array)

@cached_property
@clearable_cached_property
def all_sequences(self):
"""Returns a list of all the CPS."""
return [self._seq_arrstr(seq) for seq in self.all_sequences_array]

@cached_property
@clearable_cached_property
def smallest_sequence(self):
"""Returns the smallest reducible sequence, if any."""
return self._seq_arrstr(self.smallest_sequence_array)
Expand Down Expand Up @@ -771,7 +770,7 @@ class PhylogeneticTree(PhylogeneticNetwork):
def __init__(self, Newick=None, **kwargs):
super().__init__(eNewick=Newick, **kwargs)

@cached_property
@clearable_cached_property
def LCA_dict(self):
"""Dict that associate to each pair of taxons its least common ancestor"""
result = {}
Expand Down

0 comments on commit 7411bc1

Please sign in to comment.