def parse_actions(actions_filename): "Output dict mapping actionname to Stuct(use_upperedge, movements)." f = TabFile(actions_filename) f.head() # Action_info_count included "action", "reverse_leftright", "slide_count", "use_upper_edge" # action_info_count = 4 for line in f.parse(): info = list(f.parse_line(line)) # 0 > name # actionname = info[0] # 1-3 > important info # reverse_lr, slide_count, use_ue = map(int, info[1:action_info_count]) if not reverse_lr: transformation = lambda x: (x[0]-10, x[1]+10) elif reverse_lr == 1: transformation = reversed else: transformation = False # 4: > bodyparts and angle ranges # bodypart_angle_dict = {} for bodypart, raw_angles in parallel(f.header[action_info_count:], info[action_info_count:]): if raw_angles: angle_range = map(int, parse_definition(raw_angles)) bodypart_angle_dict[bodypart] = tuple(spread(angle_range, slide_count)) if transformation and bodypart[-2:] == '_r': left_bodypart = bodypart[:-2]+'_l' bodypart_angle_dict[left_bodypart] = tuple(spread(transformation(angle_range), slide_count)) else: continue else: break yield Struct(action=actionname, use_upperedge=use_ue, movements=bodypart_angle_dict)
def __init__(self, filename): TabFile.__init__(self, filename) self.entries = {} self.altered = False if path.exists(self.filename): self.head() self.retrieve() else: self.header = []
def __init__(self, filename): TabFile.__init__(self, filename) # Search data structure, value 1 represents str.upper() search # self.items = ('name2entry', 'initial2name', 'chem2name') for item in self.items: setattr(self, item, {}) # Not for use by user. This is for putting chem2name info into name2entry # self.name2chem = {} # For parsing outcome and relationship # self.i_outcome = self.header.index('outcome') self.i_relationship = self.header.index('relationship') self.database_fxn = None self.database = None self.setup() self.change_database()