public override async Task <MoleculeExpressionContainer> MapToModel(ExpressionContainer snapshot, ExpressionContainerMapperContext context) { if (snapshot == null) { return(null); } var molecule = context.Molecule; var individual = context.SimulationSubject; var expressionContainer = molecule.ExpressionContainer(snapshot.Name); if (expressionContainer == null) { _logger.AddWarning(PKSimConstants.Error.RelativeExpressionContainerNotFound(snapshot.Name)); return(null); } var expressionParameter = expressionContainer.RelativeExpressionParameter; await _parameterMapper.MapToModel(snapshot, expressionParameter); if (!(molecule is IndividualTransporter transporter)) { return(expressionContainer); } var species = individual.Species.Name; var transporterExpressionContainer = expressionContainer.DowncastTo <TransporterExpressionContainer>(); var membraneLocation = ModelValueFor(snapshot.MembraneLocation, MembraneLocation.Basolateral); _transportContainerUpdater.UpdateTransporterFromTemplate(transporterExpressionContainer, species, membraneLocation, transporter.TransportType); return(expressionContainer); }
public override async Task <EventMapping> MapToModel(EventSelection snapshot, PKSimProject project) { var pksimEvent = project.BuildingBlockByName <PKSimEvent>(snapshot.Name); var eventMapping = _eventMappingFactory.Create(pksimEvent); await _parameterMapper.MapToModel(snapshot.StartTime, eventMapping.StartTime); return(eventMapping); }
public override async Task <MoleculeExpressionContainer> MapToModel(ExpressionContainer snapshot, ExpressionContainerMapperContext snapshotContext) { if (snapshot == null) { return(null); } var molecule = snapshotContext.Molecule; var expressionParameterCache = snapshotContext.ExpressionParameters; var expressionContainerParameters = snapshotContext.MoleculeExpressionContainers; //Value was only defined for older version of the snapshot if (snapshot.Value.HasValue) { var relExp = expressionParameterCache[snapshot.Name]; if (relExp == null) { _logger.AddWarning(PKSimConstants.Error.RelativeExpressionContainerNotFound(snapshot.Name)); return(null); } await _parameterMapper.MapToModel(snapshot, new ParameterSnapshotContext(relExp, snapshotContext)); } //We do not return anything as container are created at construction time if (!(molecule is IndividualTransporter transporter)) { return(null); } var expressionsContainers = expressionContainerParameters.OfType <TransporterExpressionContainer>() .Where(queryPredicate(snapshotContext.IsV9FormatOrEarlier, snapshot)) .Where(x => x.TransportDirection != TransportDirectionId.None) .ToList(); if (expressionsContainers.Count == 0) { _logger.AddWarning(PKSimConstants.Error.RelativeExpressionContainerNotFound(snapshot.Name)); return(null); } var firstExpressionContainer = expressionsContainers[0]; //This is the new format if (!snapshotContext.IsV9FormatOrEarlier) { //we should only have one firstExpressionContainer.TransportDirection = snapshot.TransportDirection.Value; return(firstExpressionContainer); } expressionsContainers.Each(x => x.TransportDirection = TransportDirections.DefaultDirectionFor(transporter.TransportType, x)); //only one direction to take into consideration. all good, nothing else to do if (expressionsContainers.Count == 1) { return(firstExpressionContainer); } //This is the old format. Basolateral was the default var membraneLocation = ModelValueFor(snapshot.MembraneLocation, MembraneLocation.Basolateral); MembraneLocationConverter.ConvertMembraneLocationToParameterFraction(expressionsContainers, membraneLocation); return(firstExpressionContainer); }