Gui option for Cello Modeling

Added neccesary changes to make cello modeling an option for the user through the Gui interface
This commit is contained in:
Pedro Fontanarrosa 2019-11-01 20:17:16 -03:00
parent 299bf44d17
commit e301b76604
5 changed files with 71 additions and 32 deletions

View file

@ -110,7 +110,8 @@ public class Converter {
System.err.println("\t-t uses types in URIs");
System.err.println("\t-v <version> used for converted objects");
System.err.println("\t-r <url> The specified synbiohub repository the user wants VPR model generator to connect to");
System.err.println("\t - env <SBML environment file> is the complete directory path of the environmental file to instantiate to your model. This only works when VPR model generator is used");
System.err.println("\t -env <SBML environment file> is the complete directory path of the environmental file to instantiate to your model. This only works when VPR model generator is used");
System.err.println("\t-Cello This option is for dynamic modeling of Cello parts and parametrization");
System.exit(1);
}
@ -124,7 +125,6 @@ public class Converter {
{
//-----REQUIRED FIELD-----
String fullInputFileName = ""; //input file name
//TODO PEDRO: add option for cello or not to cello
//-----OPTIONAL FIELD-----
boolean bestPractice = false; //-b
boolean showDetail = false; //-d
@ -142,7 +142,9 @@ public class Converter {
boolean doVPR = false; //-r
boolean isDiffFile = false; //indicate if diffing of SBOL files are done
boolean isValidation = false; //indicate if only validate SBOL files
boolean topEnvir = false; // determines if there is a topEnvironment model to be instantiated
boolean topEnvir = false; // determines if there is a topEnvironment model to be instantiated
//TODO PEDRO: add option for cello or not to cello
boolean CelloModel = false; // determines if Cello-based modeling should be done
String compFileResult = ""; //-cf
String compareFile = ""; //-e
@ -166,6 +168,9 @@ public class Converter {
String flag = args[index];
switch(flag)
{
case "-Cello":
CelloModel = true;
break;
case "-b":
bestPractice = true;
break;
@ -515,20 +520,19 @@ public class Converter {
for (ModuleDefinition moduleDef : newSbolDoc.getRootModuleDefinitions())
{
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, moduleDef, newSbolDoc);
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, moduleDef, newSbolDoc, CelloModel);
SBMLutilities.exportSBMLModels(models, outputDir, outputFileName, noOutput, sbmlOut, singleSBMLOutput);
}
}
else {
ModuleDefinition topModuleDef = sbolDoc.getModuleDefinition(URI.create(topLevelURIStr));
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, topModuleDef, sbolDoc);
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, topModuleDef, sbolDoc, CelloModel);
SBMLutilities.exportSBMLModels(models, outputDir, outputFileName, noOutput, sbmlOut, singleSBMLOutput);
}
}
else
{
//TODO PEDRO calling VPR
if (doVPR) {
try {
sbolDoc = VPRModelGenerator.generateModel(urlVPR, sbolDoc, vpr_output);
@ -545,7 +549,7 @@ public class Converter {
for (ModuleDefinition moduleDef : sbolDoc.getRootModuleDefinitions())
{
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, moduleDef, sbolDoc);
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, moduleDef, sbolDoc, CelloModel);
SBMLutilities.exportSBMLModels(models, outputDir, outputFileName, noOutput, sbmlOut, singleSBMLOutput);
}
}

View file

@ -251,12 +251,9 @@ public class SBOL2SBML {
* @throws SBOLValidationException - thrown when there is an SBOL validation error
*/
public static HashMap<String,BioModel> generateModel(String projectDirectory, ModuleDefinition moduleDef, SBOLDocument sbolDoc) throws XMLStreamException, IOException, BioSimException, SBOLValidationException {
public static HashMap<String,BioModel> generateModel(String projectDirectory, ModuleDefinition moduleDef, SBOLDocument sbolDoc, boolean CelloModel) throws XMLStreamException, IOException, BioSimException, SBOLValidationException {
boolean CelloModelGenerator = true;
if (CelloModelGenerator) {
System.out.println("--------------------");
if (CelloModel) {
return CelloModeling.generateModel(projectDirectory, moduleDef, sbolDoc);
}
@ -432,11 +429,11 @@ public class SBOL2SBML {
ModuleDefinition subModuleDefFlatt = MDFlattener(sbolDoc, subModuleDef);
BioModel subTargetModel = new BioModel(projectDirectory);
if (subTargetModel.load(projectDirectory + File.separator + getDisplayID(subModuleDefFlatt) + ".xml")) {
generateSubModel(projectDirectory, subModule, resultMD, sbolDoc, subTargetModel, targetModel);
generateSubModel(projectDirectory, subModule, resultMD, sbolDoc, subTargetModel, targetModel, CelloModel);
} if ((subTargetModel=models.get(getDisplayID(subModuleDefFlatt)))!=null) {
generateSubModel(projectDirectory, subModule, resultMD, sbolDoc, subTargetModel, targetModel);
generateSubModel(projectDirectory, subModule, resultMD, sbolDoc, subTargetModel, targetModel, CelloModel);
} else {
HashMap<String,BioModel> subModels = generateSubModel(projectDirectory, subModule, resultMD, sbolDoc, targetModel);
HashMap<String,BioModel> subModels = generateSubModel(projectDirectory, subModule, resultMD, sbolDoc, targetModel, CelloModel);
for (String key : subModels.keySet()) {
models.put(key,subModels.get(key));
}
@ -460,7 +457,7 @@ public class SBOL2SBML {
* @param targetModel - The SBML local model.
*/
private static void generateSubModel(String projectDirectory, Module subModule, ModuleDefinition moduleDef, SBOLDocument sbolDoc,
BioModel subTargetModel, BioModel targetModel) {
BioModel subTargetModel, BioModel targetModel, boolean CelloModel) {
ModuleDefinition subModuleDef = sbolDoc.getModuleDefinition(subModule.getDefinitionURI());
String md5 = Utility.MD5(subTargetModel.getSBMLDocument());
targetModel.addComponent(getDisplayID(subModule), getDisplayID(subModuleDef) + ".xml",
@ -499,14 +496,14 @@ public class SBOL2SBML {
* @throws SBOLConversionException
*/
private static HashMap<String,BioModel> generateSubModel(String projectDirectory, Module subModule, ModuleDefinition moduleDef, SBOLDocument sbolDoc,
BioModel targetModel) throws XMLStreamException, IOException, BioSimException, SBOLValidationException {
BioModel targetModel, boolean CelloModel) throws XMLStreamException, IOException, BioSimException, SBOLValidationException {
ModuleDefinition subModuleDef = sbolDoc.getModuleDefinition(subModule.getDefinitionURI());
//convert each submodules into its own SBML model stored in their own .xml file.
HashMap<String,BioModel> subModels = generateModel(projectDirectory, subModuleDef, sbolDoc);
HashMap<String,BioModel> subModels = generateModel(projectDirectory, subModuleDef, sbolDoc, CelloModel);
BioModel subTargetModel = subModels.get(getDisplayID(subModuleDef));
//Perform replacement and replacedBy with each subModules to its referenced ModuleDefinition.
generateSubModel(projectDirectory, subModule, moduleDef, sbolDoc, subTargetModel, targetModel);
generateSubModel(projectDirectory, subModule, moduleDef, sbolDoc, subTargetModel, targetModel, CelloModel);
return subModels;
}
@ -643,7 +640,6 @@ public class SBOL2SBML {
}
}
}
System.out.println(getDisplayID(promoter) + " has " + promoterCnt + " promoters");
for (int i = 0; i < promoterCnt; i++) {
@ -1591,6 +1587,7 @@ public class SBOL2SBML {
System.err.println();
System.err.println("Options:");
System.err.println("\t-u URI of ModuleDefinition to convert (optional)");
System.err.println("\t-Cello This option is for dynamic modeling of Cello parts and parametrization (optional)");
System.exit(1);
}
@ -1600,7 +1597,8 @@ public class SBOL2SBML {
String outputName = null;
String uri = null;
String outputDir = null;
String inputDir = null;
String inputDir = null;
boolean CelloModel = false;
File fileFullPath;
//TODO PEDRO: add option for cello or not to cello
@ -1637,6 +1635,8 @@ public class SBOL2SBML {
case "-u":
uri = value;
break;
case "CelloModel":
CelloModel = true;
default:
usage();
return;
@ -1653,7 +1653,7 @@ public class SBOL2SBML {
if(uri!=null){
ModuleDefinition topModuleDef= sbolDoc.getModuleDefinition(URI.create(uri));
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, topModuleDef, sbolDoc);
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, topModuleDef, sbolDoc, CelloModel);
for (BioModel model : models.values())
{
model.save(outputDir + File.separator + model.getSBMLDocument().getModel().getId() + ".xml",false);
@ -1663,7 +1663,7 @@ public class SBOL2SBML {
//No ModuleDefinition URI provided so loop over all rootModuleDefinition
for (ModuleDefinition moduleDef : sbolDoc.getRootModuleDefinitions())
{
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, moduleDef, sbolDoc);
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, moduleDef, sbolDoc, CelloModel);
for (BioModel model : models.values())
{
model.save(outputDir + File.separator + model.getSBMLDocument().getModel().getId() + ".xml",false);

View file

@ -4586,7 +4586,8 @@ public class Gui implements BioObserver, MouseListener, ActionListener, MouseMot
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
generateSBMLFromSBOL(selection, root);
//TODO PEDRO revisit what boolean value to input here
generateSBMLFromSBOL(selection, root, false);
// TODO: update to attachment class
String sedmlFile = null;
for (Attachment attachment : selection.getAttachments()) {
@ -4719,7 +4720,8 @@ public class Gui implements BioObserver, MouseListener, ActionListener, MouseMot
String filePath = filename.trim();
org.sbolstandard.core2.SBOLDocument inputSBOLDoc = SBOLReader.read(new FileInputStream(filePath));
inputSBOLDoc.setDefaultURIprefix(SBOLEditorPreferences.INSTANCE.getUserInfo().getURI().toString());
int numGeneratedSBML = generateSBMLFromSBOL(inputSBOLDoc, filePath);
//TODO PEDRO revisit what boolean value to input here
int numGeneratedSBML = generateSBMLFromSBOL(inputSBOLDoc, filePath, false);
getSBOLDocument().createCopy(inputSBOLDoc);
writeSBOLDocument();
JOptionPane.showMessageDialog(frame, "Successfully Imported SBOL file containing: \n"
@ -5944,10 +5946,11 @@ public class Gui implements BioObserver, MouseListener, ActionListener, MouseMot
chosenDesign = s.getSelection();
}
boolean celloModel = s.isCelloModel();
if(s.isVPRGenerator())
{
runVPRGenerator(filePath, fileName, chosenDesign);
runVPRGenerator(filePath, fileName, chosenDesign, celloModel);
}
else if(s.isSBOLDesigner())
{
@ -5962,7 +5965,7 @@ public class Gui implements BioObserver, MouseListener, ActionListener, MouseMot
* @param fileName - The name of the SBOL file that the given SBOLDocument was created from.
* @param chosenDesign - The chosen design that the user would like to perform VPR Model Generation from.
*/
private void runVPRGenerator(String filePath, String fileName, SBOLDocument chosenDesign)
private void runVPRGenerator(String filePath, String fileName, SBOLDocument chosenDesign, boolean CelloModel)
{
try
{
@ -5993,7 +5996,7 @@ public class Gui implements BioObserver, MouseListener, ActionListener, MouseMot
VPRModelGenerator.generateModel(selectedRepo, chosenDesign, circuitID);
//update SBOL library file with newly generated components that vpr model generator created.
generateSBMLFromSBOL(chosenDesign, filePath);
generateSBMLFromSBOL(chosenDesign, filePath, CelloModel);
// TODO: should be using libSBOLj for this
SBOLUtility.copyAllTopLevels(chosenDesign, sbolDocument);
writeSBOLDocument();
@ -6173,14 +6176,14 @@ public class Gui implements BioObserver, MouseListener, ActionListener, MouseMot
* @param filePath - The file location where the SBOL document is located.
* @return The number of SBML models that was converted from SBOL.
*/
public int generateSBMLFromSBOL(SBOLDocument inputSBOLDoc, String filePath) {
public int generateSBMLFromSBOL(SBOLDocument inputSBOLDoc, String filePath, boolean CelloModel) {
int numGeneratedSBML = 0;
try {
for (ModuleDefinition moduleDef : inputSBOLDoc.getRootModuleDefinitions()) {
if (moduleDef.getModels().size()==0) {
HashMap<String,BioModel> models;
try {
models = SBOL2SBML.generateModel(root, moduleDef, inputSBOLDoc);
models = SBOL2SBML.generateModel(root, moduleDef, inputSBOLDoc, CelloModel);
for (BioModel model : models.values()) {
if (overwrite(root + File.separator + model.getSBMLDocument().getModel().getId() + ".xml",
model.getSBMLDocument().getModel().getId() + ".xml")) {

View file

@ -106,13 +106,15 @@ public class SBOLInputDialog extends InputDialog<SBOLDocument> {
private static final Part ALL_PARTS = new Part("All parts", "All");
private JCheckBox showRootDefs;
private JCheckBox celloModel;
private JRadioButton showModDefs, showCompDefs;
private JButton openSBOLDesigner, openVPRGenerator, optionsButton; //, cancelButton;
private SBOLDocument sbolDesigns;
private boolean sbolDesigner, vprGenerator;
private boolean sbolDesigner, vprGenerator, CelloModel;
/**
* An instance of the SBOL Design/Part selection dialog that will allow the user to open their selected design
@ -213,6 +215,23 @@ public class SBOLInputDialog extends InputDialog<SBOLDocument> {
filteredDesignPanel.add(showRootDefs);
builder.add("", filteredDesignPanel);
celloModel = new JCheckBox("Cello Modeling");
celloModel.setSelected(false);
celloModel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
if (celloModel.isSelected()) {
CelloModel = true;
}
else if (!celloModel.isSelected()) {
CelloModel = false;
}
}
});
filteredDesignPanel.add(celloModel);
builder.add("", filteredDesignPanel);
typeSelection = new JComboBox<Types>(Types.values());
typeSelection.setSelectedItem(Types.DNA);
typeSelection.addActionListener(new ActionListener() {
@ -406,6 +425,18 @@ public class SBOLInputDialog extends InputDialog<SBOLDocument> {
return outputDoc;
}
/**
* Check if Cello Modeling is to be performed
*/
public boolean isCelloModel() {
if (CelloModel == true) {
return true;
}
else {
return false;
}
}
private void updateRoleRefinement()
{

View file

@ -586,7 +586,8 @@ public class SynthesisView extends JTabbedPane implements ActionListener, Runnab
List<String> solutionFileIDs = new ArrayList<String>();
for (ModuleDefinition moduleDef : solution.getRootModuleDefinitions())
{
HashMap<String,BioModel> models = SBOL2SBML.generateModel(solution_dir, moduleDef, solution);
//TODO PEDRO revisit what boolean value to input here
HashMap<String,BioModel> models = SBOL2SBML.generateModel(solution_dir, moduleDef, solution, false);
solutionFileIDs.addAll(SBMLutilities.exportMultSBMLFile(models, solution_dir));
}
return solutionFileIDs;