Skip to content

Commit 06be8fa

Browse files
committedAug 6, 2021
Change travis with g.actions
1 parent cbe0b77 commit 06be8fa

13 files changed

+1926
-1632
lines changed
 

‎.github/workflows/main.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: CI-CD
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
tags:
9+
- '*'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [ubuntu-latest, macos-latest, windows-latest]
18+
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip setuptools wheel pipenv
29+
pip install -r test/requirements.txt
30+
pip install pipdeptree==0.13.1
31+
- name: Test with pytest
32+
run: |
33+
pip install pytest
34+
pip install pytest-cov
35+
cd test
36+
pytest
37+
38+
sonarcloud:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v2
42+
with:
43+
# Disabling shallow clone is recommended for improving relevancy of reporting
44+
fetch-depth: 0
45+
- name: Setup sonar repository
46+
run: |
47+
bash sonar.sh
48+
- name: SonarCloud Scan
49+
uses: sonarsource/sonarcloud-github-action@master
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
52+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
53+
54+
55+
release:
56+
needs: test
57+
if: startsWith(github.ref, 'refs/tags')
58+
runs-on: ${{ matrix.os }}
59+
strategy:
60+
matrix:
61+
os: [ubuntu-latest]
62+
python-version: [3.7]
63+
steps:
64+
- uses: actions/checkout@v2
65+
- name: Set up Python ${{ matrix.python-version }}
66+
uses: actions/setup-python@v2
67+
with:
68+
python-version: ${{ matrix.python-version }}
69+
- name: Install dependencies
70+
run: |
71+
python -m pip install --upgrade pip setuptools wheel
72+
python -m pip install twine
73+
- name: Build package
74+
run: |
75+
python setup.py sdist bdist_wheel
76+
- name: Twine upload
77+
env:
78+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
79+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
80+
run: |
81+
python -m twine upload --skip-existing --non-interactive dist/*
82+
- name: Test install
83+
run: |
84+
pip install findCPcli
85+
- name: GitHub release
86+
uses: actions/create-release@v1
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
89+
with:
90+
tag_name: ${{ github.ref }}
91+
release_name: ${{ github.ref }}
92+
body_path: ""
93+
draft: false
94+
prerelease: false

‎scripts/findCPcli

+78-59
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,20 @@ else:
4040
from findCPcore import FacadeUtils
4141
from findCPcore.utils.GrowthDependentCPConfig import GrowthDependentCPConfig
4242

43-
TASK_SPREADSHEET = "TASK_SPREADSHEET"
43+
TASK_CRITICAL_REACTIONS = "TASK_CRITICAL_REACTIONS"
4444
TASK_SENSIBILITY = "TASK_SENSIBILITY"
4545
TASK_SAVE_WITHOUT_DEM = "TASK_SAVE_WITHOUT_DEM"
4646
TASK_SAVE_WITH_FVA = "TASK_SAVE_WITH_FVA"
4747
TASK_SAVE_WITH_FVA_DEM = "TASK_SAVE_WITH_FVA_DEM"
4848

49-
MSG_SUCCESFULL_SAVE = "File succesfully saved at: {}"
49+
MSG_SUCCESFULL_SAVE = "File successfully saved at: {}"
5050
MSG_UNKNOWN_ERROR = "Error, something went wrong: {}"
5151
MSG_FURTHER_INFO = "run findCPcli -h for further information."
5252

5353
PARAM_INPUT_FILE = "<input file>"
5454
PARAM_OUTPUT_FILE = "<output file>"
5555
PARAM_REACTION_ID = "<reaction id>"
56+
PARAM_FRACTION = "<fraction>"
5657

5758
LICENSE = """
5859
findCPcli Copyright (C) 2020-2021 Alex Oarga <718123 at unizar dot es> (University of Zaragoza)
@@ -94,9 +95,9 @@ def check_error_save_final_model(error, facade, output_path, verbose_f):
9495
else:
9596
save_final_model(facade, output_path, verbose_f)
9697

97-
def run(task, model_path, output_path, verbose, objective=None):
98+
def run(task, model_path, output_path, verbose, objective=None, fraction=1.0):
9899
try:
99-
if task == TASK_SPREADSHEET:
100+
if task == TASK_CRITICAL_REACTIONS:
100101
print("Task: Save results spreadsheet")
101102
facade = Facade()
102103
error = facade.generate_spreadsheet(
@@ -107,6 +108,7 @@ def run(task, model_path, output_path, verbose, objective=None):
107108
args2=None,
108109
output_path=None,
109110
objective=objective,
111+
fraction=fraction
110112
)
111113
save_final_spreadsheet(facade, output_path, verbose_f, error)
112114

@@ -145,6 +147,7 @@ def run(task, model_path, output_path, verbose, objective=None):
145147
args1=verbose,
146148
args2=None,
147149
objective=objective,
150+
fraction=fraction
148151
)
149152
check_error_save_final_model(error, facade, output_path, verbose_f)
150153

@@ -161,6 +164,7 @@ def run(task, model_path, output_path, verbose, objective=None):
161164
args1=verbose,
162165
args2=None,
163166
objective=objective,
167+
fraction=fraction
164168
)
165169
check_error_save_final_model(error, facade, output_path, verbose_f)
166170

@@ -192,14 +196,14 @@ def read_input():
192196
)
193197
parser.add_argument(
194198
"-i",
195-
dest="inputfile",
199+
dest="input_file",
196200
required=True,
197201
metavar=PARAM_INPUT_FILE,
198202
help="Input metabolic model. Allowed file formats: .xml .json .yml",
199203
)
200204
parser.add_argument(
201205
"-o",
202-
dest="outputfile",
206+
dest="output_file",
203207
metavar=PARAM_OUTPUT_FILE,
204208
help="Output spreadsheet file with results. Allowed file formats: .xls .xlsx .ods",
205209
)
@@ -211,51 +215,52 @@ def read_input():
211215
)
212216
parser.add_argument(
213217
"-swD",
214-
dest="modelwodem",
218+
dest="model_remove_dem",
215219
metavar=PARAM_OUTPUT_FILE,
216220
help="Save output model without Dead End Metabolites. Allowed file formats: .xml .json .yml",
217221
)
218222
parser.add_argument(
219223
"-sF",
220-
dest="modelfva",
224+
dest="model_fva",
221225
metavar=PARAM_OUTPUT_FILE,
222-
help="Save output model with reactions bounds updated with Flux Variability Analysis. Allowed file formats: .xml .json .yml",
226+
help="Save output model with reactions bounds updated with Flux Variability Analysis. Allowed file formats: "
227+
".xml .json .yml",
223228
)
224229
parser.add_argument(
225230
"-swDF",
226-
dest="modelfvawodem",
231+
dest="model_fva_remove_dem",
227232
metavar=PARAM_OUTPUT_FILE,
228-
help="Save output model with reactions bounds updated with Flux Variability Analysis and without Dead End Metabolites. Allowed file formats: .xml .json .yml",
233+
help="Save output model with reactions bounds updated with Flux Variability Analysis and without Dead End "
234+
"Metabolites. Allowed file formats: .xml .json .yml",
229235
)
230236
parser.add_argument(
231237
"-objective",
232238
dest="objective",
233239
metavar=PARAM_REACTION_ID,
234240
help="Reaction id to be used as objective function with Flux Balance Analysis",
235241
)
242+
parser.add_argument(
243+
"-fraction",
244+
dest="fraction",
245+
metavar=PARAM_FRACTION,
246+
help="Fraction of optimum growth to be used in Flux Balance Analysis. Value must be beetwen 0.0 and 1.0",
247+
)
236248

237249
args = parser.parse_args()
238250

239-
input_file = args.inputfile
240-
output = args.outputfile
241-
cp = args.cp
242-
modelwodem = args.modelwodem
243-
modelfva = args.modelfva
244-
modelfvawodem = args.modelfvawodem
245-
objective = args.objective
246-
247-
return (
248-
input_file,
249-
output,
250-
cp,
251-
modelwodem,
252-
modelfva,
253-
modelfvawodem,
254-
args.verbose,
255-
objective,
256-
args.license,
257-
)
251+
params = {}
252+
params["input_file"] = args.input_file
253+
params["output"] = args.output_file
254+
params["cp"] = args.cp
255+
params["model_remove_dem"] = args.model_remove_dem
256+
params["model_fva"] = args.model_fva
257+
params["model_fva_remove_dem"] = args.model_fva_remove_dem
258+
params["objective"] = args.objective
259+
params["verbose"] = args.verbose
260+
params["license"] = args.license
261+
params["fraction"] = args.fraction
258262

263+
return params
259264

260265
def __check_model_file(path):
261266
if path[-4:] != ".xml" and path[-5:] != ".json" and path[-4:] != ".yml":
@@ -320,24 +325,38 @@ def validate_operation_selected(list_of_possible_operations):
320325
print(MSG_FURTHER_INFO)
321326
exit(1)
322327

328+
def validate_number(parameter):
329+
try:
330+
parameter = float(parameter)
331+
except:
332+
print("Error: parameter 'fraction' must be a decimal number beetwen 0.0 and 1.0")
333+
exit(1)
334+
return parameter
323335

324336
#
325337
# Main cli workflow
326338
# Input is read, validated and each task executed independently
327339
#
328340
def main():
329341
# Read input
330-
(
331-
input_file,
332-
output,
333-
cp,
334-
modelwodem,
335-
modelfva,
336-
modelfvawodem,
337-
verbose,
338-
objective,
339-
license,
340-
) = read_input()
342+
params = read_input()
343+
input_file = params["input_file"]
344+
output_file = params["output"]
345+
cp = params["cp"]
346+
model_remove_dem = params["model_remove_dem"]
347+
model_fva = params["model_fva"]
348+
model_fva_remove_dem = params["model_fva_remove_dem"]
349+
objective = params["objective"]
350+
verbose = params["verbose"]
351+
license = params["license"]
352+
fraction = params["fraction"]
353+
354+
# Default values
355+
if fraction is None:
356+
fraction = 1.0
357+
fraction = validate_number(fraction)
358+
359+
341360

342361
# Operations that dont requiere validation
343362
if license:
@@ -346,11 +365,11 @@ def main():
346365
# Note that the following save the outputh path of each operation
347366
# If the variable is None, no operation that operation has not been selected
348367
NEW_MODEL_OPERATIONS = [
349-
modelwodem,
350-
modelfva,
351-
modelfvawodem,
368+
model_remove_dem,
369+
model_fva,
370+
model_fva_remove_dem,
352371
] # Tasks that generate new models
353-
NEW_SPREADSHEET_OPS = [output, cp] # Tasks that generate spreadsheet files
372+
NEW_SPREADSHEET_OPS = [output_file, cp] # Tasks that generate spreadsheet files
354373

355374
# Check input file formats and task
356375
validate_input_model(input_file)
@@ -359,30 +378,30 @@ def main():
359378
validate_operation_selected(NEW_MODEL_OPERATIONS + NEW_SPREADSHEET_OPS)
360379

361380
# Run task
362-
if output is not None:
363-
task = TASK_SPREADSHEET
364-
out_path = output
365-
run(task, input_file, out_path, verbose, objective)
381+
if output_file is not None:
382+
task = TASK_CRITICAL_REACTIONS
383+
out_path = output_file
384+
run(task, input_file, out_path, verbose, objective, fraction)
366385

367386
if cp is not None:
368387
task = TASK_SENSIBILITY
369388
out_path = cp
370-
run(task, input_file, out_path, verbose, objective)
389+
run(task, input_file, out_path, verbose, objective, fraction)
371390

372-
if modelwodem is not None:
391+
if model_remove_dem is not None:
373392
task = TASK_SAVE_WITHOUT_DEM
374-
out_path = modelwodem
375-
run(task, input_file, out_path, verbose, objective)
393+
out_path = model_remove_dem
394+
run(task, input_file, out_path, verbose, objective, fraction)
376395

377-
if modelfva is not None:
396+
if model_fva is not None:
378397
task = TASK_SAVE_WITH_FVA
379-
out_path = modelfva
380-
run(task, input_file, out_path, verbose, objective)
398+
out_path = model_fva
399+
run(task, input_file, out_path, verbose, objective, fraction)
381400

382-
if modelfvawodem is not None:
401+
if model_fva_remove_dem is not None:
383402
task = TASK_SAVE_WITH_FVA_DEM
384-
out_path = modelfvawodem
385-
run(task, input_file, out_path, verbose, objective)
403+
out_path = model_fva_remove_dem
404+
run(task, input_file, out_path, verbose, objective, fraction)
386405

387406

388407
if __name__ == "__main__":

‎sonar.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
cp scripts/findCPcli scripts/findCPcli.py
55

66
# Run analysis
7-
sonar-scanner
7+
# sonar-scanner

‎test/data/no_args_err.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ usage: findCPcli [-h] [-v] [-l] -i <input file> [-o <output file>]
22
[-cp <output file>] [-swD <output file>] [-sF <output file>]
33
[-swDF <output file>] [-objective <reaction id>]
44
findCPcli: error: the following arguments are required: -i
5+
*** DEVELOPMENT ENVIRONMENT ***

0 commit comments

Comments
 (0)
Please sign in to comment.