1616
1717from pyneuroml .utils import get_model_file_list
1818from pyneuroml .utils .cli import build_namespace
19+ from pyneuroml .runners import run_jneuroml
20+ from pyneuroml .sedml import validate_sedml_files
1921
2022logger = logging .getLogger (__name__ )
2123logger .setLevel (logging .INFO )
2224
2325
2426DEFAULTS = {
2527 "zipfileName" : None ,
26- "zipfileExtension" : ".neux" ,
28+ "zipfileExtension" : None ,
2729 "filelist" : [],
2830} # type: typing.Dict[str, typing.Any]
2931
@@ -39,8 +41,8 @@ def process_args():
3941 parser .add_argument (
4042 "rootfile" ,
4143 type = str ,
42- metavar = "<NeuroML 2/LEMS file>" ,
43- help = "Name of the NeuroML 2/LEMS main file" ,
44+ metavar = "<NeuroML 2/LEMS file/SED-ML file >" ,
45+ help = "Name of the NeuroML 2/LEMS/SED-ML main file" ,
4446 )
4547
4648 parser .add_argument (
@@ -55,7 +57,7 @@ def process_args():
5557 type = str ,
5658 metavar = "<zip file extension>" ,
5759 default = DEFAULTS ["zipfileExtension" ],
58- help = "Extension to use for archive. " ,
60+ help = "Extension to use for archive: .neux by default " ,
5961 )
6062 parser .add_argument (
6163 "-filelist" ,
@@ -64,6 +66,11 @@ def process_args():
6466 default = DEFAULTS ["filelist" ],
6567 help = "Explicit list of files to create archive of." ,
6668 )
69+ parser .add_argument (
70+ "-sedml" ,
71+ action = "store_true" ,
72+ help = ("Generate SED-ML file from main LEMS file and use as master file." ),
73+ )
6774
6875 return parser .parse_args ()
6976
@@ -79,10 +86,32 @@ def main(args=None):
7986def cli (a : typing .Optional [typing .Any ] = None , ** kwargs : str ):
8087 """Main cli caller method"""
8188 a = build_namespace (DEFAULTS , a , ** kwargs )
89+
90+ rootfile = a .rootfile
91+ zipfile_extension = None
92+
93+ # first generate SED-ML file
94+ # use .omex as extension
95+ if (
96+ a .rootfile .startswith ("LEMS" ) and a .rootfile .endswith (".xml" )
97+ ) and a .sedml is True :
98+ logger .debug ("Generating SED-ML file from LEMS file" )
99+ run_jneuroml ("" , a .rootfile , "-sedml" )
100+
101+ rootfile = a .rootfile .replace (".xml" , ".sedml" )
102+ zipfile_extension = ".omex"
103+
104+ # validate the generated file
105+ validate_sedml_files ([rootfile ])
106+
107+ # if explicitly given, use that
108+ if a .zipfile_extension is not None :
109+ zipfile_extension = a .zipfile_extension
110+
82111 create_combine_archive (
83112 zipfile_name = a .zipfile_name ,
84- rootfile = a . rootfile ,
85- zipfile_extension = a . zipfile_extension ,
113+ rootfile = rootfile ,
114+ zipfile_extension = zipfile_extension ,
86115 filelist = a .filelist ,
87116 )
88117
@@ -109,7 +138,7 @@ def create_combine_archive(
109138
110139 :param zipfile_name: name of zip file without extension: rootfile if not provided
111140 :type zipfile_name: str
112- :param rootfile: full path to main root file
141+ :param rootfile: full path to main root file (SED-ML/LEMS/NeuroML2)
113142 :type rootfile: str
114143 :param zipfile_extension: extension for zip file, starting with ".".
115144 :type zipfile_extension: str
@@ -177,43 +206,36 @@ def create_combine_archive_manifest(
177206 with open (manifest , "w" ) as mf :
178207 print ('<?xml version="1.0" encoding="utf-8"?>' , file = mf )
179208 print (
180- """
181- <omexManifest
182- xmlns="http://identifiers.org/combine.specifications/omex-manifest">
183- """ ,
209+ """<omexManifest xmlns="http://identifiers.org/combine.specifications/omex-manifest">""" ,
184210 file = mf ,
185211 )
186212
187213 print (
188- """
189- <content location="."
190- format="http://identifiers.org/combine.specifications/omex"/>
191- """ ,
214+ """\t <content location="." format="http://identifiers.org/combine.specifications/omex"/>""" ,
192215 file = mf ,
193216 )
194217
195218 for f in filelist :
219+ if f .endswith (".xml" ) and f .startswith ("LEMS" ):
220+ # TODO: check what the string for LEMS should be
221+ format_string = "http://identifiers.org/combine.specifications/neuroml"
222+ elif f .endswith (".nml" ):
223+ format_string = "http://identifiers.org/combine.specifications/neuroml"
224+ elif f .endswith (".sedml" ):
225+ format_string = "http://identifiers.org/combine.specifications/sed-ml"
226+
196227 if f == rootfile :
197- print (
198- f"""
199- <content location="{ f } " master="true"
200- format="http://identifiers.org/combine.specifications/neuroml"/>
201- """ ,
202- file = mf ,
203- )
228+ master_string = 'master="true"'
204229 else :
205- print (
206- f"""
207- <content location="{ f } "
208- format="http://identifiers.org/combine.specifications/neuroml"/>
209- """ ,
210- file = mf ,
211- )
230+ master_string = ""
231+
232+ print (
233+ f"""\t <content location="{ f } " { master_string } format="{ format_string } "/>""" ,
234+ file = mf ,
235+ )
212236
213237 print (
214- """
215- </omexManifest>
216- """ ,
238+ """</omexManifest>""" ,
217239 file = mf ,
218240 flush = True ,
219241 )
0 commit comments