def parseInteractions(dom,network): """ <interaction id="678614" imexId="IM-12113-2"> <names> <shortLabel>pf1130-pf1128-2</shortLabel> <fullName>Affinity purification by hydroxy apatite chromatography</fullName> </names> <xref> <primaryRef refTypeAc="MI:0356" refType="identity" id="EBI-2507294" dbAc="MI:0469" db="intact"/> <secondaryRef refType="imex source" id="MI:0469" dbAc="MI:0488" db="psi-mi"/> <secondaryRef refTypeAc="MI:0662" refType="imex-primary" id="IM-12113-2" dbAc="MI:0670" db="imex"/> </xref> <experimentList> <experimentRef>678502</experimentRef> </experimentList> <participantList> <participant id="678615"> <names> <shortLabel>n/a</shortLabel> </names> <xref> <primaryRef refTypeAc="MI:0356" refType="identity" id="EBI-2507299" dbAc="MI:0469" db="intact"/> </xref> <interactorRef>678518</interactorRef> <biologicalRole> <names> <shortLabel>unspecified role</shortLabel> <fullName>unspecified role</fullName> </names> <xref> <primaryRef refTypeAc="MI:0356" refType="identity" id="MI:0499" dbAc="MI:0488" db="psi-mi"/> <secondaryRef refTypeAc="MI:0356" refType="identity" id="EBI-77781" dbAc="MI:0469" db="intact"/> <secondaryRef refTypeAc="MI:0358" refType="primary-reference" id="14755292" dbAc="MI:0446" db="pubmed"/> </xref> </biologicalRole> <experimentalRoleList> <experimentalRole> <names> <shortLabel>neutral component</shortLabel> <fullName>neutral component</fullName> </names> <xref> <primaryRef refTypeAc="MI:0356" refType="identity" id="MI:0497" dbAc="MI:0488" db="psi-mi"/> <secondaryRef refTypeAc="MI:0356" refType="identity" id="EBI-55" dbAc="MI:0469" db="intact"/> <secondaryRef refTypeAc="MI:0358" refType="primary-reference" id="14755292" dbAc="MI:0446" db="pubmed"/> </xref> </experimentalRole> </experimentalRoleList> </participant> """ ems = dom.getElementsByTagName("interaction") connections = [] nodeCount = 0 for em in ems: #interactions.append(interaction) participants = em.getElementsByTagName("participant") con_nodes = [] for p in participants: node = Node() node.network = network._id nodeCount+=1 node._id = "node%s_%d" %(node.network[4:], nodeCount) node.role = getText(p, "biologicalRole", "names", "shortLabel") #node.refs['intact'] = p.getAttribute("id") setPrimaryRef(p, node) ref = getText(p, 'interactorRef') if ref: node.refs['entity'] = ref # temporary con_nodes.append(node) connection = Connection() connection._id = "conn_intact_%s" % em.getAttribute("id") connection.refs={} setPrimaryRef(em, connection) connection.type=getText( em.getElementsByTagName("interactionType")[0], 'shortLabel') connection.label = getText(em,'shortLabel') connection.network = network._id connection.nodes = con_nodes connections.append(connection) network.connections = connections
def load(self): self.columnIndexes = {} headers = self.rows.next() for i in range (len(headers)): col = headers[i] if col not in SUPPORTED_COLUMNS: raise Exception("Invalid column: %s. Accepted columns are: %s" %(col, SUPPORTED_COLUMNS)) self.columnIndexes[col] = i #networks, connections, entities, nodes entities = {} nodes = {} networks = {} for row in self.rows: entityA = None dbid = self.getCol('NodeA_DBID',row ) if dbid: dbid = dbid.lower() _id = 'enti_%s' %dbid if _id not in entities: entityA = Entity() entityA._id = _id entityA.dbref = {} pair = dbid.split(':') if(len(pair)!=2): self._error("Invalid NodeA_DBID: %s" %dbid) continue entityA.dbref[pair[0]] = pair[1] entityA.group = self.getCol('NodeA_Category',row) #entity.label = 'Metformin' entityA.name = self.getCol('NodeA',row) entities[_id] = entityA else: entityA=entities[_id] #Node B entityB = None dbid = self.getCol('NodeB_DBID',row, False) if dbid: dbid = dbid.lower() _id = 'enti_%s' %dbid if _id not in entities: entityB = Entity() entityB._id = _id entityB.dbref = {} pair = dbid.split(':') if(len(pair)!=2): self._error("Invalid NodeB_DBID: %s" %dbid) continue entityB.dbref[pair[0].strip()] = pair[1].strip() entityB.group = self.getCol('NodeB_Category',row) #entity.label = 'Metformin' entityB.name = self.getCol('NodeB' ,row ) entities[_id] = entityB else: entityB = entities[_id] edgeType = self.getCol('Edge',row, False) if not edgeType: continue con = Connection() con.type = edgeType nodeA = nodes[entityA._id] if entityA._id in nodes else self.newNode(entityA) nodeB = nodes[entityB._id] if entityB._id in nodes else self.newNode(entityB) nodes[entityA._id] = nodeA nodes[entityB._id] = nodeB con.entities=[entityA._id, entityB._id] # this is for search con.nodes = [nodeA._id, nodeB._id] con._nodes = [nodeA, nodeB] con.refs = {} edgeRefs = self.getCol('Edge_Ref',row, False) if edgeRefs: # comma separated pairs = edgeRefs.split(",") if len(pairs) == 1: pairs = edgeRefs.split("\n") for p in pairs: pair = p.split(':') refs = pair[1].split(';') if len(refs) == 1: refs = pair[1] con.refs[pair[0].lower().strip()] = refs networkName = self.getCol('Network',row) or 'DEFAULT' network = networks[networkName] if networkName in networks else Network() network.name = networkName network.owner='peop_precon' networks[networkName] = network network._connections = network._connections or [] network._connections.append(con) con.network = network._id con.owner='precon' #TBD, error return networks, self.errors
def parseInteractions(dom, network): """ <interaction id="678614" imexId="IM-12113-2"> <names> <shortLabel>pf1130-pf1128-2</shortLabel> <fullName>Affinity purification by hydroxy apatite chromatography</fullName> </names> <xref> <primaryRef refTypeAc="MI:0356" refType="identity" id="EBI-2507294" dbAc="MI:0469" db="intact"/> <secondaryRef refType="imex source" id="MI:0469" dbAc="MI:0488" db="psi-mi"/> <secondaryRef refTypeAc="MI:0662" refType="imex-primary" id="IM-12113-2" dbAc="MI:0670" db="imex"/> </xref> <experimentList> <experimentRef>678502</experimentRef> </experimentList> <participantList> <participant id="678615"> <names> <shortLabel>n/a</shortLabel> </names> <xref> <primaryRef refTypeAc="MI:0356" refType="identity" id="EBI-2507299" dbAc="MI:0469" db="intact"/> </xref> <interactorRef>678518</interactorRef> <biologicalRole> <names> <shortLabel>unspecified role</shortLabel> <fullName>unspecified role</fullName> </names> <xref> <primaryRef refTypeAc="MI:0356" refType="identity" id="MI:0499" dbAc="MI:0488" db="psi-mi"/> <secondaryRef refTypeAc="MI:0356" refType="identity" id="EBI-77781" dbAc="MI:0469" db="intact"/> <secondaryRef refTypeAc="MI:0358" refType="primary-reference" id="14755292" dbAc="MI:0446" db="pubmed"/> </xref> </biologicalRole> <experimentalRoleList> <experimentalRole> <names> <shortLabel>neutral component</shortLabel> <fullName>neutral component</fullName> </names> <xref> <primaryRef refTypeAc="MI:0356" refType="identity" id="MI:0497" dbAc="MI:0488" db="psi-mi"/> <secondaryRef refTypeAc="MI:0356" refType="identity" id="EBI-55" dbAc="MI:0469" db="intact"/> <secondaryRef refTypeAc="MI:0358" refType="primary-reference" id="14755292" dbAc="MI:0446" db="pubmed"/> </xref> </experimentalRole> </experimentalRoleList> </participant> """ ems = dom.getElementsByTagName("interaction") connections = [] nodeCount = 0 for em in ems: #interactions.append(interaction) participants = em.getElementsByTagName("participant") con_nodes = [] for p in participants: node = Node() node.network = network._id nodeCount += 1 node._id = "node%s_%d" % (node.network[4:], nodeCount) node.role = getText(p, "biologicalRole", "names", "shortLabel") #node.refs['intact'] = p.getAttribute("id") setPrimaryRef(p, node) ref = getText(p, 'interactorRef') if ref: node.refs['entity'] = ref # temporary con_nodes.append(node) connection = Connection() connection._id = "conn_intact_%s" % em.getAttribute("id") connection.refs = {} setPrimaryRef(em, connection) connection.type = getText( em.getElementsByTagName("interactionType")[0], 'shortLabel') connection.label = getText(em, 'shortLabel') connection.network = network._id connection.nodes = con_nodes connections.append(connection) network.connections = connections