Skip to content

fix: bug in merge result#46

Merged
ypriverol merged 2 commits into
bigbio:mainfrom
yueqixuan:main
Jun 10, 2026
Merged

fix: bug in merge result#46
ypriverol merged 2 commits into
bigbio:mainfrom
yueqixuan:main

Conversation

@yueqixuan

@yueqixuan yueqixuan commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved peptide identification index preservation during algorithm result merging.
    • Enhanced handling of missing peptide identifications in merged output.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@yueqixuan, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 53 minutes and 48 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fa76dd07-01ac-4f50-abe1-bc66e8e17c4b

📥 Commits

Reviewing files that changed from the base of the PR and between 509f24b and bd3d40a.

📒 Files selected for processing (1)
  • onsite/onsitec.py
📝 Walkthrough

Walkthrough

The merge_algorithm_results function in onsite/onsitec.py was refactored to accept a new input_idparquet parameter. The merge indexing mechanism now preserves LucXor's peptide identification indices instead of generating new ones via a local counter. The output logic was restructured to align datatypes, update a template DataFrame, mark missing identifications, and thread the parameter through to storage.

Changes

Merge Algorithm Results Refactoring

Layer / File(s) Summary
Function signature and merge indexing
onsite/onsitec.py
Function signature extended to require input_idparquet. Merge loop refactored to remove merged_pep_idx counter and use LucXor-provided peptide_identification_index values.
Result output and template update
onsite/onsitec.py
Output subset indexed by peptide identification and hit index. Column datatypes aligned with template DataFrame. Template updated with merged values; missing entries marked with score = np.nan and score_type = onsite_combined_score. Result saved via save_dataframes with source_idparquet parameter.
Call site integration
onsite/onsitec.py
run_all_algorithms_from_single_cli updated to pass id_file as input_idparquet argument to merge_algorithm_results.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 The peptides now wear their true names,
From LucXor's blessed identification frames,
Templates align with careful care,
Missing scores marked here and there,
Merged results flow through fresh refactored gates.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix: bug in merge result' is vague and generic, lacking specific details about which bug was fixed or what the actual change entails. Use a more descriptive title that specifies the bug being fixed, such as 'fix: preserve LucXor peptide_identification_index in merge_algorithm_results' or similar that clearly indicates the specific issue addressed.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codacy-production

codacy-production Bot commented Jun 10, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 4 complexity · 0 duplication

Metric Results
Complexity 4
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
onsite/onsitec.py (2)

188-188: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Pass id_file into the all command's merge call.

merge_algorithm_results() now requires input_idparquet, but Line 188 still passes four arguments. onsite all ... will fail with TypeError before any merged output is written.

Suggested fix
-            merge_algorithm_results(ascore_out, phosphors_out, lucxor_out, out_file)
+            merge_algorithm_results(ascore_out, phosphors_out, lucxor_out, out_file, id_file)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@onsite/onsitec.py` at line 188, The call to merge_algorithm_results in the
"all" command is missing the new required input_idparquet parameter; update the
call merge_algorithm_results(ascore_out, phosphors_out, lucxor_out, out_file) to
include the id file variable (e.g., id_file) as the first or named
input_idparquet argument so it matches the new signature
merge_algorithm_results(input_idparquet, ascore_out, phosphors_out, lucxor_out,
out_file); locate the call where the "all" command invokes
merge_algorithm_results and add the id_file/input_idparquet parameter.

295-304: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Use the real peptide_identification_index, not the join tuple's row index.

_join_psms_by_ref() returns DataFrame indices for ai, pi, and li (the merge test asserts li against lucxor.index). This loop then filters peptide_identification_index == ai/pi/li and writes li back out on Line 371. Once a peptide identification has multiple hits, the merge starts reading and updating the wrong rows.

Suggested fix
     for ai, pi, li in triples:
+        a_pep_idx = int(ascore_df.iloc[ai]["peptide_identification_index"])
+        p_pep_idx = int(phosphors_df.iloc[pi]["peptide_identification_index"])
+        l_pep_idx = int(lucxor_df.iloc[li]["peptide_identification_index"])
+
         a_metas = _get_metas_dict(ascore_df, ai)
         p_metas = _get_metas_dict(phosphors_df, pi)
         l_metas = _get_metas_dict(lucxor_df, li)

         # Get the actual row data from LucXor for base properties
         for hit_idx in range(3):
-            a_hit_row = ascore_df[(ascore_df["peptide_identification_index"] == ai) & (ascore_df["hit_index"] == hit_idx)]
-            p_hit_row = phosphors_df[(phosphors_df["peptide_identification_index"] == pi) & (phosphors_df["hit_index"] == hit_idx)]
-            l_hit_row = lucxor_df[(lucxor_df["peptide_identification_index"] == li) & (lucxor_df["hit_index"] == hit_idx)]
+            a_hit_row = ascore_df[(ascore_df["peptide_identification_index"] == a_pep_idx) & (ascore_df["hit_index"] == hit_idx)]
+            p_hit_row = phosphors_df[(phosphors_df["peptide_identification_index"] == p_pep_idx) & (phosphors_df["hit_index"] == hit_idx)]
+            l_hit_row = lucxor_df[(lucxor_df["peptide_identification_index"] == l_pep_idx) & (lucxor_df["hit_index"] == hit_idx)]
...
-                "peptide_identification_index": li,
+                "peptide_identification_index": l_pep_idx,

Also applies to: 371-371

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@onsite/onsitec.py` around lines 295 - 304, The loop is using the tuple values
ai/pi/li (which are DataFrame indices returned by _join_psms_by_ref) to filter
rows by the peptide_identification_index column, causing the wrong rows to be
read/updated when a peptide_identification has multiple hits; change the three
filters to match the DataFrame index instead (e.g., replace
ascore_df["peptide_identification_index"] == ai with ascore_df.index == ai, or
better use ascore_df.loc[ai] combined with hit_index==hit_idx) for a_hit_row,
p_hit_row, and l_hit_row and ensure the subsequent update that writes li back
uses the same index-based selection so you update the correct rows.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@onsite/onsitec.py`:
- Around line 379-384: The code fails when merged_rows is empty because out_df
has no columns and set_index(["peptide_identification_index","hit_index"])
raises KeyError; fix by detecting this zero-merge case right after out_df =
pd.DataFrame(merged_rows) and constructing an out_df that contains the expected
index columns and score columns (or at minimum the peptide_identification_index
and hit_index columns) populated from lucxor_df unique pairs (or set to NaN)
before calling set_index; ensure you reference merged_rows, out_df, full_df,
lucxor_df and use set_index(["peptide_identification_index","hit_index"]) only
after this fallback is in place so the downstream merge/writes produce rows with
missing scores instead of crashing.

---

Outside diff comments:
In `@onsite/onsitec.py`:
- Line 188: The call to merge_algorithm_results in the "all" command is missing
the new required input_idparquet parameter; update the call
merge_algorithm_results(ascore_out, phosphors_out, lucxor_out, out_file) to
include the id file variable (e.g., id_file) as the first or named
input_idparquet argument so it matches the new signature
merge_algorithm_results(input_idparquet, ascore_out, phosphors_out, lucxor_out,
out_file); locate the call where the "all" command invokes
merge_algorithm_results and add the id_file/input_idparquet parameter.
- Around line 295-304: The loop is using the tuple values ai/pi/li (which are
DataFrame indices returned by _join_psms_by_ref) to filter rows by the
peptide_identification_index column, causing the wrong rows to be read/updated
when a peptide_identification has multiple hits; change the three filters to
match the DataFrame index instead (e.g., replace
ascore_df["peptide_identification_index"] == ai with ascore_df.index == ai, or
better use ascore_df.loc[ai] combined with hit_index==hit_idx) for a_hit_row,
p_hit_row, and l_hit_row and ensure the subsequent update that writes li back
uses the same index-based selection so you update the correct rows.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8af28ad7-6259-44fc-879d-dd54c74b87ee

📥 Commits

Reviewing files that changed from the base of the PR and between 9b8c531 and 509f24b.

📒 Files selected for processing (1)
  • onsite/onsitec.py

Comment thread onsite/onsitec.py
Comment on lines 379 to +384
out_df = pd.DataFrame(merged_rows)
save_dataframes(output_file, out_df, proteins_df, template_df=lucxor_df)

full_df = lucxor_df.copy()

out_df = out_df.set_index(["peptide_identification_index", "hit_index"])
full_df = full_df.set_index(["peptide_identification_index", "hit_index"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Handle the zero-merge path before calling set_index.

When no triples survive the join, pd.DataFrame(merged_rows) has no columns, so Line 383 raises KeyError instead of writing an output where every score is marked missing. This is reachable whenever the tools have no common spectrum_reference or every common PSM is skipped for sequence mismatch.

Suggested fix
-    out_df = pd.DataFrame(merged_rows)
-
     full_df = lucxor_df.copy()
+    out_df = (
+        pd.DataFrame(merged_rows)
+        if merged_rows
+        else full_df.iloc[0:0].copy()
+    )

     out_df = out_df.set_index(["peptide_identification_index", "hit_index"])
     full_df = full_df.set_index(["peptide_identification_index", "hit_index"])
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@onsite/onsitec.py` around lines 379 - 384, The code fails when merged_rows is
empty because out_df has no columns and
set_index(["peptide_identification_index","hit_index"]) raises KeyError; fix by
detecting this zero-merge case right after out_df = pd.DataFrame(merged_rows)
and constructing an out_df that contains the expected index columns and score
columns (or at minimum the peptide_identification_index and hit_index columns)
populated from lucxor_df unique pairs (or set to NaN) before calling set_index;
ensure you reference merged_rows, out_df, full_df, lucxor_df and use
set_index(["peptide_identification_index","hit_index"]) only after this fallback
is in place so the downstream merge/writes produce rows with missing scores
instead of crashing.

@ypriverol ypriverol self-requested a review June 10, 2026 12:11
@ypriverol ypriverol merged commit 1fb2a7d into bigbio:main Jun 10, 2026
3 checks passed
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.

2 participants