Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
thehoglet committed Dec 3, 2017
1 parent 1024243 commit b729991
Show file tree
Hide file tree
Showing 10 changed files with 429 additions and 33 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
37 changes: 5 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# User-specific files
*.suo
Expand Down Expand Up @@ -42,11 +40,10 @@ TestResult.xml
[Rr]eleasePS/
dlldata.c

# .NET Core
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json

*_i.c
*_p.c
Expand Down Expand Up @@ -113,10 +110,6 @@ _TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover

# Visual Studio code coverage results
*.coverage
*.coveragexml

# NCrunch
_NCrunch_*
.*crunch*.local.xml
Expand Down Expand Up @@ -150,7 +143,7 @@ publish/
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
#*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
Expand All @@ -166,7 +159,7 @@ PublishScripts/
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignorable files
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets

Expand Down Expand Up @@ -199,6 +192,7 @@ ClientBin/
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# Since there are multiple workflows, uncomment next line to ignore bower_components
Expand All @@ -219,7 +213,6 @@ UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
*.ndf

# Business Intelligence projects
*.rdl.data
Expand All @@ -234,20 +227,13 @@ FakesAssemblies/

# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/

# Typescript v1 declaration files
typings/

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
Expand All @@ -272,17 +258,4 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc

# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config

# Telerik's JustMock configuration file
*.jmconfig

# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
*.pyc
25 changes: 25 additions & 0 deletions PoulinTheil.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoulinTheil", "PoulinTheil\PoulinTheil.csproj", "{306322FA-BC8A-445B-B669-60CD884209EA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{306322FA-BC8A-445B-B669-60CD884209EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{306322FA-BC8A-445B-B669-60CD884209EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{306322FA-BC8A-445B-B669-60CD884209EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{306322FA-BC8A-445B-B669-60CD884209EA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E6E2A606-BD31-4197-8301-5CCA0CA41A3B}
EndGlobalSection
EndGlobal
122 changes: 122 additions & 0 deletions PoulinTheil/ExcelFunctions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using ExcelDna.Integration;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace PoulinTheil
{
public class ExcelFunctions
{
[ExcelFunction(Description = "Pt:p at steady state, assuming a homogenous distribution and passive diffusion of drugs in tissues, from a ratio of solubility and macromolecular binding between tissues and plasma.")]
public static object Ptp_Eq11(
[ExcelArgument("rat|rabbit|mouse")] string species,
[ExcelArgument("brain|heart|lung|muscle|skin|intestine|spleen|bone")] string tissue,
[ExcelArgument("Log vegetable oil:water partition coefficient")] double logKvow,
[ExcelArgument("Unbound fraction in lipid non-depleted plasma")] double fup
)
{
species = species.Trim().ToLowerInvariant();
tissue = tissue.Trim().ToLowerInvariant();

if (tissue == "plasma") return ExcelError.ExcelErrorValue;
if(!_Vw.ContainsKey(tissue) || !_Vw.First().Value.ContainsKey(species)) return ExcelError.ExcelErrorValue;
var Vwt = _Vw[tissue][species];
var Vnt = _Vn[tissue][species];
var Vpht = _Vph[tissue][species];
if (double.IsNaN(Vwt) || double.IsNaN(Vnt) || double.IsNaN(Vpht)) return ExcelError.ExcelErrorNA;

var Vwp = _Vw["plasma"][species];
var Vnp = _Vn["plasma"][species];
var Vphp = _Vph["plasma"][species];

if (fup <= 0.0) return ExcelError.ExcelErrorDiv0;
var nKaCmp = (1.0 / fup) - 1.0;
var nKaCmt = nKaCmp * 0.5;
var fut = 1.0 / (1.0 + nKaCmt);

var Kvow = Pow(10, logKvow);

var StSw = Kvow * (Vnt + 0.3 * Vpht) + (Vwt + 0.7 * Vpht);
var SpSw = Kvow * (Vnp + 0.3 * Vphp) + (Vwp + 0.7 * Vphp);

var P = (StSw / SpSw) * (fup / fut);

return P;
}

[ExcelFunction(Description = "Pt:p, assuming non-homogenous distribution, of drugs residing predominantly in the interstitial space of tissues.")]
public static object Ptp_Eq14(
[ExcelArgument("brain|heart|lung|muscle|skin|intestine|spleen|bone")] string tissue,
[ExcelArgument("Unbound fraction in lipid non-depleted plasma")] double fup
)
{
tissue = tissue.Trim().ToLowerInvariant();

if (tissue == "plasma") return ExcelError.ExcelErrorValue;
if (!_Ft.ContainsKey(tissue)) return ExcelError.ExcelErrorValue;
var Ft = _Ft[tissue];

if (fup <= 0.0) return ExcelError.ExcelErrorDiv0;
var nKaCmp = (1.0 / fup) - 1.0;
var nKaCmt = nKaCmp * 0.5;
var fut = 1.0 / (1.0 + nKaCmt);

var P = (Ft / _Fp) * (fup / fut);

return P;
}

private static IDictionary<string, IDictionary<string, double>> _Vw = new SortedDictionary<string, IDictionary<string, double>>
{
["plasma"] = new SortedDictionary<string, double> { ["rabbit"] = 0.94, ["rat"] = 0.96, ["mouse"] = 0.96 },
["brain"] = new SortedDictionary<string, double> { ["rabbit"] = 0.74, ["rat"] = 0.75, ["mouse"] = 0.71 },
["heart"] = new SortedDictionary<string, double> { ["rabbit"] = 0.79, ["rat"] = 0.77, ["mouse"] = 0.78 },
["lung"] = new SortedDictionary<string, double> { ["rabbit"] = 0.78, ["rat"] = 0.78, ["mouse"] = 0.81 },
["muscle"] = new SortedDictionary<string, double> { ["rabbit"] = 0.77, ["rat"] = 0.74, ["mouse"] = 0.67 },
["skin"] = new SortedDictionary<string, double> { ["rabbit"] = 0.70, ["rat"] = 0.70, ["mouse"] = double.NaN },
["intestine"] = new SortedDictionary<string, double> { ["rabbit"] = 0.70, ["rat"] = 0.70, ["mouse"] = 0.70 },
["spleen"] = new SortedDictionary<string, double> { ["rabbit"] = double.NaN, ["rat"] = 0.77, ["mouse"] = 0.79 },
["bone"] = new SortedDictionary<string, double> { ["rabbit"] = 0.35, ["rat"] = 0.35, ["mouse"] = double.NaN },
};

private static IDictionary<string, IDictionary<string, double>> _Vn = new SortedDictionary<string, IDictionary<string, double>>
{
["plasma"] = new SortedDictionary<string, double> { ["rabbit"] = 0.0015, ["rat"] = 0.00147, ["mouse"] = 0.0026 },
["brain"] = new SortedDictionary<string, double> { ["rabbit"] = 0.05, ["rat"] = 0.0393, ["mouse"] = 0.031 },
["heart"] = new SortedDictionary<string, double> { ["rabbit"] = 0.031, ["rat"] = 0.0117, ["mouse"] = 0.017 },
["lung"] = new SortedDictionary<string, double> { ["rabbit"] = 0.0332, ["rat"] = 0.0199, ["mouse"] = 0.0218 },
["muscle"] = new SortedDictionary<string, double> { ["rabbit"] = 0.0338, ["rat"] = 0.009, ["mouse"] = 0.0167 },
["skin"] = new SortedDictionary<string, double> { ["rabbit"] = 0.0205, ["rat"] = 0.0205, ["mouse"] = double.NaN },
["intestine"] = new SortedDictionary<string, double> { ["rabbit"] = 0.032, ["rat"] = 0.032, ["mouse"] = 0.032 },
["spleen"] = new SortedDictionary<string, double> { ["rabbit"] = double.NaN, ["rat"] = 0.0077, ["mouse"] = 0.0120 },
["bone"] = new SortedDictionary<string, double> { ["rabbit"] = 0.0222, ["rat"] = 0.0222, ["mouse"] = double.NaN },
};

private static IDictionary<string, IDictionary<string, double>> _Vph = new SortedDictionary<string, IDictionary<string, double>>
{
["plasma"] = new SortedDictionary<string, double> { ["rabbit"] = 0.0012, ["rat"] = 0.00083, ["mouse"] = 0.0032 },
["brain"] = new SortedDictionary<string, double> { ["rabbit"] = 0.064, ["rat"] = 0.0532, ["mouse"] = 0.05 },
["heart"] = new SortedDictionary<string, double> { ["rabbit"] = 0.0082, ["rat"] = 0.0141, ["mouse"] = 0.014 },
["lung"] = new SortedDictionary<string, double> { ["rabbit"] = 0.0142, ["rat"] = 0.0170, ["mouse"] = 0.0162 },
["muscle"] = new SortedDictionary<string, double> { ["rabbit"] = 0.0062, ["rat"] = 0.01, ["mouse"] = 0.0273 },
["skin"] = new SortedDictionary<string, double> { ["rabbit"] = 0.0155, ["rat"] = 0.0155, ["mouse"] = double.NaN },
["intestine"] = new SortedDictionary<string, double> { ["rabbit"] = 0.015, ["rat"] = 0.015, ["mouse"] = 0.015 },
["spleen"] = new SortedDictionary<string, double> { ["rabbit"] = double.NaN, ["rat"] = 0.0136, ["mouse"] = 0.0107 },
["bone"] = new SortedDictionary<string, double> { ["rabbit"] = 0.0005, ["rat"] = 0.0005, ["mouse"] = double.NaN },
};

private static IDictionary<string, double> _Ft = new SortedDictionary<string, double>
{
["brain"] = 0.17,
["heart"] = 0.1,
["lung"] = 0.188,
["muscle"] = 0.12,
["skin"] = 0.302,
["intestine"] = 0.094,
["spleen"] = 0.15,
["bone"] = 0.1,
};

private static double _Fp = 0.63;
}
}
20 changes: 20 additions & 0 deletions PoulinTheil/PoulinTheil-AddIn.dna
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<DnaLibrary Name="PoulinTheil Add-In" RuntimeVersion="v4.0">
<ExternalLibrary Path="PoulinTheil.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" />

<!--
The RuntimeVersion attribute above allows two settings:
* RuntimeVersion="v2.0" - for .NET 2.0, 3.0 and 3.5
* RuntimeVersion="v4.0" - for .NET 4 and 4.5

Additional referenced assemblies can be specified by adding 'Reference' tags.
These libraries will not be examined and registered with Excel as add-in libraries,
but will be packed into the -packed.xll file and loaded at runtime as needed.
For example:

<Reference Path="Another.Library.dll" Pack="true" />

Excel-DNA also allows the xml for ribbon UI extensions to be specified in the .dna file.
See the main Excel-DNA site at http://excel-dna.net for downloads of the full distribution.
-->

</DnaLibrary>
Loading

0 comments on commit b729991

Please sign in to comment.