Skip to content

Commit

Permalink
Bug fixes, UI + installation overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroSant committed Mar 26, 2024
1 parent a52d3ce commit f6a4bef
Show file tree
Hide file tree
Showing 26 changed files with 1,678 additions and 2,308 deletions.
44 changes: 44 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.16)
message(STATUS "Using CMake version ${CMAKE_VERSION}")
cmake_policy(VERSION 3.16)

project(EWF LANGUAGES CXX VERSION 1.0.1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

option(BUILD_SHARED_LIBS "Enable compilations of shared libraries" OFF)

option(PYTHON_BINDINGS "Whether to build python bindings" ON)
if (PYTHON_BINDINGS)
include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG 80dc998efced8ceb2be59756668a7e90e8bef917 # Version 2.10.1
)
FetchContent_GetProperties(pybind11)
if (NOT pybind11_POPULATED)
FetchContent_Populate(pybind11)
add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
endif()
endif()

add_subdirectory(src)

#Clang format target
find_program(CLANG_FORMAT_EXE NAMES "clang-format-16" "clang-format-15" "clang-format-14" "clang-format-13" "clang-format-12"
"clang-format-11" "clang-format-10" "clang-format" DOC "Path to clang-format executable"
)
if (NOT CLANG_FORMAT_EXE)
message(STATUS "clang-format not found.")
else ()
message(STATUS "clang-format found: ${CLANG_FORMAT_EXE}")
add_custom_target(
EWF_clang_format
COMMAND ${CLANG_FORMAT_EXE} -style=file -i ${CMAKE_SOURCE_DIR}/src/*pp
COMMAND ${CLANG_FORMAT_EXE} -style=file -i ${CMAKE_SOURCE_DIR}/example/*pp
COMMAND ${CLANG_FORMAT_EXE} -style=file -i ${CMAKE_SOURCE_DIR}/test/*pp
)
endif ()
18 changes: 0 additions & 18 deletions Makefile

This file was deleted.

16 changes: 0 additions & 16 deletions R-plotter.r

This file was deleted.

45 changes: 21 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
#EWF
# EWF

An efficient simulator for exact Wright-Fisher diffusion and diffusion bridge paths, accounting for a wide class of selective regimes (genic, diploid and arbitrary polynomial selection), and the presence/absence of mutation. Please consult the _UserManual.pdf_ for all details with regards to installing dependencies, setting the correct linker flags, running the program and configuring the program input.
An efficient simulator for exact Wright-Fisher diffusion and diffusion bridge paths, accounting for a wide class of selective regimes (genic, diploid and arbitrary polynomial selection), and the presence/absence of mutation. Please consult the _UserManual.pdf_ for all details with regards to installing dependencies, installing the program, and calling it from within python.

*Dependencies*

EWF has been tested out on Ubuntu 20.04, and requires the following:
EWF requires the following:

- g++ compiler (tested on version 9.4.0)
- libconfig library (tested on version 1.7.3), available from http://hyperrealm.github.io/libconfig
- boost library (tested on version 1.78.0), available from https://boost.org
- R (tested on version 4.2.1 using RStudio version 2022.07.1+554), available from https://www.r-project.org/
- g++ compiler
- boost library (https://boost.org)
- python and pip
- CMake
- pybind11

*Compilation*
*Installation*

Please ensure that the compiler and linker flags in 'Makefile' point towards where the 'libconfig' and 'boost' libraries are on your platform! Please ignore the [-Wmaybe-uninitialized ] compiler warnings generated by the PolynomialRootFinder.cpp file!
To install, run the following instructions in terminal at the root directory of EWF:
`mkdir build`
`cd build`
`cmake ..`
`cmake --build .`
`cd ..`
`pip install .`

*Configuration files*
*Calling in python*

The underlying Wright-Fisher diffusion/diffusion bridge can be configured via the 'config.cfg' file, where the mutation and selection parameters can be suitably altered.
Once installed, you can call EWF from python by including
`import EWF_pybind`
at the start of your python script. Please see the scripts in the `examples` directory for more details and use cases.

The configuration setup for simulating draws from the law of a _diffusion_ are found in 'configDiffusion.cfg' which allows for the start points, start times and sample times to be modified (as well as number of samples to generate and mesh size if the truncated transition density is desired). If multiple simulation setups are desired, the corresponding setup inputs need to be entered as an array. Precise instructions on input syntax can be found in the file itself.

The configuration setup for simulating draws from the law of a _diffusion bridge_ are found in 'configBridge.cfg' which allows for the start/end points and times, sampling times, number of bridges to simulate, etc. to be modified. Please see the details within the configuration file for exact instructions with regards to input syntax. The number of simulations and mesh sizes (for the truncated transition density) can also be modified.

*Running the program*

When in the root directory run 'run.sh'. This first compiles the program by invoking the makefile, and subsequently calls the program using './main horses' where the second argument invokes the demo described below. The program can be run as a diffusion or diffusion bridge simulator by changing the program invocation to simply './main', whence the program asks whether the user desires to simulate draws from a diffusion law or from a diffusion bridge law, whether they wish to condition on non-absorption and further offers the option of computing a truncation to the transition density.

*Output files*

Output for the diffusion simulator is saved using the format 'YYYY-MM-DD-HH-mmAbsDiffusionSamplesX%T%S%.txt' for the samples generated (where 'Abs' is either 'Conditioned' (if absorption is not allowed at the boundaries) or 'Unconditioned' (if absorption at the boundaries is allowed), 'T' denotes the start time and 'S' the sampling time), and 'YYYY-MM-DD-HH-mmAbsDiffusionDensityX%T%S%.txt' for the truncated transition density.

A similar system is in place for the diffusion bridge simulator, where the output is saved as 'YYYY-MM-DD-HH-mmAbsBridgeSamplesX%Z%T1%T2%S%.txt' with 'X' denoting the start point, 'Z' the end point, 'T1' the start time, 'T2' the end time and 'S' the sampling time. A similar setup is in place for the truncated transition density.
If you come across any bugs, or have any queries/comments/suggestions please do get in touch using the email address [email protected]!
Binary file modified UserManual.pdf
Binary file not shown.
42 changes: 0 additions & 42 deletions config.cfg

This file was deleted.

48 changes: 0 additions & 48 deletions configBridge.cfg

This file was deleted.

36 changes: 0 additions & 36 deletions configDiffusion.cfg

This file was deleted.

63 changes: 0 additions & 63 deletions configHorseCoat.cfg

This file was deleted.

51 changes: 51 additions & 0 deletions examples/bridge_diffusion_sim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import EWF_pybind as EWF
import numpy as np
import matplotlib.pyplot as plt

# Simple python script to construct Wright--Fisher class and run diffusion simulator

# Define Wright--Fisher diffusion class parameters
mutation_vector = np.array([0.5, 0.5])
non_neutral = False
sigma = 0.0
selectionSetup = 0
dominance_parameter = 0.0
selectionPolynomialDegree = 1
selectionCoefficients = np.array([])

# Create and initialise WrightFisher class
WF = EWF.WrightFisher(mutation_vector, non_neutral, sigma, selectionSetup, dominance_parameter, selectionPolynomialDegree, selectionCoefficients)

# Define simulation parameters
nSim = 10000
x = 0.5
z = 0.5
startT = 0.0
endT = 0.5
sampleT = 0.25
Absorption = False
Filename_sim = "EWF_diffusion_bridge_sim.txt"

# Run simulator
WF.BridgeDiffusionRunner(nSim, x, z, startT, endT, sampleT, Absorption, Filename_sim)

# Define parameters for pointwise transition density evaluation
meshSize = 100
Filename_eva = "EWF_diffusion_bridge_eva.txt"

# Run transition density evaluator
WF.BridgeDiffusionDensityCalculator(meshSize, x, z, startT, endT, sampleT, Absorption, Filename_eva)

# Load in data, create histogram and generate plot
data = np.loadtxt(Filename_sim)
density = np.loadtxt(Filename_eva)
Filename_png = "EWF_diffusion_bridge.png"

fig, ax = plt.subplots(1,1)
counts = plt.hist(data, bins=50, density=True)
ax.plot(density[density[:, 1] <= max(counts[0]), 0], density[density[:, 1] <= max(counts[0]), 1], linewidth = 2)
ax.set_xlabel("Sample draws")
ax.set_ylabel("Density")
ax.set_title("Histogram of sample draws (blue), truncated density (orange)")
plt.savefig(Filename_png)
plt.close()
Loading

0 comments on commit f6a4bef

Please sign in to comment.