Changeset 633
- Timestamp:
- 11/23/16 17:58:33 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mds-and-trees/tree-genealogy.py
r628 r633 6 6 import time as timelib 7 7 from PIL import Image, ImageDraw, ImageFont 8 from scipy import stats 9 import numpy as np 8 10 9 11 class LoadingError(Exception): … … 129 131 end_text = "Time " + str(max(self.design.tree.time)) 130 132 if self.design.TIME == "GENERATIONAL": 131 start_text = "Depth " + str(self.design.props['adepth ']['min'])132 end_text = "Depth " + str(self.design.props['adepth ']['max'])133 start_text = "Depth " + str(self.design.props['adepth_min']) 134 end_text = "Depth " + str(self.design.props['adepth_max']) 133 135 134 136 self.add_dashed_line(file, (self.width*0.7, self.h_margin), (self.width, self.h_margin)) … … 362 364 self.compute_kind() 363 365 self.compute_time() 366 self.compute_progress() 364 367 self.compute_custom() 365 368 … … 387 390 x1_dist = 0 388 391 x2_dist = 0 389 miny = y- 500390 maxy = y+ 500392 miny = y-20 393 maxy = y+20 391 394 i_left = bisect.bisect_left(self.y_sorted, miny) 392 395 i_right = bisect.bisect_right(self.y_sorted, maxy) … … 554 557 self.normalize_prop('children') 555 558 559 def compute_progress(self): 560 self.props["progress"] = [0 for x in range(len(self.tree.children))] 561 for i in range(len(self.props['children'])): 562 times = sorted([self.props["time"][self.tree.children[i][j]]*100000 for j in range(len(self.tree.children[i]))]) 563 if len(times) > 4: 564 times = [times[i+1] - times[i] for i in range(len(times)-1)] 565 #print(times) 566 slope, intercept, r_value, p_value, std_err = stats.linregress(range(len(times)), times) 567 self.props['progress'][i] = slope if not np.isnan(slope) and not np.isinf(slope) else 0 568 569 for i in range(0, 5): 570 self.props['progress'][self.props['progress'].index(min(self.props['progress']))] = 0 571 self.props['progress'][self.props['progress'].index(max(self.props['progress']))] = 0 572 573 mini = min(self.props['progress']) 574 maxi = max(self.props['progress']) 575 for k in range(len(self.props['progress'])): 576 if self.props['progress'][k] == 0: 577 self.props['progress'][k] = mini 578 579 #for k in range(len(self.props['progress'])): 580 # self.props['progress'][k] = 1-self.props['progress'][k] 581 582 self.normalize_prop('progress') 583 556 584 def normalize_prop(self, prop): 557 noneless = [v for v in self.props[prop] if type(v) ==int or type(v)==float]585 noneless = [v for v in self.props[prop] if type(v)!=str] 558 586 if len(noneless) > 0: 559 587 max_val = max(noneless) 560 588 min_val = min(noneless) 589 print(prop, max_val, min_val) 561 590 self.props[prop +'_max'] = max_val 562 591 self.props[prop +'_min'] = min_val 563 592 for i in range(len(self.props[prop])): 564 593 if self.props[prop][i] is not None: 565 self.props[prop][i] = 0 if max_val == 0 else (self.props[prop][i] - min_val) / max_val566 594 qqq = self.props[prop][i] 595 self.props[prop][i] = 0 if max_val == min_val else (self.props[prop][i] - min_val) / (max_val - min_val) 567 596 568 597 class TreeData: … … 584 613 default_props = ["Time", "FromIDs", "ID", "Operation", "Inherited"] 585 614 586 ids = {}615 self.ids = {} 587 616 def get_id(id, createOnError = True): 588 617 if createOnError: 589 if id not in ids:590 ids[id] = len(ids)618 if id not in self.ids: 619 self.ids[id] = len(self.ids) 591 620 else: 592 if id not in ids:621 if id not in self.ids: 593 622 return None 594 return ids[id]623 return self.ids[id] 595 624 596 625 file = open(filename) … … 630 659 # make sure that ID's of parents are lower than that of their children 631 660 for i in range(0, len(creature["FromIDs"])): 632 if creature["FromIDs"][i] not in ids:661 if creature["FromIDs"][i] not in self.ids: 633 662 get_id("virtual_parent") 634 663 … … 642 671 # we assign to each parent its contribution to the genotype of the child 643 672 for i in range(0, len(creature["FromIDs"])): 644 if creature["FromIDs"][i] in ids:673 if creature["FromIDs"][i] in self.ids: 645 674 parent_id = get_id(creature["FromIDs"][i]) 646 675 else:
Note: See TracChangeset
for help on using the changeset viewer.