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

Commit f62aa697 authored by Aishwarya Alex's avatar Aishwarya Alex
Browse files

Working for APPBEL (removed binary characters from .bel and nested...

Working for APPBEL (removed binary characters from .bel and nested association(split to 2 senetnces)
parent 7701705d
......@@ -109,7 +109,7 @@ def get_details_from_element(node, index, statement_num, evidence, expStatementF
f.write(element + "\n")
f.close()
if parameter is not None:
belnamespace = parameter.get(ns_tag("ns"))
belnamespace = parameter.get(ns_tag("ns"))if parameter.get(ns_tag("ns")) is not None else ""
namespaceDict = NT.getNamespaceDict()
miriamnamespace = belnamespace
if namespaceDict.has_key(belnamespace):
......@@ -158,6 +158,7 @@ def get_details_from_element(node, index, statement_num, evidence, expStatementF
def convertXBEL(filepath):
# create new output file 1.nodes.txt 2.reactions.txt
print filepath
nodeFile = "outputs/nodes.txt"
nFile = open(nodeFile, "w")
nFile.write("IDENTIFIER\tTYPE\tNAME\tURN\tSPECIES\tDISEASE\tCELL\tTISSUE\tCELLSTRUCTURE\tCELLLINE\tOTHER_ANNOTATION\n")
......@@ -166,36 +167,37 @@ def convertXBEL(filepath):
rFile = open(reactionFile, "w")
rFile.write("IDENTIFIER\tTYPE\tREACTANTS\tMODIFIERS\tPRODUCTS\tMODIFIER_TYPE\tSPECIES\tANNOTATIONS\n")
rFile.close()
tree = ET.parse(filepath)
root = tree.getroot()
# create new files
f = open("outputs/additional/toMapEntities.txt", "w")
f.close()
f = open("outputs/additional/toMapReactions.txt", "w")
f.close()
# LOAD namespace DIctionary
namespaceDict = NT.getNamespaceDict()
reactionDict = NT.getReactionDict()
# get all statement nodes, annotation and sub nodes (complex, or composite structures)
reactionIdentifier = 0
totalSpecies = 0
expStatementFile = "outputs/additional/exceptionalStatements.txt"
file = open(expStatementFile, 'w')
file.write("GROUP|STATEMENT_NUMBER|DETAILS|NODEINFO|EVIDENCE\n")
file.close()
evidence = ""
speciesMap={}
for index, statementGr in enumerate(root.iter(tag=ns_tag('statementGroup'))):
for statement_num, statement in enumerate(statementGr.findall(ns_tag('statement'))):
print "\n\n\n############################################"
print "GROUP" + str(index + 1) + " :: STATEMENT " + str(statement_num + 1) + " \t\t\t**" + str(reactionIdentifier)
print "############################################"
reactionIdentifier += 1 # statement number
try:
try:
tree = ET.parse(filepath)
root = tree.getroot()
# create new files
f = open("outputs/additional/toMapEntities.txt", "w")
f.close()
f = open("outputs/additional/toMapReactions.txt", "w")
f.close()
# LOAD namespace DIctionary
namespaceDict = NT.getNamespaceDict()
reactionDict = NT.getReactionDict()
# get all statement nodes, annotation and sub nodes (complex, or composite structures)
reactionIdentifier = 0
totalSpecies = 0
expStatementFile = "outputs/additional/exceptionalStatements.txt"
file = open(expStatementFile, 'w')
file.write("GROUP|STATEMENT_NUMBER|DETAILS|NODEINFO|EVIDENCE\n")
file.close()
evidence = ""
speciesMap={}
for index, statementGr in enumerate(root.iter(tag=ns_tag('statementGroup'))):
for statement_num, statement in enumerate(statementGr.findall(ns_tag('statement'))):
print "\n\n\n############################################"
print "GROUP" + str(index + 1) + " :: STATEMENT " + str(statement_num + 1) + " \t\t\t**" + str(reactionIdentifier)
print "############################################"
reactionIdentifier += 1 # statement number
##annotation for evidence statement: pubmedid, journal, evidence , species , cellLine
annoGroup = statement.find(ns_tag('annotationGroup'))
# get_node_info_recursive(annoGroup)
......@@ -204,6 +206,7 @@ def convertXBEL(filepath):
evidence = annoGroup.find(ns_tag("evidence")).text if annoGroup is not None else evidence
citation = annoGroup.find(ns_tag("citation")) if annoGroup is not None else citation
referenceType = citation.get(ns_tag("type")) if annoGroup is not None else referenceType
referenceType=namespaceDict.get(referenceType) if namespaceDict.get(referenceType) is not None else referenceType
reference = citation.find(ns_tag("reference")).text if annoGroup is not None else reference
annoMap = get_annotation_details(annoGroup) if annoGroup is not None else annoMap
species = getAnnoElement(annoMap, "SPECIES")
......@@ -215,7 +218,7 @@ def convertXBEL(filepath):
annoEntry = species + "\t" + disease + "\t" + cell + "\t" + tissue + "\t" + cellstructure + "\t" + cellline
keyList = annoMap.keys()
otherKeys = set(keyList) - set(['SPECIES', 'DISEASE', 'CELL', 'TISSUE', 'CELLSTRUCTURE', 'CELLLINE'])
print otherKeys
#print otherKeys
otherAnnotation = [each + ":" + annoMap[each] for each in otherKeys]
print "EVIDENCE: " + evidence
print "------RELATIONSHIP------\n" + relationship
......@@ -293,7 +296,7 @@ def convertXBEL(filepath):
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" + species+"\t"+ namespaceDict[referenceType] + ":" + reference + "\n"
reactionEntry = "r" + str(reactionIdentifier) + "\t" + relationship + "\t" + reactant + "\t" + modifier + "\t" + product + "\t" + modifierType + "\t" + species+"\t"+ referenceType + ":" + reference + "\n"
print reactionEntry
rFile = open(reactionFile, "a")
rFile.write(reactionEntry)
......@@ -301,12 +304,13 @@ def convertXBEL(filepath):
rFile.close()
# if reactionIdentifier==25:
# exit()
except Exception as ex:
print " !!!EXCEPTION!!! : " + str(ex)
except Exception as ex:
print " !!!EXCEPTION!!! : " + str(ex.args)
exit()
exit()
# Convert file
# /home/alex/PhD/Bel2CellD/full_abstract3.xbel
convertXBEL('/home/alex/PhD/Bel2CellD/small_corpus.xbel')
#/home/alex/PhD/Bel2CellD/small_corpus.xbel
convertXBEL('/home/alex/PhD/APP/Aetionomy_AD.xbel')
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