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

SBML initialAmount is not supported, but initialConcentration is #374

Closed
djinnome opened this issue Sep 24, 2024 · 2 comments · Fixed by #382
Closed

SBML initialAmount is not supported, but initialConcentration is #374

djinnome opened this issue Sep 24, 2024 · 2 comments · Fixed by #382

Comments

@djinnome
Copy link
Contributor

djinnome commented Sep 24, 2024

Hi folks,

If an SBML model contains initialAmount instead of initialConcentration, then MIRA cannot read in the intial amount.

From the libsbml specification:

The optional attributes "initialAmount" and "initialConcentration", both having a data type of double, can be used to set the initial quantity of the species in the compartment where the species is located. These attributes are mutually exclusive; i.e., only one can have a value on any given instance of a Species_t object. Missing "initialAmount" and "initialConcentration" values implies that their values either are unknown, or to be obtained from an external source, or determined by an InitialAssignment_t or other SBML construct elsewhere in the model.

Until MIRA supports initialAmount, here is a workaround:

def update_SBML_for_MIRA(original_sbml_file, updated_sbml_file):
    """Updates the SBML file to ensure that the species name, initial concentrations, and has_only_substance_units are set."""
    
    # Read the SBML file
    document = libsbml.readSBMLFromFile(original_sbml_file)
    model = document.getModel()
    
    for species in model.getListOfSpecies():
        # Check if species has a valid ID
        if not species.isSetId() or not species.getId():
            raise ValueError("A species found without a valid ID.")
        
        # Set the species name to the ID if the name is not valid
        if not species.isSetName() or not species.getName():
            species.setName(species.getId())
        
        # Set initial concentration using initial amount if not already valid
        if not species.isSetInitialConcentration() or species.getInitialConcentration() <= 0:
            if species.isSetInitialAmount() and species.getInitialAmount() >= 0:
                species.setInitialConcentration(species.getInitialAmount())
            else:
                raise ValueError(f"Species '{species.getId()}' does not have a valid initial concentration or amount.")
        
        # Set has_only_substance_units to False
        species.setHasOnlySubstanceUnits(False)
    
    # Write the updated SBML file
    libsbml.writeSBMLToFile(document, updated_sbml_file)
@djinnome djinnome changed the title initialAmount is not supported, but initialConcentration is SBML initialAmount is not supported, but initialConcentration is Sep 24, 2024
@bgyori
Copy link
Member

bgyori commented Oct 4, 2024

@djinnome is there a specific SBML file which uses initialAmount that we could look at to test against?

@djinnome
Copy link
Contributor Author

djinnome commented Oct 4, 2024

Yes:
igfr.uncorrected.xml.gz

And after calling

update_SBML_for_MIRA('igfr.uncorrected.xml', 'igfr.xml')

you should get
igfr.xml.gz

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

Successfully merging a pull request may close this issue.

2 participants