fix: build the database when a uniprot_N column of complex_input.csv is unused - #232
Open
cindykrafft wants to merge 1 commit into
Open
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #224.
Cause.
db_utils.create_dbrunssanity_test_report_unknown_proteins, which checks that every subunit accession incomplex_input.csvexists inprotein_input.csvby merging eachuniprot_Ncolumn against theuniprotcolumn (cellphonedb/utils/db_utils.py:603). When no complex in the file fills one of theuniprot_Ncolumns present in the header, pandas reads that column as an all-NaNfloat64column, and the merge against the string column raises(
float64 and strunder pandas 3). That is the normal shape of a custom database built the way theT0_BuildDBfromFilesnotebook describes: the releasedcomplex_input.csvheader hasuniprot_1..uniprot_5, only one released complex usesuniprot_5and four useuniprot_4, so any subset that drops those rows fails to build. Converting the columns to strings before saving the CSV does not help, becausecreate_dbre-reads the files. #137 (2023, closed) shows the same traceback from the same merge for a custom database with an essentially emptycomplex_input.csv.Fix. The sanity test now takes the non-empty accessions of each subunit column (
dropna()) and reports those absent fromprotein_input.csv. That is exactly what the outer merge computed (uniprotnull anduniprot_Nnot 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 fromprotein_input.csv(both are reported by both versions). No result of any analysis method is affected.Test.
CreateDbUnitTestsinmethod_tests.py(a newTestCasewith its ownsetUp, so it needs no database download and runs in CI as-is):test_create_db_with_unused_subunit_columns:create_dbon hand-written input files with the standard four-column header and a single dimer (uniprot_3/uniprot_4empty), checking the zip is produced with the expected complex and its two-row composition — fails on master with theValueErrorabove;test_unknown_complex_proteins_still_reported: the sanity test on a frame with an all-NaNfloat64column 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
masterand pass with the change;flake8 . --count --select=E9,F63,F7,F82reports 0 andflake8 . --count --exit-zero --max-complexity=10 --max-line-length=127reports 0 before and after. The rest ofmethod_tests.pyis unchanged by this PR (the four tests that read../../../example_data/test.h5adfail onmasterin 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