// 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
}
}