forked from RuleWorld/PyBioNetGen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponentGroups.py
More file actions
788 lines (712 loc) · 32.6 KB
/
componentGroups.py
File metadata and controls
788 lines (712 loc) · 32.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
from bionetgen.atomizer.utils import readBNGXML
import argparse
from collections import defaultdict
# from cStringIO import StringIO
from io import StringIO
from bionetgen.atomizer.utils import extractAtomic
from copy import deepcopy
import networkx as nx
def molecule2stateTuples(molecule):
"""
Receives a molecule structure, returns a tuple detailing the state of the contained states
"""
tupleList = []
for component in molecule.components:
componentDefinition = [component.name]
componentDefinition.append(1 if len(component.bonds) > 0 else 0)
componentDefinition.append(
"" if len(component.states) == 0 else component.activeState
)
tupleList.append(tuple(componentDefinition))
return tupleList
def extractCenterContext(rules, excludeReverse=False):
transformationCenter = []
transformationContext = []
transformationProduct = []
atomicArray = []
actionNames = []
label = []
doubleModificationRules = []
for idx, rule in enumerate(rules):
(
tatomicArray,
ttransformationCenter,
ttransformationContext,
tproductElements,
tactionNames,
tlabelArray,
) = extractAtomic.extractTransformations([rule], True)
if (
excludeReverse
and "_reverse_" in rule[0].label
and len([x for x in tactionNames if "ChangeCompartment" not in x]) > 1
):
continue
label.append(rule[0].label)
if len([x for x in tactionNames if "ChangeCompartment" not in x]) > 1:
doubleModificationRules.append(rule[0].label)
transformationCenter.append(ttransformationCenter)
transformationContext.append(ttransformationContext)
actionNames.append(tactionNames)
atomicArray.append(tatomicArray)
transformationProduct.append(tproductElements)
return (
label,
transformationCenter,
transformationContext,
transformationProduct,
atomicArray,
actionNames,
doubleModificationRules,
)
def askQuestions(inputfile, molecule, center, context=None):
_, rules, _ = readBNGXML.parseXML(inputfile)
ruleArray = []
contextArray = []
for idx, rule in enumerate(rules):
(
tatomicArray,
ttransformationCenter,
ttransformationContext,
tproductElements,
tactionNames,
tlabelArray,
) = extractAtomic.extractTransformations([rule], True)
if any(
[molecule in y and center in y for x in ttransformationCenter for y in x]
):
if context:
ruleArray.append(str(rule[0]).split(":")[0])
contextArray.append(
[
y
for x in ttransformationContext
for y in x
if context in y and molecule in y
]
)
else:
print(rule)
return ruleArray, contextArray
def getChemicalStates(rules):
"""
goes through a list of rules and creates a dictionary (molecules) of possible chemical states of its components
"""
chemicalStates = defaultdict(list)
for rule in rules:
for chemicalSet in [rule[0].reactants, rule[0].products]:
for chemical in chemicalSet:
for molecule in chemical.molecules:
stateTuple = molecule2stateTuples(molecule)
chemicalStates[molecule.name].append(stateTuple)
return chemicalStates
def patternsFromString(chemical):
patterndict = defaultdict(list)
chemicalString = str(chemical)
molecules = chemicalString.split(".")
for molecule in molecules:
partitions = molecule.split("(")
if "!" in partitions[1]:
componentName = partitions[1].split("!")[0]
patterndict[partitions[0]].append((componentName, 1, ""))
elif "~" in partitions[1]:
componentName = partitions[1].split("~")[0]
stateName = partitions[1].split("~")[1][:-1]
patterndict[partitions[0]].append((componentName, 0, stateName))
else:
componentName = partitions[1][:-1]
patterndict[partitions[0]].append((componentName, 0, ""))
return patterndict
def getRestrictedChemicalStates(labelArray, products, contexts, doubleAction):
"""
goes through a list of reaction center and their associated context and creates a dictionary of molecules
of possible chemical states
"""
# sortedChemicalStates = defaultdict(lambda: defaultdict(lambda: defaultdict(set)))
sortedChemicalStates = defaultdict(
lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
)
doubleActionDict = defaultdict(
lambda: defaultdict(
lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
)
)
for label, product, context in zip(labelArray, products, contexts):
# reaction centers are also the context for other reaction centers. We deal with them separately
if label in doubleAction:
pDict = defaultdict(list)
for referenceProduct in product:
for p in referenceProduct:
result = patternsFromString(p)
for molecule in result:
for pattern in result[molecule]:
pDict[molecule].append(pattern)
pDict2 = deepcopy(pDict)
for molecule in pDict:
for componentState in pDict[molecule]:
for componentState2 in [
x for x in pDict2[molecule] if x[0] != componentState[0]
]:
isActive1 = componentState[1] == 1 or componentState[2] not in [
"",
"0",
]
isActive2 = componentState2[1] == 1 or componentState2[
2
] not in ["", "0"]
moleculeName = molecule.split("%")[0]
doubleActionDict[moleculeName][componentState[0]][isActive1][
componentState2[0]
][isActive2].append(label)
for indvproduct, indvcontext in zip(product, context):
pDict = defaultdict(list)
cDict = defaultdict(list)
for p in indvproduct:
result = patternsFromString(p)
for molecule in result:
for pattern in result[molecule]:
pDict[molecule].append(pattern)
for c in indvcontext:
result = patternsFromString(c)
for molecule in result:
for pattern in result[molecule]:
cDict[molecule].append(pattern)
for molecule in pDict:
for componentState in pDict[molecule]:
# FIXME: This is to account for dimers where or places where there is more than one components with the same name. Truly this should be enother kind of classification
for componentState2 in [
x for x in cDict[molecule] if x[0] != componentState[0]
]:
sortedChemicalStates[molecule][componentState][
componentState2[0]
][componentState2[1:]].append(label)
# sortedChemicalStates[molecule][componentState][componentState2[0]].add(componentState2[1:])
return sortedChemicalStates, doubleActionDict
def sortChemicalStates(chemicalStates):
"""
sorts a dictionary of chemicalStates into a dictionary of molecules of chemicalStates
of their associated-same-molecule-components (and their states)
"""
sortedChemicalStates = defaultdict(lambda: defaultdict(lambda: defaultdict(set)))
for molecule in chemicalStates:
for stateInstance in chemicalStates[molecule]:
for componentState in stateInstance:
for componentState2 in stateInstance:
if componentState == componentState2:
continue
sortedChemicalStates[molecule][componentState][
componentState2[0]
].add(componentState2[1:])
return sortedChemicalStates
def isActive(state):
if state[0] == 1 or state[1] not in ["", "0"]:
return True
return False
def componentStateSize(molecules, moleculeName, componentName):
for molecule in molecules:
if molecule.name == moleculeName:
for component in molecule.components:
if component.name == componentName:
return max(2, len(component.states))
def analyzeDependencies(
componentStateCollection, state, moleculeName, molecules, dependencies
):
for componentName in componentStateCollection:
stateSize = componentStateSize(molecules, moleculeName, componentName)
if stateSize == len(componentStateCollection[componentName]):
dependencies[moleculeName]["independent"].add((state, componentName))
# print(moleculeName,state,componentName,componentStateCollection[componentName])
elif len(componentStateCollection[componentName]) == 1:
activeState = list(componentStateCollection[componentName])[0]
if isActive((state[1], state[2])) and isActive(activeState):
dependencies[moleculeName]["requirement"].add(
((componentName, activeState[0], activeState[1]), state)
)
elif isActive((state[1], state[2])) and not isActive(activeState):
dependencies[moleculeName]["nullrequirement"].add(
(((componentName, activeState[0], activeState[1])), state)
)
# elif (not isActive((state[1], state[2]))) and isActive(activeState):
# print(moleculeName, componentName,activeState,state)
# dependencies[moleculeName]['nullrequirement'].add(((state, (componentName, activeState[0], activeState[1]))))
def detectDependencies(stateDictionary, molecules):
dependencies = defaultdict(lambda: defaultdict(set))
preprocessing = defaultdict(lambda: defaultdict(dict))
# preprocess for dimer information
for moleculeName in stateDictionary:
parsedMoleculeName = moleculeName.split("%")[0]
# parsedMoleculeName = moleculeName
for state in stateDictionary[moleculeName]:
preprocessing[parsedMoleculeName][state].update(
stateDictionary[moleculeName][state]
)
for moleculeName in preprocessing:
for state in preprocessing[moleculeName]:
analyzeDependencies(
preprocessing[moleculeName][state],
state,
moleculeName,
molecules,
dependencies,
)
return dependencies
def reverseState(moleculeName, state, molecules):
for molecule in molecules:
if molecule.name == moleculeName:
for component in molecule.components:
if component.name == state[0]:
if len(component.states) <= 1:
if isActive(state[1:]):
return (state[0], 0, "")
else:
return (state[0], 1, "")
else:
if isActive(state[1:]):
return (state[0], 0, "0")
else:
return (
state[0],
0,
[x for x in component.states if x != "0"][0],
)
def getMutualExclusions(stateDictionary, molecules):
for molecule in stateDictionary:
stateDictionary[molecule]["exclusion"] = [
x
for x in stateDictionary[molecule]["nullrequirement"]
if (
reverseState(molecule, x[1], molecules),
reverseState(molecule, x[0], molecules),
)
in stateDictionary[molecule]["nullrequirement"]
]
stateDictionary[molecule]["nullrequirement"] = [
x
for x in stateDictionary[molecule]["nullrequirement"]
if x not in stateDictionary[molecule]["exclusion"]
]
def getMotifRelationships(stateDictionary, molecules):
motifDictionary = defaultdict(lambda: defaultdict(list))
for molecule in stateDictionary:
motifDictionary[molecule]["exclusion"] = set(
[
tuple(sorted([x[0][0], x[1][0]]))
for x in stateDictionary[molecule]["nullrequirement"]
if (
reverseState(molecule, x[1], molecules),
reverseState(molecule, x[0], molecules),
)
in stateDictionary[molecule]["nullrequirement"]
]
)
motifDictionary[molecule]["inclusion"] = set(
[
tuple(sorted([x[0][0], x[1][0]]))
for x in stateDictionary[molecule]["requirement"]
if (x[1], x[0]) in stateDictionary[molecule]["requirement"]
]
)
motifDictionary[molecule]["ordering"] = set(
[
tuple([x[0][0], x[1][0]])
for x in stateDictionary[molecule]["requirement"]
if (reverseState(molecule, x[1], molecules), x[0])
in stateDictionary[molecule]["nullrequirement"]
]
)
motifDictionary[molecule]["fullIndependence"] = set(
[
tuple(sorted([x[0][0], x[1]]))
for x in stateDictionary[molecule]["independent"]
if isActive(x[0][1:])
and any(
x[1] == y[0][0] and x[0][0] == y[1] and isActive(y[0][1:])
for y in stateDictionary[molecule]["independent"]
)
]
)
motifDictionary[molecule]["partialIndependence+"] = set(
[
tuple([x[0][0], x[1]])
for x in stateDictionary[molecule]["independent"]
if isActive(x[0][1:])
and any(
x[1] in y[1] and x[0][0] in y[0]
for y in stateDictionary[molecule]["requirement"]
)
]
)
motifDictionary[molecule]["partialIndependence-"] = set(
[
tuple([x[0][0], x[1]])
for x in stateDictionary[molecule]["independent"]
if isActive(x[0][1:])
and any(
x[1] in y[1] and x[0][0] in y[0]
for y in stateDictionary[molecule]["nullrequirement"]
)
]
)
motifDictionary[molecule]["repression"] = set(
[tuple([x[0], x[1]]) for x in stateDictionary[molecule]["repression"]]
)
return motifDictionary
def removeIndirectDependencies(dependencies, stateSpace, motifFlag=False):
"""
goes through the list of dependencies and search for those states that requires more than 1 condition.
If true, it will check if any of the set of prerequirements is a sufficient conditions for any of the other prerequirements
to be valid. If true it will remove those redundant prerequirements them
"""
relationship = "ordering" if motifFlag else "requirement"
indirect = defaultdict(set)
for molecule in dependencies:
for requirement in set([x[1] for x in dependencies[molecule][relationship]]):
prerequirements = [
x[0]
for x in dependencies[molecule][relationship]
if requirement == x[1]
]
# if a particular state has more than one requirement
if len(prerequirements) > 1:
candidateMolecules = [x for x in stateSpace.keys() if molecule in x]
relevantStateSpace = defaultdict(lambda: defaultdict(set))
for candidate in candidateMolecules:
for x in prerequirements:
if motifFlag:
for referenceCandidate in stateSpace[candidate]:
if x in referenceCandidate and isActive(
referenceCandidate
):
relevantStateSpace[x].update(
stateSpace[candidate][referenceCandidate]
)
else:
relevantStateSpace[x].update(
stateSpace[candidate][x]
) # = {x: stateSpace[molecule][x] for x in prerequirements}
for rsp in relevantStateSpace:
for partner in relevantStateSpace[rsp]:
partnerDefinition = list(relevantStateSpace[rsp][partner])
if motifFlag:
# is any single prerequirement a sufficient condition for any other other ones?
if (
len(partnerDefinition) == 1
and partner in prerequirements
and isActive(
(partnerDefinition[0][0], partnerDefinition[0][1])
)
):
# if so mark for deletion
indirect[molecule].add((partner, requirement))
else:
# is any single prerequirement a sufficient condition for any other other ones?
if (
len(partnerDefinition) == 1
and (
partner,
partnerDefinition[0][0],
partnerDefinition[0][1],
)
in prerequirements
):
# if so mark for deletion
indirect[molecule].add(
(
(
partner,
partnerDefinition[0][0],
partnerDefinition[0][1],
),
requirement,
)
)
for molecule in indirect:
for indirectDependency in indirect[molecule]:
dependencies[molecule][relationship].remove(indirectDependency)
def formatComponent(state, tense):
if state[0] == 1:
if tense == "past":
compStr = "be bound"
else:
compStr = "bind"
else:
compStr = "be in state {0}".format(state[1])
return compStr
def printDependencyLog(dependencies):
log = StringIO()
for molecule in dependencies:
for requirementType in dependencies[molecule]:
# if requirementType in ['independent']:
# continue
for baseMolecule in dependencies[molecule][requirementType]:
if requirementType == "requirement":
log.write(
"Molecule {0} needs component {1} to {2} for component {3} to {4}\n".format(
molecule,
baseMolecule[0][0],
formatComponent(baseMolecule[0][1:], "past"),
baseMolecule[1][0],
formatComponent(baseMolecule[1][1:], "present"),
)
)
elif requirementType == "exclusion":
log.write(
"In molecule {0} component {1} is mutually exclusive of component {2}\n".format(
molecule, baseMolecule[0][0], baseMolecule[1][0]
)
)
if requirementType == "nullrequirement":
pass
# if requirementType == 'independent':
# log.write('The setting of {0} to {1} in molecule {3} is independent from {2}\n'.format(baseMolecule[0][0],baseMolecule[0][1],baseMolecule[1],molecule))
return log.getvalue()
def removeCounter(requirementDependencies):
finalDependencies = defaultdict(lambda: defaultdict(set))
for requirement in requirementDependencies:
req2 = requirement.split("%")[0]
for dependencies in requirementDependencies[requirement]:
finalDependencies[req2][dependencies] = finalDependencies[req2][
dependencies
].union(requirementDependencies[requirement][dependencies])
return finalDependencies
def getExclusionClusters(requirementDependencies):
graphExclusionCliques = {x: [] for x in requirementDependencies.keys()}
for molecule in requirementDependencies.keys():
g = nx.Graph()
gmod = nx.Graph()
for exclusionRelationship in requirementDependencies[molecule]["exclusion"]:
if not exclusionRelationship[0].lower().endswith(
"mod"
) and not exclusionRelationship[1].lower().endswith("mod"):
g.add_edge(exclusionRelationship[0], exclusionRelationship[1])
elif exclusionRelationship[0].lower().endswith(
"mod"
) and exclusionRelationship[1].lower().endswith("mod"):
gmod.add_edge(exclusionRelationship[0], exclusionRelationship[1])
for graph in [g, gmod]:
if graph.nodes():
while len(graph.nodes()) > 1:
cliques = sorted(
list(nx.find_cliques(graph)), key=len, reverse=True
)
if len(cliques[0]) > 1:
graphExclusionCliques[molecule].append(cliques[0])
else:
break
for node in cliques[0]:
graph.remove_node(node)
return graphExclusionCliques
def getContextRequirements(
inputfile, collapse=True, motifFlag=False, excludeReverse=False
):
"""
Receives a BNG-XML file and returns the contextual dependencies implied by this file
"""
molecules, rules, _ = readBNGXML.parseXML(inputfile)
(
label,
center,
context,
product,
atomicArray,
actions,
doubleAction,
) = extractCenterContext(rules, excludeReverse=excludeReverse)
reactionCenterStateDictionary, doubleActionDict = getRestrictedChemicalStates(
label, product, context, doubleAction
)
# molecule1 = 'socs3'
# molecule2 = 'shp2'
# print(molecule1,molecule2)
# print('---',reactionCenterStateDictionary['gp130%0'][(molecule1,1,'')][molecule2])
# print('---',reactionCenterStateDictionary['gp130%0'][(molecule2,1,'')][molecule1])
# print(reactionCenterStateDictionary['STAT3%0'][('astmod',0,'AST')])
# print('++++')
# print(reactionCenterStateDictionary['Ras%0'][('Ras_GTPmod',0,'Ras_GTP')]['Ras_GDPmod'])
backupstatedictionary = deepcopy(reactionCenterStateDictionary)
# print(reactionCenterStateDictionary['EGFR%1'][('_Pmod',0,'_P')])
# print(reactionCenterStateDictionary['EGFR%0'][('_Pmod',0,'_P')])
# return
# chemicalStates = getChemicalStates(rules)
# totalStateDictionary = sortChemicalStates(chemicalStates)
# print(reactionCenterStateDictionary['Shc%0'][('egfr', 0, '')]['mmod'])
requirementDependencies = detectDependencies(
reactionCenterStateDictionary, molecules
)
# print(requirementDependencies['JAK']['requirement'])
# repression
for molecule in reactionCenterStateDictionary:
moleculeName = molecule.split("%")[0]
for element in reactionCenterStateDictionary[molecule]:
if not isActive(element[1:]):
for partner in reactionCenterStateDictionary[molecule][element]:
for state in reactionCenterStateDictionary[molecule][element][
partner
]:
if isActive(state):
repressiveState = (partner, state[0], state[1])
if (
reverseState(moleculeName, element, molecules),
repressiveState,
) in requirementDependencies[moleculeName]["requirement"]:
# or (repressiveState, element[0]) in requirementDependencies[moleculeName]['independent']:
requirementDependencies[moleculeName]["repression"].add(
(repressiveState[0], element[0])
)
if motifFlag:
requirementDependencies = getMotifRelationships(
requirementDependencies, molecules
)
exclusionCliques = getExclusionClusters(requirementDependencies)
removeIndirectDependencies(
requirementDependencies, backupstatedictionary, motifFlag
)
else:
removeIndirectDependencies(requirementDependencies, backupstatedictionary)
getMutualExclusions(requirementDependencies, molecules)
exclusionCliques = {}
processNodes = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
if motifFlag:
# double interactions
print(doubleActionDict["gp130"])
multiInteractionDict = defaultdict(
lambda: defaultdict(lambda: defaultdict(list))
)
doubleInteractions = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
for molecule in [x for x in requirementDependencies if x in doubleActionDict]:
for motif in requirementDependencies[molecule]:
for relationship in requirementDependencies[molecule][motif]:
for combination1 in [True, False]:
for combination2 in [True, False]:
if (
len(
doubleActionDict[molecule][relationship[0]][
combination1
][relationship[1]][combination2]
)
> 0
):
multiInteractionDict[molecule][
(combination1, combination2)
][relationship] = tuple(
doubleActionDict[molecule][relationship[0]][
combination1
][relationship[1]][combination2]
)
doubleInteractions[molecule][tuple(relationship)][
motif
].append((combination1, combination2))
for molecule in doubleInteractions:
for relationship in doubleInteractions[molecule]:
for motif in doubleInteractions[molecule][relationship]:
if motif in [
"partialIndependence-",
"partialIndependence+",
"fullIndependence",
]:
requirementDependencies[molecule][motif].remove(relationship)
for combination in doubleInteractions[molecule][relationship][
motif
]:
label = multiInteractionDict[molecule][combination][
relationship
]
if combination[0] and combination[1]:
requirementDependencies[molecule][
"doubleActivation"
].append(relationship)
processNodes[molecule]["doubleActivation"][relationship] = (
"{0}_{1}".format(molecule, "_".join(label))
)
elif not combination[0] and combination[1]:
if motif in ["ordering"]:
requirementDependencies[molecule][motif].remove(
relationship
)
elif motif in ["repression"]:
if (
relationship[1],
relationship[0],
) in requirementDependencies[molecule][motif]:
requirementDependencies[molecule][motif].remove(
(relationship[1], relationship[0])
)
requirementDependencies[molecule]["reprordering"].append(
relationship
)
processNodes[molecule]["reprordering"][relationship] = (
"{0}_{1}".format(molecule, "_".join(label))
)
elif not combination[0] and not combination[1]:
processNodes[molecule]["doubleRepression"][relationship] = (
"{0}_{1}".format(molecule, "_".join(label))
)
if motif == "repression":
requirementDependencies[molecule][motif].remove(
relationship
)
requirementDependencies[molecule][
"doubleRepression"
].append(relationship)
elif motif == "partialIndependence-":
# requirementDependencies[molecule][motif].remove(relationship)
requirementDependencies[molecule][
"doubleRepression"
].append(relationship)
return (
requirementDependencies,
backupstatedictionary,
exclusionCliques,
processNodes,
)
def reverseContextDict(dependencies):
"""
returns a molecule/component pair/relationship hierarchy
@param a molecule/relationship/component pair hierarchy
"""
reverseDependencies = defaultdict(lambda: defaultdict(str))
for molecule in dependencies:
for dependencyType in dependencies[molecule]:
if dependencyType == "independent":
for relationship in dependencies[molecule][dependencyType]:
if relationship[0][1] == 1 or relationship[0][2] not in [
"0",
0,
"",
]:
reverseDependencies[molecule][
(relationship[0][0], relationship[1])
] = "independent"
else:
for relationship in dependencies[molecule][dependencyType]:
if dependencyType == "exclusion":
reverseDependencies[molecule][
(relationship[1][0], relationship[0][0])
] = "nullrequirement"
reverseDependencies[molecule][
(relationship[0][0], relationship[1][0])
] = "nullrequirement"
else:
reverseDependencies[molecule][
(relationship[1][0], relationship[0][0])
] = dependencyType
return reverseDependencies
def defineConsole():
"""
defines the program console line commands
"""
parser = argparse.ArgumentParser(description="SBML to BNGL translator")
parser.add_argument("-i", "--input", type=str, help="settings file", required=True)
return parser
if __name__ == "__main__":
parser = defineConsole()
namespace = parser.parse_args()
inputFile = namespace.input
# print(askQuestions(inputFile, 'EGFR', 'shc','grb2'))
dependencies, backup, _, _ = getContextRequirements(
inputFile, collapse=True, motifFlag=True
)
# print(dependencies)
# print(dict(dependencies['EGFR']))
# print(backup)
# print(printDependencyLog(dependencies))