LineageTree 1.0.2__tar.gz → 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: LineageTree
3
- Version: 1.0.2
3
+ Version: 1.1.0
4
4
  Summary: Lineage tree structure for TGMM algorithm
5
5
  Home-page: https://github.com/leoguignard/TGMMlibraries
6
6
  Author: Leo Guignard
@@ -10,7 +10,7 @@ profile = "black"
10
10
  line_length = 79
11
11
 
12
12
  [tool.bumpver]
13
- current_version = "1.0.2"
13
+ current_version = "1.1.0"
14
14
  version_pattern = "MAJOR.MINOR.PATCH[-TAG]"
15
15
  commit_message = "bump version {old_version} -> {new_version}"
16
16
  commit = true
@@ -1,4 +1,4 @@
1
- from setuptools import setup, find_packages
1
+ from setuptools import setup
2
2
  from codecs import open
3
3
  from os import path
4
4
 
@@ -13,7 +13,7 @@ with open(path.join(here, "README.md")) as f:
13
13
 
14
14
  setup(
15
15
  name="LineageTree",
16
- version="1.0.2",
16
+ version="1.1.0",
17
17
  description="Lineage tree structure for TGMM algorithm",
18
18
  long_description=long_description,
19
19
  long_description_content_type='text/markdown',
@@ -1,2 +1,2 @@
1
- __version__ = "1.0.2"
1
+ __version__ = "1.1.0"
2
2
  from .lineageTree import lineageTree
@@ -15,7 +15,7 @@ from itertools import combinations
15
15
  from numbers import Number
16
16
  import struct
17
17
  from scipy.spatial.distance import cdist
18
-
18
+ import pickle as pkl
19
19
 
20
20
  class lineageTree(object):
21
21
  def get_next_id(self):
@@ -455,34 +455,26 @@ class lineageTree(object):
455
455
  )
456
456
  dwg.save()
457
457
 
458
- def to_treex(self):
458
+ def to_treex(self, sampling=1):
459
459
  """Convert the lineage tree into a treex file."""
460
460
  from treex.tree import Tree
461
461
 
462
- # id_to_tree = {id: Tree() for id in self.nodes}
463
-
464
- # for id_m, ids_d in self.successor.items():
465
- # for id_d in ids_d:
466
- # id_to_tree[id_m].add_subtree(id_to_tree[id_d])
467
- # roots = [id_to_tree[id] for id in set(self.successor).difference(self.predecessor)]
468
-
469
- roots = set(self.successor).difference(self.predecessor)
470
- id_to_tree = {}
471
- root_trees = []
472
- for r in roots:
473
- to_do = [r]
474
- while 0 < len(to_do):
475
- curr = to_do.pop()
476
- cycle = self.get_cycle(curr)
477
- lifetime = len(cycle)
478
- cell = Tree()
479
- cell.add_attribute_to_id("len", lifetime)
480
- if cycle[0] in self.predecessor:
481
- id_to_tree[self.predecessor[cycle[0]][0]].add_subtree(cell)
482
- else:
483
- root_trees.append(cell)
484
- id_to_tree[cycle[-1]] = cell
485
- to_do.extend(self.successor.get(cycle[-1], []))
462
+ id_to_tree = {id: Tree() for id in self.nodes}
463
+ times_to_consider = [t for t, n in self.time_nodes.items() if 0<len(n)]
464
+ times_to_consider = times_to_consider[::sampling]
465
+ for t in times_to_consider:
466
+ for id_mother in self.time_nodes[t]:
467
+ ids_daughters = self.successor.get(id_mother, [])
468
+ new_ids_daughters = ids_daughters.copy()
469
+ for _ in range(sampling-1):
470
+ tmp = []
471
+ for d in new_ids_daughters:
472
+ tmp.extend(self.successor.get(d, [d]))
473
+ new_ids_daughters = tmp
474
+ for daugther in new_ids_daughters: ## For each daughter in the list of daughters
475
+ id_to_tree[id_mother].add_subtree(id_to_tree[daugther]) ## Add the Treex daughter as a subtree of the Treex mother
476
+
477
+ roots = [id_to_tree[id] for id in set(self.successor).difference(self.predecessor)]
486
478
 
487
479
  return roots
488
480
 
@@ -576,7 +568,7 @@ class lineageTree(object):
576
568
  ]
577
569
  if spatial:
578
570
  edges_to_use += [
579
- (e, ei)
571
+ e
580
572
  for e in s_edges
581
573
  if t_min < self.time[e[0]] < t_max
582
574
  ]
@@ -963,11 +955,13 @@ class lineageTree(object):
963
955
 
964
956
  unique_id = 0
965
957
  id_corres = {}
958
+ self.image_label = {}
966
959
  for n in nodes:
967
960
  if n in prob_cells:
968
961
  self.prob_cells.add(unique_id)
969
962
  # if n in pos and n in names:
970
963
  t = n // 10**4
964
+ self.image_label[unique_id] = n % 10**4
971
965
  self.lT2pkl[unique_id] = n
972
966
  self.pkl2lT[n] = unique_id
973
967
  self.name[unique_id] = names.get(n, "")
@@ -1047,8 +1041,7 @@ class lineageTree(object):
1047
1041
  return dictionary
1048
1042
 
1049
1043
  def _read_from_ASTEC_pkl(self, file_path, eigen=False):
1050
- import pickle as pkl
1051
-
1044
+
1052
1045
  with open(file_path, "rb") as f:
1053
1046
  tmp_data = pkl.load(f, encoding="latin1")
1054
1047
  f.close()
@@ -1577,6 +1570,20 @@ class lineageTree(object):
1577
1570
  self.is_root = is_root
1578
1571
  self.max_id = max(self.nodes)
1579
1572
 
1573
+ def write(self, fname):
1574
+ if os.path.splitext(fname)[-1] != '.lT':
1575
+ os.path.extsep.join(fname, 'lT')
1576
+ with open(fname, 'bw') as f:
1577
+ pkl.dump(self, f)
1578
+ f.close()
1579
+
1580
+ @classmethod
1581
+ def load(clf, fname):
1582
+ with open(fname, 'br') as f:
1583
+ lT = pkl.load(f)
1584
+ f.close()
1585
+ return lT
1586
+
1580
1587
  def get_idx3d(self, t):
1581
1588
  """Get a 3d kdtree for the dataset at time *t* .
1582
1589
  The kdtree is stored in *self.kdtrees[t]*
@@ -1936,5 +1943,7 @@ class lineageTree(object):
1936
1943
  self.read_from_ASTEC(file_format, eigen)
1937
1944
  elif file_type == "csv":
1938
1945
  self.read_from_csv(file_format, z_mult, link=1, delim=delim)
1946
+ elif file_format is not None and '.lT' in file_format:
1947
+ self.read(file_format)
1939
1948
  elif file_format is not None:
1940
1949
  self.read_from_binary(file_format)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: LineageTree
3
- Version: 1.0.2
3
+ Version: 1.1.0
4
4
  Summary: Lineage tree structure for TGMM algorithm
5
5
  Home-page: https://github.com/leoguignard/TGMMlibraries
6
6
  Author: Leo Guignard
File without changes
File without changes
File without changes