Location: Metabolic Component Library @ b9be078f1e21 / CellML-source / CellMLTools / src / cellmlexamples / TeLICeMTest.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/cellmlexamples/TeLICeMTest.java

package cellmlexamples;
import java.io.File;

import sun.rmi.runtime.NewThreadAction;
import tools.CellMLReader;
import tools.CellMLWriter;
import cellml_api.CellMLBootstrap;
import cellml_api.Model;
import cellml_services.TeLICeMModelResult;
import cellml_services.TeLICeMService;


public class TeLICeMTest {
	
	private CellMLBootstrap bootstrap;
	private TeLICeMService ts;
	
	public TeLICeMTest() {
		System.loadLibrary("java_cellml");
		bootstrap = cellml_bootstrap.CellMLBootstrap.createCellMLBootstrap();
		
		System.loadLibrary("java_telicems");
		ts = cellml_bootstrap.TeLICeMSService.createTeLICeMService();
	}

	public String getTeliFromURL(String url){
		Model model = CellMLReader.loadFromURL(bootstrap, url);
		return getTeliFromModel(model);
	}
	
	public String getTeliFromModel(Model model){
		return ts.showModel(model);
	}
	
	public void writeModelFromTeliToFile(String teli, String fname){
		Model model = getModelFromTeli(teli);
		CellMLWriter.writeToFile(model, fname);
	}
	
	public Model getModelFromTeli(String teli){
		TeLICeMModelResult tsRes = ts.parseModel(teli);
		return tsRes.getModelResult();
	}
	
	
	public static void main(String[]args){
		TeLICeMTest teliTools = new TeLICeMTest();
		
		// Load CellML model
		String url = "TestModelRDF.cellml";
		String url2 = "test_import/Example_MassAction_1_flat.cellml";
		String url3 = "test_import/Example_MassAction_1.cellml";
		
		String teli = teliTools.getTeliFromURL(url3);
		System.out.println(teli);
		
		// Create new Model from Teli format
		Model model_out = teliTools.getModelFromTeli(teli);
		
		// Write model
		CellMLWriter.writeToFile(model_out, "teli_test.cellml");
	}
}