Skip to content

fix: build the database when a uniprot_N column of complex_input.csv is unused - #232

Open
cindykrafft wants to merge 1 commit into
ventolab:masterfrom
cindykrafft:fix/issue-224-create-db-empty-subunit-column
Open

fix: build the database when a uniprot_N column of complex_input.csv is unused#232
cindykrafft wants to merge 1 commit into
ventolab:masterfrom
cindykrafft:fix/issue-224-create-db-empty-subunit-column

Conversation

@cindykrafft

Copy link
Copy Markdown

Fixes #224.

Cause. db_utils.create_db runs sanity_test_report_unknown_proteins, which checks that every subunit accession in complex_input.csv exists in protein_input.csv by merging each uniprot_N column against the uniprot column (cellphonedb/utils/db_utils.py:603). When no complex in the file fills one of the uniprot_N columns present in the header, pandas reads that column as an all-NaN float64 column, and the merge against the string column raises

ValueError: You are trying to merge on float64 and object columns for key 'uniprot_3'. If you wish to proceed you should use pd.concat

(float64 and str under pandas 3). That is the normal shape of a custom database built the way the T0_BuildDBfromFiles notebook describes: the released complex_input.csv header has uniprot_1..uniprot_5, only one released complex uses uniprot_5 and four use uniprot_4, so any subset that drops those rows fails to build. Converting the columns to strings before saving the CSV does not help, because create_db re-reads the files. #137 (2023, closed) shows the same traceback from the same merge for a custom database with an essentially empty complex_input.csv.

Fix. The sanity test now takes the non-empty accessions of each subunit column (dropna()) and reports those absent from protein_input.csv. That is exactly what the outer merge computed (uniprot null and uniprot_N not null), without depending on the column dtype. The warning text and content are unchanged: on the released v5.0.0 input files, master and this branch print identical output, both as-is (no warning) and with two proteins removed from protein_input.csv (both are reported by both versions). No result of any analysis method is affected.

Test. CreateDbUnitTests in method_tests.py (a new TestCase with its own setUp, so it needs no database download and runs in CI as-is):

  • test_create_db_with_unused_subunit_columns: create_db on hand-written input files with the standard four-column header and a single dimer (uniprot_3/uniprot_4 empty), checking the zip is produced with the expected complex and its two-row composition — fails on master with the ValueError above;
  • test_unknown_complex_proteins_still_reported: the sanity test on a frame with an all-NaN float64 column and one unknown accession still names that accession and nothing else — also fails on master.

Run. Python 3.12, pandas 2.3.3: the two new tests fail on unmodified master and pass with the change; flake8 . --count --select=E9,F63,F7,F82 reports 0 and flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 reports 0 before and after. The rest of method_tests.py is unchanged by this PR (the four tests that read ../../../example_data/test.h5ad fail on master in this checkout for the pre-existing path reason that #210 addresses).

Found while working through open issues in Mytochondria, a volunteer project that verifies fixes for the software behind published results (methods and harnesses: https://github.com/cindykrafft/mytochondria/tree/main/audits/cellphonedb)


Generated by Claude Code

…is unused

db_utils.create_db raised

    ValueError: You are trying to merge on float64 and object columns for key 'uniprot_3'

whenever no complex in complex_input.csv filled one of the uniprot_N subunit
columns present in the header - the normal case for a custom database built from a
subset of the released files, whose header has uniprot_1..uniprot_5 while most
complexes are dimers. pandas reads such a column as all-NaN float64, and
sanity_test_report_unknown_proteins merged it against the string 'uniprot' column
of protein_input.csv.

The sanity test now takes the non-empty accessions of each subunit column and
reports those absent from protein_input.csv, which is what the outer merge computed,
without depending on the column dtype. Warning text and content are unchanged.

Adds CreateDbUnitTests (no database download): create_db on hand-written input
files whose uniprot_3/uniprot_4 columns are empty, and a check that unknown
subunits are still reported while empty slots are skipped.

Fixes ventolab#224

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TaHntBDKuZJpMAAMenkC44
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 this pull request may close these issues.

problems in build database by files

1 participant