Skip to content

Commit

Permalink
adjust to MP changes + make diff optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Schmoho committed Aug 19, 2024
1 parent d9c085e commit 4fe0669
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 29 deletions.
5 changes: 3 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
;; state management library
[mount "0.1.18"]
[org.clojure/tools.logging "1.3.0"]
[ch.qos.logback/logback-classic "1.2.3"]
[ch.qos.logback/logback-classic "1.5.7"
:exclusions [org.slf4j/slf4j-api]]
[cheshire "5.13.0"]
[clj-http "3.13.0"]
[org.clojure/tools.cli "1.1.230"]

[edu.ucsd.sbrg.ModelPolisher "2.1.8"]
[edu.ucsd.sbrg.ModelPolisher "2.1.10"]

;; dev time
[ring/ring-devel "1.12.2"]]
Expand Down
1 change: 1 addition & 0 deletions resources/default-request-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"allow-model-to-be-saved-on-server": true,
"produce-diff": true,
"sbo-terms": {
"add-generic-terms": true
},
Expand Down
1 change: 1 addition & 0 deletions resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<configuration scan="true" scanPeriod="5 seconds">
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d [%thread] %X{run.id} %-5level %logger{36} - %msg%n</pattern>
Expand Down
22 changes: 11 additions & 11 deletions src/edu/tue/csb/mpserver/http/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
(let [{:keys [context sbml-doc]} params
pre-validation-results (validate/validate (:tempfile params))
mp-parameters (-> context :mp-parameters)]
(log/debug "Validation results:" pre-validation-results)
(do

(when (and (not (parameters/dont-fix? mp-parameters))
(not-empty (:validation pre-validation-results)))
(fixing/fix! sbml-doc))
(fixing/fix! sbml-doc context))

(when (or (empty? (:validation pre-validation-results))
(parameters/polish-even-if-model-invalid? mp-parameters))
(polishing/polish! sbml-doc context))
(let [polish? (or (empty? (:validation pre-validation-results))
(parameters/polish-even-if-model-invalid? mp-parameters))]
(when polish?
(polishing/polish! sbml-doc context)

(when (parameters/annotate-with-bigg? mp-parameters)
(log/debug "Annotating with BiGG")
(annotation/annotate-with-bigg! sbml-doc context))
(when (parameters/annotate-with-bigg? mp-parameters)
(log/debug "Annotating with BiGG")
(annotation/annotate-with-bigg! sbml-doc context))

(when (parameters/annotate-with-adb? mp-parameters)
(log/debug "Annotating with ADB")
(annotation/annotate-with-adb! sbml-doc context))
(when (parameters/annotate-with-adb? mp-parameters)
(log/debug "Annotating with ADB")
(annotation/annotate-with-adb! sbml-doc context))))

(let [base64-model (io/sbml-doc->base64 context sbml-doc)
tmp (java.io.File/createTempFile "postpolish-" ".xml")]
Expand Down
24 changes: 14 additions & 10 deletions src/edu/tue/csb/mpserver/http/middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,21 @@
[handler]
(fn wrapped-with-diff-handler
[{:keys [params] :as req}]
(let [{:keys [sbml-doc]} params
(let [{:keys [config sbml-doc]} params
old-doc (.clone sbml-doc)
resp (handler req)]
(log/debug "Calculating diff.")
(try
(let [diff (diff/diff old-doc sbml-doc)]
(log/debug "Done calculating diff.")
(assoc-in resp [:body :diff] diff))
(catch Throwable t
(log/error t "Failed diff.")
(assoc-in resp [:body :diff] {:message "Sorry, calculating the diff failed for some reason."}))))))
resp (handler req)
produce-diff? (:produce-diff config)]
(if produce-diff?
(do
(log/debug "Calculating diff.")
(try
(let [diff (diff/diff old-doc sbml-doc)]
(log/debug "Done calculating diff.")
(assoc-in resp [:body :diff] diff))
(catch Throwable t
(log/error t "Failed diff.")
(assoc-in resp [:body :diff] {:message "Sorry, calculating the diff failed for some reason."}))))
resp))))


(defn wrap-with-save-file!
Expand Down
2 changes: 1 addition & 1 deletion src/edu/tue/csb/mpserver/wrapper/annotation.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

(defn annotate-with-bigg! [^SBMLDocument doc {:keys [mp-parameters registry observers]}]
(let [bigg-params (.. mp-parameters (annotation) (biggAnnotationParameters))
sbo-params (.. mp-parameters (sboTerms))
sbo-params (.. mp-parameters (sboParameters))
bigg (BiGGDB.)
bigg-annotator (BiGGSBMLAnnotator. bigg bigg-params sbo-params registry observers)]
(.annotate bigg-annotator doc)))
Expand Down
4 changes: 2 additions & 2 deletions src/edu/tue/csb/mpserver/wrapper/fixing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
(edu.ucsd.sbrg.fixing SBMLFixer)
(java.io OutputStream)))

(defn fix! [sbml-doc]
(let [fixer (SBMLFixer.)]
(defn fix! [sbml-doc {:keys [mp-parameters]}]
(let [fixer (SBMLFixer. (.fixing mp-parameters))]
(.fix fixer sbml-doc 0)))
2 changes: 1 addition & 1 deletion src/edu/tue/csb/mpserver/wrapper/io.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[input ^Parameters params]
(try
(let [registry (IdentifiersOrg.)]
(.read (ModelReader. (.sboTerms params) registry) input))
(.read (ModelReader. (.sboParameters params) registry) input))
(catch Exception e
(throw (ex-info "Reading file failed"
{:type :parse/file
Expand Down
2 changes: 1 addition & 1 deletion src/edu/tue/csb/mpserver/wrapper/parameters.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
(.. params (fixing) (dontFix)))

(defn polish-even-if-model-invalid? [^Parameters params]
(.. params (fixing) (polishEvenIfModelInvalid)))
(.. params (polishing) (polishEvenIfModelInvalid)))
2 changes: 1 addition & 1 deletion src/edu/tue/csb/mpserver/wrapper/polishing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

(defn polish! [^SBMLDocument doc {:keys [mp-parameters registry observers]}]
(let [polisher (SBMLPolisher. (.polishing mp-parameters)
(.sboTerms mp-parameters)
(.sboParameters mp-parameters)
registry
observers)]
(.polish polisher doc)))
Expand Down

0 comments on commit 4fe0669

Please sign in to comment.