示例#1
0
    def check_required_attributes(self, entity_set_index, attribute_list):
        """Check that all the elements of the given entity_set have all
the attributes in the attribute_list.
        """
        # get_entities will validate entity_set_index
        entities = self.get_entities(entity_set_index)

        if type(entities) == types.GeneratorType:
            # @@ figure out how to check generator attributes !!
            return

        # check each attribute
        typeList = [types.ListType, types.DictType]  #, types.InstanceType]
        from mglutil.util.misc import isInstance
        for attr in attribute_list:
            # get returns the subset of entities
            # for which the expression is true
            ents = entities.get(lambda x: hasattr(x, attr))
            if ents == None or len(ents) != len(entities):
                raise AttributeError, \
                      "All Entities do not have required Entity attribute (%s) " % attr
            ent0 = entities[0]
            if type(getattr(ent0, attr)) in typeList \
              or isInstance(getattr(ent0, attr)) is True:
                if len(getattr(ent0, attr)) == 0:
                    raise ValueError, \
                          "Required Entity attribute (%s) has zero length" % attr
    def check_required_attributes(self, entity_set_index, attribute_list):
        """Check that all the elements of the given entity_set have all
the attributes in the attribute_list.
        """
        # get_entities will validate entity_set_index
        entities = self.get_entities( entity_set_index)

        if type(entities) == types.GeneratorType:
            # @@ figure out how to check generator attributes !!
            return

        # check each attribute
        typeList = [types.ListType, types.DictType]#, types.InstanceType]
        from mglutil.util.misc import isInstance
        for attr in attribute_list:
            # get returns the subset of entities
            # for which the expression is true
            ents = entities.get( lambda x: hasattr(x, attr))
            if ents==None or len(ents)!=len(entities):
                raise AttributeError, \
                      "All Entities do not have required Entity attribute (%s) " % attr
            ent0 = entities[0]
            if type(getattr(ent0, attr)) in typeList \
              or isInstance(getattr(ent0, attr)) is True:
                if len(getattr(ent0, attr))==0:
                    raise ValueError, \
                          "Required Entity attribute (%s) has zero length" % attr
 def process(self, nodes, criteria, sets=None):
     # print "in process with len(nodes)=", len(nodes), ' and criteria=', criteria
     # print "type(criteria)==", type(criteria)
     msg_to_return = ""
     if type(criteria) == str:
         selected, msg = self.do_op(nodes, criteria, sets=sets)
         # print " back in process with len(selected) = ", len(selected)
         msg_to_return += msg
     # elif type(criteria)==types.InstanceType:
     elif isInstance(criteria) is True:
         selected = criteria
     return selected, msg_to_return
示例#4
0
 def process(self, nodes, criteria, sets=None):
     #print "in process with len(nodes)=", len(nodes), ' and criteria=', criteria
     #print "type(criteria)==", type(criteria)
     msg_to_return = ""
     if type(criteria)==types.StringType:
         selected, msg = self.do_op(nodes, criteria, sets=sets)
         #print " back in process with len(selected) = ", len(selected)
         msg_to_return += msg
     #elif type(criteria)==types.InstanceType:
     elif isInstance(criteria) is True:
         selected = criteria
     return selected, msg_to_return
    def _strArg(self, arg):
        """
        Method to turn a command argument into a string for logging purposes
        Add support for TreeNodes and TreeNodeSets
        """
        #if type(arg)==types.InstanceType:
        from mglutil.util.misc import isInstance
        if isInstance(arg) is True:
            if issubclass(arg.__class__, TreeNode):
                return '"' + arg.full_name() + '", ', None
                
            if issubclass(arg.__class__, TreeNodeSet):
                stringRepr = arg.getStringRepr()
                if stringRepr:
                    return '"' + stringRepr + '", ', None
                else:
                    name = ""
                    mols, elems = self.vf.getNodesByMolecule(arg)
                    for elem in elems:
                        name = name + elem.full_name() +';'
                    return '"' + name + '", ', None

        return Command._strArg(self, arg)
示例#6
0
    def _strArg(self, arg):
        """
        Method to turn a command argument into a string for logging purposes
        Add support for TreeNodes and TreeNodeSets
        """
        #if type(arg)==types.InstanceType:
        from mglutil.util.misc import isInstance
        if isInstance(arg) is True:
            if issubclass(arg.__class__, TreeNode):
                return '"' + arg.full_name() + '", ', None

            if issubclass(arg.__class__, TreeNodeSet):
                stringRepr = arg.getStringRepr()
                if stringRepr:
                    return '"' + stringRepr + '", ', None
                else:
                    name = ""
                    mols, elems = self.vf.getNodesByMolecule(arg)
                    for elem in elems:
                        name = name + elem.full_name() + ';'
                    return '"' + name + '", ', None

        return Command._strArg(self, arg)
示例#7
0
 def setroot(self, atom):
     """
     setroot to 'C11' or 'hsg1:A:ILE2:CA'
     """
     if type(atom)==types.StringType:
         if find(atom, ':')>-1:
             #have to use full_name list
             #check that it is an atom
             mols = ProteinSet([self])
             nodes = mols.NodesFromName(atom)
             if not nodes:
                 return 'invalid root name'
             if nodes.__class__!=AtomSet:
                 return 'invalid root name: not atom level'
         else:
             nodes = self.allAtoms.get(lambda x, n = atom:x.name==n)
         if not nodes:
             return 'invalid root name'
         if len(nodes)>1:
             return 'root name must be unique'
         atom = nodes[0]
     #elif type(atom)!=types.InstanceType:
     elif isInstance(atom) is False:
         return atom, ' invalid root atom'
     elif atom.__class__!=Atom:
         return atom, ' can only select an Atom instance as root'
     #fix this rnum0 stuff
     #in case toggling back and forth
     if hasattr(self, 'autoRoot') and hasattr(self.autoRoot, 'rnum0'):
         delattr(self.autoRoot, 'rnum0')
     #if there is an old root, remove rnum0
     if hasattr(self, 'ROOT') and hasattr(self.ROOT, 'rnum0'):
         delattr(self.ROOT, 'rnum0')
     self.ROOT = atom
     self.ROOT.rnum0 = 0
     return self.ROOT
示例#8
0
 def setroot(self, atom):
     """
     setroot to 'C11' or 'hsg1:A:ILE2:CA'
     """
     if type(atom) == bytes:
         if find(atom, ':') > -1:
             #have to use full_name list
             #check that it is an atom
             mols = ProteinSet([self])
             nodes = mols.NodesFromName(atom)
             if not nodes:
                 return 'invalid root name'
             if nodes.__class__ != AtomSet:
                 return 'invalid root name: not atom level'
         else:
             nodes = self.allAtoms.get(lambda x, n=atom: x.name == n)
         if not nodes:
             return 'invalid root name'
         if len(nodes) > 1:
             return 'root name must be unique'
         atom = nodes[0]
     #elif type(atom)!=types.InstanceType:
     elif isInstance(atom) is False:
         return atom, ' invalid root atom'
     elif atom.__class__ != Atom:
         return atom, ' can only select an Atom instance as root'
     #fix this rnum0 stuff
     #in case toggling back and forth
     if hasattr(self, 'autoRoot') and hasattr(self.autoRoot, 'rnum0'):
         delattr(self.autoRoot, 'rnum0')
     #if there is an old root, remove rnum0
     if hasattr(self, 'ROOT') and hasattr(self.ROOT, 'rnum0'):
         delattr(self.ROOT, 'rnum0')
     self.ROOT = atom
     self.ROOT.rnum0 = 0
     return self.ROOT