Skip to content

Commit

Permalink
Merge pull request #620 from LCSB-BioCore/develop
Browse files Browse the repository at this point in the history
Develop→master for 1.3.1
  • Loading branch information
exaexa authored May 16, 2022
2 parents 2b71b8f + 6d0e83c commit 74bd583
Show file tree
Hide file tree
Showing 16 changed files with 443 additions and 112 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/pr-cmd-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

on:
issue_comment:
types: [created]

name: PR auto-formatting command

jobs:
format:
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER' || github.event.issue.user.id == github.event.comment.user.id) && startsWith(github.event.comment.body, '/format') }}
name: auto-format
runs-on: ubuntu-latest
steps:
- name: Clone the repository
uses: actions/checkout@v2
- name: Checkout the pull request code
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr checkout ${{ github.event.issue.number }}
- name: Install JuliaFormatter and format
run: |
julia -e 'import Pkg; Pkg.add("JuliaFormatter")'
julia -e 'using JuliaFormatter; format(".")'
- name: Remove trailing whitespace
run: |
find -name '*.jl' -or -name '*.md' -or -name '*.toml' -or -name '*.yml' | while read filename ; do
# remove any trailing spaces
sed --in-place -e 's/\s*$//' "$filename"
# add a final newline if missing
if [[ -s "$filename" && $(tail -c 1 "$filename" |wc -l) -eq 0 ]] ; then
echo >> "$filename"
fi
# squash superfluous final newlines
sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' "$filename"
done
- name: Commit and push the changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ `git status -s | wc -l` -ne 0 ] ; then
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com"
git commit -a -m "automatic formatting" -m "triggered by @$GITHUB_ACTOR on PR #${{ github.event.issue.number }}"
if git push
then gh pr comment ${{ github.event.issue.number }} --body \
":heavy_check_mark: auto-formatting triggered by [this comment](${{ github.event.comment.html_url }}) succeeded, commited as `git rev-parse HEAD`"
else gh pr comment ${{ github.event.issue.number }} --body \
":x: auto-formatting triggered by [this comment](${{ github.event.comment.html_url }}) failed, perhaps someone pushed to the PR in the meantime?"
fi
else
echo "No changes, all good!"
fi
41 changes: 41 additions & 0 deletions .github/workflows/pr-formatcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

on:
pull_request:

name: Formatting check

jobs:
formatcheck:
name: check-code-format
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v2
- name: Install JuliaFormatter and format
run: |
julia -e 'import Pkg; Pkg.add("JuliaFormatter")'
julia -e 'using JuliaFormatter; format(".")'
- name: Remove trailing whitespace
run: |
find -name '*.jl' -or -name '*.md' -or -name '*.toml' -or -name '*.yml' | while read filename ; do
# remove any trailing spaces
sed --in-place -e 's/\s*$//' "$filename"
# add a final newline if missing
if [[ -s "$filename" && $(tail -c 1 "$filename" |wc -l) -eq 0 ]] ; then
echo >> "$filename"
fi
# squash superfluous final newlines
sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' "$filename"
done
- name: Report any problems
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ `git status -s | wc -l` -ne 0 ]
then gh pr comment ${{ github.event.number }} --body \
":red_square:  Commit ${{ github.event.pull_request.head.sha }} requires formatting!\
"$'\n\n'"Required formatting changes summary:\
"$'\n```\n'"`git diff --stat`"$'\n```'
else gh pr comment ${{ github.event.number }} --body \
":green_circle:  Commit ${{ github.event.pull_request.head.sha }} is formatted properly."
fi
38 changes: 0 additions & 38 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,44 +189,6 @@ mac:julia1.6:
<<: *global_julia16
<<: *global_env_mac

#
# CODE FORMAT CHECKER
#

format:
stage: test
script:
- |
docker run -v "$PWD":/project $CI_REGISTRY/r3/docker/julia-custom julia -e 'using JuliaFormatter; format("/project", verbose=true);'
- |
if [ `docker run -i -v "$PWD":/git alpine/git status -s | wc -l` -ne 0 ] ; then
GITHUB_COMMENT=":red_square: &nbsp;Commit ${CI_COMMIT_SHORT_SHA} requires formatting!\
"$'\n\n'"Required formatting changes summary:\
"$'\n```\n'"`docker run -i -v \"$PWD\":/git alpine/git diff --stat`"$'\n```'
else
GITHUB_COMMENT=":green_circle: &nbsp;Commit ${CI_COMMIT_SHORT_SHA} is formatted properly."
fi
- |
export GITHUB_TOKEN="${GITHUB_ACCESS_TOKEN_FORMATTER}"
export GITHUB_OWNER="lcsb-biocore"
export GITHUB_REPO="cobrexa.jl"
export GITHUB_COMMENT_TYPE=pr
export GITHUB_PR_ISSUE_NUMBER="${CI_EXTERNAL_PULL_REQUEST_IID}"
export GITHUB_COMMENT_FORMAT=""
export GITHUB_COMMENT
- |
docker run -i --rm \
-e GITHUB_TOKEN \
-e GITHUB_OWNER \
-e GITHUB_REPO \
-e GITHUB_COMMENT_TYPE \
-e GITHUB_PR_ISSUE_NUMBER \
-e GITHUB_COMMENT_FORMAT \
-e GITHUB_COMMENT \
cloudposse/github-commenter
<<: *global_dind
<<: *global_trigger_pull_request

#
# ASSETS
#
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "COBREXA"
uuid = "babc4406-5200-4a30-9033-bf5ae714c842"
authors = ["The developers of COBREXA.jl"]
version = "1.3.0"
version = "1.3.1"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down
6 changes: 6 additions & 0 deletions docs/src/functions/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ Pages = map(file -> joinpath("base", "types", "abstract", file), readdir("../src
Modules = [COBREXA]
Pages = map(file -> joinpath("base", "types", file), readdir("../src/base/types"))
```

## Model type wrappers
```@autodocs
Modules = [COBREXA]
Pages = map(file -> joinpath("base", "types", "wrappers", file), readdir("../src/base/types/wrappers"))
```
19 changes: 5 additions & 14 deletions src/analysis/gecko.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,15 @@ function make_gecko_model(
push!(coupling_row_mass_group, _gecko_capacity(grp, idxs, mms, gmgb_(grp)))
end

# create model with dummy objective
gm = GeckoModel(
spzeros(length(columns) + length(coupling_row_gene_product)),
GeckoModel(
[
_gecko_reaction_column_reactions(columns, model)' * objective(model)
spzeros(length(coupling_row_gene_product))
],
columns,
coupling_row_reaction,
collect(zip(coupling_row_gene_product, gpb_.(gids[coupling_row_gene_product]))),
coupling_row_mass_group,
model,
)

#=
Set objective. This is a separate field because gene products can also be objectives.
This way they can be set as objectives by the user.
=#
gm.objective .= [
_gecko_reaction_column_reactions(gm)' * objective(gm.inner)
spzeros(length(coupling_row_gene_product))
]

return gm
end
4 changes: 2 additions & 2 deletions src/analysis/sampling/warmup_variability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function warmup_from_variability(
end
)

map(fetch, save_at.(workers, :cobrexa_sampling_warmup_optmodel, Ref(save_model)))
asyncmap(fetch, save_at.(workers, :cobrexa_sampling_warmup_optmodel, Ref(save_model)))

fluxes = hcat(
dpmap(
Expand All @@ -92,7 +92,7 @@ function warmup_from_variability(
)

# free the data on workers
map(fetch, remove_from.(workers, :cobrexa_sampling_warmup_optmodel))
asyncmap(fetch, remove_from.(workers, :cobrexa_sampling_warmup_optmodel))

return fluxes, lbs, ubs
end
Expand Down
21 changes: 12 additions & 9 deletions src/analysis/screening.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ function _screen_impl(
workers = [myid()],
)::Array where {V<:AbstractVector,A,N}

map(fetch, save_at.(workers, :cobrexa_screen_variants_model, Ref(model)))
map(fetch, save_at.(workers, :cobrexa_screen_variants_analysis_fn, Ref(analysis)))
map(fetch, get_from.(workers, Ref(:(precache!(cobrexa_screen_variants_model)))))
asyncmap(fetch, save_at.(workers, :cobrexa_screen_variants_model, Ref(model)))
asyncmap(fetch, save_at.(workers, :cobrexa_screen_variants_analysis_fn, Ref(analysis)))
asyncmap(fetch, get_from.(workers, Ref(:(precache!(cobrexa_screen_variants_model)))))

res = pmap(
(vars, args)::Tuple -> screen_variant(
Expand All @@ -144,8 +144,8 @@ function _screen_impl(
zip(variants, args),
)

map(fetch, remove_from.(workers, :cobrexa_screen_variants_model))
map(fetch, remove_from.(workers, :cobrexa_screen_variants_analysis_fn))
asyncmap(fetch, remove_from.(workers, :cobrexa_screen_variants_model))
asyncmap(fetch, remove_from.(workers, :cobrexa_screen_variants_analysis_fn))

return res
end
Expand Down Expand Up @@ -276,7 +276,7 @@ function _screen_optmodel_modifications_impl(
workers = [myid()],
)::Array where {V<:AbstractVector,VF<:AbstractVector,A,N}

map(
asyncmap(
fetch,
save_at.(
workers,
Expand All @@ -290,12 +290,15 @@ function _screen_optmodel_modifications_impl(
),
),
)
map(fetch, save_at.(workers, :cobrexa_screen_optmodel_modifications_fn, Ref(analysis)))
asyncmap(
fetch,
save_at.(workers, :cobrexa_screen_optmodel_modifications_fn, Ref(analysis)),
)

res = pmap(_screen_optmodel_item, CachingPool(workers), zip(modifications, args))

map(fetch, remove_from.(workers, :cobrexa_screen_optmodel_modifications_data))
map(fetch, remove_from.(workers, :cobrexa_screen_optmodel_modifications_fn))
asyncmap(fetch, remove_from.(workers, :cobrexa_screen_optmodel_modifications_data))
asyncmap(fetch, remove_from.(workers, :cobrexa_screen_optmodel_modifications_fn))

return res
end
10 changes: 6 additions & 4 deletions src/base/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ function make_optimization_model(model::MetabolicModel, optimizer; sense = MAX_S
xl, xu = bounds(model)

optimization_model = Model(optimizer)
@variable(optimization_model, x[i = 1:n])
@variable(optimization_model, x[1:n])
@objective(optimization_model, sense, objective(model)' * x)
@constraint(optimization_model, mb, stoichiometry(model) * x .== balance(model)) # mass balance
@constraint(optimization_model, lbs, xl .<= x) # lower bounds
@constraint(optimization_model, ubs, x .<= xu) # upper bounds

C = coupling(model) # empty if no coupling
cl, cu = coupling_bounds(model)
isempty(C) || @constraint(optimization_model, c_lbs, cl .<= C * x) # coupling lower bounds
isempty(C) || @constraint(optimization_model, c_ubs, C * x .<= cu) # coupling upper bounds
isempty(C) || begin
cl, cu = coupling_bounds(model)
@constraint(optimization_model, c_lbs, cl .<= C * x) # coupling lower bounds
@constraint(optimization_model, c_ubs, C * x .<= cu) # coupling upper bounds
end

return optimization_model
end
Expand Down
15 changes: 13 additions & 2 deletions src/base/types/MetabolicModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ _missing_impl_error(m, a) = throw(MethodError(m, a))
"""
reactions(a::MetabolicModel)::Vector{String}
Return a vector of reaction identifiers in a model.
Return a vector of reaction identifiers in a model. The vector precisely
corresponds to the columns in [`stoichiometry`](@ref) matrix.
For technical reasons, the "reactions" may sometimes not be true reactions but
various virtual and helper pseudo-reactions that are used in the metabolic
modeling, such as metabolite exchanges, separate forward and reverse reactions,
supplies of enzymatic and genetic material and virtual cell volume, etc. To
simplify the view of the model contents use [`reaction_flux`](@ref).
"""
function reactions(a::MetabolicModel)::Vector{String}
_missing_impl_error(reactions, (a,))
Expand All @@ -21,7 +28,11 @@ end
"""
metabolites(a::MetabolicModel)::Vector{String}
Return a vector of metabolite identifiers in a model.
Return a vector of metabolite identifiers in a model. The vector precisely
corresponds to the rows in [`stoichiometry`](@ref) matrix.
As with [`reactions`](@ref)s, some metabolites in models may be virtual,
representing purely technical equality constraints.
"""
function metabolites(a::MetabolicModel)::Vector{String}
_missing_impl_error(metabolites, (a,))
Expand Down
Loading

2 comments on commit 74bd583

@exaexa
Copy link
Collaborator Author

@exaexa exaexa commented on 74bd583 May 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/60338

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.1 -m "<description of version>" 74bd5833a21f34c472d142d55b52b9aedad09235
git push origin v1.3.1

Please sign in to comment.