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

Commit 26bdf570 authored by Aishwarya Alex's avatar Aishwarya Alex
Browse files

restrucred code, class

parent d67b9503
......@@ -4,4 +4,5 @@ abundance_GOCCTERM PHENOTYPE
abundance_GOCCACC PHENOTYPE
abundance_MESHCL PHENOTYPE
abundance_CHEBIID SIMPLE_MOLECULE
abundance_GO PHENOTYPE
\ No newline at end of file
abundance_GO PHENOTYPE
abundance_HGNC PROTEIN
\ No newline at end of file
catalyticActivity urn:miriam:go:GO:0003824
chaperoneActivity urn:miriam:go:GO:1903332
gtpBoundActivity urn:miriam:go:GO:0008277
chaperoneActivity urn:miriam:go:GO:1903332
kinaseActivity urn:miriam:go:GO:0016301
peptidaseActivity urn:miriam:go:GO:0008233
phosphataseActivity urn:miriam:go:GO:0016791
ribosylationActivity urn:miriam:go:GO:1990404
transcriptionalActivity urn:miriam:go:GO:0006355
transportActivity urn:miriam:go:GO:0005215
degradation urn:miriam:go:GO:0009056
\ No newline at end of file
......@@ -3,10 +3,8 @@ RGD urn:miriam:rgd.symbol
MGI urn:miriam:mgi.symbol
PubMed urn:miriam:pubmed
GO urn:miriam:go
MESHPP urn:miriam:mesh.2012
MESHCL urn:miriam:mesh.2012
MESHD urn:miriam:mesh.2012
MESH urn:miriam:mesh.2012
CHEBIID urn:miriam:chebi:CHEBI
CHEBI urn:miriam:chebi:CHEBI
GOCCTERM urn:miriam:go
\ No newline at end of file
GOCCTERM urn:miriam:go
ENSMBL urn:miriam:ensembl
\ No newline at end of file
......@@ -4,5 +4,4 @@ directlyDecreases NEGATIVE_INFLUENCE
decreases UNKNOWN_NEGATIVE_INFLUENCE
positiveCorrelation UNKNOWN_REDUCED_MODULATION
negativeCorrelation UNKNOWN_REDUCED_MODULATION
complexAbundance COMPLEX
translocation TRANSPORT
\ No newline at end of file
......@@ -4,10 +4,10 @@
# description :functions to translate namespaces : BEL to miriam URN
# author :Aishwarya Alex
# date :20160428
# version :0.1
# version :0.2
# usage :python pyscript.py
# notes :
# python_version :2.7.10
# python_version :2.7.10 /3.5.2
##############################################################################################
# Import the modules needed to run the script.
......
......@@ -3,10 +3,10 @@
# title :xBEL2CellD.py
# description :This script will generate 2 tab delimited files(reactions.txt, nodes.txt) from an .XBEL file
# author :Aishwarya Alex
# version :0.1
# version :0.2
# usage :python pyscript.py
# notes :
# python_version :2.7.10
# python_version :2.7.10 /3.5.2
##############################################################################################
# Import the modules needed to run the script.
......@@ -27,13 +27,6 @@ class xBEL2CellD:
self.reflect_client = reflectclient.ReflectClient()
# # Get meshID from reflect
# def getMeshIDfromTerm(self, term):
# mesh_id = term
# mDict = self.mDict
# mesh_id = mDict[term.lower()] if mDict.has_key(term.lower()) is True else term
# return mesh_id
# func to get parameters(function, name and namespace) for elements (any node SUBJECT,OBJECT, MODIFIER(if nested))
def get_details_from_node(self,speciesMap, node):
......@@ -41,7 +34,15 @@ class xBEL2CellD:
returnVal = []
term = node.find(self.ns_tag("term"))
leafTerm = self.get_leafTerm(term)
nestedDict = self.NT.getDict("inputs/belSpeciesNestedAnnotationsDictFile.txt")
nodeEntry = self.get_entry_for_term(leafTerm)
if leafTerm !=term:
element = term.get(self.ns_tag('function')) if term.get(self.ns_tag('function')) is not None else ""
elementAnno=nestedDict.get(element)
if elementAnno is not None:
nodeEntry=nodeEntry+"\t"+elementAnno
else:
self.check_to_add_in_file(element, "outputs/additional/skippedLevels.txt")
returnVal = self.getSpecies(nodeEntry, speciesMap) # add entry or retrieve existing Id
return returnVal
except Exception as detailsEx:
......@@ -73,6 +74,7 @@ class xBEL2CellD:
else:
# add not handled entity to file
self.check_to_add_in_file(element, "outputs/additional/toMapEntities.txt")
elementName="abundance"
# check for abundance element name from namespace
if element == "abundance" or belnamespace == "":
......@@ -213,7 +215,6 @@ class xBEL2CellD:
element = term.get(self.ns_tag('function')) if term.get(self.ns_tag("function")) is not None else None
parameter = term.find(self.ns_tag("parameter")) if term.find(self.ns_tag("parameter")) is not None else None
if element is not None and parameter is None:
self.check_to_add_in_file(element, "outputs/additional/skippedLevels.txt")
nextTerm = term.find(self.ns_tag("term"))
return self.get_leafTerm(nextTerm)
return leafterm
......@@ -246,12 +247,11 @@ class xBEL2CellD:
print(filepath)
nodeFile = "outputs/nodes.txt"
nFile = open(nodeFile, "w")
nFile.write("IDENTIFIER\tTYPE\tNAME\tURN\n")
nFile.write("IDENTIFIER\tTYPE\tNAME\tURN\tANNOTATIONS\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.close()
try:
tree = ET.parse(filepath)
......@@ -271,6 +271,7 @@ class xBEL2CellD:
speciesMap = {}
# get all statement nodes, annotation and sub nodes (complex, or composite structures)
reactionIdentifier = 0
belStatementNumber=0
expStatementFile = "outputs/additional/exceptionalStatements.txt"
file = open(expStatementFile, 'w')
file.write("GROUP|STATEMENT_NUMBER|RELATIONSHIP|EVIDENCE\n")
......@@ -281,7 +282,7 @@ class xBEL2CellD:
print("\n\n\n############################################")
print("GROUP" + str(index + 1) + " :: STATEMENT " + str(statement_num + 1))
print("############################################")
reactionIdentifier += 1 # statement number
belStatementNumber += 1 # statement number
##annotation for evidence statement: pubmedid, journal, evidence , species , cellLine
annoGroup = statement.find(self.ns_tag('annotationGroup'))
......@@ -300,7 +301,7 @@ 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 = species + "\t" + disease + "\t" + cell + "\t" + tissue + "\t" + cellstructure + "\t" + cellline
annoEntry = disease + "\t" + cell + "\t" + tissue + "\t" + cellstructure + "\t" + cellline
keyList = list(annoMap.keys())
otherKeys = set(keyList) - set(['SPECIES', 'DISEASE', 'CELL', 'TISSUE', 'CELLSTRUCTURE', 'CELLLINE'])
# print otherKeys
......@@ -316,60 +317,31 @@ class xBEL2CellD:
object = statement.find(self.ns_tag("object"))
nested = object.find(self.ns_tag("statement")) if object is not None else None
# IF RELATIONSHIP IS MEPTY, check for subject node type is reaction
# 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'))
print("------RELATIONSHIP------\n" + relationship)
# entityDict = NT.getdict("inputs/EntityDictFile.txt")
# OBJECT IS NOT NONE : Statement has atleast reactnat and product
if object is not None:
if nested is not None:
# print "Get modifier, subject and object"
try:
modObject = subject
subject = nested.find(self.ns_tag("subject"))
object = nested.find(self.ns_tag("object"))
modifierType = relationship
relationship = nested.get(self.ns_tag("relationship")) # if nested.get(ns_tag("relationship")) is not None else "complexAbundance")
print("MODIFIER :")
returnedVal = self.get_details_from_node(speciesMap, modObject)
speciesMap = returnedVal[1]
modifier = returnedVal[0]
except Exception as nestedException:
print("!!! EXCEPTION in nested statement!!!")
print(" !!!EXCEPTION!!! : " + str(nestedException.args))
f = open(expStatementFile, 'a')
f.write(
str(index) + "|" + str(statement_num) + "|" + str(
relationship) + "|" + evidence + "\n")
f.write(" !!!EXCEPTION!!! : " + str(
nestedException.args) + "==================================\n")
f.close()
# exit()
# REACTANT AND PRODUCTS
print("REACTANT :")
returnedVal = self.get_details_from_node(speciesMap, subject)
speciesMap = returnedVal[1]
reactant = returnedVal[0]
print("PRODUCT :")
returnedVal = self.get_details_from_node(speciesMap, object)
speciesMap = returnedVal[1]
product = returnedVal[0]
# if reaction is ComplexAbundance
elif relationship == "complexAbundance":
relationship = reactionDict[relationship]
complexTerms = subject.find(self.ns_tag('term')).findall(self.ns_tag('term'))
complexList = []
for each in complexTerms:
nodeEntry = self.get_entry_for_term(each)
returnedVal = self.getSpecies(nodeEntry, speciesMap)
complexList.append(returnedVal[0])
# print "Handle complex"
reactant = ','.join(complexList)
alreadyIn = [line.strip() for line in open("outputs/additional/toMapReactions.txt", "r")]
if relationship not in alreadyIn:
f = open("outputs/additional/toMapReactions.txt", "a")
f.write(relationship + "\n")
f.close()
# if reaction is ComplexAbundance
if relationship == "complexAbundance":
complexTerms = subject.find(self.ns_tag('term')).findall(self.ns_tag('term'))
complexList = []
for each in complexTerms:
nodeEntry = self.get_entry_for_term(each)
returnedVal = self.getSpecies(nodeEntry, speciesMap)
complexList.append(returnedVal[0])
# print "Handle complex"
reactant = ','.join(complexList)
f = open(expStatementFile, 'a')
f.write("RELATIONSHIP: " + str(relationship) + "|" + evidence + "\n")
reactionEntry = "BEL statement number: " + str(belStatementNumber) + "\nReactant: " + reactant + "\nProduct: " + product + "\n" + referenceType + ":" + reference + "\n###########################\n"
f.write(reactionEntry)
f.close()
# Do nothing --ignore standalone complex node
continue
# if reaction is reaction: then get list of reactnats and products
elif relationship == 'reaction':
......@@ -394,25 +366,84 @@ class xBEL2CellD:
productList.append(returnedVal[0])
print("Handle complex")
product = ','.join(productList)
f = open(expStatementFile, 'a')
f.write("RELATIONSHIP: "+str(relationship) + "|" + evidence + "\n")
reactionEntry = "BEL statement number: " + str(belStatementNumber) + "\nReactant: " + reactant + "\nProduct: " + product + "\n" + referenceType + ":" + reference + "\n###########################\n"
f.write(reactionEntry)
f.close()
# Do nothing --not translatable
continue
print("REACTION : ")
if modifierType in list(reactionDict.keys()):
modifierType = reactionDict[modifierType]
if relationship in list(reactionDict.keys()):
relationship = reactionDict[relationship]
else:
alreadyIn = [line.strip() for line in open("outputs/additional/toMapReactions.txt", "r")]
if relationship not in alreadyIn:
f = open("outputs/additional/toMapReactions.txt", "a")
f.write(relationship + "\n")
f.close()
reactionEntry = "r" + str(
reactionIdentifier) + "\t" + relationship + "\t" + reactant + "\t" + modifier + "\t" + product + "\t" + modifierType + "\t" + referenceType + ":" + reference + "\t" + species + "\t" + annoEntry + "\t" + str(
otherAnnotation) + "\n"
print(reactionEntry)
reactionFile = open("outputs/reactions.txt", 'a')
reactionFile.write(reactionEntry)
reactionFile.close()
print("------RELATIONSHIP------\n" + relationship)
# entityDict = NT.getdict("inputs/EntityDictFile.txt")
# OBJECT IS NOT NONE : Statement has at least reactant and product
if object is not None:
if nested is not None:
# print "Get modifier, subject and object"
try:
modObject = subject
subject = nested.find(self.ns_tag("subject"))
object = nested.find(self.ns_tag("object"))
modifierType = relationship
relationship = nested.get(self.ns_tag("relationship")) # if nested.get(ns_tag("relationship")) is not None else "complexAbundance")
print("MODIFIER :")
returnedVal = self.get_details_from_node(speciesMap, modObject)
speciesMap = returnedVal[1]
modifier = returnedVal[0]
except Exception as nestedException:
print("!!! EXCEPTION in nested statement!!!")
print(" !!!EXCEPTION!!! : " + str(nestedException.args))
f = open(expStatementFile, 'a')
f.write("RELATIONSHIP: " + str(relationship) + "|" + evidence + "\n")
reactionEntry = "BEL statement number: " + str( belStatementNumber) + "\nReactant: " + reactant + "\nProduct: " + product + "\n" + referenceType + ":" + reference + "\n###########################\n"
f.write(reactionEntry)
f.close()
# exit()
# REACTANT AND PRODUCTS
print("REACTANT :")
returnedVal = self.get_details_from_node(speciesMap, subject)
speciesMap = returnedVal[1]
reactant = returnedVal[0]
print("PRODUCT :")
returnedVal = self.get_details_from_node(speciesMap, object)
speciesMap = returnedVal[1]
product = returnedVal[0]
print("REACTION : ")
if modifierType in list(reactionDict.keys()):
modifierType = reactionDict[modifierType]
if relationship in list(reactionDict.keys()):
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" + annoEntry + "\t" + str(
otherAnnotation) + "\n"
print(reactionEntry)
reactionFile = open("outputs/reactions.txt", 'a')
reactionFile.write(reactionEntry)
reactionFile.close()
else:
alreadyIn = [line.strip() for line in open("outputs/additional/toMapReactions.txt", "r")]
if relationship not in alreadyIn:
f = open("outputs/additional/toMapReactions.txt", "a")
f.write(relationship + "\n")
f.close()
f = open(expStatementFile, 'a')
f.write("RELATIONSHIP: " + str(relationship) + "|" + evidence + "\n")
reactionEntry = "BEL statement number: " + str(belStatementNumber) + "\nReactant: " + reactant + "\nProduct: " + product + "\n" + referenceType + ":" + reference + "\n###########################\n"
f.write(reactionEntry)
f.close()
continue
print("#########################################################################################################\n")
print("Total BEL Statements: "+str(belStatementNumber))
print("\nTotal statements converted to reaction: "+str(reactionIdentifier))
except Exception as ex:
print(" !!!EXCEPTION!!! : " + str(ex.args))
f = open(expStatementFile, 'a')
......
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