forked from binfalse/BiVeS-SBML
/
SBMLCompartment.java
152 lines (130 loc) · 4.58 KB
/
SBMLCompartment.java
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
/**
*
*/
package de.unirostock.sems.bives.sbml.parser;
import de.unirostock.sems.bives.algorithm.DiffReporter;
import de.unirostock.sems.bives.algorithm.SimpleConnectionManager;
import de.unirostock.sems.bives.markup.MarkupDocument;
import de.unirostock.sems.bives.markup.MarkupElement;
import de.unirostock.sems.bives.sbml.exception.BivesSBMLParseException;
import de.unirostock.sems.bives.tools.BivesTools;
import de.unirostock.sems.xmlutils.ds.DocumentNode;
/**
* The Class SBMLCompartment, a bounded space in which species are located.
*
* @author Martin Scharm
*/
public class SBMLCompartment
extends SBMLGenericIdNameObject
implements DiffReporter
{
/** The spatial dimensions. */
private double spatialDimensions; //optional
/** The size. */
private double size; //optional
/** The units. */
private SBMLUnitDefinition units; //optional
/** The constant flag. */
private boolean constant;
/** The compartment type. */
private SBMLCompartmentType compartmentType; // only level < 3
/**
* Instantiates a new SBML compartment.
*
* @param documentNode the document node encoding this entity in the corresponding XML tree
* @param sbmlModel the SBML model
* @throws BivesSBMLParseException the bives sbml parse exception
*/
public SBMLCompartment (DocumentNode documentNode, SBMLModel sbmlModel) throws BivesSBMLParseException
{
super (documentNode, sbmlModel);
String tmp = documentNode.getAttributeValue ("compartmentType");
if (tmp != null)
{
compartmentType = sbmlModel.getCompartmentType (tmp);
if (compartmentType == null)
throw new BivesSBMLParseException ("no valid compartmentType for species "+id+" defined: " + tmp);
}
if (documentNode.getAttributeValue ("spatialDimensions") != null)
{
try
{
spatialDimensions = Double.parseDouble (documentNode.getAttributeValue ("spatialDimensions"));
}
catch (Exception e)
{
throw new BivesSBMLParseException ("spatialDimensions in compartment "+id+" of unexpected format: " + documentNode.getAttributeValue ("spatialDimensions"));
}
}
if (documentNode.getAttributeValue ("size") != null)
{
try
{
size = Double.parseDouble (documentNode.getAttributeValue ("size"));
}
catch (Exception e)
{
throw new BivesSBMLParseException ("size in compartment "+id+" of unexpected format: " + documentNode.getAttributeValue ("size"));
}
}
if (documentNode.getAttributeValue ("units") != null)
{
String unitStr = documentNode.getAttributeValue ("units");
units = sbmlModel.getUnitDefinition (unitStr);
if (units == null)
throw new BivesSBMLParseException ("Unit attribute in compartment "+id+" not defined: " + unitStr);
}
if (documentNode.getAttributeValue ("constant") != null)
{
try
{
constant = Boolean.parseBoolean (documentNode.getAttributeValue ("constant"));
}
catch (Exception e)
{
throw new BivesSBMLParseException ("constant attr in compartment "+id+" of unexpected format: " + documentNode.getAttributeValue ("constant"));
}
}
else
constant = true; // level <= 2
}
/* (non-Javadoc)
* @see de.unirostock.sems.bives.algorithm.DiffReporter#reportMofification(de.unirostock.sems.bives.algorithm.SimpleConnectionManager, de.unirostock.sems.bives.algorithm.DiffReporter, de.unirostock.sems.bives.algorithm.DiffReporter)
*/
@Override
public MarkupElement reportModification (SimpleConnectionManager conMgmt, DiffReporter docA, DiffReporter docB)
{
SBMLCompartment a = (SBMLCompartment) docA;
SBMLCompartment b = (SBMLCompartment) docB;
if (a.getDocumentNode ().getModification () == 0 && b.getDocumentNode ().getModification () == 0)
return null;
String idA = a.getNameAndId (), idB = b.getNameAndId ();
MarkupElement me = null;
if (idA.equals (idB))
me = new MarkupElement (idA);
else
me = new MarkupElement (MarkupDocument.delete (idA) + " "+MarkupDocument.rightArrow ()+" " + MarkupDocument.insert (idB));
BivesTools.genAttributeMarkupStats (a.documentNode, b.documentNode, me);
return me;
}
/* (non-Javadoc)
* @see de.unirostock.sems.bives.algorithm.DiffReporter#reportInsert()
*/
@Override
public MarkupElement reportInsert ()
{
MarkupElement me = new MarkupElement (MarkupDocument.insert (getNameAndId ()));
me.addValue (MarkupDocument.insert ("inserted"));
return me;
}
/* (non-Javadoc)
* @see de.unirostock.sems.bives.algorithm.DiffReporter#reportDelete()
*/
@Override
public MarkupElement reportDelete ()
{
MarkupElement me = new MarkupElement (MarkupDocument.delete (getNameAndId ()));
me.addValue (MarkupDocument.delete ("deleted"));
return me;
}
}