Changeset 709
- Timestamp:
- 10/01/17 00:06:54 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mds-and-trees/tree-genealogy.py
r708 r709 711 711 return self.ids[id] 712 712 713 def try_to_load(input): 714 creature = False 715 try: 716 creature = json.loads(input) 717 except ValueError: 718 print("Json format error - the line cannot be read. Breaking the loading loop.") 719 # fixing arrays by removing the last element 720 # ! assuming that only the last line is broken ! 721 self.parents.pop() 722 self.children.pop() 723 self.time.pop() 724 self.kind.pop() 725 self.life_lenght.pop() 726 return creature 727 713 728 file = open(filename) 714 729 … … 720 735 if line_arr[0] == CLI_PREFIX: 721 736 line_arr = line_arr[1].split(' ', 1) 722 if line_arr[0] == "[ OFFSPRING]":737 if line_arr[0] == "[BORN]": 723 738 nodes += 1 724 739 … … 736 751 loaded_so_far = 0 737 752 lasttime = timelib.time() 753 754 get_id("virtual_parent") 755 738 756 for line in file: 739 757 line_arr = line.split(' ', 1) … … 741 759 if line_arr[0] == CLI_PREFIX: 742 760 line_arr = line_arr[1].split(' ', 1) 743 if line_arr[0] == "[OFFSPRING]": 744 try: 745 creature = json.loads(line_arr[1]) 746 except ValueError: 747 print("Json format error - the line cannot be read. Breaking the loading loop.") 748 # fixing arrays by removing the last element 749 # ! assuming that only the last line is broken ! 750 self.parents.pop() 751 self.children.pop() 752 self.time.pop() 753 self.kind.pop() 754 self.life_lenght.pop() 761 if line_arr[0] == "[BORN]": 762 creature = try_to_load(line_arr[1]) 763 if not creature: 755 764 nodes -= 1 756 765 break 757 766 767 creature_id = get_id(creature["ID"]) 768 769 # debug 770 if loaded_so_far%1000 == 0: 771 #print(". " + str(creature_id) + " " + str(timelib.time() - lasttime)) 772 lasttime = timelib.time() 773 774 if "Time" in creature: 775 self.time[creature_id] = creature["Time"] 776 777 for prop in creature: 778 if prop not in default_props: 779 if prop not in self.props: 780 self.props[prop] = [0 for i in range(nodes)] 781 self.props[prop][creature_id] = creature[prop] 782 783 loaded_so_far += 1 784 785 if line_arr[0] == "[OFFSPRING]": 786 creature = try_to_load(line_arr[1]) 787 if not creature: 788 nodes -= 1 789 break 790 758 791 if "FromIDs" in creature: 759 760 792 # make sure that ID's of parents are lower than that of their children 761 793 for i in range(0, len(creature["FromIDs"])): … … 763 795 get_id("virtual_parent") 764 796 765 creature_id = get_id(creature["ID"]) 766 767 # debug 768 if loaded_so_far%1000 == 0: 769 #print(". " + str(creature_id) + " " + str(timelib.time() - lasttime)) 770 lasttime = timelib.time() 797 creature_id = get_id(creature["ID"])#, False) 771 798 772 799 # we assign to each parent its contribution to the genotype of the child … … 781 808 self.parents[creature_id][parent_id] = inherited 782 809 783 if "Time" in creature:784 self.time[creature_id] = creature["Time"]785 786 810 if "Kind" in creature: 787 811 self.kind[creature_id] = creature["Kind"] 788 789 for prop in creature:790 if prop not in default_props:791 if prop not in self.props:792 self.props[prop] = [0 for i in range(nodes)]793 self.props[prop][creature_id] = creature[prop]794 795 loaded_so_far += 1796 812 else: 797 813 raise LoadingError("[OFFSPRING] misses the 'FromIDs' field!") 798 if line_arr[0] == "[DIED]": 799 creature = json.loads(line_arr[1]) 814 815 if line_arr[0] == "[DIED]" or line_arr[0] == "[BORN]": 816 creature = try_to_load(line_arr[1]) 817 if not creature: 818 nodes -= 1 819 break 800 820 creature_id = get_id(creature["ID"], False) 801 821 if creature_id is not None: … … 811 831 812 832 print("NOTE: all individuals with parent not provided or missing were connected to a single 'virtual parent' node: " + str(merged_with_virtual_parent)) 833 834 for c_id in range(1, nodes): 835 if not self.parents[c_id]: 836 self.parents[c_id][get_id("virtual_parent")] = 1 813 837 814 838 for k in range(len(self.parents)):
Note: See TracChangeset
for help on using the changeset viewer.