def startElement(self, name, attrs): if self.current_XMLNode is None: self.current_XMLNode = XMLNode(name=name, attrs=attrs) else: t = XMLNode(name=name, attrs=attrs) self.current_XMLNode.addChild(t) self.xmlnode_hierarchylist.append(self.current_XMLNode) self.current_XMLNode = t
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:NEXT-STEP": # NOT USED FOR THE MOMENT... self.next_xref = current_child.attrs["rdf:resource"] elif current_child.name == "bp:STEP-INTERACTIONS": self.step_interactions_xref.append(current_child.attrs["rdf:resource"])
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:PATHWAY-COMPONENTS": #print "Adding component ",current_child.attrs["rdf:resource"] self.pathway_components.append( current_child.attrs["rdf:resource"]) BiopaxEntity.set_attributes(self, XMLNode)
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:CONTROLLER": self.controller_xref = current_child.attrs["rdf:resource"] elif current_child.name == "bp:CONTROLLED": self.controlled_xref = current_child.attrs["rdf:resource"] elif current_child.name == "bp:CONTROL-TYPE": control_type = current_child.getValue() if control_type == "ACTIVATION": self.control_type = "activates" elif control_type == "INHIBITION": self.control_type = "inhibits" elif control_type == "INHIBITION-ALLOSTERIC": self.control_type = "allosteric_inhibition" elif control_type == "INHIBITION-COMPETITIVE": self.control_type = "competitive_inhibition" elif control_type == "INHIBITION-IRREVERSIBLE": self.control_type = "irreversible_inhibition" elif control_type == "INHIBITION-NONCOMPETITIVE": self.control_type = "non_competitive_inhibition" elif control_type == "INHIBITION-OTHER": self.control_type = "inhibits" elif control_type == "INHIBITION-UNCOMPETITIVE": self.control_type = "uncompetitive_inhibition" elif control_type == "ACTIVATION-NONALLOSTERIC": self.control_type = "nonallosteric_activation" elif control_type == "ACTIVATION-ALLOSTERIC": self.control_type = "allosteric_activation" else: raise ValueError("Control type %s not recognized" % control_type) BiopaxPhysicalInteraction.set_attributes(self, XMLNode)
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:CONTROLLER": self.controller_xref = current_child.attrs["rdf:resource"] elif current_child.name == "bp:CONTROLLED": self.controlled_xref = current_child.attrs["rdf:resource"] elif current_child.name == "bp:CONTROL-TYPE": control_type = current_child.getValue() if control_type == "ACTIVATION": self.control_type = "activates" elif control_type == "INHIBITION": self.control_type = "inhibits" elif control_type == "INHIBITION-ALLOSTERIC": self.control_type = "allosteric_inhibition" elif control_type == "INHIBITION-COMPETITIVE": self.control_type = "competitive_inhibition" elif control_type == "INHIBITION-IRREVERSIBLE": self.control_type = "irreversible_inhibition" elif control_type == "INHIBITION-NONCOMPETITIVE": self.control_type = "non_competitive_inhibition" elif control_type == "INHIBITION-OTHER": self.control_type = "inhibits" elif control_type == "INHIBITION-UNCOMPETITIVE": self.control_type = "uncompetitive_inhibition" elif control_type == "ACTIVATION-NONALLOSTERIC": self.control_type = "nonallosteric_activation" elif control_type == "ACTIVATION-ALLOSTERIC": self.control_type = "allosteric_activation" else: raise ValueError("Control type %s not recognized" %control_type) BiopaxPhysicalInteraction.set_attributes(self,XMLNode)
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:NAME": self.name = current_child.getValue() elif current_child.name == "bp:TAXON-XREF": self.tax_ref = current_child.attrs["rdf:resource"] else: print current_child.name," not recognized"
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:NAME": self.name = current_child.getValue() elif current_child.name == "bp:TAXON-XREF": self.tax_ref = current_child.attrs["rdf:resource"] else: print current_child.name, " not recognized"
def startElement(self, name, attrs): if self.current_XMLNode is None: self.current_XMLNode = XMLNode(name = name, attrs = attrs) else: t = XMLNode(name = name, attrs = attrs) self.current_XMLNode.addChild(t) self.xmlnode_hierarchylist.append(self.current_XMLNode) self.current_XMLNode = t
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:LEFT": self.left_xrefs.append(current_child.attrs["rdf:resource"]) elif current_child.name == "bp:RIGHT": self.right_xrefs.append(current_child.attrs["rdf:resource"]) elif current_child.name == "bp:EC-NUMBER": self.ec_number.append(current_child.getValue()) BiopaxEntity.set_attributes(self, XMLNode)
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:COFACTOR": self.cofactor = current_child.attrs["rdf:resource"] # NOT IMPLEMENTED YET!!! elif current_child.name == "bp:DIRECTION": self.direction = current_child.getValue() # NOT IMPLEMENTED YET!!! BiopaxControl.set_attributes(self,XMLNode)
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:LEFT": self.left_xrefs.append(current_child.attrs["rdf:resource"]) elif current_child.name == "bp:RIGHT": self.right_xrefs.append(current_child.attrs["rdf:resource"]) elif current_child.name == "bp:EC-NUMBER": self.ec_number.append(current_child.getValue()) BiopaxEntity.set_attributes(self,XMLNode)
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:COFACTOR": self.cofactor = current_child.attrs["rdf:resource"] # NOT IMPLEMENTED YET!!! elif current_child.name == "bp:DIRECTION": self.direction = current_child.getValue() # NOT IMPLEMENTED YET!!! BiopaxControl.set_attributes(self, XMLNode)
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:CELLULAR-LOCATION": self.cellular_location_xref = current_child.attrs["rdf:resource"] elif current_child.name == "bp:PHYSICAL-ENTITY": self.physical_entity_xref = current_child.attrs["rdf:resource"] elif current_child.name == "bp:STOICHIOMETRIC-COEFFICIENT": self.stoichiometric_coefficient = current_child.getValue() elif current_child.name == "bp:SEQUENCE-FEATURE-LIST": # TO CHECK WHAT TO DO pass BiopaxEntity.set_attributes(self,XMLNode)
def set_attributes(self, XMLNode): """ """ for current_child in XMLNode.getChilds(): if current_child.name == "bp:NAME": self.name = current_child.getValue() elif current_child.name == "bp:ORGANISM": self.organism = current_child.attrs["rdf:resource"] elif current_child.name == "bp:XREF": self.xrefs.append(current_child.attrs["rdf:resource"]) elif current_child.name == "bp:SYNONYMS": self.synonyms.append(current_child.getValue()) elif current_child.name == "bp:SHORT_NAME": self.short_name = current_child.getValue() elif current_child.name == "bp:COMMENT": self.comments.append(current_child.getValue())
class BiopaxLevel2Handler(handler.ContentHandler): """ Class to handle content in Biopax Level2 XML files """ def _identity(a): return a def _entrez_funct(a): return str(a).replace("gi|","") datatype_operations = { "uniprot": _identity, "ncbi_taxonomy": _identity, "tigr": _identity, "reactome": _identity, "chebi": _identity, "go": _identity, "pubchem compound" : _identity, "glycan" : _identity, "compound" : _identity, "entrez": _entrez_funct } biopax_objects_dict = { "bp:unificationxref": BiopaxXREF, "bp:relationshipxref": BiopaxXREF, "bp:publicationxref": BiopaxXREF, "bp:opencontrolledvocabulary": BiopaxOpenControlledVocabulary, "bp:biosource": BiopaxBioSource, "bp:protein": BiopaxProtein, "bp:complex": BiopaxComplex, "bp:dna": BiopaxDNA, "bp:rna": BiopaxRNA, "bp:smallmolecule": BiopaxSmallMolecule, "bp:physicalentity": BiopaxSmallMolecule, "bp:pathway": BiopaxPathway, "bp:interaction": BiopaxInteraction, "bp:physcialinteraction": BiopaxPhysicalInteraction, "bp:conversion": BiopaxConversion, "bp:control": BiopaxControl, "bp:biochemicalreaction": BiopaxBiochemicalReaction, "bp:complexassembly": BiopaxComplexAssembly, "bp:transport": BiopaxTransport, "bp:catalysis": BiopaxCatalysis, "bp:modulation": BiopaxModulation, "bp:sequenceparticipant": BiopaxPhysicalEntityParticipant, "bp:physicalentityparticipant": BiopaxPhysicalEntityParticipant, "bp:pathwaystep": BiopaxPathwayStep } #"bp:transportwithbiochemicalreaction":, # "bp:physicalentityparticipant":, # "bp:proteinparticipant":, # "bp:complexparticipant":, # "bp:rnaparticipant":, # "bp:dnaparticipant":, # "bp:smallmoleculeparticipant": } def get_biana_data_type(self, type): return BiopaxLevel2Parser.BiopaxLevel2Handler.datatype_to_biana_type[type.lower()] def __init__(self): print "initalizing BiopaxLevel2Handler" self.current_XMLNode = None self.step = 0 self.xmlnode_hierarchylist = [] self.biopaxElements = {} BiopaxEntity.resources = self.biopaxElements BiopaxEntity.controlled_relations = {} handler.ContentHandler.__init__(self) def _get_cross_ref(self, xref_id): if xref_id[0] == '#': xref_id = xref_id[1:] try: return self.unification_xrefs[xref_id] except: return self._get_cross_ref( xref_id = self.recursive_xref[xref_id] ) def _get_link(self, xref_id): if xref_id[0] == '#': xref_id = xref_id[1:] return self.links[ xref_id ] # ContentHandler methods def startDocument(self): return def endDocument(self): self.step += 1 def startElement(self, name, attrs): if self.current_XMLNode is None: self.current_XMLNode = XMLNode(name = name, attrs = attrs) else: t = XMLNode(name = name, attrs = attrs) self.current_XMLNode.addChild(t) self.xmlnode_hierarchylist.append(self.current_XMLNode) self.current_XMLNode = t def endElement(self, name): name = name.lower() if name!=self.current_XMLNode.name.lower(): raise ValueError("ERROR IN XML FILE") if BiopaxLevel2Parser.BiopaxLevel2Handler.biopax_objects_dict.has_key(name): self.biopaxElements['#'+self.current_XMLNode.attrs["rdf:ID"]] = BiopaxLevel2Parser.BiopaxLevel2Handler.biopax_objects_dict[name](self.current_XMLNode) # Sets the current object the parent if len(self.xmlnode_hierarchylist)>0: self.current_XMLNode = self.xmlnode_hierarchylist.pop() else: self.current_XMLNode = None return def characters(self, text): #print text self.current_XMLNode.addValue(text.replace('.<','<').replace('br>','>').encode("ascii","ignore")) #self.current_XMLNode.addValue(text.replace('.<','<').replace('br>','>').decode("ascii","ignore")) def toBiana(self): for current_element in self.biopaxElements.values(): current_element.toBiana()
class BiopaxLevel2Handler(handler.ContentHandler): """ Class to handle content in Biopax Level2 XML files """ def _identity(a): return a def _entrez_funct(a): return str(a).replace("gi|", "") datatype_operations = { "uniprot": _identity, "ncbi_taxonomy": _identity, "tigr": _identity, "reactome": _identity, "chebi": _identity, "go": _identity, "pubchem compound": _identity, "glycan": _identity, "compound": _identity, "entrez": _entrez_funct } biopax_objects_dict = { "bp:unificationxref": BiopaxXREF, "bp:relationshipxref": BiopaxXREF, "bp:publicationxref": BiopaxXREF, "bp:opencontrolledvocabulary": BiopaxOpenControlledVocabulary, "bp:biosource": BiopaxBioSource, "bp:protein": BiopaxProtein, "bp:complex": BiopaxComplex, "bp:dna": BiopaxDNA, "bp:rna": BiopaxRNA, "bp:smallmolecule": BiopaxSmallMolecule, "bp:physicalentity": BiopaxSmallMolecule, "bp:pathway": BiopaxPathway, "bp:interaction": BiopaxInteraction, "bp:physcialinteraction": BiopaxPhysicalInteraction, "bp:conversion": BiopaxConversion, "bp:control": BiopaxControl, "bp:biochemicalreaction": BiopaxBiochemicalReaction, "bp:complexassembly": BiopaxComplexAssembly, "bp:transport": BiopaxTransport, "bp:catalysis": BiopaxCatalysis, "bp:modulation": BiopaxModulation, "bp:sequenceparticipant": BiopaxPhysicalEntityParticipant, "bp:physicalentityparticipant": BiopaxPhysicalEntityParticipant, "bp:pathwaystep": BiopaxPathwayStep } #"bp:transportwithbiochemicalreaction":, # "bp:physicalentityparticipant":, # "bp:proteinparticipant":, # "bp:complexparticipant":, # "bp:rnaparticipant":, # "bp:dnaparticipant":, # "bp:smallmoleculeparticipant": } def get_biana_data_type(self, type): return BiopaxLevel2Parser.BiopaxLevel2Handler.datatype_to_biana_type[ type.lower()] def __init__(self): print "initalizing BiopaxLevel2Handler" self.current_XMLNode = None self.step = 0 self.xmlnode_hierarchylist = [] self.biopaxElements = {} BiopaxEntity.resources = self.biopaxElements BiopaxEntity.controlled_relations = {} handler.ContentHandler.__init__(self) def _get_cross_ref(self, xref_id): if xref_id[0] == '#': xref_id = xref_id[1:] try: return self.unification_xrefs[xref_id] except: return self._get_cross_ref( xref_id=self.recursive_xref[xref_id]) def _get_link(self, xref_id): if xref_id[0] == '#': xref_id = xref_id[1:] return self.links[xref_id] # ContentHandler methods def startDocument(self): return def endDocument(self): self.step += 1 def startElement(self, name, attrs): if self.current_XMLNode is None: self.current_XMLNode = XMLNode(name=name, attrs=attrs) else: t = XMLNode(name=name, attrs=attrs) self.current_XMLNode.addChild(t) self.xmlnode_hierarchylist.append(self.current_XMLNode) self.current_XMLNode = t def endElement(self, name): name = name.lower() if name != self.current_XMLNode.name.lower(): raise ValueError("ERROR IN XML FILE") if BiopaxLevel2Parser.BiopaxLevel2Handler.biopax_objects_dict.has_key( name): self.biopaxElements['#' + self.current_XMLNode.attrs[ "rdf:ID"]] = BiopaxLevel2Parser.BiopaxLevel2Handler.biopax_objects_dict[ name](self.current_XMLNode) # Sets the current object the parent if len(self.xmlnode_hierarchylist) > 0: self.current_XMLNode = self.xmlnode_hierarchylist.pop() else: self.current_XMLNode = None return def characters(self, text): #print text self.current_XMLNode.addValue( text.replace('.<', '<').replace('br>', '>').encode("ascii", "ignore")) #self.current_XMLNode.addValue(text.replace('.<','<').replace('br>','>').decode("ascii","ignore")) def toBiana(self): for current_element in self.biopaxElements.values(): current_element.toBiana()
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:TERM": self.term = current_child.getValue() elif current_child.name == "bp:XREF": self.xref = current_child.attrs["rdf:resource"]
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:DB": self.db = current_child.getValue() elif current_child.name == "bp:ID": self.id = current_child.getValue()
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:COMPONENTS": self.components.append(current_child.attrs["rdf:resource"]) BiopaxPhysicalEntity.set_attributes(self, XMLNode)
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:PATHWAY-COMPONENTS": #print "Adding component ",current_child.attrs["rdf:resource"] self.pathway_components.append(current_child.attrs["rdf:resource"]) BiopaxEntity.set_attributes(self,XMLNode)
def set_attributes(self, XMLNode): for current_child in XMLNode.getChilds(): if current_child.name == "bp:COMPONENTS": self.components.append( current_child.attrs["rdf:resource"] ) BiopaxPhysicalEntity.set_attributes(self,XMLNode)