tlubitz / SBtab

SBtab - Table format for Systems Biology:
www.sbtab.net
MIT License
6 stars 8 forks source link

cannot read sbtab, from csv or pd.dataframe #75

Closed Karrenbelt closed 5 years ago

Karrenbelt commented 5 years ago

Trying to balance my parameters, I wish to supply the sbtab_data file

pb = ParameterBalancing(model) sbtab_data = pb.make_sbtab(sbtab_data, 'data.tsv')

so I need to generate it first. Either trying to convert my dataframe via from_data_frame yields the following error

>>> sbtab_data = SBtab.SBtabTable.from_data_frame(data, 'data_table_id.csv', '!Quantity')

Traceback (most recent call last):
  File "/Users/Zarathustra/ETH/repositories/sbml_tools/venv/lib/python3.6/site-packages/sbtab/SBtab.py", line 994, in add_sbtab_string
    sbtab = SBtabTable(sbtab_string, filename)
  File "/Users/Zarathustra/ETH/repositories/sbml_tools/venv/lib/python3.6/site-packages/sbtab/SBtab.py", line 93, in __init__
    self.table = self._cut_table_string(self.preprocess)
  File "/Users/Zarathustra/ETH/repositories/sbml_tools/venv/lib/python3.6/site-packages/sbtab/SBtab.py", line 158, in _cut_table_string
    if row.replace(delimiter, '') != '' and row.replace(delimiter, '') != '[]':
TypeError: replace() argument 1 must be str, not bool

Next, I tried writing to a file (attached) and reading this

>>> tab = SBtab.read_csv('test_tab.csv', 'quantity')

Traceback (most recent call last):
  File "/Users/Zarathustra/ETH/repositories/sbml_tools/venv/lib/python3.6/site-packages/sbtab/SBtab.py", line 1032, in check_type_validity
    supported_types = misc.extract_supported_table_types()
  File "/Users/Zarathustra/ETH/repositories/sbml_tools/venv/lib/python3.6/site-packages/sbtab/misc.py", line 345, in extract_supported_table_types
    t = row[sbtab_def.columns_dict['!IsPartOf']]
KeyError: '!IsPartOf'

and more exceptions following in hadnling the exception above.

The exception above is raised as follows:

from sbtab import misc
supported_types = misc.extract_supported_table_types()

Any suggestions how to get my sbtab read as such so I can feed it to pb.make_sbtab() would be greatly appreciated

tlubitz commented 5 years ago

Hi there,

if you want to use parameter balancing in this way (I assume you are trying to embed this in your own Python module?), then the most straightforward way would be to use the function parameter_balancing_wrapper() in file parameter_balancing/standalone_version/parameter_balancing_core.py

You can do this as follows: (balanced_sbml_file, balanced_sbtab_file) = parameter_balancing_wrapper(sbml, sbtab_data_name=sbtab)

...where "sbml" and "sbtab" are the paths to your two input files. And these two paths are the only thing you need.

If you want to dig deeper in the interface, it may be interesting for you to have a closer look at the parameter_balancing_wrapper() function. It is well documented and shows how all input files (either optional or mandatory) can be fed into the balancing process.

Feel free to ask follow-ups; if everything's well, please close the issue.

Karrenbelt commented 5 years ago

Hi Timo,

I ran into some SBtab issues trying to use the parameter balancing, and I believe these are caused by the fact that you aren't using the latest SBtab in your parameter balancing.

Issues such as the delimiter being set to False by default, not being detected, and then not raising an exception (first case listed above), the file not being imported (last case listed above), and even some other things like a 'map' being return whereas it should be a list (in python3 at least), and the sbtab.to_dataframe and from_dataframe not working. All of these issues are no longer there when I import (the latest) SBtab separately, which leads me to believe that you might need to update the parameter balancing to use the latest version of sbtab.

I hope this helps, best, Michiel

tlubitz commented 5 years ago

Hi Michiel,

sorry for the late response. I understand and see the problem you're running into. It is true that SBtab kept developing while PB stood still on an older version of SBtab. When I last worked SBtab and it progressed further, there were very limited resources to adapt PB to the new SBtab, given that the latter is not necessarily downward-compatible. That's why we promote the usage of PB via e.g. the online interface or the parameter_balancing_wrapper, which works fine with the comprised older version of SBtab.

However, PB should be able to be incorporated into workflows and thus should work on the most current version of SBtab, which also holds several fixes (e.g. on the data_frame functions) that are required for a usage without errors.

At the moment, my resources are a bit limited in regard to doing this work. I have put it on my list though and will take care of it as soon as there is a free slot. We are talking, hopefully, still about September. You will know when the problem is sorted out when I close this issue.

Thanks for the feedback and all the best, Timo

tlubitz commented 5 years ago

PB code and the installer are upgraded to the newest version of SBtab. I tested all rudimentary functionalities, but since we have no unit testing in this project, any feedback on your experience is much appreciated. If there are any issues, please open another issue on the repo.

Thanks and all the best, Timo