package componentlibrary; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.HashSet; import java.util.List; import java.util.TreeMap; import componentlibrary.RComponent.*; import tools.opencsv.CSVReader; /* CSV import of the component information and creating of the list of components */ public class RComponentImporter { private static final String COMPONENT_FILE="C:/Users/mkoenig/Desktop/CellML/models/MetabolicLibraryCellML/components.csv"; public static TreeMap readComponentsFromCSV() throws Exception{ TreeMap cMap = new TreeMap(); CSVReader reader; try { reader = new CSVReader(new FileReader(COMPONENT_FILE)); List lines = reader.readAll(); String [] line; // ignore the header line System.out.println("*** START COMPONENT PARSING ***"); for(int i=1; i parseMechanisms(String text) throws Exception{ HashSet mSet = new HashSet(); // Split the text & parse all the single mechanisms String[] tokens = text.split(";"); for (String token: tokens){ token = token.trim(); if (token.length()>0){ Mechanism m = parseMechanism(token); mSet.add(m); } } return mSet; } private static Mechanism parseMechanism(String text) throws Exception{ Mechanism m = findMechanismByName(text); if (m == null){ raiseParseError(Mechanism.class.getName(), text); } return m; } private static Mechanism findMechanismByName(String name){ for(Mechanism m : Mechanism.values()){ if( m.name().equals(name)){ return m; } } return null; } private static void raiseParseError(String type, String text) throws Exception{ throw new Exception(type + ": |" + text + "|"); } private static void printLine(String[] line, int i){ System.out.println("*** Component <" + i + ">"); System.out.println("name : " + line[0]); System.out.println("mechanisms : " + line[1]); System.out.println("reversibility : " + line[2]); System.out.println("modifier : " + line[3]); System.out.println("--------------------------"); } public static void main(String[] args) throws Exception{ TreeMap cSet = readComponentsFromCSV(); int count = 1; for (RComponent c: cSet.values()){ c.print(count); count++; } } }