Skip to content

Commit 6a9b158

Browse files
Merge pull request #97 from cdanielmachado/development
Latest development changes
2 parents 88d1ee7 + 68389a6 commit 6a9b158

File tree

8 files changed

+73
-40
lines changed

8 files changed

+73
-40
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ docs/_build/*
88
Dockerfile
99
.idea/*
1010
*.DS_Store
11-
.vscode/*
11+
.vscode/*
12+
carveme/universe/download bigg fasta.ipynb
13+
carveme/data/generated/bigg_proteins.dmnd

carveme/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from reframed import set_default_solver
55
from reframed.solvers.solver import default_parameters, Parameter
66

7-
__version__ = '1.3.0'
7+
__version__ = '1.4.1'
88

99
project_dir = os.path.abspath(os.path.dirname(__file__)) + '/'
1010

carveme/cli/carve.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,26 @@
1111
from reframed.io.sbml import sanitize_id
1212
import argparse
1313
import os
14+
import os.path
1415
import pandas as pd
1516
from multiprocessing import Pool
1617
from glob import glob
18+
import subprocess
19+
20+
21+
def first_run_check():
22+
diamond_db = project_dir + config.get('generated', 'diamond_db')
23+
if not os.path.exists(diamond_db):
24+
print("Running diamond for the first time, please wait while we build the internal database...")
25+
fasta_file = project_dir + config.get('input', 'fasta_file')
26+
cmd = ['diamond', 'makedb', '--in', fasta_file, '-d', diamond_db[:-5]]
27+
try:
28+
exit_code = subprocess.call(cmd)
29+
except OSError:
30+
print('Unable to run diamond (make sure diamond is available in your PATH).')
31+
else:
32+
if exit_code != 0:
33+
print('Failed to run diamond (wrong arguments).')
1734

1835

1936
def build_model_id(name):
@@ -87,7 +104,7 @@ def maincall(inputfile, input_type='protein', outputfile=None, diamond_args=None
87104
if input_type == 'protein' or input_type == 'dna':
88105
if verbose:
89106
print('Running diamond...')
90-
diamond_db = project_dir + config.get('input', 'diamond_db')
107+
diamond_db = project_dir + config.get('generated', 'diamond_db')
91108
blast_output = os.path.splitext(inputfile)[0] + '.tsv'
92109
exit_code = run_blast(inputfile, input_type, blast_output, diamond_db, diamond_args, verbose)
93110

@@ -230,7 +247,7 @@ def maincall(inputfile, input_type='protein', outputfile=None, diamond_args=None
230247
m2, n2 = len(model.metabolites), len(model.reactions)
231248
print('Added {} reactions and {} metabolites'.format((n2 - n1), (m2 - m1)))
232249

233-
if init_env: #Should initialize enviroment again as new exchange reactions can be acquired during gap-filling
250+
if init_env: # Initializes environment again as new exchange reactions can be acquired during gap-filling
234251
init_env.apply(model, inplace=True, warning=False)
235252

236253
save_cbmodel(model, outputfile, flavor=flavor)
@@ -328,7 +345,9 @@ def main():
328345
elif args.cobra:
329346
flavor = 'cobra'
330347
else:
331-
flavor = None
348+
flavor = config.get('sbml', 'default_flavor')
349+
350+
first_run_check()
332351

333352
if not args.recursive:
334353
if len(args.input) > 1:
@@ -390,4 +409,4 @@ def f(x):
390409

391410

392411
if __name__ == '__main__':
393-
main()
412+
main()

carveme/cli/gapfill.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def maincall(inputfile, media, mediadb=None, universe=None, universe_file=None,
3838
universe_file = project_dir + config.get('generated', 'default_universe')
3939

4040
try:
41-
universe_model = load_cbmodel(universe_file)
41+
universe_model = load_cbmodel(universe_file, flavor='cobra')
4242
except IOError:
4343
if universe:
4444
raise IOError('Failed to load universe "{0}". Please run build_universe.py --{0}.'.format(universe))
@@ -113,7 +113,7 @@ def main():
113113
elif args.cobra:
114114
flavor = 'cobra'
115115
else:
116-
flavor = None
116+
flavor = config.get('sbml', 'default_flavor')
117117

118118
maincall(inputfile=args.input,
119119
media=args.media.split(','),

carveme/cli/merge_community.py

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from carveme.reconstruction.utils import load_media_db
66

77

8-
def maincall(inputfiles, flavor=None, split_pool=False, no_biomass=False, init=None, mediadb=None, ext_comp_id=None, outputfile=None):
8+
def maincall(inputfiles, flavor=None, init=None, mediadb=None, outputfile=None):
99

1010
if not flavor:
1111
flavor = config.get('sbml', 'default_flavor')
@@ -16,17 +16,9 @@ def maincall(inputfiles, flavor=None, split_pool=False, no_biomass=False, init=N
1616
model_id = 'community'
1717
outputfile = 'community.xml'
1818

19-
if ext_comp_id is None:
20-
ext_comp_id = 'C_e'
21-
2219
models = [load_cbmodel(inputfile, flavor=flavor) for inputfile in inputfiles]
23-
24-
community = Community(model_id, models,
25-
extracellular_compartment_id=ext_comp_id,
26-
merge_extracellular_compartments=(not split_pool),
27-
create_biomass=(not no_biomass))
28-
29-
merged = community.generate_merged_model()
20+
community = Community(model_id, models)
21+
model = community.merged_model
3022

3123
if init:
3224
if not mediadb:
@@ -37,14 +29,10 @@ def maincall(inputfiles, flavor=None, split_pool=False, no_biomass=False, init=N
3729
except IOError:
3830
raise IOError('Failed to load media library:' + mediadb)
3931

40-
if split_pool:
41-
fmt_func = lambda x: f"R_EX_M_{x}_e_pool"
42-
else:
43-
fmt_func = lambda x: f"R_EX_{x}_e"
44-
init_env = Environment.from_compounds(media_db[init], fmt_func=fmt_func)
45-
init_env.apply(merged, inplace=True)
32+
init_env = Environment.from_compounds(media_db[init])
33+
init_env.apply(model, inplace=True)
4634

47-
save_cbmodel(merged, outputfile, flavor=flavor)
35+
save_cbmodel(model, outputfile, flavor=flavor)
4836

4937

5038
def main():
@@ -54,17 +42,10 @@ def main():
5442

5543
parser.add_argument('-o', '--output', dest='output', help="SBML output file (community)")
5644

57-
parser.add_argument('--split-pool', action='store_true', dest='split_pool',
58-
help='Keep individual extracellular compartments separated from common metabolite pool.')
59-
60-
parser.add_argument('--no-community-biomass', action='store_true', dest='no_biomass',
61-
help='Do not create a common community biomass equation.')
62-
6345
parser.add_argument('-i', '--init', dest='init',
6446
help="Initialize model with given medium")
6547

6648
parser.add_argument('--mediadb', help="Media database file")
67-
parser.add_argument('--ext', help="Extracellular compartment identifier in the models (default 'C_e').")
6849

6950
sbml = parser.add_mutually_exclusive_group()
7051
sbml.add_argument('--cobra', action='store_true', help="SBML input/output in old cobra format")
@@ -81,15 +62,12 @@ def main():
8162
elif args.cobra:
8263
flavor = 'cobra'
8364
else:
84-
flavor = None
65+
flavor = config.get('sbml', 'default_flavor')
8566

8667
maincall(inputfiles=args.input,
8768
flavor=flavor,
88-
split_pool=args.split_pool,
89-
no_biomass=args.no_biomass,
9069
init=args.init,
9170
mediadb=args.mediadb,
92-
ext_comp_id=args.ext,
9371
outputfile=args.output)
9472

9573

carveme/config.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ unbalanced_metabolites = data/input/unbalanced_metabolites.csv
88
manually_curated = data/input/manually_curated.csv
99
refseq = data/input/refseq_release_201.tsv.gz
1010
fasta_file = data/input/bigg_proteins.faa
11-
diamond_db = data/input/bigg_proteins.dmnd
1211

1312
[generated]
1413
folder = data/generated/
@@ -17,6 +16,7 @@ model_specific_data = data/generated/model_specific_data.csv.gz
1716
universe_draft = data/generated/universe_draft.xml.gz
1817
default_universe = data/generated/universe_bacteria.xml.gz
1918
bigg_gibbs = data/generated/bigg_gibbs.csv
19+
diamond_db = data/generated/bigg_proteins.dmnd
2020

2121

2222
[solver]
-33.9 MB
Binary file not shown.

setup.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
'data/input/metabolomics_park2016.csv',
2525
'data/input/unbalanced_metabolites.csv',
2626
'data/input/bigg_proteins.faa',
27-
'data/input/bigg_proteins.dmnd',
2827
'data/input/equilibrator_compounds.tsv.gz',
2928
'data/input/refseq_release_201.tsv.gz',
3029
'data/generated/bigg_gibbs.csv',
@@ -35,13 +34,48 @@
3534
'data/generated/universe_grampos.xml.gz',
3635
'data/generated/universe_gramneg.xml.gz',
3736
'data/generated/universe_archaea.xml.gz',
37+
'data/benchmark/media_db.tsv',
38+
'data/benchmark/biolog/bsub/biolog_carbon.tsv',
39+
'data/benchmark/biolog/bsub/biolog_phosphorus.tsv',
40+
'data/benchmark/biolog/bsub/biolog_nitrogen.tsv',
41+
'data/benchmark/biolog/bsub/biolog_sulfur.tsv',
42+
'data/benchmark/biolog/ecol/biolog_carbon.tsv',
43+
'data/benchmark/biolog/ecol/biolog_phosphorus.tsv',
44+
'data/benchmark/biolog/ecol/biolog_nitrogen.tsv',
45+
'data/benchmark/biolog/ecol/biolog_sulfur.tsv',
46+
'data/benchmark/biolog/paer/biolog_carbon.tsv',
47+
'data/benchmark/biolog/rsol/biolog_carbon.tsv',
48+
'data/benchmark/biolog/rsol/biolog_phosphorus.tsv',
49+
'data/benchmark/biolog/rsol/biolog_nitrogen.tsv',
50+
'data/benchmark/biolog/rsol/biolog_sulfur.tsv',
51+
'data/benchmark/biolog/sone/biolog_carbon.tsv',
52+
'data/benchmark/biolog/sone/biolog_nitrogen.tsv',
53+
'data/benchmark/essentiality/bsub.tsv',
54+
'data/benchmark/essentiality/ecol.tsv',
55+
'data/benchmark/essentiality/mgen.tsv',
56+
'data/benchmark/essentiality/paer.tsv',
57+
'data/benchmark/essentiality/sone.tsv',
58+
'data/benchmark/fasta/Bsubtilis_168.faa',
59+
'data/benchmark/fasta/Paeruginosa_PAO1.faa',
60+
'data/benchmark/fasta/Ecoli_K12_MG1655.faa',
61+
'data/benchmark/fasta/M_genitalium_G37.faa',
62+
'data/benchmark/fasta/Rsolanacearum_GMI1000.faa',
63+
'data/benchmark/fasta/Soneidensis_MR1.faa',
64+
'data/benchmark/models/bsub.xml',
65+
'data/benchmark/models/rsol.xml',
66+
'data/benchmark/models/ecol.xml',
67+
'data/benchmark/models/paer.xml',
68+
'data/benchmark/models/sone.xml',
69+
'data/benchmark/models/mgen.xml',
70+
'data/benchmark/results/biolog.tsv',
71+
'data/benchmark/results/essentiality.tsv',
3872
]
3973
}
4074

4175

4276
setup(
4377
name='carveme',
44-
version='1.3.0',
78+
version='1.4.1',
4579
description="CarveMe: automated metabolic model reconstruction",
4680
long_description=readme,
4781
author="Daniel Machado",

0 commit comments

Comments
 (0)