Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR using ftINIT. MipGap too high, trying with a different run. #511

Closed
ShwetaNagre opened this issue Mar 23, 2023 · 55 comments
Closed

ERROR using ftINIT. MipGap too high, trying with a different run. #511

ShwetaNagre opened this issue Mar 23, 2023 · 55 comments
Assignees

Comments

@ShwetaNagre
Copy link

ShwetaNagre commented Mar 23, 2023

Hello,
I am trying to create context-specific GEM models for my transcriptomic data using the Cobra toolbox and gurobi solver in Matlab. I have created models before using the same Human-GEM guide. Now it's showing me some error due to high MipGap and I feel it is because of the solver.

command for creating model:

model1 = ftINIT(prepData, data_struct.tissues{1}, [], [], data_struct, {}, getHumanGEMINITSteps('1+0'), false, true);

The error shown after running this is:

ftINIT: Running step 1
MILP detected.
MipGap too high, trying with a different run. MipGap = Inf New MipGap Limit = 0.003
MILP detected.
Error using dispEM
Failed to find good enough solution within the time frame. MIPGap: Inf


Error in ftINIT (line 281)
        dispEM(['Failed to find good enough solution within the time frame. MIPGap: ' num2str(mipGap)]);
 

Any help would be appreciated.
Thank you.

@ShwetaNagre ShwetaNagre changed the title MipGap too high, trying with a different run. MipGap = Inf New MipGap Limit = 0.003 MILP detected. dispEM(['Failed to find good enough solution within the time frame. MIPGap: ' num2str(mipGap)]); ERROR using ftINIT. MipGap too high, trying with a different run. Mar 23, 2023
@johan-gson
Copy link
Collaborator

@ShwetaNagre Did you get past this issue?

@ShwetaNagre
Copy link
Author

Hi @johan-gson,
Yes, it was working afterward with the same code.

@johan-gson
Copy link
Collaborator

Ok, I'm closing this now.

@manas-kohli
Copy link
Collaborator

Hi @ShwetaNagre could I ask how you got past this issue since I've now run into the same problem myself while trying to run ftINIT on windows

@johan-gson
Copy link
Collaborator

johan-gson commented Apr 1, 2023 via email

@johan-gson
Copy link
Collaborator

Turns out I had, if you have the latest version. And, I have been running it on Windows during the development, so that should not be an issue. Are you sure you have converted the genes correctly, that may lead to such errors.

@johan-gson
Copy link
Collaborator

I.e., if you have gene symbols in your RNA-Seq data you need to set the convertGenes to true, if you have ensembl genes you should set it to false.

@manas-kohli
Copy link
Collaborator

Hi johan, I did update gurobi recently but actually realised I just made a stupid mistake and had two versions of RAVEN floating around and so that produced the error. Sometimes it's the simple things but I reckon if others get this error, it probably can be due to conflicting versions of RAVEN/Gurobi. Thanks for the quick response though, I do appreciate it

@johan-gson
Copy link
Collaborator

johan-gson commented Apr 1, 2023 via email

@ShwetaNagre
Copy link
Author

Sorry for the late reply @manas-kohli, good that you got this cleared.
This error was indeed due to the versions of RAVEN/Gurobi. I too updated my RAVEN and then it worked.

Hey @johan-gson can these RAVEN version specifications be mentioned on the HUMAN-GEM guide as well? So, that it would be more helpful to others. Cause when I created some models in Feb'23 it worked well with it and just showed the problem with an updated version of RAVEN.

Thank you.

@johan-gson
Copy link
Collaborator

@ShwetaNagre Sorry, forgot to answer this. Could you clarify - is it with the newer version of RAVEN you get problems?

@mihai-sysbio
Copy link
Member

I think @edkerk mentioned that RAVEN is going to have an "auto-update" function that will make sure RAVEN is running the latest version, so perhaps this part doesn't need to be added to the guide. A note on Gurobi on the other hand might be useful.

@johan-gson
Copy link
Collaborator

It should work fine with the new version (10) of Gurobi after a change in one of the parameters, so there should be no need for that either.

@mihai-sysbio
Copy link
Member

It should work fine with the new version (10) of Gurobi after a change in one of the parameters, so there should be no need for that either.

Right, but atm there is nothing specified on the Gurobi version during installation. My suggestion would be to at least add in the word "latest version of the [Gurobi Optimizer]".

@edkerk
Copy link
Member

edkerk commented Apr 18, 2023

@mihai-sysbio No auto-update, checkInstallation just reports if there is a newer version and nudges the user to update.

@MengJ-bioDyn
Copy link

MengJ-bioDyn commented Jun 17, 2023

@johan-gson

Sorry to bring this up again, could you tell me what change did you make in "after a change in one of the parameters, so there should be no need for that either."?
I have ran into the same problem with Gurobi 10.0.1 and RAVEN 2.8.1, Matlab R2019b, and i am confused with the other's solutions.
ftINIT: Running step 1 MILP detected. MipGap too high, trying with a different run. MipGap = Inf New MipGap Limit = 0.003 MILP detected. Error using dispEM (line 49) Failed to find good enough solution within the time frame. MIPGap: Inf Error in ftINIT (line 281) dispEM(['Failed to find good enough solution within the time frame. MIPGap: ' num2str(mipGap)]);

Thank you very much in advance!!

@johan-gson
Copy link
Collaborator

@MengJ-bioDyn If you send me your code and the data I could test to run it and see if I can make it work. It can be multiple things. One thing is to make sure that the genes are the same - if you created the prepData with ENSEMBL, it has to be ENSEMBL etc. Also important to remove the versions of the ENSEMBL genes, i.e., if ENSG0000000001111111.2 then remove .2 from the gene for all genes. I think I should have fixed the Gurobi thing in the code, so if there is still a problem with that it is a new bug.

@johan-gson
Copy link
Collaborator

My email address is johan.gson@gmail.com if you are willing to send your data and code.

@johan-gson
Copy link
Collaborator

Hi Meng,

Not sure where the data is, could you by any chance share it via google drive?

@johan-gson
Copy link
Collaborator

ok, will have a look!

@johan-gson
Copy link
Collaborator

Hi, do you also have the code, I didn't see it? It looks like the data is in log (TPM + 1) and then centered, since you have negative values? Is that so?

@MengJ-bioDyn
Copy link

MengJ-bioDyn commented Jun 17, 2023 via email

@johan-gson
Copy link
Collaborator

Hi, I still don't see any code, did you attach a text file or something, I didn't see it? It is not a huge problem, I can use some old code I have. But, there is a problem with the data, there is just no way that is log(TPM + 1) since it contains negative numbers (log(TPM + 1) can never become negative). It doesn't look centered either? Is it log(TPM + x), where the pseudocount x is something smaller than 1? For example this row: ENSG00000000005,ENSG00000000005.5,TNMD,-3.444843513,-3.444843513,-3.444843513,-3.444843513,-3.444843513,-3.444843513,-3.388346749,-3.444843513
This is something you need to figure out, how the data was transformed. If you produced the data in your lab, that should be easy to do! I'll be happy to help once you figured that out so we can convert it back to TPM.

@johan-gson
Copy link
Collaborator

johan-gson commented Jun 19, 2023 via email

@rsango6
Copy link

rsango6 commented Aug 14, 2023

Hi there, I am here to report the same error:

Error using dispEM
Failed to find good enough solution within the time frame. MIPGap: Inf

Error in ftINIT (line 281)
        dispEM(['Failed to find good enough solution within the time frame. MIPGap: ' num2str(mipGap)]);

I have gone through all the comments, have the most recent RAVEN version (2.8.4) and Gurobi version 10.0.2.
My gene names are all in order, i.e. they are ENSEMBL-style like so:


                GeneName        AT_1      AT_2      AT_3      AT_4 
    ______________________    ______    ______    ______    ______

    {'ENSMUSG00000000001'}    81.164    87.099    76.508    86.454
    {'ENSMUSG00000000003'}         0         0         0         0
    {'ENSMUSG00000000028'}    6.3361    17.716    6.8409    3.0719
    {'ENSMUSG00000000037'}    3.8911    9.5444    8.2382    4.5037
    {'ENSMUSG00000000049'}    4.2952    7.6122    1.6615    1.3399

Would appreciate if anyone has any feedback on this! Many thanks

@johan-gson
Copy link
Collaborator

Hmm, could you check in prepData.minModel, if the grRules uses gene symbols as well, just to make sure? And the data is in TPM?

@haowang-bioinfo
Copy link
Member

Hmm, could you check in prepData.minModel, if the grRules uses gene symbols as well, just to make sure? And the data is in TPM?

would it be good to have some checks for gene formats?

@rsango6
Copy link

rsango6 commented Aug 16, 2023

Hmm, could you check in prepData.minModel, if the grRules uses gene symbols as well, just to make sure? And the data is in TPM?

Hello,
Yes, the data is in TPM, as obtained from Salmon quantification tool.
I have checked both prepData.refModel.grRules and prepData.minModel.grRules.

In prepData.refModel.grRules:

>> prepData.refModel.grRules(1:10)

ans =

  10×1 cell array

    {'Adh1 or Adh4 or Adh5 or Adh6b or Adh7 or Adhfe1'    }
    {'Akr1a1'                                             }
    {'Acss2'                                              }
    {'Acss1 or Acss3'                                     }
    {'Acss2'                                              }
    {'Acss2'                                              }
    {'Ldha or Ldhb'                                       }
    {'Ldha or Ldhal6b or Ldhb or Ldhc'                    }
    {'Aldh1a3 or Aldh3a1 or Aldh3b1 or Aldh3b2 or Aldh3b3'}
    {'Aldh1b1 or Aldh2 or Aldh3a2 or Aldh7a1 or Aldh9a1'  }

As for prepData.minModel.grRules, this is an just an empty array with no grRules. Could this be the reason for the error?

In addition, prepData.minModel.genes is also empty.

@johan-gson
Copy link
Collaborator

Yes, this doesn't sound good, that is most likely the error. Did you by any chance set convertGenes to true? That is not a good idea for Mouse-GEM, this should be false. If not, could you set a breakpoint in the code and see where they are cleared?

@rsango6
Copy link

rsango6 commented Aug 16, 2023

Yes, this doesn't sound good, that is most likely the error. Did you by any chance set convertGenes to true? That is not a good idea for Mouse-GEM, this should be false. If not, could you set a breakpoint in the code and see where they are cleared?

Hi,

No, I have left convertGenes as is, so this flag is false.
I also tried just running prepHumanModelForftINIT as shown in tutorial like so:

prepDataHuman = prepHumanModelForftINIT(ihuman, false, ...
    '/path/to/Human-GEM/data/metabolicTasks/metabolicTasks_Essential.txt', ...
    'path/to/Human-GEM/model/reactions.tsv');

Here I also get the same error:

>> prepDataHuman.minModel

ans = 

  struct with fields:

                     id: 'Human-GEM'
            description: 'Generic genome-scale metabolic model of Homo sapiens'
                   rxns: {7079×1 cell}
                   mets: {2798×1 cell}
                      S: [2798×7079 double]
                     lb: [7079×1 double]
                     ub: [7079×1 double]
                    rev: [7079×1 double]
                      c: [7079×1 double]
                      b: [2798×1 double]
                  comps: {9×1 cell}
              compNames: {9×1 cell}
               rxnNames: {7079×1 cell}
                grRules: {7079×1 cell}
             rxnGeneMat: [7079×0 double]
             subSystems: {7079×1 cell}
                eccodes: {7079×1 cell}
               rxnNotes: {7079×1 cell}
                  genes: {}
         geneShortNames: {}

Here the prepDataHuman.minModel.grRules looks like its populated with values, but it's not:

>> prepDataHuman.minModel.grRules(1:5)

ans =

  5×1 cell array

    {0×0 char}
    {0×0 char}
    {0×0 char}
    {0×0 char}
    {0×0 char}

I then looked into how prepData is generated, and realized that at step 4 "Second simplification (~1 hour)" Parallel Computing Toolbox wasn't installed. I installed it, ran prepHumanModelForftINIT and got the same results, so it's not even that. It's weird, because I would be expecting the code to yell because of issues if nothing is detected in prepData.minModel.genes and prepData.minModel.grRules.

I hope I haven't made this super confusing!

@rsango6
Copy link

rsango6 commented Aug 16, 2023

Another update from my side:

I decided to manually impute missing grRules values inside prepData.minModel like so:

common_rxns = intersect(MouseGEM.rxns, prepData.minModel.rxns)
grRules = MouseGEM.grRules(ismember(MouseGEM.rxns, common_rxns))
prepData.minModel.grRules = grRules

and running:

model1 = ftINIT(prepData, data_struct.tissues{1}, [], [], data_struct, {}, getHumanGEMINITSteps('1+0'), false, true)

produces again the same error. maybe it also needs prepData.minModel.genes structure to be populated with values.

@johan-gson
Copy link
Collaborator

Hi, sorry, I misremembered, the GrRules should be empty in the minModel. Would it be possible for you to send me your code and data, and I can debug and see what is happening? You can send it to johan.gson@gmail.com. I can probably figure this out quickly, although there are no guarantees. One final thing to check: could you check if the b field in the mouse model has two columns? This is a bug that has been haunting mouse-GEM for a long time :).

@johan-gson
Copy link
Collaborator

See SysBioChalmers/Mouse-GEM#22

@johan-gson
Copy link
Collaborator

In minModel, all linearly dependent reactions are merged, which makes the model smaller and thereby faster to solve. There is no good way to merge grRules, so the field is cleared - this is not used in ftINIT anyways.

@rsango6
Copy link

rsango6 commented Aug 17, 2023

Hi, sorry, I misremembered, the GrRules should be empty in the minModel. Would it be possible for you to send me your code and data, and I can debug and see what is happening? You can send it to johan.gson@gmail.com. I can probably figure this out quickly, although there are no guarantees. One final thing to check: could you check if the b field in the mouse model has two columns? This is a bug that has been haunting mouse-GEM for a long time :).

I have removed the second column in MouseGEM.b but to no avail. I am sending you my stuff to your email, thanks a lot for helping me out :)

@mihai-sysbio
Copy link
Member

Just noting here, however this gets solved, please follow up with a new issue to update either code (ftINIT or wherever else), or perhaps the guide. At least, I think the guide should be updated with some self-debugging code, so that people can self-diagnose some of the more common issues.

@johan-gson
Copy link
Collaborator

Thanks for the data, I will have a look. I don't see any obvious mistakes by just looking at your code, it looks good. Let me get back once I have debugged this.

@haowang-bioinfo Could you take a look at if the b field still has two columns in the latest Mouse-GEM? We have tried to fix this several times now, and it still comes back and bites us :)

@haowang-bioinfo
Copy link
Member

haowang-bioinfo commented Aug 17, 2023

@johan-gson yes I just checked the latest Mouse-GEM, which still has two columns in the b field - fix it now

@johan-gson
Copy link
Collaborator

@haowang-bioinfo The error must be in the script converting from human to mouse - no point fixing it in the model. But you probably realize that :). Would be good to add a test case that specifically tests this before releases, this problem seems to have a magic ability to come back.

@johan-gson
Copy link
Collaborator

Hi @rsango6, I tested it on my computer, and it worked, which is a bit confusing. I am using Gurobi 9.5, maybe I have not tested exactly the version you are running. One thing I see in the data is that the TPM doesn't sum to 10^6, so I would rescale it, but it is not what is causing the failure. What versions of Mouse-GEM and Human-GEM are you using?

@johan-gson
Copy link
Collaborator

I'm using the latest mouse gem

@johan-gson
Copy link
Collaborator

And, I didn't do any manipulations of the model except fixing the .b field, exactly as you did. I did not run the lines manipulating the grRules, that should not be done.

@rsango6
Copy link

rsango6 commented Aug 17, 2023

Hi @rsango6, I tested it on my computer, and it worked, which is a bit confusing. I am using Gurobi 9.5, maybe I have not tested exactly the version you are running. One thing I see in the data is that the TPM doesn't sum to 10^6, so I would rescale it, but it is not what is causing the failure. What versions of Mouse-GEM and Human-GEM are you using?

I am using:

Human-GEM v1.16.0
Mouse-GEM v1.6.0
RAVEN v2.8.4
MATLAB v2019b

and now have switched from Gurobi v10.02 to Gurobi v9.5.2. I thought that maybe the reason could be that TPM are loaded not as numeric values, rather as characters. Though still getting the same error. It does tell me at start of the analysis with ftINIT call there is a WARNING: Exchange metabolites are still present in the model. Use simplifyModel if this is not intended. Could that be the reason why? However, I had to use addBoundaryMets() on the mouseGEM otherwise I would get an error at a previous step with prepHumanModelForftINIT:

Step 3: Check tasks (~10 min)
Attempt to grow array along ambiguous dimension.

Error in closeModel (line 50)
        closedModel.b(numel(closedModel.b)+1)=0;

Error in prepINITModel (line 82)
    bModel = closeModel(cModel);

Error in prepHumanModelForftINIT (line 133)
prepDataHumanGEM = prepINITModel(m, taskStruct, spontRxnNames, convertGenes, customRxnsToIgnore, 'e');

It's rather strange that it is working for you and not in my case. By the way, TPM values are all obtained from Salmon as is, haven't manipulated with them in any way so that is also weird that there are also some discrepancies too. I need to think why that would be the case.

@johan-gson
Copy link
Collaborator

Ok, probably not a Gurobi thing then, which is good, could have been complicated to solve. This is strange. I also used RAVEN 2.8.4. I used the latest mouse-GEM, just downloaded it, I guess that is the same. And, the same MATLAB version. I do have an older Human-GEM though, something from devel in the middle. Does it work with the prepData I emailed you, could you test that?

@rsango6
Copy link

rsango6 commented Aug 17, 2023

Ok, probably not a Gurobi thing then, which is good, could have been complicated to solve. This is strange. I also used RAVEN 2.8.4. I used the latest mouse-GEM, just downloaded it, I guess that is the same. And, the same MATLAB version. I do have an older Human-GEM though, something from devel in the middle. Does it work with the prepData I emailed you, could you test that?

I can confirm I have now tried with your prepData object, and for both getHumanGEMINITSteps('1+0') and getHumanGEMINITSteps('1+1') and within seconds I have successful generation of the models.

Really interesting as to what has gone wrong in my case when generating prepData, seeing we are using dependencies with identical versions. Maybe something to do with the OS -> I am running the whole thing on macOS Ventura 13.4.1

@johan-gson
Copy link
Collaborator

johan-gson commented Aug 17, 2023 via email

haowang-bioinfo added a commit that referenced this issue Aug 18, 2023
- This is to resolve recurring issue reported in #511
@haowang-bioinfo
Copy link
Member

@haowang-bioinfo The error must be in the script converting from human to mouse - no point fixing it in the model. But you probably realize that :). Would be good to add a test case that specifically tests this before releases, this problem seems to have a magic ability to come back.

the fix is now implemented by bb4cc9f in #692

@rsango6
Copy link

rsango6 commented Aug 20, 2023 via email

@johan-gson
Copy link
Collaborator

johan-gson commented Aug 20, 2023 via email

@johan-gson
Copy link
Collaborator

johan-gson commented Aug 21, 2023 via email

@rsango6
Copy link

rsango6 commented Feb 2, 2024

Hi @johan-gson, did you have any luck finding a solution to this issue? Thanks!

@johan-gson
Copy link
Collaborator

Sorry I have not. I will try to take another look at this in the coming weeks. Sorry for the delay, I have a pretty heavy workload right now.

@rsango6
Copy link

rsango6 commented Feb 2, 2024

No worries, thanks for your efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants