opencobra / driven

Data-Driven Constraint-based analysis
http://biosustain.github.io/driven/
Apache License 2.0
12 stars 9 forks source link

optlang error in optimization #21

Open jotech opened 5 years ago

jotech commented 5 years ago

I'm getting an error when trying to compute a condition-specific model by driven.imat. It seems to be an issue with optlang:

AssertionError                            Traceback (most recent call last)
/usr/lib/python3/dist-packages/optlang/expression_parsing.py in _parse_quadratic_expression(expression, expanded)
    128                 term = 1.0 * term
--> 129             assert term.is_Mul, "What is this? {}".format(type(term))
    130             factors = term.args

AssertionError: What is this? <class 'optlang.gurobi_interface.Variable'>

A small example with random expression data to reproduce the problem:

import cobra.test
from numpy.random import random
from numpy import array
from numpy import percentile
import driven

model = cobra.test.create_test_model("textbook")
identifiers = [g.id for g in model.genes]
conditions = ["test"]
expression  = array([random(len(identifiers)) * 100]).transpose()
expression.shape == (len(identifiers), len(conditions))
exprof = driven.ExpressionProfile(identifiers, conditions, expression)

low_cutoff  = percentile(expression, 25)
high_cutoff = percentile(expression, 75)
model.solver = "gurobi" # cplex
model_cond  = driven.imat(model, exprof, (low_cutoff, high_cutoff), condition="test")

Although this error occurs with gurobi and cplex set as solver, it works fine with glpk (in reasonable time only for smaller models).

I tried python 2 and 3. The optlang package is the latest version (1.4.4)

Complete error log

jotech commented 5 years ago

@arabidopsis @Midnighter sorry for pushing this again but I really can't get it run. I tried different python versions (2.7,3.6,3.7), solvers (gurobi,cplex) and systems (debian, centos) and I'm stuck... Could you maybe just have a look if my code above makes sense or do you have another minimal example which is working for you? This would be amazing! I really appreciate any help :)

Midnighter commented 5 years ago

I'm a bit hesitant to step in here because we're not officially supporting this package yet. There's a lot of work to do, we haven't released anything yet, so it's a mixed bag of really old code and some newer code that hasn't been glued together.

jotech commented 5 years ago

hi @Midnighter thanks for your answer! But are there plans to continue this project? Would be really great to have some python code for creating tissue-specific models!

Midnighter commented 5 years ago

Yes, we do want to pick up work on this again. For starters we will focus on diversifying data types, i.e., better support for fluxomics, metabolomics. Even though tissue-specific models are not our speciality, we do want to make transcriptomics and proteomics more useful so there will naturally be some overlap in methods. Timeline-wise you might see something appearing as soon as July.

Midnighter commented 5 years ago

Btw, you should also look around at https://opencobra.github.io/cobrapy/packages/ you might find a fit for your use-case there.