VicTorres23 / Cell_Factory_Design_2024_Bugs_Found

Here we can see all of the bugs encountered while doing the Cell Factory Design Tutotial found in: https://www.youtube.com/watch?v=ZNA_sP6KXbc
0 stars 0 forks source link

Cameo Production Envelope Out-of-Date #1

Open tiekneeshrimp opened 4 days ago

tiekneeshrimp commented 4 days ago

When I tried to execute this cell in tutorial:

from cameo.flux_analysis import phenotypic_phase_plane as ppp
from cameo.visualization.plotting.with_plotly import PlotlyPlotter
from cameo.visualization import plotting

abc_model = cobra.io.load_json_model('ABC_model.json')
for rxn in abc_model.reactions:
    rxn.lower_bound = 0
abc_model.reactions.R_1.upper_bound = 10

production_envelope = ppp( abc_model,
                              variables=[abc_model.reactions.R_8],
                              objective=abc_model.reactions.R_9,
                              points=21)

result_df = production_envelope.data_frame.rename( columns  = dict(
                                                            R_8 = 'growth_rate',
                                          objective_upper_bound = 'bioproduct_maximum',
                                          objective_lower_bound = 'bioproduct_minimum'))
plotter = PlotlyPlotter()
production_envelope.plot(plotter, 
                         title='Production envelope between bioproduct yield and growth rate for WT ABC model',
                         points=[(5,5), (20,0),(10,0)])

I got this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[13], line 20
     15 result_df = production_envelope.data_frame.rename( columns  = dict(
     16                                                             R_8 = 'growth_rate',
     17                                           objective_upper_bound = 'bioproduct_maximum',
     18                                           objective_lower_bound = 'bioproduct_minimum'))
     19 plotter = PlotlyPlotter()
---> 20 production_envelope.plot(plotter, 
     21                          title='Production envelope between bioproduct yield and growth rate for WT ABC model',
     22                          points=[(5,5), (20,0),(10,0)])

File ~\AppData\Local\anaconda3\Lib\site-packages\cameo\flux_analysis\analysis.py:818, in PhenotypicPhasePlaneResult.plot(self, plotter, grid, width, height, title, axis_font_size, palette, points, points_colors, estimate, **kwargs)
    814         _df = pandas.DataFrame([[row[upper], row[lower], row[variable], "WT"]],
    815                                columns=dataframe.columns)
    816         dataframe = dataframe.append(_df)
--> 818     plot = plotter.production_envelope(dataframe, grid=grid, width=width, height=height,
    819                                        title=title, y_axis_label=y_axis_label, x_axis_label=x_axis_label,
    820                                        palette=palette, points=points, points_colors=points_colors)
    822 elif len(self.variable_ids) == 2:
    823     var_1 = self.variable_ids[0]

File ~\AppData\Local\anaconda3\Lib\site-packages\cameo\visualization\plotting\with_plotly.py:140, in PlotlyPlotter.production_envelope(self, dataframe, grid, width, height, title, points, points_colors, palette, x_axis_label, y_axis_label)
    137 width, height = self.golden_ratio(width, height)
    139 data = []
--> 140 palette = self._palette(palette, len(variables))
    141 for variable, color in zip_repeat(variables, palette):
    142     _dataframe = dataframe[dataframe["strain"] == variable]

File ~\AppData\Local\anaconda3\Lib\site-packages\cameo\visualization\plotting\abstract.py:336, in AbstractPlotter._palette(palette, number)
    333 if isinstance(palette, str):
    334     palette = mapper.map_palette(palette, number)
--> 336 if isinstance(palette, collections.Iterable):
    337     return palette
    338 elif isinstance(palette, Palette):

AttributeError: module 'collections' has no attribute 'Iterable'
tiekneeshrimp commented 4 days ago

Looks like cameo python plotter needs to be updated (line 336): https://github.com/biosustain/cameo/blob/64508711aa7d17f51cc454dc0574f6d533ac5356/cameo/visualization/plotting/abstract.py#L336