Skip to content

Commit

Permalink
Merge pull request #97 from cdanielmachado/development
Browse files Browse the repository at this point in the history
Latest development changes
  • Loading branch information
cdanielmachado authored Oct 13, 2020
2 parents 88d1ee7 + 68389a6 commit 6a9b158
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 40 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ docs/_build/*
Dockerfile
.idea/*
*.DS_Store
.vscode/*
.vscode/*
carveme/universe/download bigg fasta.ipynb
carveme/data/generated/bigg_proteins.dmnd
2 changes: 1 addition & 1 deletion carveme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from reframed import set_default_solver
from reframed.solvers.solver import default_parameters, Parameter

__version__ = '1.3.0'
__version__ = '1.4.1'

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

Expand Down
27 changes: 23 additions & 4 deletions carveme/cli/carve.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,26 @@
from reframed.io.sbml import sanitize_id
import argparse
import os
import os.path
import pandas as pd
from multiprocessing import Pool
from glob import glob
import subprocess


def first_run_check():
diamond_db = project_dir + config.get('generated', 'diamond_db')
if not os.path.exists(diamond_db):
print("Running diamond for the first time, please wait while we build the internal database...")
fasta_file = project_dir + config.get('input', 'fasta_file')
cmd = ['diamond', 'makedb', '--in', fasta_file, '-d', diamond_db[:-5]]
try:
exit_code = subprocess.call(cmd)
except OSError:
print('Unable to run diamond (make sure diamond is available in your PATH).')
else:
if exit_code != 0:
print('Failed to run diamond (wrong arguments).')


def build_model_id(name):
Expand Down Expand Up @@ -87,7 +104,7 @@ def maincall(inputfile, input_type='protein', outputfile=None, diamond_args=None
if input_type == 'protein' or input_type == 'dna':
if verbose:
print('Running diamond...')
diamond_db = project_dir + config.get('input', 'diamond_db')
diamond_db = project_dir + config.get('generated', 'diamond_db')
blast_output = os.path.splitext(inputfile)[0] + '.tsv'
exit_code = run_blast(inputfile, input_type, blast_output, diamond_db, diamond_args, verbose)

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

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

save_cbmodel(model, outputfile, flavor=flavor)
Expand Down Expand Up @@ -328,7 +345,9 @@ def main():
elif args.cobra:
flavor = 'cobra'
else:
flavor = None
flavor = config.get('sbml', 'default_flavor')

first_run_check()

if not args.recursive:
if len(args.input) > 1:
Expand Down Expand Up @@ -390,4 +409,4 @@ def f(x):


if __name__ == '__main__':
main()
main()
4 changes: 2 additions & 2 deletions carveme/cli/gapfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def maincall(inputfile, media, mediadb=None, universe=None, universe_file=None,
universe_file = project_dir + config.get('generated', 'default_universe')

try:
universe_model = load_cbmodel(universe_file)
universe_model = load_cbmodel(universe_file, flavor='cobra')
except IOError:
if universe:
raise IOError('Failed to load universe "{0}". Please run build_universe.py --{0}.'.format(universe))
Expand Down Expand Up @@ -113,7 +113,7 @@ def main():
elif args.cobra:
flavor = 'cobra'
else:
flavor = None
flavor = config.get('sbml', 'default_flavor')

maincall(inputfile=args.input,
media=args.media.split(','),
Expand Down
36 changes: 7 additions & 29 deletions carveme/cli/merge_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from carveme.reconstruction.utils import load_media_db


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

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

if ext_comp_id is None:
ext_comp_id = 'C_e'

models = [load_cbmodel(inputfile, flavor=flavor) for inputfile in inputfiles]

community = Community(model_id, models,
extracellular_compartment_id=ext_comp_id,
merge_extracellular_compartments=(not split_pool),
create_biomass=(not no_biomass))

merged = community.generate_merged_model()
community = Community(model_id, models)
model = community.merged_model

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

if split_pool:
fmt_func = lambda x: f"R_EX_M_{x}_e_pool"
else:
fmt_func = lambda x: f"R_EX_{x}_e"
init_env = Environment.from_compounds(media_db[init], fmt_func=fmt_func)
init_env.apply(merged, inplace=True)
init_env = Environment.from_compounds(media_db[init])
init_env.apply(model, inplace=True)

save_cbmodel(merged, outputfile, flavor=flavor)
save_cbmodel(model, outputfile, flavor=flavor)


def main():
Expand All @@ -54,17 +42,10 @@ def main():

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

parser.add_argument('--split-pool', action='store_true', dest='split_pool',
help='Keep individual extracellular compartments separated from common metabolite pool.')

parser.add_argument('--no-community-biomass', action='store_true', dest='no_biomass',
help='Do not create a common community biomass equation.')

parser.add_argument('-i', '--init', dest='init',
help="Initialize model with given medium")

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

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

maincall(inputfiles=args.input,
flavor=flavor,
split_pool=args.split_pool,
no_biomass=args.no_biomass,
init=args.init,
mediadb=args.mediadb,
ext_comp_id=args.ext,
outputfile=args.output)


Expand Down
2 changes: 1 addition & 1 deletion carveme/config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ unbalanced_metabolites = data/input/unbalanced_metabolites.csv
manually_curated = data/input/manually_curated.csv
refseq = data/input/refseq_release_201.tsv.gz
fasta_file = data/input/bigg_proteins.faa
diamond_db = data/input/bigg_proteins.dmnd

[generated]
folder = data/generated/
Expand All @@ -17,6 +16,7 @@ model_specific_data = data/generated/model_specific_data.csv.gz
universe_draft = data/generated/universe_draft.xml.gz
default_universe = data/generated/universe_bacteria.xml.gz
bigg_gibbs = data/generated/bigg_gibbs.csv
diamond_db = data/generated/bigg_proteins.dmnd


[solver]
Expand Down
Binary file removed carveme/data/input/bigg_proteins.dmnd
Binary file not shown.
38 changes: 36 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
'data/input/metabolomics_park2016.csv',
'data/input/unbalanced_metabolites.csv',
'data/input/bigg_proteins.faa',
'data/input/bigg_proteins.dmnd',
'data/input/equilibrator_compounds.tsv.gz',
'data/input/refseq_release_201.tsv.gz',
'data/generated/bigg_gibbs.csv',
Expand All @@ -35,13 +34,48 @@
'data/generated/universe_grampos.xml.gz',
'data/generated/universe_gramneg.xml.gz',
'data/generated/universe_archaea.xml.gz',
'data/benchmark/media_db.tsv',
'data/benchmark/biolog/bsub/biolog_carbon.tsv',
'data/benchmark/biolog/bsub/biolog_phosphorus.tsv',
'data/benchmark/biolog/bsub/biolog_nitrogen.tsv',
'data/benchmark/biolog/bsub/biolog_sulfur.tsv',
'data/benchmark/biolog/ecol/biolog_carbon.tsv',
'data/benchmark/biolog/ecol/biolog_phosphorus.tsv',
'data/benchmark/biolog/ecol/biolog_nitrogen.tsv',
'data/benchmark/biolog/ecol/biolog_sulfur.tsv',
'data/benchmark/biolog/paer/biolog_carbon.tsv',
'data/benchmark/biolog/rsol/biolog_carbon.tsv',
'data/benchmark/biolog/rsol/biolog_phosphorus.tsv',
'data/benchmark/biolog/rsol/biolog_nitrogen.tsv',
'data/benchmark/biolog/rsol/biolog_sulfur.tsv',
'data/benchmark/biolog/sone/biolog_carbon.tsv',
'data/benchmark/biolog/sone/biolog_nitrogen.tsv',
'data/benchmark/essentiality/bsub.tsv',
'data/benchmark/essentiality/ecol.tsv',
'data/benchmark/essentiality/mgen.tsv',
'data/benchmark/essentiality/paer.tsv',
'data/benchmark/essentiality/sone.tsv',
'data/benchmark/fasta/Bsubtilis_168.faa',
'data/benchmark/fasta/Paeruginosa_PAO1.faa',
'data/benchmark/fasta/Ecoli_K12_MG1655.faa',
'data/benchmark/fasta/M_genitalium_G37.faa',
'data/benchmark/fasta/Rsolanacearum_GMI1000.faa',
'data/benchmark/fasta/Soneidensis_MR1.faa',
'data/benchmark/models/bsub.xml',
'data/benchmark/models/rsol.xml',
'data/benchmark/models/ecol.xml',
'data/benchmark/models/paer.xml',
'data/benchmark/models/sone.xml',
'data/benchmark/models/mgen.xml',
'data/benchmark/results/biolog.tsv',
'data/benchmark/results/essentiality.tsv',
]
}


setup(
name='carveme',
version='1.3.0',
version='1.4.1',
description="CarveMe: automated metabolic model reconstruction",
long_description=readme,
author="Daniel Machado",
Expand Down

0 comments on commit 6a9b158

Please sign in to comment.