Anthony-Nolan / Atlas

A free & open-source Donor Search Algorithm Service
GNU General Public License v3.0
9 stars 5 forks source link

Invalid Operation Exception when Dpb1 set in both LociToScore and LociToExcludeFromAggregateScore #887

Open seanmobrien opened 1 year ago

seanmobrien commented 1 year ago

Describe the bug When a search request sends Dbp1 in both the LociToScore and LociToExcludeFromAggregateScore fields, the search fails at the MatchPrediction stage. This message is found in application logs:

Exception: System.InvalidOperationException: Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.Min[TSource](IEnumerable`1 source, IComparer`1 comparer)
at Atlas.MatchingAlgorithm.Services.Search.Scoring.Aggregation.ScoreResultAggregator.CategoriseMatch(IList`1 nonDpb1ScoreResults, LocusScoreDetails dpb1ScoreDetails) in /home/vsts/work/1/s/Atlas.MatchingAlgorithm/Services/Search/Scoring/Aggregation/ScoreResultAggregator.cs:line 64
at Atlas.MatchingAlgorithm.Services.Search.Scoring.Aggregation.ScoreResultAggregator.AggregateScoreDetails(ScoreResultAggregatorParameters parameters) in /home/vsts/work/1/s/Atlas.MatchingAlgorithm/Services/Search/Scoring/Aggregation/ScoreResultAggregator.cs:line 40
at Atlas.MatchingAlgorithm.Services.Search.Scoring.DonorScoringService.BuildScoreResult(ScoringCriteria criteria, DonorScoringInfo donorScoringInfo, Dpb1TceGroupMatchType dpb1TceGroupMatchType) in /home/vsts/work/1/s/Atlas.MatchingAlgorithm/Services/Search/Scoring/DonorScoringService.cs:line 181
at Atlas.MatchingAlgorithm.Services.Search.Scoring.DonorScoringService.ScoreDonorHlaAgainstPatientMetadata(PhenotypeInfo`1 donorHla, ScoringCriteria scoringCriteria, PhenotypeInfo`1 patientScoringMetadata) in /home/vsts/work/1/s/Atlas.MatchingAlgorithm/Services/Search/Scoring/DonorScoringService.cs:line 135
at Atlas.MatchingAlgorithm.Services.Search.Scoring.MatchScoringService.StreamScoringUnranked(StreamingMatchResultsScoringRequest request)+MoveNext() in /home/vsts/work/1/s/Atlas.MatchingAlgorithm/Services/Search/Scoring/MatchScoringService.cs:line 104
at Atlas.MatchingAlgorithm.Services.Search.Scoring.MatchScoringService.StreamScoringUnranked(StreamingMatchResultsScoringRequest request)+MoveNext() in /home/vsts/work/1/s/Atlas.MatchingAlgorithm/Services/Search/Scoring/MatchScoringService.cs:line 102
at Atlas.MatchingAlgorithm.Services.Search.Scoring.MatchScoringService.StreamScoringUnranked(StreamingMatchResultsScoringRequest request)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at System.Linq.AsyncEnumerable.<ToListAsync>g__Core|424_0[TSource](IAsyncEnumerable`1 source, CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToList.cs:line 36
at System.Linq.AsyncEnumerable.<ToListAsync>g__Core|424_0[TSource](IAsyncEnumerable`1 source, CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToList.cs:line 41
at Atlas.MatchingAlgorithm.Services.Search.Scoring.MatchScoringService.StreamScoring(StreamingMatchResultsScoringRequest request) in /home/vsts/work/1/s/Atlas.MatchingAlgorithm/Services/Search/Scoring/MatchScoringService.cs:line 63
at Atlas.MatchingAlgorithm.Services.Search.SearchService.Search(SearchRequest matchingRequest, Nullable`1 cutOffDate) in /home/vsts/work/1/s/Atlas.MatchingAlgorithm/Services/Search/SearchService.cs:line 83
at Atlas.MatchingAlgorithm.Services.Search.SearchRunner.RunSearch(IdentifiedSearchRequest identifiedSearchRequest) in /home/vsts/work/1/s/Atlas.MatchingAlgorithm/Services/Search/SearchRunner.cs:line 66

To Reproduce Steps to reproduce the behavior:

  1. Send a search request that has Dpb1 set in both the LociToScore and LociToExcludeFromAggregateScore fields. See Inputs for a same request
  2. View application error logs and observe search request failure

Expected behaviour Search request should complete successfully

Inputs/Outputs

{
  "searchDonorType": 1,
  "matchCriteria": {
    "donorMismatchCount": 2,
    "locusMismatchCriteria": {
      "a": 2,
      "b": 2,
      "c": 2,
      "dpb1": null,
      "dqb1": 2,
      "drb1": 2
    },
    "includeBetterMatches": true
  },
  "scoringCriteria": {
    "lociToScore": [
    "Dpb1"
    ],
    "lociToExcludeFromAggregateScore": [
      "Dpb1"
    ]
  },
  "searchHlaData": {
            "a": {
                "position1": "*01:01",
                "position2": "*24:02"
            },
            "b": {
                "position1": "*08:01",
                "position2": "*07:02"
            },
            "c": {
                "position1": "*07:01",
                "position2": "*07:02"
            },
            "dpb1": {
                "position1": "*02:01",
                "position2": "*87:01"
            },
            "dqb1": {
                "position1": "*02:01",
                "position2": "*06:02"
            },
            "drb1": {
                "position1": "*03:01",
                "position2": "*15:01"
            }
  },
  "patientEthnicityCode": null,
  "patientRegistryCode": null,
  "runMatchPrediction": true,
  "donorRegistryCodes": null
}

Atlas Build & Runtime Info (please complete the following information):

Additional context This issue was detected in WMDA's environment

mmelchers commented 1 year ago

@seanmobrien am I correct in remembering that this issue got fixed in the ATLAS code base? If so, could you please close this ticket?

seanmobrien commented 1 year ago

No updates have been made for this issue. @zabeen indicated this issue only occurs when a manually-crafted search request is sent to ATLAS; my understanding is it is a lower priority issue.

zabeen commented 1 year ago

I have moved this down to the wishlist backlog as it is not causing any issue to WMDA as it stands, but it is worth cleaning up eventually.

mmelchers commented 1 year ago

will this cause issues now that we turn on scoring for A,B,C, DRB1 and DQB1 besides the existing DPB1 and will need to exclude DPB1?

without excluding DPB1 it seems like it is counted and will we get n/12 match classes in many cases. Or am i missing something?

zabeen commented 1 year ago

@mmelchers

will this cause issues now that we turn on scoring for A,B,C, DRB1 and DQB1 besides the existing DPB1 and will need to exclude DPB1?

no issue, that is how we run searches in Anthony Nolan.

The issue described above arises when DPB1 is the only locus listed in lociToScore and then also listed in lociToExcludeFromAggregateScore.