- Author:
- Randall Britten <r.britten@auckland.ac.nz>
- Date:
- 2013-04-17 15:40:27+12:00
- Desc:
- Trivial whitespace changes, and moved import to be adjacent to peer import.
- Permanent Source URI:
- https://models.cellml.org/w/matthiaskoenig/MetabolicComponentLibrary/rawfile/38fe44af096fb53d9b250091fe0563b33b5f778f/CellML-source/CellMLTools/src/componentlibrary/LibraryGenerator.java
package componentlibrary;
import java.util.TreeMap;
import tools.CellMLLoader;
import tools.CellMLReader;
import tools.CellMLWriter;
import cellml_api.CellMLComponent;
import cellml_api.CellMLElement;
import cellml_api.Model;
import cellml_api.Units;
import cellml_api.UnitsIterator;
import cellml_api.UnitsSet;
/* Generates a compact library from the single components and units
* for reuse.
* This is the file which is ultimately imported.
*/
public class LibraryGenerator {
//private static final String LIBRARY_FILE="C:/Users/mkoenig/Desktop/CellML/models/MetabolicLibraryCellML/MetabolicComponentLibrary-v0.1.cellml";
private static final String LIBRARY_FILE="MetabolicComponentLibrary-v0.1.cellml";
/* Collects all units and basic components in one CellML file. */
public static void generateCompactLibraryFile(TreeMap<String, RCellMLComponent> rccMap){
CellMLLoader cLoader = new CellMLLoader();
Model lib_model = CellMLReader.createModel(cLoader.getCellMLBootstrap(), "1.1");
lib_model.setName("MetabolicComponentLibrary" );
// Get the kinetics components (library components & respective units)
for (String key: rccMap.keySet()){
RCellMLComponent rcc = rccMap.get(key);
Model model = rcc.getModel();
// Copy the units
UnitsSet unitsSet = model.getAllUnits();
UnitsIterator iter = unitsSet.iterateUnits();
for (int i=0; i<unitsSet.getLength(); i++){
Units units = iter.nextUnits();
ComponentCopy.insertCellMLElementToModel((CellMLElement) units, lib_model);
}
// Copy the kinetics component
CellMLComponent component = rcc.getKineticsComponent();
ComponentCopy.insertCellMLElementToModel((CellMLElement) component, lib_model);
}
// Write the model to the library file
CellMLWriter.writeToFile(lib_model, LIBRARY_FILE);
}
public static void generateZip(){
//TODO: pack the necessary resources
}
public static void main(String[] args) throws Exception{
TreeMap<String, RComponent> cMap = RComponentImporter.readComponentsFromCSV();
TreeMap<String, RCellMLComponent> rccMap = RCellMLComponent.generateRCellMLComponents(cMap);
LibraryGenerator.generateCompactLibraryFile(rccMap);
}
}