Skip to content

Commit

Permalink
Add SSE support for Apple M1
Browse files Browse the repository at this point in the history
- Update README for version 2.x.x
- Remove old makefiles
- Add examples of json files
  • Loading branch information
4ment committed Mar 12, 2024
1 parent ce99407 commit dade424
Show file tree
Hide file tree
Showing 33 changed files with 10,467 additions and 8,845 deletions.
82 changes: 22 additions & 60 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.5)

SET(DEFAULT_SSE_LEVEL "sse3")

Expand All @@ -8,7 +8,7 @@ SET( LIBRARY_NAME "PHYC" )

SET( ${LIBRARY_NAME}_MAJOR_VERSION 2 )
SET( ${LIBRARY_NAME}_MINOR_VERSION 0 )
SET( ${LIBRARY_NAME}_PATCH_LEVEL 0 )
SET( ${LIBRARY_NAME}_PATCH_LEVEL 1-dev )


#####################################################################
Expand Down Expand Up @@ -144,65 +144,22 @@ ENDIF(USE_AVX_SUPPORT)
#####################################################################

IF(USE_SSE_SUPPORT)

IF(AUTO_SSE_SUPPORT)
SET(SSE_C_TESTS "sse4_2" "sse4_1" "sse4" "sse3" "sse2" "sse")

message(STATUS "Checking SSE instructions support by current CPU")
foreach(sse_test ${SSE_C_TESTS})
#IF(NOT SSE_FOUND)
IF(WIN32)
SET(SSE_CHECK_COMMAND "FAILURE")
elseif(APPLE)
SET(SSE_CHECK_COMMAND "sysctl -a | grep ${sse_test}")
else()#other os
SET(SSE_CHECK_COMMAND "grep ${sse_test} /proc/cpuinfo")
ENDIF(WIN32)

#execute_process(COMMAND ${SSE_CHECK_COMMAND} RESULT_VARIABLE ret_var OUTPUT_VARIABLE out_var)
execute_process(COMMAND sh -c ${SSE_CHECK_COMMAND} OUTPUT_VARIABLE out_var)

IF(NOT out_var STREQUAL "")
SET(SSE_FOUND TRUE)
MESSAGE(STATUS "${sse_test} detected and working")
set(USE_SSE_SET ${sse_test})

STRING(REGEX REPLACE "_" "." USE_SSE_SET ${USE_SSE_SET})
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m${USE_SSE_SET}")

#string(TOUPPER ${USE_SSE_SET} UPPER)
#SET(UPPER "__${UPPER}__")
#add_definitions("-D${UPPER}")
#MESSAGE(STATUS "${UPPER}")

ENDIF(NOT out_var STREQUAL "")

#ENDIF(NOT SSE_FOUND)
endforeach(sse_test)

IF(NOT SSE_FOUND)
message(STATUS "SSE not supported")
SET(${LIBRARY_NAME}_SSE_ENABLED, "0")
ELSE(NOT SSE_FOUND)
add_definitions("-DSSE3_ENABLED")

STRING(REGEX REPLACE "_" "." USE_SSE_SET ${USE_SSE_SET})
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m${USE_SSE_SET}")
SET(${LIBRARY_NAME}_SSE_ENABLED "1")
SET(${LIBRARY_NAME}_SSE_LEVEL ${USE_SSE_SET})
ENDIF(NOT SSE_FOUND)
ELSE(AUTO_SSE_SUPPORT)
IF(NOT SSE_LEVEL)
SET(SSE_LEVEL ${DEFAULT_SSE_LEVEL})
ENDIF(NOT SSE_LEVEL)

message(STATUS "Using SSE ${SSE_LEVEL}")

add_definitions("-DSSE3_ENABLED")
IF(NOT SSE_LEVEL)
SET(SSE_LEVEL ${DEFAULT_SSE_LEVEL})
ENDIF(NOT SSE_LEVEL)

add_definitions("-DSSE3_ENABLED")

IF(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
MESSAGE(STATUS "Using sse2neon for arm64 Apple M1")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+fp+simd+crypto+crc")
ELSE()
MESSAGE(STATUS "Using SSE ${SSE_LEVEL}")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m${SSE_LEVEL}")
SET(${LIBRARY_NAME}_SSE_ENABLED "1")
SET(${LIBRARY_NAME}_SSE_LEVEL ${SSE_LEVEL})
ENDIF(AUTO_SSE_SUPPORT)
ENDIF()

SET(${LIBRARY_NAME}_SSE_ENABLED "1")
SET(${LIBRARY_NAME}_SSE_LEVEL ${SSE_LEVEL})
ELSE(USE_SSE_SUPPORT)
SET(${LIBRARY_NAME}_SSE_ENABLED "0")
SET(${LIBRARY_NAME}_SSE_LEVEL "0")
Expand Down Expand Up @@ -327,6 +284,11 @@ ELSE()
file(GLOB HEADER_FILES src/phyc/*.h)
ENDIF(DISABLE_GSL)

include_directories("${PROJECT_SOURCE_DIR}/contrib")
SET(HEADER_FILES "${HEADER_FILES};${PROJECT_BINARY_DIR}/phyc/neon2sse.h")
file(COPY ${PROJECT_SOURCE_DIR}/contrib/neon2sse.h
DESTINATION ${PROJECT_BINARY_DIR}/phyc)

SET(HEADER_FILES "${HEADER_FILES};${PROJECT_BINARY_DIR}/phyc/PhyCConfig.h")

# Include the directory itself as a path to include directories
Expand Down
113 changes: 69 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,91 @@
physher
=======
# physher

[![CMake](https://github.com/4ment/physher/actions/workflows/cmake.yml/badge.svg)](https://github.com/4ment/physher/actions/workflows/cmake.yml)
[![License: GPL v2](https://img.shields.io/badge/License-GPLv2-blue.svg)](https://www.gnu.org/licenses/gpl-2.0)

## About physher

``physher`` is a program for estimating evolutionary rates and divergence times from genetic, amino acid, codon, and generic data.

The current version of physher is incompatible with the first version.
Documentation for installing physher1 can be found [here](https://github.com/4ment/physher/wiki/Install) and the manual is located [here](https://github.com/4ment/physher/wiki/Usage).

Introduction
------------
## Getting Started

Physher is a maximum likelihood-based method for estimating evolutionary rates and divergence times from genetic, amino acid, codon, and generic data. Phylogenetic trees should be open with Figtree from this [website](http://tree.bio.ed.ac.uk/software/figtree/) or [Seqotron](https://github.com/4ment/seqotron/).
A C compiler such as ``gcc`` or ``clang`` is required. It is also requires the [GSL] library.
On Debian-based systems, dependencies can be installed via ``apt``:

For more details about the configuration file and command line arguments see the [wiki](https://github.com/4ment/physher/wiki/Usage)
```bash
sudo apt install gcc gsl
```

On MacOS, dependencies can be installed using a package manager such as [Homebrew](https://brew.sh).
```bash
brew install llvm gsl
```

Features
--------
Other package managers such as [conda](https://conda.io) and [MacPorts](https://www.macports.org) can also be used to install dependencies.

* Substitution models:
* Nucleotide: Reversible: GTR, HKY, K80, and JC69 + any models using encoding 00000 ... 01234. Non reversible: UREV (stationary) and NONSTAT (non stationary).
* Codon: GY94.
* Amino acid: Dayhoff, LG, and WAG.
* General: custom state space (e.g. phylogeography).
### Dependencies
- [GSL]
- [sse2neon] (already included in physher)

* Rate heterogeneity among sites:
* Gamma distributed.
* Proportion of invariant site.
### Installation

To build ``physher`` from source you can run
```bash
git clone https://github.com/4ment/physher
cmake -S physher/ -B physher/build
cmake --build physher/build/ --target install
```

### Check install
If the installation was successful, this command should print the version of `physher`
```bash
physher
```

* Molecular clock:
* No clock
* Strict clock: constant rate across lineages.
* Local clock: monophyletic lineages evolve at the same rate.
* Discrete clock: a discrete distribution of rates is assigned to lineages without any restriction on the rate distribution.

* Search algorithms for clock models:
* Greedy algorithm (local clock only).
* Genetic algorithm (discrete clock only).

* Topology search:
* Nearest neighbor interchange (NNI)
### Building C++ wrappers (optional)
A subset of physher's functionalities is exposed in C++ wrappers. These wrappers are used in [torchtree](https://github.com/4ment/torchtree), a python program, through bindings and [torchtree-physher](https://github.com/4ment/torchtree-physher).
A C++ compiler such as g++ or clang++ is required. Compilers can be installed using ``apt`` or ``homebrew``

* Confidence intervals
* Non-parametric bootstrap (Normal and percentile) using _bootstrap_ program (only available for strict clock models).
```bash
git clone https://github.com/4ment/physher
cmake -S physher/ -B physher/build -DBUILD_CPP_WRAPPER=on
cmake --build physher/build/ --target install
```

* Model averaging of divergence times and substitution rate
* Using modelavg program (only available using the genetic algorithm with discrete clocks).
### Testing (optional)

```bash
cmake -S physher/ -B physher/build -DBUILD_TESTING=on
cmake --build physher/build/ --target install
ctest --test-dir physher/build/
```

Getting started
---------------
## Quick start
```bash
cd examples/fluA
physher JC69-time-ELBO.json
```

[Install physher](https://github.com/4ment/physher/wiki/Install)
## physher in action

[Online manual](https://github.com/4ment/physher/wiki/Usage)
Some examples of projects using ``physher``
- [marginal-experiments](https://github.com/4ment/marginal-experiments): Evaluation of 19 dubious ways to compute marginal likelihood estimates. [10.1093/sysbio/syz046](https://doi.org/10.1093/sysbio/syz046).
- [phylostan](https://github.com/4ment/phylostan/tree/master/examples): Comparison of phylostan and ``physher`` using variational inference. [10.1101/702944](https://doi.org/10.1101/702944).
- [gradient-benchmark](https://github.com/4ment/gradient-benchmark): Benchmarking of automatic differentiation and analical gradients. [10.1093/gbe/evad099](https://doi.org/10.1093/gbe/evad099)
- [torchtree-physher](https://github.com/4ment/torchtree-physher): Plugin provinding fast calculation of phylogenetic functions in ``physher`` to [torchtree].

## License

Associated programs
-------------------------
Distributed under the GPLv2 License. See [LICENSE](LICENSE) for more information.

* _bootstrap_: calculate confidence intervals using bootstrap trees generated by a strict clock with _physher_. Every tree need to have the same topology.
* _simultron_: simulate nucleotide data given a fixed tree topology.
* _modelavg_: model average of trees generated by genetic algorithm with a discrete clock.
## Citing physher

Fourment M and Holmes EC. Novel non-parametric models to estimate evolutionary rates and divergence times from heterochronous sequence data. _BMC Evolutionary Biology_, 2014. doi: [10.1186/s12862-014-0163-6](https://doi.org/10.1186/s12862-014-0163-6)

Reference
---------

Fourment M and Holmes EC. Novel non-parametric models to estimate evolutionary rates and divergence times from heterochronous sequence data. BMC Evolutionary Biology 14:163, 2014.
[GSL]: https://www.gnu.org/software/gsl
[sse2neon]: https://github.com/DLTcollab/sse2neon
[torchtree]: https://github.com/4ment/torchtree
Loading

0 comments on commit dade424

Please sign in to comment.