3dem / model-angelo

Automatic atomic model building program for cryo-EM maps
MIT License
110 stars 18 forks source link

WIP: Getting cleaner and less error prone HMM parsing ready #61

Closed jamaliki closed 8 months ago

jamaliki commented 10 months ago

Hey @althonos

I'm not sure you remember, but we had a chat here about getting ModelAngelo's HMM parsing all done with pyhmmer's utilities: https://github.com/althonos/pyhmmer/issues/40

I think it is close right now, but it seems to be having an issue with the consensus part of the HMM. Could you take a look if you have a chance? I get the following error:

Traceback (most recent call last):
  File "/Users/kiarash/Desktop/code/cambridge/3dem_model_angelo/model-angelo/model_angelo/utils/aa_probs_to_hmm_new.py", line 93, in <module>
    hmm = aa_log_probs_to_hmm("test", probs, confidence)
  File "/Users/kiarash/Desktop/code/cambridge/3dem_model_angelo/model-angelo/model_angelo/utils/aa_probs_to_hmm_new.py", line 83, in aa_log_probs_to_hmm
    hmm.validate()
  File "pyhmmer/plan7.pyx", line 3220, in pyhmmer.plan7.HMM.validate
  File "pyhmmer/plan7.pyx", line 3246, in pyhmmer.plan7.HMM.validate
ValueError: Invalid HMM: p7H_CONS flag down, but consensus string is present

There's quite a bit of code, but what is really important is line 66 onwards. If you wish, you can see how we do it in aa_probs_to_hmm.py

althonos commented 10 months ago

Hi @jamaliki,

This error was caused by an outdated fix (althonos/pyhmmer#5) which was causing the consensus flag to be always set. Since the update to v0.10.0 it shouldn't be needed anymore (but I forgot to remove it), so I'l make a new patch release. Make sure to require at least PyHMMER v0.10.1 and you should be all set! :)

jamaliki commented 10 months ago

Thanks, worked like a charm @althonos! Going to do some testing but it should be the same. Are there any ways to write the composition row as well?

althonos commented 10 months ago

You don't have to set it manually, it will be computed from the HMM occupancy, just call HMM.set_composition after you're done filling it (typically right before HMM.validate). Then the consensus attribute of the HMM will be a VectorF that you're free to edit if you want.

You can also call HMM.set_consensus if you wish to build or record a consensus.

jamaliki commented 10 months ago

Thanks @althonos, that's great!