}
// Species
for (Species species : model.getListOfSpecies()) {
id = species.getId();
CyNode node = Cytoscape.getCyNode(id, true);
nodeAttributes.setAttribute(id, CySBMLConstants.ATT_ID, id);
nodeAttributes.setAttribute(id, CySBMLConstants.ATT_TYPE, CySBMLConstants.NODETYPE_SPECIES);
if (species.isSetName()){
nodeAttributes.setAttribute(id, CySBMLConstants.ATT_NAME, species.getName());
} else {
nodeAttributes.setAttribute(id, CySBMLConstants.ATT_NAME, id);
}
if (species.isSetInitialConcentration()){
nodeAttributes.setAttribute(id, CySBMLConstants.ATT_INITIAL_CONCENTRATION,
new Double(species.getInitialConcentration()));
}
if (species.isSetInitialAmount()){
nodeAttributes.setAttribute(id, CySBMLConstants.ATT_INITIAL_AMOUNT,
new Double(species.getInitialAmount()));
}
if (species.isSetSBOTerm()){
nodeAttributes.setAttribute(id, CySBMLConstants.ATT_SBOTERM,
species.getSBOTermID());
}
if (species.isSetCompartment()){
nodeAttributes.setAttribute(id,
CySBMLConstants.ATT_COMPARTMENT, species.getCompartment());
}
if (species.isSetBoundaryCondition()){
nodeAttributes.setAttribute(id, CySBMLConstants.ATT_BOUNDARY_CONDITION,
new Boolean(species.getBoundaryCondition()));
}
if (species.isSetConstant()){
nodeAttributes.setAttribute(id, CySBMLConstants.ATT_CONSTANT,
new Boolean(species.getConstant()));
}
if (species.isSetMetaId()){
nodeAttributes.setAttribute(id, CySBMLConstants.ATT_METAID, species.getMetaId());
}
if (species.isSetHasOnlySubstanceUnits()){
nodeAttributes.setAttribute(id, CySBMLConstants.ATT_HAS_ONLY_SUBSTANCE_UNITS,
new Boolean(species.getHasOnlySubstanceUnits()));
}
nodeIds.add(node.getRootGraphIndex());
}
// Reactions
String rid;
for (Reaction reaction : model.getListOfReactions()) {
rid = reaction.getId();
CyNode node = Cytoscape.getCyNode(rid, true);
nodeAttributes.setAttribute(rid, CySBMLConstants.ATT_TYPE, CySBMLConstants.NODETYPE_REACTION);
nodeAttributes.setAttribute(rid, CySBMLConstants.ATT_ID, reaction.getId());
if (reaction.isSetSBOTerm()){
nodeAttributes.setAttribute(rid, CySBMLConstants.ATT_SBOTERM, reaction.getSBOTermID());
}
if (reaction.isSetName()){
nodeAttributes.setAttribute(rid, CySBMLConstants.ATT_NAME, reaction.getName());
} else {
nodeAttributes.setAttribute(rid, CySBMLConstants.ATT_NAME, rid);
}
if (reaction.isSetCompartment()){
nodeAttributes.setAttribute(rid, CySBMLConstants.ATT_COMPARTMENT, reaction.getCompartment());
} else {
nodeAttributes.setAttribute(rid, CySBMLConstants.ATT_COMPARTMENT, "-");
}
// Reactions are reversible by default
if (reaction.isSetReversible()){
nodeAttributes.setAttribute(rid, CySBMLConstants.ATT_REVERSIBLE,
new Boolean(reaction.getReversible()));
} else {
nodeAttributes.setAttribute(rid, CySBMLConstants.ATT_REVERSIBLE,
new Boolean(true));
}
if (reaction.isSetMetaId()){
nodeAttributes.setAttribute(rid, CySBMLConstants.ATT_METAID, reaction.getMetaId());
}
nodeIds.add(node.getRootGraphIndex());
//products
Double stoichiometry;
for (SpeciesReference speciesRef : reaction.getListOfProducts()) {
CyNode product = Cytoscape.getCyNode(speciesRef.getSpecies(), false);
CyEdge edge = Cytoscape.getCyEdge(node, product, Semantics.INTERACTION,
CySBMLConstants.EDGETYPE_REACTION_PRODUCT, true);
if (speciesRef.isSetStoichiometry()){
stoichiometry = speciesRef.getStoichiometry();
} else {
stoichiometry = 1.0;
}
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_STOICHIOMETRY, stoichiometry);
if (speciesRef.isSetSBOTerm()){
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_SBOTERM, speciesRef.getSBOTermID());
}
if (speciesRef.isSetMetaId()){
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_METAID, speciesRef.getMetaId());
}
edgeIds.add(edge.getRootGraphIndex());
}
//reactants
for (SpeciesReference speciesRef : reaction.getListOfReactants()) {
CyNode reactant = Cytoscape.getCyNode(speciesRef.getSpecies(), false);
CyEdge edge = Cytoscape.getCyEdge(node, reactant, Semantics.INTERACTION,
CySBMLConstants.EDGETYPE_REACTION_REACTANT, true);
if (speciesRef.isSetStoichiometry()){
stoichiometry = speciesRef.getStoichiometry();
} else {
stoichiometry = 1.0;
}
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_STOICHIOMETRY, stoichiometry);
if (speciesRef.isSetSBOTerm()){
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_SBOTERM, speciesRef.getSBOTermID());
}
if (speciesRef.isSetMetaId()){
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_METAID, speciesRef.getMetaId());
}
edgeIds.add(edge.getRootGraphIndex());
}
//modifier
for (ModifierSpeciesReference msref : reaction.getListOfModifiers()) {
CyNode modifier = Cytoscape.getCyNode(msref.getSpecies(), false);
CyEdge edge = Cytoscape.getCyEdge(modifier, node, Semantics.INTERACTION,
CySBMLConstants.EDGETYPE_REACTION_MODIFIER, true);
stoichiometry = 1.0;
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_STOICHIOMETRY, stoichiometry);
if (msref.isSetSBOTerm()){
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_SBOTERM, msref.getSBOTermID());
}
if (msref.isSetMetaId()){
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_METAID, msref.getMetaId());
}
edgeIds.add(edge.getRootGraphIndex());
}
//parse the parameters from the kinetic laws
//TODO: better handling of the kinetic information
if (reaction.isSetKineticLaw()){
KineticLaw law = reaction.getKineticLaw();
if (law.isSetListOfLocalParameters()){
for (LocalParameter parameter: law.getListOfLocalParameters()){
String attName = "kineticLaw-" + parameter.getId();
String attUnitsName = "kineticLaw-" + parameter.getId() + "-units";
if (parameter.isSetValue()){
nodeAttributes.setAttribute(rid, attName, parameter.getValue());
}
if (parameter.isSetUnits()){
nodeAttributes.setAttribute(rid, attUnitsName, parameter.getValue());
}
}
}
}
}
////////////// QUALITATIVE SBML MODEL ////////////////////////////////////////////
//Must the network be generated again for the qual model ??
QualitativeModel qModel = (QualitativeModel) model.getExtension(QualConstant.namespaceURI);
if (qModel != null){
//QualSpecies
String qsid;
for (QualitativeSpecies qSpecies : qModel.getListOfQualitativeSpecies()){
qsid = qSpecies.getId();
CyNode node = Cytoscape.getCyNode(qsid, true);
nodeAttributes.setAttribute(qsid, CySBMLConstants.ATT_ID, qsid);
nodeAttributes.setAttribute(qsid, CySBMLConstants.ATT_TYPE, CySBMLConstants.NODETYPE_QUAL_SPECIES);
if (qSpecies.isSetName()){
nodeAttributes.setAttribute(qsid, CySBMLConstants.ATT_NAME, qSpecies.getName());
} else {
nodeAttributes.setAttribute(qsid, CySBMLConstants.ATT_NAME, qsid);
}
if (qSpecies.isSetInitialLevel()){
nodeAttributes.setAttribute(qsid,
CySBMLConstants.ATT_INITIAL_LEVEL, new Integer(qSpecies.getInitialLevel()));
}
if (qSpecies.isSetMaxLevel()){
nodeAttributes.setAttribute(qsid,
CySBMLConstants.ATT_MAX_LEVEL, new Double(qSpecies.getMaxLevel()));
}
if (qSpecies.isSetSBOTerm()){
nodeAttributes.setAttribute(qsid,
CySBMLConstants.ATT_SBOTERM, qSpecies.getSBOTermID());
}
if (qSpecies.isSetCompartment()){
nodeAttributes.setAttribute(qsid,
CySBMLConstants.ATT_COMPARTMENT, qSpecies.getCompartment());
}
if (qSpecies.isSetConstant()){
nodeAttributes.setAttribute(qsid,
CySBMLConstants.ATT_CONSTANT, new Boolean(qSpecies.getConstant()));
}
if (qSpecies.isSetMetaId()){
nodeAttributes.setAttribute(qsid, CySBMLConstants.ATT_METAID, qSpecies.getMetaId());
}
nodeIds.add(node.getRootGraphIndex());
}
// QualTransitions
String qtid;
for (Transition qTransition : qModel.getListOfTransitions()){
qtid = qTransition.getId();
CyNode tNode = Cytoscape.getCyNode(qtid, true);
nodeAttributes.setAttribute(qtid, CySBMLConstants.ATT_TYPE, CySBMLConstants.NODETYPE_QUAL_TRANSITION);
nodeAttributes.setAttribute(qtid, CySBMLConstants.ATT_ID, qtid);
nodeAttributes.setAttribute(qtid, CySBMLConstants.ATT_COMPARTMENT, "-");
if (qTransition.isSetSBOTerm()){
nodeAttributes.setAttribute(qtid, CySBMLConstants.ATT_SBOTERM, qTransition.getSBOTermID());
}
if (qTransition.isSetName()){
nodeAttributes.setAttribute(qtid, CySBMLConstants.ATT_NAME, qTransition.getName());
} else {
nodeAttributes.setAttribute(qtid, CySBMLConstants.ATT_NAME, qtid);
}
if (qTransition.isSetMetaId()){
nodeAttributes.setAttribute(qtid, CySBMLConstants.ATT_METAID, qTransition.getMetaId());
}
nodeIds.add(tNode.getRootGraphIndex());
//outputs
for (Output output : qTransition.getListOfOutputs()) {
CyNode outNode = Cytoscape.getCyNode(output.getQualitativeSpecies(), false);
CyEdge edge = Cytoscape.getCyEdge(tNode, outNode, Semantics.INTERACTION,
CySBMLConstants.EDGETYPE_TRANSITION_OUTPUT, true);
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_STOICHIOMETRY, new Double(1.0));
if (output.isSetSBOTerm()){
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_SBOTERM, output.getSBOTermID());
}
if (output.isSetMetaId()){
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_METAID, output.getMetaId());
}
edgeIds.add(edge.getRootGraphIndex());
}
//inputs
for (Input input : qTransition.getListOfInputs()) {
CyNode inNode = Cytoscape.getCyNode(input.getQualitativeSpecies(), false);
CyEdge edge = Cytoscape.getCyEdge(tNode, inNode, Semantics.INTERACTION,
CySBMLConstants.EDGETYPE_TRANSITION_INPUT, true);
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_STOICHIOMETRY, new Double(1.0));
if (input.isSetSBOTerm()){
edgeAttributes.setAttribute(edge.getIdentifier(), CySBMLConstants.ATT_SBOTERM, input.getSBOTermID());