basico icon indicating copy to clipboard operation
basico copied to clipboard

Call to `__build_result_from_ts` (et all?) causes ValueError when imported SBML model names species "Time"

Open CodeByDrescher opened this issue 1 year ago • 2 comments

Specifically, the call:

df.set_index('Time')

Causes an exception in Pandas, as it will find two Columns named "Time".

The example SBML model attached has a model with id="s23" and name="Time". ExampleSBML.zip

A Data Handler is initialized with both "Time" and "[Time]"

After running the time course, the resulting DataFrame has two columns with "Time" as its label.

When Basico tries to set the index to time, Pandas generates a ValueError.

CodeByDrescher avatar Oct 08 '24 15:10 CodeByDrescher

Are you running run_time_course_with_output(['Time', '[Time]']) that succeeds here. since the error message comes from __build_result_from_ts the time series object is being used, that one will have the species name without the brackets. And it would not be using the data handler.

But yes, the lookup by DisplayName only will fail if the name is not unique. I can add a method that goes through all model elements disambiguating elements with the same name.

fbergmann avatar Oct 08 '24 19:10 fbergmann

@CodeByDrescher I've released 0.76 that avoids this issue:

  • basico will no longer try to set the index, and instead issue a warning Duplicate column names in time series consider using use_sbml_id=True, or running ensure_unique_names()
  • the new function ensure_unique_names() appends a count to the name ensuring uniqueness

This release avoids the exception you encountered, though it would return a dataframe where multiple columns would have the same name. You could avoid that by calling ensure_unique_names, or using the flag on import:

>>> import_sbml("BIOMD0000000465_url.xml", ensure_unique_names=True)
>>> get_species("Time")
         compartment       type    unit  initial_concentration  ...            key sbml_id transition_time  display_name
name                                                            ...
Time (1)        Cell  reactions  nmol/l                    0.0  ...  Metabolite_25     s23             0.0      Time (1)

[1 rows x 15 columns]

fbergmann avatar Oct 09 '24 12:10 fbergmann

this has been resolved

fbergmann avatar Nov 11 '24 08:11 fbergmann