Skip to content

Fixes #3421 Enable PK-Sim ExpressionProfile from MoBi.R#3420

Merged
rwmcintosh merged 2 commits intoV13from
2278-create-expression-profile-from-r
Feb 25, 2026
Merged

Fixes #3421 Enable PK-Sim ExpressionProfile from MoBi.R#3420
rwmcintosh merged 2 commits intoV13from
2278-create-expression-profile-from-r

Conversation

@rwmcintosh
Copy link
Member

@rwmcintosh rwmcintosh commented Feb 25, 2026

Fixes #3421 Enable PK-Sim ExpressionProfile from MoBi.R

Description

Allow MoBi to call into PK-Sim to create an Expression profile. First is to create the default profile without the database query.

Type of change

Please mark relevant options with an x in the brackets.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires documentation changes (link at least one user or developer documentation issue):
  • Algorithm update - updates algorithm documentation/questions/answers etc.
  • Other (please describe):

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Integration tests
  • Unit tests
  • Manual tests
  • No tests required

Reviewer checklist

Mark everything that needs to be checked before merging the PR.

  • Check if the code is well documented
  • Check if the behavior is what is expected
  • Check if the code is well tested
  • Check if the code is readable and well formatted
  • Additional checks (document below if any)
  • Check if documentation update issue(s) are created if the option This change requires a documentation update above is selected

Screenshots (if appropriate):

Questions (if appropriate):

Summary by CodeRabbit

  • New Features

    • Added the ability to create and exchange expression profiles by specifying a category, molecule name, and species. The system automatically validates the species to ensure validity and provides clear error messaging.
  • Chores

    • Enhanced error messages for improved user feedback when invalid categories or unrecognized species are encountered.
    • Expanded test coverage to ensure robust building block creation functionality.

@rwmcintosh rwmcintosh self-assigned this Feb 25, 2026
@rwmcintosh rwmcintosh added this to v13 Feb 25, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

This PR introduces expression profile creation functionality by adding error message helpers, converting BuildingBlockCreator to a static class with a new CreateExpressionProfile API, and adding comprehensive test coverage for the new creation patterns and error handling.

Changes

Cohort / File(s) Summary
Error Message Helpers
src/PKSim.Assets/PKSimConstants.cs
Adds two new error message generation methods: InvalidProteinCategory and CouldNotFindValidSpecies for consistent error reporting.
Expression Profile Creation
src/PKSim.R/Exchange/BuildingBlockCreator.cs
Converts BuildingBlockCreator to a static class. Introduces CreateExpressionProfile public API and internal helper to build expression profiles with species validation and category assignment. Refactors CreateIndividual to use new Api.ResolveTasks-based workflow.
Building Block Creation Tests
tests/PKSim.R.Tests/BuildingBlockCreatorSpecs.cs
Adds test contexts for CreateIndividual with populated characteristics, and expression profile creation for MetabolizingEnzyme, TransportProtein, and ProteinBindingPartner. Includes invalid species validation test.

Sequence Diagram

sequenceDiagram
    actor Client
    participant BuildingBlockCreator
    participant SpeciesRepository
    participant ProfileBuilder
    participant ExpressionProfile

    Client->>BuildingBlockCreator: CreateExpressionProfile(category, molecule, species)
    BuildingBlockCreator->>SpeciesRepository: Validate species exists
    alt Species Valid
        SpeciesRepository-->>BuildingBlockCreator: Species confirmed
        BuildingBlockCreator->>ProfileBuilder: Build profile by category type
        ProfileBuilder->>ExpressionProfile: Create with category
        ExpressionProfile-->>ProfileBuilder: Profile instance
        ProfileBuilder-->>BuildingBlockCreator: Apply defaults
        BuildingBlockCreator-->>Client: Return profile
    else Species Invalid
        SpeciesRepository-->>BuildingBlockCreator: Species not found
        BuildingBlockCreator-->>Client: Throw ArgumentException
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • msevestre
  • PavelBal
  • benjaperez1983

Poem

🐰 A species hops through validation's gate,
Building blocks now gather in their fate,
Expressions dance with molecules so bright,
Error messages keep all things right!
Static classes hold their creation's might.

🚥 Pre-merge checks | ✅ 2 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements expression profile creation from R/MoBi, but linked issue #2278 only describes a UI 'Stop' button sizing issue with no code requirements. Clarify the correct linked issue for this feature. The PR objectives mention creating expression profiles, but #2278 does not support this scope.
Out of Scope Changes check ⚠️ Warning The PR adds extensive expression profile creation functionality across multiple files, but the linked issue #2278 only addresses a UI button size problem. Either link to the correct issue(s) that specify expression profile creation requirements or document why these changes address the UI issue.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title references issue #3421 and mentions enabling PK-Sim ExpressionProfile from MoBi.R, which aligns with the implementation adding expression profile creation capabilities.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2278-create-expression-profile-from-r

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/PKSim.R.Tests/BuildingBlockCreatorSpecs.cs (1)

56-70: Strengthen success-path assertions beyond non-null.

These tests currently pass even if the wrong profile type/category/species gets serialized. Please deserialize or inspect the payload and assert expected fields (at least molecule, species, and profile type/category) per scenario.

Also applies to: 94-124

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/PKSim.R.Tests/BuildingBlockCreatorSpecs.cs` around lines 56 - 70, The
test CreateExchangeMetabolizingEnzyme currently only asserts the returned string
is non-null; update it to deserialize the returned payload from
BuildingBlockCreator.CreateExpressionProfile(MetabolizingEnzyme, "CYP3A4",
CoreConstants.Species.HUMAN) and assert that the resulting object has the
expected molecule/name ("CYP3A4"), species (CoreConstants.Species.HUMAN or
equivalent value), and profile type/category indicating a metabolizing enzyme;
apply the same stronger assertions to the other similar tests that call
BuildingBlockCreator.CreateExpressionProfile so each verifies molecule, species
and profile type/category rather than just non-null.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/PKSim.R/Exchange/BuildingBlockCreator.cs`:
- Around line 36-63: The code conflates "protein type" and "expression profile
category" by using the same parameter (category) to pick the generic T and then
writing it into expressionProfile.Category; fix by separating those concerns: in
CreateExpressionProfile compute a distinct proteinType selector (e.g. determine
which generic T to use based on category using the
TransportProtein/ProteinBindingPartner/MetabolizingEnzyme constants) but keep
the original input as profileCategory, then change createExpressionProfile<T> to
accept a profileCategory parameter (or overload it) and set
expressionProfile.Category = profileCategory (not the type label); update calls
to createExpressionProfile<T>(...) accordingly and ensure
expressionProfile.Category only contains the intended profile category string.

---

Nitpick comments:
In `@tests/PKSim.R.Tests/BuildingBlockCreatorSpecs.cs`:
- Around line 56-70: The test CreateExchangeMetabolizingEnzyme currently only
asserts the returned string is non-null; update it to deserialize the returned
payload from BuildingBlockCreator.CreateExpressionProfile(MetabolizingEnzyme,
"CYP3A4", CoreConstants.Species.HUMAN) and assert that the resulting object has
the expected molecule/name ("CYP3A4"), species (CoreConstants.Species.HUMAN or
equivalent value), and profile type/category indicating a metabolizing enzyme;
apply the same stronger assertions to the other similar tests that call
BuildingBlockCreator.CreateExpressionProfile so each verifies molecule, species
and profile type/category rather than just non-null.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4403830 and 3fad03d.

📒 Files selected for processing (3)
  • src/PKSim.Assets/PKSimConstants.cs
  • src/PKSim.R/Exchange/BuildingBlockCreator.cs
  • tests/PKSim.R.Tests/BuildingBlockCreatorSpecs.cs

@rwmcintosh rwmcintosh changed the title Fixes #2278 create expression profile from r Fixes #3421 Enable PK-Sim ExpressionProfile from MoBi.R Feb 25, 2026
@rwmcintosh rwmcintosh linked an issue Feb 25, 2026 that may be closed by this pull request
@rwmcintosh rwmcintosh merged commit ab525b9 into V13 Feb 25, 2026
2 checks passed
@github-project-automation github-project-automation bot moved this to Done in v13 Feb 25, 2026
@rwmcintosh rwmcintosh deleted the 2278-create-expression-profile-from-r branch February 25, 2026 16:47
@Yuri05 Yuri05 moved this from Done to Verified in v13 Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Verified

Development

Successfully merging this pull request may close these issues.

Enable PK-Sim ExpressionProfile from MoBi.R

2 participants