commandline.pl 5 KB
Newer Older
Thierry Martinez's avatar
Thierry Martinez committed
1 2 3 4 5 6 7
:- module(
  commandline,
  [
    do_arguments/0
  ]
).

FAGES Francois's avatar
doc  
FAGES Francois committed
8
:- doc('
9 10
\\section{Biocham files}

FAGES Francois's avatar
doc  
FAGES Francois committed
11 12 13 14 15 16
Biocham file names are suffixed by \\texttt{.bc}. In a Biocham file, everything following the character percent is a comment.
Some other file formats are used.').

:- doc('
Biocham models can be imported from, and exported to, other file formats using the following suffixes:
\\begin{itemize}
FAGES Francois's avatar
FAGES Francois committed
17 18
\\item \\texttt{.xml} for Systems Biology Markup Language (SBML) files, more precisely SBML2 files for reaction networks and SBML3qual files for influence networks;
\\item \\texttt{.ode} for Ordinary Differential Equation files (ODEs in XXPAUT format), allowing us to infer and import a reaction network from ODEs using a heuristic inference algorithm described in \\cite{FGS15tcs}.
FAGES Francois's avatar
manuel  
FAGES Francois committed
19
\\item \\texttt{.ipynb} for Jupyter notebook files.
FAGES Francois's avatar
doc  
FAGES Francois committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
\\end{itemize}
Biocham numerical data time series can be imported/exported in 
\\begin{itemize}
\\item \\texttt{.csv} comma-separated values format (spreadsheet format).
\\end{itemize}
The following files can also be used to export some Biocham objects:
\\begin{itemize}
\\item \\texttt{.tex} LaTeX format for exporting ODEs and graphs;
\\item \\texttt{.dot} for exporting graphs;
\\item \\texttt{.plot} for exporting numerical data time series;
\\item \\texttt{.smv} for exporting boolean transition systems and Computation Tree Logic (CTL) queries for the NuSMV model-checker;
\\item \\texttt{.dot} for exporting graphs.
\\end{itemize}
').

FAGES Francois's avatar
options  
FAGES Francois committed
35
:- doc('\\section{Biocham call options}').
Thierry Martinez's avatar
Thierry Martinez committed
36

Thierry Martinez's avatar
Thierry Martinez committed
37 38 39 40
do_arguments :-
  current_prolog_flag(argv, Argv),
  do_arguments(Argv).

Thierry Martinez's avatar
Thierry Martinez committed
41

Thierry Martinez's avatar
Thierry Martinez committed
42 43
:- dynamic(file/1).

Thierry Martinez's avatar
Thierry Martinez committed
44

Thierry Martinez's avatar
Thierry Martinez committed
45 46 47 48 49
do_arguments(Argv) :-
  retractall(file(_)),
  parse_arguments(Argv),
  load_files.

Thierry Martinez's avatar
Thierry Martinez committed
50

Thierry Martinez's avatar
Thierry Martinez committed
51 52 53 54 55 56 57 58
load_files :-
  \+ (
    file(File),
    \+ (
      load(File)
    )
  ).

Thierry Martinez's avatar
Thierry Martinez committed
59

Thierry Martinez's avatar
Thierry Martinez committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
parse_arguments([]).

parse_arguments([Arg | Argv]) :-
  (
    Arg = '--'
  ->
    add_files(Argv)
  ;
    atom_concat('--', _, Arg)
  ->
    (
      option(_, Arg, Argv, ArgTail)
    ->
      parse_arguments(ArgTail)
    ;
      throw(error(unknown_option(Arg)))
    )
  ;
    add_file(Arg),
    parse_arguments(Argv)
  ).


Thierry Martinez's avatar
Thierry Martinez committed
83
option('', '--trace', Arg, Arg) :-
Thierry Martinez's avatar
Thierry Martinez committed
84 85 86
  leash(-all),
  trace.

Thierry Martinez's avatar
Thierry Martinez committed
87 88 89 90
option('', '--generate-doc', Arg, Arg) :-
  generate_doc,
  quit.

SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
91 92 93
option('', '--version', Arg, Arg) :-
   quit.

94
option('', '--jupyter', [], []) :-
95
  set_counter(graph_png, 0),
96
  set_counter(plot_csv, 0),
97
  set_counter(plot_png, 0),
98
  set_plot_driver(gnu_plot_csv),
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
99
  set_image_viewer_driver(img_tag),
100
  set_draw_graph_driver(graph_png).
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
101

102
option('', '--list-commands', [], []) :-
103 104 105
  forall(
    (
      current_functor(Functor, Arity),
106 107
      predicate_info(Functor/Arity, _ArgumentTypes, _, BiochamCommand, _),
      member(BiochamCommand, [yes, variantargs])
108 109 110 111 112 113 114
    ),
    (
      % Pred =.. [Functor | ArgumentTypes],
      format('~a~n', [Functor])
    )
  ),
  quit.
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
115

FAGES Francois's avatar
options  
FAGES Francois committed
116 117 118
:- doc('\\texttt{biocham [file]}
launches Biocham and optionnally loads the file given as argument.').

FAGES Francois's avatar
FAGES Francois committed
119
:- doc('\\texttt{biocham --trace --generate-doc --version --list-commands} are possible options (prefixed by two dashes).').
FAGES Francois's avatar
options  
FAGES Francois committed
120

FAGES Francois's avatar
FAGES Francois committed
121
:- doc('\\texttt{biocham --notebook [notebook.ipynb]}  launches Jupyter (see
122
  \\url{http://jupyter-notebook.readthedocs.io/}) with a biocham kernel, and
FAGES Francois's avatar
FAGES Francois committed
123
  loads the corresponding notebook (ipynb suffix). If no notebook is provided, a biocham notebook can be created with the new menu.
FAGES Francois's avatar
FAGES Francois committed
124

125
To execute a Biocham command enter Shift-Return.
FAGES Francois's avatar
FAGES Francois committed
126

SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
127
All shortcuts are described in the \\emph{keyboard menu}.
FAGES Francois's avatar
FAGES Francois committed
128
 The following video
129 130
  \\url{https://www.youtube.com/watch?v=e9cSF3eVQv0} is a quite nice
  introduction to the Jupyter notebook''s concepts, all can be adapted to
131
  Biocham as a kernel.
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
132
  \\html{<div><iframe width="640" height="360"
133
  src="https://www.youtube-nocookie.com/embed/e9cSF3eVQv0?rel=0&start=287&end=779"
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
134 135
  frameborder="0" allowfullscreen></iframe></div>}

FAGES Francois's avatar
options  
FAGES Francois committed
136 137 138 139 140 141 142 143
  The only \\emph{magic commands} available in the notebook and not in Biocham are 

\\texttt{%load file.bc} which creates a cell for each command contained in a Biocham file

and
  \\texttt{%slider k1 k2 …}, which  creates sliders to change the given
  parameters'' value, and run \\command{numerical_simulation} followed by
  \\command{plot} at each change.
FAGES Francois's avatar
FAGES Francois committed
144
').
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
145

FAGES Francois's avatar
FAGES Francois committed
146
:- doc('
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
147
  The environment variable \\texttt{BIOCHAM_TIMEOUT} can be used to change the
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
148
  default notebook-kernel communication timeout of 120 (seconds).
149
').
150

FAGES Francois's avatar
FAGES Francois committed
151 152
:- doc('\\texttt{biocham_debug} launches Biocham with the Prolog toplevel.').

153 154 155 156
option('', '--notebook', Args, []) :-
  Cmd =.. [
    jupyter,
    notebook,
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
157 158 159
    '--KernelSpecManager.whitelist=["biocham"]',
    '--NbConvertBase.display_data_priority=["image/png", "text/html"]'
    | Args
160
  ],
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
161 162 163 164
  library_path(Lib),
  file_directory_name(Lib, Dir),
  % Change to biocham directory to be sure to find the biocham_kernel Python
  % module
165 166 167 168 169 170 171 172 173
  (
    getenv('PYTHONPATH', Pythonpath)
  ->
    true
  ;
    Pythonpath = ''
  ),
  atomic_list_concat([Pythonpath, Dir], ':', NewPythonpath),
  setenv('PYTHONPATH', NewPythonpath),
174
  exec(Cmd),
175 176 177
  quit.


Thierry Martinez's avatar
Thierry Martinez committed
178 179 180 181 182 183 184 185
add_files(Files) :-
  \+ (
    member(File, Files),
    \+ (
      add_file(File)
    )
  ).

Thierry Martinez's avatar
Thierry Martinez committed
186

Thierry Martinez's avatar
Thierry Martinez committed
187 188
add_file(File) :-
  assertz(file(File)).