Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1930 lumen mucosa transporter #1940

Merged
merged 3 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member Author

Choose a reason for hiding this comment

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

@Yuri05 This is what we discussed yesterday

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);
}
}
}