Menu

[r267]: / csharp_codes / PrimeHandle / Data / PrimeModel.cs  Maximize  Restore  History

Download this file

184 lines (165 with data), 5.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
// Copyright primekinetics.org © 2009
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Data;
namespace PrimeKinetics.PrimeHandle.Data
{
/// <summary>
/// PrimeModel class gets and manipulates chemical models.
/// </summary>
public class PrimeModel
{
#region Variables
private XmlDocument _document;
#endregion
#region Constructors
/// <summary>
/// Initializes the class components.
/// </summary>
public PrimeModel()
{
_document = null;
}
/// <summary>
/// Initializes the class components given the input XmlDocument.
/// </summary>
/// <param name="xmldoc"> The input XmlDocument</param>
public PrimeModel(XmlDocument xmldoc)
{
_document = xmldoc;
}
#endregion Constructors
#region Properties
/// <summary>
/// Gets or sets the Document property as an XmlDocument.
/// </summary>
public XmlDocument Document
{
get
{
return _document;
}
set
{
_document = value;
}
}
#endregion Properties
#region Methods
/// <summary>
/// Gets the primeID of the document.
/// </summary>
/// <returns>
/// Return the PrimeID string.
/// </returns>
public String GetPrimeID()
{
return Common.GetPrimeID(Document);
}
/// <summary>
/// Gets the preferred key of the document.
/// </summary>
/// <returns>
/// Return the string of preferred key.
/// </returns>
public String GetPreferredKey()
{
return Common.GetPreferredKey(Document);
}
/// <summary>
/// Gets the text content of additional data items of the document.
/// </summary>
/// <returns>
/// Return the string array of additional data.
/// </returns>
public String[] GetAdditionalDataItems()
{
return Common.GetAdditionalDataItems(Document);
}
/// <summary>
/// Gets the bibliography information table of the prime XmlDocument.
/// </summary>
/// <returns>
/// Return the DataTable of bibliography links.
/// </returns>
public DataTable GetBibliography()
{
return Common.GetBibliography(Document);
}
/// <summary>
/// Gets the species table of the model.
/// </summary>
/// <returns>
/// Return the DataTable of species primeID and preferred keys.
/// </returns>
public DataTable GetSpecies()
{
DataTable dt = new DataTable();
dt.Columns.Add("primeID");
dt.Columns.Add("key");
XmlNodeList nodelist = Common.GetField(Document, "speciesSet/speciesLink");
foreach (XmlNode node in nodelist)
{
DataRow dbRow = dt.NewRow();
XmlAttribute xa = node.Attributes["primeID"];
if (xa != null) dbRow["primeID"] = xa.Value;
xa = node.Attributes["preferredKey"];
if (xa != null) dbRow["key"] = xa.Value;
dt.Rows.Add(dbRow);
}
return dt;
}
/// <summary>
/// Gets the reaction table of the model.
/// </summary>
/// <returns>
/// Return the DataTable of reaction primeID and preferred keys.
/// </returns>
public DataTable GetReactions()
{
DataTable dt = new DataTable();
dt.Columns.Add("primeID");
dt.Columns.Add("key");
XmlNodeList nodelist = Common.GetField(Document, "reactionSet/reactionLink");
foreach (XmlNode node in nodelist)
{
DataRow dbRow = dt.NewRow();
XmlAttribute xa = node.Attributes["primeID"];
if (xa != null) dbRow["primeID"] = xa.Value;
xa = node.Attributes["preferredKey"];
if (xa != null) dbRow["key"] = xa.Value;
dt.Rows.Add(dbRow);
}
return dt;
}
/// <summary>
/// Gets the details of the document
/// </summary>
/// <returns>
/// Return the string of details.
/// </returns>
public override String ToString()
{
String str = String.Empty;
//str += "chemicalModel: ";
str += GetPreferredKey();
var dt = (DataTable)GetBibliography();
if (dt.Rows.Count > 0) str += " -- ";
for (int i = 0; i < dt.Rows.Count; i++)
{
str += dt.Rows[i]["key"].ToString() + "; ";
}
str = str.TrimEnd("; ".ToCharArray());
int nSpe = GetSpecies().Rows.Count;
int nReac = GetReactions().Rows.Count;
str += " (" + nSpe.ToString() + " species, " + nReac.ToString()
+ " reactions)";
return str;
}
#endregion Methods
}
}