Gitlab is now using https://gitlab.lcsb.uni.lu as it's primary address. Please update your bookmarks. FAQ.

Commit 678cfb3f authored by Aishwarya Alex's avatar Aishwarya Alex
Browse files

Location information with nodes

parent a8604901
......@@ -14,7 +14,7 @@
from future.standard_library import install_aliases
install_aliases()
import reflectclient, os, urllib, sqlite3, requests,logging,re
import reflectclient, os, urllib, sqlite3, requests,logging,re,codecs
from io import open
from reflectclient.config import EntityType
from SPARQLWrapper import SPARQLWrapper, JSON
......@@ -74,6 +74,22 @@ class namespaceTranslator:
meshResult = result['results']['bindings'][0]['d']['value'].split("/")[-1]
meshID = meshResult if meshResult is not None else None
return meshID
def get_locationMap_from_mapping_file(self,filename):
mergeDict={}
locationMap={}
locFile=open(filename,'r')
for line in locFile:
locList=line.strip("\n").split("\t")
term=locList[0]
locationType=locList[1]
mergeTerm=locList[2]
if mergeTerm!="":
mergeDict[term]=mergeTerm
else:
locationMap[term]=locationType
locationMapList=[mergeDict,locationMap]
return locationMapList
def getDict(self, filename):
dict = {}
......@@ -382,6 +398,7 @@ class namespaceTranslator:
logging.info(ex, ex.args)
# NT= namespaceTranslator()
#NT= namespaceTranslator()
# NT.getChemicalTermfromCHEBIID("26523")
# logging.info (NT.getMeshIDfromdb(NT.meshCursor,"insomnia"))
This diff is collapsed.
This diff is collapsed.
......@@ -26,7 +26,7 @@ class xBEL2CellD:
self.meshCursor=self.NT.meshCursor
self.reflect_client = reflectclient.ReflectClient()
self.nodeDict={}
self.nodeFrame=pandas.DataFrame(columns=['IDENTIFIER','TYPE','NAME','URN','ANNOTATIONS','LOCATION','CELL','TISSUE','CELLSTRUCTURE','CELLLINE','OTHER_ANNOTATION'])
#self.nodeFrame=pandas.DataFrame(columns=['IDENTIFIER','TYPE','NAME','URN','ANNOTATIONS','CELL','TISSUE','COMPARTMENT','OTHER_ANNOTATION'])
......@@ -267,8 +267,9 @@ class xBEL2CellD:
nodeFile.close()
nodeEntry.strip("\n")
nodeInfoList=nodeEntry.split("\t")
if len(nodeInfoList)==11:
self.nodeFrame=self.nodeFrame.append(nodeInfoList,ignore_index=True)
if len(nodeInfoList)==9:
#self.nodeFrame=self.nodeFrame.append(nodeInfoList,ignore_index=True)
logging.info("Node columns matching")
else:
logging.info("Number of column entries less than expected!!")
exit()
......@@ -284,11 +285,13 @@ class xBEL2CellD:
logging.info(filepath)
nodeFile = "outputs/nodes.txt"
nFile = open(nodeFile, "w")
nFile.write("IDENTIFIER\tTYPE\tNAME\tURN\tANNOTATIONS\tLOCATION\tCELL\tTISSUE\tCELLSTRUCTURE\tCELLLINE\tOTHER_ANNOTATION\n")
#nFile.write("IDENTIFIER\tTYPE\tNAME\tURN\tANNOTATIONS\tLOCATION\tCELL\tTISSUE\tCELLSTRUCTURE\tCELLLINE\tOTHER_ANNOTATION\n")
nFile.write("IDENTIFIER\tTYPE\tNAME\tURN\tANNOTATIONS\tCELL\tTISSUE\tCOMPARTMENT\tOTHER_ANNOTATION\n")
nFile.close()
reactionFile = "outputs/reactions.txt"
rFile = open(reactionFile, "w")
rFile.write("IDENTIFIER\tTYPE\tREACTANTS\tMODIFIERS\tPRODUCTS\tMODIFIER_TYPE\tREFERNCE\tSPECIES\tDISEASE\tCELL\tTISSUE\tCELLSTRUCTURE\tCELLLINE\tOTHER_ANNOTATION\n")
#rFile.write("IDENTIFIER\tTYPE\tREACTANTS\tMODIFIERS\tPRODUCTS\tMODIFIER_TYPE\tREFERNCE\tSPECIES\tDISEASE\tCELL\tTISSUE\tCELLSTRUCTURE\tCELLLINE\tOTHER_ANNOTATION\n")
rFile.write("IDENTIFIER\tTYPE\tREACTANTS\tMODIFIERS\tPRODUCTS\tMODIFIER_TYPE\tREFERENCE\tSPECIES\tDISEASE\tCELL\tTISSUE\tCOMPARTMENT\tOTHER_ANNOTATION\n")
rFile.close()
try:
tree = ET.parse(filepath)
......@@ -304,6 +307,11 @@ class xBEL2CellD:
# LOAD namespace DIctionary
namespaceDict = self.NT.getDict("inputs/namespaceDictFile.txt")
reactionDict = self.NT.getDict("inputs/reactionDictFile.txt")
l = self.NT.get_locationMap_from_mapping_file("inputs/location_mapping.txt")
mergeMap = l[0]
locationTypeMap = l[1]
# create dictionary for species
speciesMap = {}
# get all statement nodes, annotation and sub nodes (complex, or composite structures)
......@@ -338,7 +346,20 @@ class xBEL2CellD:
tissue = self.get_annotation_from_element(annoMap, "TISSUE")
cellline = self.get_annotation_from_element(annoMap, "CELLLINE")
cellstructure = self.get_annotation_from_element(annoMap, "CELLSTRUCTURE")
annoEntry = cell + "\t" + tissue + "\t" + cellstructure + "\t" + cellline
compartment_f=""
cell_f=""
tissue_f=""
for each in (cell, cellstructure, cellline, tissue):
term=mergeMap[each] if each in mergeMap.keys() else each
locType=locationTypeMap[term] if term in locationTypeMap.keys() else ""
if locType=="COMPARTMENT":
compartment_f=term if compartment_f =="" or compartment_f==term else compartment_f+";"+term
elif locType=="CELL":
cell_f=term if cell_f =="" or cell_f==term else cell_f+";"+term
elif locType=="TISSUE":
tissue_f=term if tissue_f =="" or tissue_f==term else tissue_f+";"+term
keyList = list(annoMap.keys())
otherKeys = set(keyList) - set(['SPECIES', 'DISEASE', 'CELL', 'TISSUE', 'CELLSTRUCTURE', 'CELLLINE'])
# logging.info otherKeys
......@@ -349,7 +370,7 @@ class xBEL2CellD:
# if each not in location:
# location.append(each)
# location=",".join(location)
location=""
logging.info("EVIDENCE: " + evidence)
reactant = ""
modifier = ""
......@@ -359,7 +380,6 @@ class xBEL2CellD:
subject = statement.find(self.ns_tag("subject"))
object = statement.find(self.ns_tag("object"))
nested = object.find(self.ns_tag("statement")) if object is not None else None
# IF RELATIONSHIP IS EMPTY, check for subject node type is reaction
if relationship is None:
relationship = subject.find(self.ns_tag('term')).get(self.ns_tag('function'))
......@@ -439,7 +459,7 @@ class xBEL2CellD:
object = nested.find(self.ns_tag("object"))
modifierType = "MODIFIER_"+relationship
relationship = nested.get(self.ns_tag("relationship"))
locationAnnotation = location + "\t" + annoEntry
locationAnnotation = cell_f + "\t" + tissue_f + "\t" + compartment_f
logging.info("MODIFIER :")
returnedVal = self.get_details_from_node(speciesMap, modObject,locationAnnotation,otherAnnotation)
speciesMap = returnedVal[1]
......@@ -461,7 +481,7 @@ class xBEL2CellD:
product = returnedVal[0]
reactionIdentifier += 1
reactionEntry = "r" + str(
reactionIdentifier) + "\t" + modifierType + "\t" + modifier + "\t" + "" + "\t" + reactant + "\t" + "" + "\t" + referenceType + ":" + reference + "\t" + species + "\t"+disease + "\t" + annoEntry + "\t" + ";".join(otherAnnotation) + "\n"
reactionIdentifier) + "\t" + modifierType + "\t" + modifier + "\t" + "" + "\t" + reactant + "\t" + "" + "\t" + referenceType + ":" + reference + "\t" + species + "\t"+disease + "\t" + locationAnnotation + "\t" + ";".join(otherAnnotation) + "\n"
logging.info(reactionEntry)
reactionFile = open("outputs/reactions.txt", 'a')
reactionFile.write(reactionEntry)
......@@ -489,7 +509,8 @@ class xBEL2CellD:
relationship="translocation"
modObject=subject
logging.info("MODIFIER : ")
locationAnnotation = location + "\t" + annoEntry
locationAnnotation = cell_f + "\t" + tissue_f + "\t" + compartment_f
returnedVal = self.get_details_from_node(speciesMap, modObject,locationAnnotation,otherAnnotation)
if returnedVal is None:
modifier=""
......@@ -500,13 +521,33 @@ class xBEL2CellD:
if len(locationList)==2:
logging.info("REACTANT :")
location=locationList[0].text
locationAnnotation = location + "\t" + annoEntry
term = mergeMap[location] if location in mergeMap.keys() else location
locType = locationTypeMap[term]
if locType == "COMPARTMENT":
compartment_f = term if compartment_f == "" or compartment_f == term else compartment_f + ";" + term
elif locType == "CELL":
cell_f = term if cell_f == "" or cell_f == term else cell_f + ";" + term
elif locType == "TISSUE":
tissue_f = term if tissue_f == "" or tissue_f == term else tissue_f + ";" + term
locationAnnotation=cell_f + "\t" + tissue_f + "\t" + compartment_f
# locationAnnotation = location + "\t" + annoEntry
returnedVal = self.get_details_from_node(speciesMap, translocationNode,locationAnnotation,otherAnnotation)
speciesMap = returnedVal[1]
reactant = returnedVal[0]
logging.info("PRODUCT :")
location = locationList[1].text
locationAnnotation = location + "\t" + annoEntry
term = mergeMap[location] if location in mergeMap.keys() else location
locType = locationTypeMap[term]
if locType == "COMPARTMENT":
compartment_f = term if compartment_f == "" or compartment_f == term else compartment_f + ";" + term
elif locType == "CELL":
cell_f = term if cell_f == "" or cell_f == term else cell_f + ";" + term
elif locType == "TISSUE":
tissue_f = term if tissue_f == "" or tissue_f == term else tissue_f + ";" + term
locationAnnotation = cell_f + "\t" + tissue_f + "\t" + compartment_f
returnedVal = self.get_details_from_node(speciesMap, translocationNode,locationAnnotation,otherAnnotation)
speciesMap = returnedVal[1]
product = returnedVal[0]
......@@ -525,14 +566,14 @@ class xBEL2CellD:
else:
# REACTANT AND PRODUCTS
logging.info("REACTANT :")
locationAnnotation = location + "\t" + annoEntry
locationAnnotation = cell_f + "\t" + tissue_f + "\t" + compartment_f
returnedVal = self.get_details_from_node(speciesMap, subject,locationAnnotation,otherAnnotation)
if returnedVal is None:
continue
speciesMap = returnedVal[1]
reactant = returnedVal[0]
logging.info("PRODUCT :")
locationAnnotation = location + "\t" + annoEntry
locationAnnotation = cell_f + "\t" + tissue_f + "\t" + compartment_f
returnedVal = self.get_details_from_node(speciesMap, object,locationAnnotation,otherAnnotation)
if returnedVal is None:
continue
......@@ -559,7 +600,7 @@ class xBEL2CellD:
relationship = reactionDict[relationship]
reactionIdentifier += 1
reactionEntry = "r" + str(
reactionIdentifier) + "\t" + relationship + "\t" + reactant + "\t" + modifier + "\t" + product + "\t" + modifierType + "\t" + referenceType + ":" + reference + "\t" + species + "\t"+disease +"\t" + annoEntry + "\t" +";".join(otherAnnotation) + "\n"
reactionIdentifier) + "\t" + relationship + "\t" + reactant + "\t" + modifier + "\t" + product + "\t" + modifierType + "\t" + referenceType + ":" + reference + "\t" + species + "\t"+disease +"\t" + locationAnnotation+ "\t" +";".join(otherAnnotation) + "\n"
logging.info(reactionEntry)
reactionFile = open("outputs/reactions.txt", 'a')
reactionFile.write(reactionEntry)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment