def annotate_function_with_types(f): if hasattr(f, '_orig_arg_names'): arg_names = f._orig_arg_names else: arg_names = f.func_code.co_varnames[0:f.func_code.co_argcount] argtypes = [] for name in arg_names: arg_type = types.get(name, 'any') if arg_type not in VALID_ARG_TYPES: raise ValueError( "Argument type %s is not valid, must be one of %s, " "for argument %s" % (arg_type, VALID_ARG_TYPES, name)) argtypes.append(arg_type) for n in types.keys(): if n not in arg_names and n != 'result': raise ValueError("Type specified for unknown argument " + n) return_type = types.get('result', 'float') if return_type not in VALID_RETURN_TYPES: raise ValueError("Result type %s is not valid, " "must be one of %s" % (return_type, VALID_RETURN_TYPES)) f._arg_types = argtypes f._return_type = return_type f._orig_arg_names = arg_names f._annotation_attributes = getattr( f, '_annotation_attributes', []) + ['_arg_types', '_return_type'] return f
def resType(resCode): """ Classify residues as aromatic (a), charged (c) or polar (p). @param resCode: amino acid code @type resCode: str @return: list of types this residue belongs to... @rtype: a|c|p OR None """ types = { 'a': ['F', 'Y', 'W', 'H'], ## aromatic 'c': ['E', 'D', 'L', 'R', 'H'], ## charged 'p': ['Q', 'N', 'S'] } ## polar result = [] for t in types.keys(): if resCode in types[t]: result += [t] if result == []: result = ['u'] return result
def hexacode_types(): # We go thru the Cartesian product [0,1,2,3] x ... x [0,1,2,3] with 6 factors""" all_words = list(cartesian(*([[0, 1, 2, 3]] * 6))) print( """\nDetermine types of all words of GF(4)^6 with respect to the hexacode: The 1st entry is the weight of the vector v. Other entries are present if v is no hexacode word. Then the other entries are the (sorted) tuple of the weights of all hexacode words that have minimal distance to v.""") types = {} samples = {} for a in all_words: newtype = codeword_type(a) if not newtype in types: types[newtype] = 0 samples[newtype] = (a, decode_cocode(a)) types[newtype] += 1 n = 0 for k in sorted(types.keys()): if k[0] != n: print('') print(str(k) + ':' + str(types[k]) + ',', end=' ') n = k[0] return types
def annotate_function_with_types(f): if hasattr(f, '_orig_arg_names'): arg_names = f._orig_arg_names else: arg_names = f.func_code.co_varnames[0:f.func_code.co_argcount] argtypes = [] for name in arg_names: arg_type = types.get(name, 'any') if arg_type not in VALID_ARG_TYPES: raise ValueError("Argument type %s is not valid, must be one of %s, " "for argument %s" % (arg_type, VALID_ARG_TYPES, name)) argtypes.append(arg_type) for n in types.keys(): if n not in arg_names and n!='result': raise ValueError("Type specified for unknown argument "+n) return_type = types.get('result', 'float') if return_type not in VALID_RETURN_TYPES: raise ValueError("Result type %s is not valid, " "must be one of %s" % (return_type, VALID_RETURN_TYPES)) f._arg_types = argtypes f._return_type = return_type f._orig_arg_names = arg_names f._annotation_attributes = getattr(f, '_annotation_attributes', [])+['_arg_types', '_return_type'] return f
def resType( resCode ): """ Classify residues as aromatic (a), charged (c) or polar (p). @param resCode: amino acid code @type resCode: str @return: list of types this residue belongs to... @rtype: a|c|p OR None """ types = {'a' : ['F','Y','W','H'], ## aromatic 'c' : ['E','D','L','R','H'], ## charged 'p' : ['Q','N','S'] } ## polar result = [] for t in types.keys(): if resCode in types[t]: result += [t] if result == []: result = ['u'] return result
def show_help(self): """Show help for the action command.""" args = self.arguments opts = self.options types = TypeHelper.get_actionable_types(expendNestedTypes=True, groupOptions=True) subst = {} if not args or self.is_supported_type(types.keys(), args[0]): if len(args) == 2 and len(opts) == 2: helptext = self.helptext1 subst['type'] = args[0] subst['id'] = args[1] base = self.resolve_base(self.options) obj = self.get_object(args[0], args[1], base, context_variants=types[args[0]]) if obj is None: self.error(Messages.Error.NO_SUCH_OBJECT % (args[1], args[1])) actions = self._get_action_methods(obj) subst['actions'] = self.format_list(actions) if len(args) == 3 and len(opts) == 2: helptext = self.helptext1 subst['type'] = args[0] subst['id'] = args[1] subst['action'] = args[0] base = self.resolve_base(self.options) obj = self.get_object(args[1], args[2], base, context_variants=types[args[0]]) if obj is None: self.error(Messages.Error.NO_SUCH_OBJECT % (args[0], args[1])) actions = self._get_action_methods(obj) if args[0] not in actions: self.error(Messages.Error.NO_SUCH_ACTION % args[2]) options = self.get_options(method=args[0], resource=obj, context_variants=types[args[0]]) subst['actions'] = self.format_list(actions) subst['options'] = self.format_list(options, bullet='', sort=False) elif len(args) == 1: helptext = self.helptext0 subst['types'] = self.format_map({args[0]: types[args[0]]}) subst['type'] = args[0] elif len(args) == 2: helptext = self.helptext1 subst['type'] = args[0] subst['id'] = args[1] base = self.resolve_base(opts) obj = self.get_object(args[0], args[1], base, context_variants=types[args[0]]) if obj is None: self.error(Messages.Error.NO_SUCH_OBJECT % (args[0], args[1])) actions = self._get_action_methods(obj) subst['actions'] = self.format_list(actions) elif len(args) == 3: helptext = self.helptext1 subst['type'] = args[0] subst['id'] = args[1] subst['action'] = args[2] base = self.resolve_base(self.options) obj = self.get_object(args[0], args[1], base, context_variants=types[args[0]]) if obj is None: self.error(Messages.Error.NO_SUCH_OBJECT % (args[0], args[1])) actions = self._get_action_methods(obj) if args[2] not in actions: self.error(Messages.Error.NO_SUCH_ACTION % args[2]) options = self.get_options(method=args[2], resource=obj, sub_resource=base, context_variants=types[args[0]]) subst['actions'] = self.format_list(actions) subst['options'] = self.format_list(options, bullet='', sort=False) else: helptext = self.helptext0 subst['types'] = self.format_map(types) # scope = '%s:%s' % (type(obj).__name__, args[2]) statuses = self.get_statuses() subst['statuses'] = self.format_list(statuses) helptext = self.format_help(helptext, subst) self.write(helptext)
def show_help(self): """Show help for the action command.""" args = self.arguments opts = self.options types = TypeHelper.get_actionable_types( expendNestedTypes=True, groupOptions=True ) subst = {} if not args or self.is_supported_type(types.keys(), args[0]): if len(args) == 2 and len(opts) == 2: helptext = self.helptext1 subst['type'] = args[0] subst['id'] = args[1] base = self.resolve_base(self.options) obj = self.get_object( args[0], args[1], base, context_variants=types[args[0]] ) if obj is None: self.error( Messages.Error.NO_SUCH_OBJECT % (args[1], args[1]) ) actions = self._get_action_methods(obj) subst['actions'] = self.format_list(actions) if len(args) == 3 and len(opts) == 2: helptext = self.helptext1 subst['type'] = args[0] subst['id'] = args[1] subst['action'] = args[0] base = self.resolve_base(self.options) obj = self.get_object( args[1], args[2], base, context_variants=types[args[0]] ) if obj is None: self.error( Messages.Error.NO_SUCH_OBJECT % (args[0], args[1]) ) actions = self._get_action_methods(obj) if args[0] not in actions: self.error( Messages.Error.NO_SUCH_ACTION % args[2] ) options = self.get_options( method=args[0], resource=obj, context_variants=types[args[0]] ) subst['actions'] = self.format_list(actions) subst['options'] = self.format_list(options, bullet='', sort=False) elif len(args) == 1: helptext = self.helptext0 subst['types'] = self.format_map({args[0]:types[args[0]]}) subst['type'] = args[0] elif len(args) == 2: helptext = self.helptext1 subst['type'] = args[0] subst['id'] = args[1] base = self.resolve_base(opts) obj = self.get_object( args[0], args[1], base, context_variants=types[args[0]] ) if obj is None: self.error( Messages.Error.NO_SUCH_OBJECT % (args[0], args[1]) ) actions = self._get_action_methods(obj) subst['actions'] = self.format_list(actions) elif len(args) == 3: helptext = self.helptext1 subst['type'] = args[0] subst['id'] = args[1] subst['action'] = args[2] base = self.resolve_base(self.options) obj = self.get_object( args[0], args[1], base, context_variants=types[args[0]] ) if obj is None: self.error( Messages.Error.NO_SUCH_OBJECT % (args[0], args[1]) ) actions = self._get_action_methods(obj) if args[2] not in actions: self.error(Messages.Error.NO_SUCH_ACTION % args[2]) options = self.get_options( method=args[2], resource=obj, sub_resource=base, context_variants=types[args[0]] ) subst['actions'] = self.format_list(actions) subst['options'] = self.format_list(options, bullet='', sort=False) else: helptext = self.helptext0 subst['types'] = self.format_map(types) # scope = '%s:%s' % (type(obj).__name__, args[2]) statuses = self.get_statuses() subst['statuses'] = self.format_list(statuses) helptext = self.format_help(helptext, subst) self.write(helptext)