Cellprofiler analyst - Hit Table error

Hi @DStirling , I’m still following the CPA tutorial and I think I might found an other issue in CPA 3.0.1:

The error occurs when you double click on asterisk in the first column which is supposed to open the selected image (Image 17 in this example)
Error thrown:

An error occurred in the program:
KeyError: (17, 'plate_1', 'E09', 167, 157, 10, 0.8576915542931923, 0.14230844575914095, 0.7801004582789878, 0, 0, 0)

Traceback (most recent call last):
  File "cpa/tableviewer.py", line 872, in on_dclick_label
  File "cpa/tableviewer.py", line 210, in get_object_keys_at_row
  File "cpa/datamodel.py", line 192, in GetObjectCountFromImage

Tell me if I can help you…or if I did something wrong :crazy_face:

An other “cosmetic issue” with Hit Tables:
When trying to save the Hit Table in the Database: The default Table Name contains invalid characters.

But, you don’t know that until you click to save it and throws the warning:

Capture d’écran 2021-05-02 à 14.10.55

Maybe just replacing wrong characters by default with “_” should be OK?

An other problem (or the same I don’t know):
If you set up correct name to the Hit Table to be saved in the database (permanently):
CPA throws this error:

An error occurred in the program:
AttributeError: 'list' object has no attribute 'replace'

Traceback (most recent call last):
  File "cpa/tableviewer.py", line 968, in on_save_table_to_db
  File "cpa/dbconnect.py", line 1792, in CreateTableFromData
  File "cpa/dbconnect.py", line 104, in clean_up_colnames
  File "cpa/dbconnect.py", line 104, in <listcomp>

This last error doesn’t show up you save it as CSV file.

Thanks for reporting all this, I’ll put together some fixes this week.

For now, it looks like the first error can be worked around by right-clicking the row and using the ‘show image’ button.

For the second we just need to clean up the default name a bit, currently it’s pulling whatever the window name is.

For that last error I’ll have to take a closer look at what’s going on, something is getting into the list of column names that shouldn’t be there.

Very much appreciate you finding these, there’s quite a bit of obscure functionality in CPA which is tricky to test with every possible database structure.

I think I found the source of the error:
I told you that saving Hit Table as CSV doesn’t throw errors. But If you open the csv file you see that some columns keep wrong characters for sqlite dbase:
Capture d’écran 2021-05-03 à 10.03.49

if you replace them, and then import csv through DB Browser into Cellprofiler’s sqlite dbase, it works.

I’m sorry I have zero skills in python programming so I can not help more than that. :sweat_smile:

I believe I’ve now fixed these issues (except default table names, I don’t think there’s a good way to automatically generate this without the user entering something). That’ll be in 3.0.2 when that rolls around. I don’t think this is urgent enough to merit an immediate release, we’ll probably wait a week or two to catch any other bugs that are found before building a new version. Thanks for the info!

If you’re interested, the first problem was that CPA wasn’t getting the correct column names which tell it which column reflects the Image number. Instead it grabbed all columns and couldn’t find an image matching a long series of numbers.

The latter issue was just in the table saving system. CPA automatically cleans up the column names to remove invalid characters, but in the Python 3 upgrade that got slightly broken. It works now.

Thanks for the explanations :wink: