Skip to content

Commit

Permalink
Fixes #1930 lument mucosa transporter
Browse files Browse the repository at this point in the history
* WIP #1930 lumen mucosa

* Fixes #1930 lument mucosa transporter

* Fixes #1930 lument mucosa transporter
  • Loading branch information
msevestre authored Nov 2, 2021
1 parent a4455e1 commit 87f252b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/PKSim.Core/Mappers/ProcessToProcessBuilderMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using PKSim.Core.Repositories;
using PKSim.Core.Services;
using static PKSim.Core.CoreConstants.Compartment;
using static PKSim.Core.CoreConstants.Organ;

namespace PKSim.Core.Mappers
{
Expand Down Expand Up @@ -187,7 +188,7 @@ public IReactionBuilder InductionReactionFrom(InteractionProcess interactionProc
reaction.AddProduct(new ReactionPartnerBuilder(protein.Name, 1));

//Induction occurs only in Intracellular and Interstitial
reaction.ContainerCriteria.Add(new InContainerCondition(CoreConstants.Organ.TISSUE_ORGAN));
reaction.ContainerCriteria.Add(new InContainerCondition(TISSUE_ORGAN));
reaction.ContainerCriteria.Add(new NotMatchTagCondition(PLASMA));
reaction.ContainerCriteria.Add(new NotMatchTagCondition(BLOOD_CELLS));
reaction.ContainerCriteria.Add(new NotMatchTagCondition(ENDOSOME));
Expand Down Expand Up @@ -359,8 +360,9 @@ private IReadOnlyCollection<InducedProcess> allInducedProcessesFor(IndividualTra
inducedProcessCache.Add(inducedProcess);
}

inducedProcess.AddSourceOrgan(transportTemplate.SourceOrgan);
inducedProcess.AddTargetOrgan(transportTemplate.TargetOrgan);
// For lumen transport. The source organ or target organ is in fact defined as a compartment
inducedProcess.AddSourceOrgan(transportTemplate.SourceOrgan.IsLumen() ? transportTemplate.SourceCompartment : transportTemplate.SourceOrgan);
inducedProcess.AddTargetOrgan(transportTemplate.TargetOrgan.IsLumen() ? transportTemplate.TargetCompartment : transportTemplate.TargetOrgan);
}
}

Expand All @@ -369,19 +371,36 @@ private IReadOnlyCollection<InducedProcess> allInducedProcessesFor(IndividualTra

private void updateTransporterTagsFor(ITransportBuilder transporterBuilder, InducedProcess inducedProcess)
{
var allSourceTags = transporterBuilder.SourceCriteria.OfType<TagCondition>()
.Select(x => x.Tag).ToList();
var sourceCriteria = transporterBuilder.SourceCriteria;
var allSourceTags = sourceCriteria.OfType<MatchTagCondition>().Select(x => x.Tag).ToList();
var (sourceIsLumen, sourceIsMucosa) = (allSourceTags.Contains(LUMEN), allSourceTags.Contains(MUCOSA));

//More than one tag coming from the database => This is a specific transport and we do not need to do anything
if (allSourceTags.Count > 1)
return;
var targetCriteria = transporterBuilder.TargetCriteria;
var allTargetTags = targetCriteria.OfType<MatchTagCondition>().Select(x => x.Tag).ToList();
var (targetIsLumen, targetIsMucosa) = (allTargetTags.Contains(LUMEN), allTargetTags.Contains(MUCOSA));

var isLumen = sourceIsLumen || targetIsLumen;
var isMucosa = sourceIsMucosa || targetIsMucosa;

foreach (var organName in inducedProcess.OrgansToExclude)
if (isLumen && isMucosa)
{
transporterBuilder.SourceCriteria.Add(new NotMatchTagCondition(organName));
//We just want to remove GI segments from the include list as we know, that the transport is between Lumen and Mucosa in this case
var segmentToDeletes = inducedProcess.OrgansToExclude.Intersect(LumenSegmentsDuodenumToRectum).ToList();
var criteria = sourceIsLumen ? sourceCriteria : targetCriteria;
addAsNotMatchToCriteria(criteria, segmentToDeletes);
return;
}

// This is a specific transport and we do not need to do anything
if (allSourceTags.Count > 1)
return;

addAsNotMatchToCriteria(sourceCriteria, inducedProcess.OrgansToExclude);
}

private void addAsNotMatchToCriteria(DescriptorCriteria criteria, IEnumerable<string> list)
=> list.Each(x => criteria.Add(new NotMatchTagCondition(x)));

private ITransportBuilder activeTransportFrom(CompoundProcess process, InducedProcess inducedProcess, IFormulaCache formulaCache)
{
//retrieve process for the simulation and create a clone
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Linq;
using OSPSuite.BDDHelper;
using OSPSuite.BDDHelper.Extensions;
using OSPSuite.Core.Domain;
using PKSim.Core.Mappers;
using PKSim.Core.Model;
using PKSim.Infrastructure;

namespace PKSim.IntegrationTests
{
public abstract class concern_for_ProcessToProcessBuilderMapper : ContextWithLoadedProject<IProcessToProcessBuilderMapper>
{
public override void GlobalContext()
{
base.GlobalContext();
LoadProject("Mucosa_MultipleTransportDirections");
}
}

public class When_creating_a_simulation_using_transport_in_multiple_mucosa_directions : concern_for_ProcessToProcessBuilderMapper
{
private Simulation _simulation;

protected override void Context()
{
base.Context();
var ind = FindByName<Individual>("I1");
var comp = FindByName<Compound>("C1");
var prot = FindByName<Protocol>("IV");
_simulation = DomainFactoryForSpecs.CreateSimulationWith(ind, comp, prot);
}

[Observation]
public void should_not_create_too_many_transporters()
{
var transportInLumenToMucosa = _simulation.Model.Neighborhoods.EntityAt<IContainer>("Lumen_lil_LowerIleum_cell", "C1", "T1-a");
transportInLumenToMucosa.GetChildren<IContainer>(x => x.ContainerType == ContainerType.Transport).Count().ShouldBeEqualTo(1);
}
}
}

0 comments on commit 87f252b

Please sign in to comment.