Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Aishwarya Alex
xBELtoCellD
Commits
26bdf570
Commit
26bdf570
authored
Feb 08, 2018
by
Aishwarya Alex
Browse files
restrucred code, class
parent
d67b9503
Changes
6
Hide whitespace changes
Inline
Side-by-side
inputs/abundanceEntity.txt
View file @
26bdf570
...
...
@@ -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
inputs/belSpeciesNestedAnnotationsDictFile.txt
0 → 100644
View file @
26bdf570
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
inputs/namespaceDictFile.txt
View file @
26bdf570
...
...
@@ -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
inputs/reactionDictFile.txt
View file @
26bdf570
...
...
@@ -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
namespaceTranslator.py
View file @
26bdf570
...
...
@@ -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.
...
...
xBEL2CellD.py
View file @
26bdf570
...
...
@@ -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
\t
TYPE
\t
NAME
\t
URN
\n
"
)
nFile
.
write
(
"IDENTIFIER
\t
TYPE
\t
NAME
\t
URN
\
t
ANNOTATIONS
\
n
"
)
nFile
.
close
()
reactionFile
=
"outputs/reactions.txt"
rFile
=
open
(
reactionFile
,
"w"
)
rFile
.
write
(
"IDENTIFIER
\t
TYPE
\t
REACTANTS
\t
MODIFIERS
\t
PRODUCTS
\t
MODIFIER_TYPE
\t
REFERNCE
\t
SPECIES
\t
DISEASE
\t
CELL
\t
TISSUE
\t
CELLSTRUCTURE
\t
CELLLINE
\t
OTHER_ANNOTATION
\n
"
)
rFile
.
write
(
"IDENTIFIER
\t
TYPE
\t
REACTANTS
\t
MODIFIERS
\t
PRODUCTS
\t
MODIFIER_TYPE
\t
REFERNCE
\t
SPECIES
\t
DISEASE
\t
CELL
\t
TISSUE
\t
CELLSTRUCTURE
\t
CELLLINE
\t
OTHER_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
(
"############################################"
)
reactionIdentifi
er
+=
1
# statement number
belStatementNumb
er
+=
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
M
EPTY, check for subject node type is reaction
# IF RELATIONSHIP IS E
M
PTY, 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
)
+
"
\n
Reactant: "
+
reactant
+
"
\n
Product: "
+
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
)
+
"
\n
Reactant: "
+
reactant
+
"
\n
Product: "
+
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
)
+
"
\n
Reactant: "
+
reactant
+
"
\n
Product: "
+
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
)
+
"
\n
Reactant: "
+
reactant
+
"
\n
Product: "
+
product
+
"
\n
"
+
referenceType
+
":"
+
reference
+
"
\n
###########################
\n
"
f
.
write
(
reactionEntry
)
f
.
close
()
continue
print
(
"#########################################################################################################
\n
"
)
print
(
"Total BEL Statements: "
+
str
(
belStatementNumber
))
print
(
"
\n
Total statements converted to reaction: "
+
str
(
reactionIdentifier
))
except
Exception
as
ex
:
print
(
" !!!EXCEPTION!!! : "
+
str
(
ex
.
args
))
f
=
open
(
expStatementFile
,
'a'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment