Location: Metabolic Component Library @ b9be078f1e21 / CellML-source / CellMLTools / src / componentlibrary / LibraryGenerator.java

Author:
Matthias K?nig <matthias.koenig@charite.de>
Date:
2013-04-18 21:52:42+02:00
Desc:
Wolf Heinrich Example implemented and working !
Permanent Source URI:
https://models.cellml.org/w/matthiaskoenig/MetabolicComponentLibrary/rawfile/b9be078f1e2152d7c1b817af12a7ddcb8db3c0df/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);
		
	}
	
	
}