Skip to content

Commit

Permalink
Convert this into a standalone library with its own namespace. (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA authored Jul 18, 2024
1 parent 0eaf5c4 commit cba5747
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 188 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/check-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
push:
branches:
- master
pull_request:

name: Check CMake install

jobs:
install:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Get latest CMake
uses: lukka/get-cmake@latest

- name: Configure the build
run: cmake -S . -B build -DSCRAN_AGGREGATE_TESTS=OFF

- name: Install the library
run: sudo cmake --install build

- name: Test downstream usage
run: |
mkdir _downstream
touch _downstream/source.cpp
cat << EOF > _downstream/CMakeLists.txt
cmake_minimum_required(VERSION 3.24)
project(test_install)
add_executable(whee source.cpp)
find_package(libscran_scran_aggregate)
target_link_libraries(whee libscran::scran_aggregate)
EOF
cd _downstream && cmake -S . -B build
60 changes: 53 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,66 @@
cmake_minimum_required(VERSION 3.14)

project(scran_aggregate_across_cells
project(scran_aggregate
VERSION 1.0.0
DESCRIPTION "Aggregate expression values across cells"
LANGUAGES CXX)

add_library(scran_aggregate_across_cells INTERFACE)
target_compile_features(scran_aggregate_across_cells INTERFACE cxx_std_17)
target_include_directories(scran_aggregate_across_cells INTERFACE include/scran)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

add_subdirectory(extern)
target_link_libraries(scran_aggregate_across_cells INTERFACE tatami::tatami)
# Library
add_library(scran_aggregate INTERFACE)
add_library(libscran::scran_aggregate ALIAS scran_aggregate)

target_include_directories(scran_aggregate INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/scran_aggregate>)
target_compile_features(scran_aggregate INTERFACE cxx_std_17)

# Dependencies
option(SCRAN_AGGREGATE_FETCH_EXTERN "Automatically fetch scran_aggregate's external dependencies." ON)
if(SCRAN_AGGREGATE_FETCH_EXTERN)
add_subdirectory(extern)
else()
find_package(tatami_tatami 3.0.0 CONFIG REQUIRED)
endif()

target_link_libraries(scran_aggregate INTERFACE tatami::tatami)

# Tests
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
option(SCRAN_AGGREGATE_TESTS "Build scran_aggregate's test suite." ON)
else()
option(SCRAN_AGGREGATE_TESTS "Build scran_aggregate's test suite." OFF)
endif()

if(SCRAN_AGGREGATE_TESTS)
include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
endif()
endif()

# Install
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/scran_aggregate)

install(TARGETS scran_aggregate
EXPORT scran_aggregateTargets)

install(EXPORT scran_aggregateTargets
FILE libscran_scran_aggregateTargets.cmake
NAMESPACE libscran::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libscran_scran_aggregate)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/libscran_scran_aggregateConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libscran_scran_aggregate)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/libscran_scran_aggregateConfigVersion.cmake"
COMPATIBILITY SameMajorVersion)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libscran_scran_aggregateConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/libscran_scran_aggregateConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libscran_scran_aggregate)
66 changes: 46 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Aggregate expression values across cells

![Unit tests](https://github.com/libscran/aggregate_across_cells/actions/workflows/run-tests.yaml/badge.svg)
![Documentation](https://github.com/libscran/aggregate_across_cells/actions/workflows/doxygenate.yaml/badge.svg)
[![Codecov](https://codecov.io/gh/libscran/aggregate_across_cells/graph/badge.svg?token=JWV0I4WJX2)](https://codecov.io/gh/libscran/aggregate_across_cells)
![Unit tests](https://github.com/libscran/scran_aggregate/actions/workflows/run-tests.yaml/badge.svg)
![Documentation](https://github.com/libscran/scran_aggregate/actions/workflows/doxygenate.yaml/badge.svg)
[![Codecov](https://codecov.io/gh/libscran/scran_aggregate/graph/badge.svg?token=JWV0I4WJX2)](https://codecov.io/gh/libscran/scran_aggregate)

## Overview

Expand All @@ -15,16 +15,16 @@ factored out into a separate C++ library for easier re-use.
## Quick start

Given a [`tatami::Matrix`](https://github.com/tatami-inc/tatami) and an array of group assignments,
the `aggregate_across_cells::compute()` function will compute the aggregate statistics across all genes for each group.
the `aggregate_across_cells()` function will compute the aggregate statistics across all genes for each group.

```cpp
#include "scran/aggregate_across_cells.hpp"
#include "scran_aggregate/scran_aggregate.hpp"

tatami::Matrix<double, int>* ptr = some_data_source();
const tatami::Matrix<double, int>& mat = some_data_source();
std::vector<int> groupings = some_groupings();

scran::aggregate_across_cells::Options opt;
auto res = scran::aggregate_across_cells::compute(ptr, groupings.data(), opt);
scran_aggregate::AggregateAcrossCellsOptions opt;
auto res = scran_aggregate::aggregate_across_cells(mat, groupings.data(), opt);

res.sums; // vector of vectors of per-group sums across genes.
res.sums[0]; // vector of sums for the first group across genes.
Expand All @@ -33,11 +33,9 @@ res.detected; // vector of vectors of the number of detected cells per gene.

The array of groupings should contain integer assignments to groups 0, 1, 2, etc.
For more complex groupings defined from combinations of multiple factors,
the `combine_factors::compute()` utility will create group assignments from unique combinations of those factors:
the `combine_factors()` utility will create group assignments from unique combinations of those factors:

```cpp
#include "scran/combine_factors.hpp"

std::vector<int> grouping1 { 0, 0, 1, 1, 2, 2 };
std::vector<int> grouping2 { 0, 1, 0, 1, 0, 1 };

Expand All @@ -53,28 +51,56 @@ res.factors[0]; // values of grouping1 for each unique combination.
res.factors[1]; // values of grouping2 for each unique combination.
```
Check out the [reference documentation](https://libscran.github.io/aggregate_across_cells) for more details.
Check out the [reference documentation](https://libscran.github.io/scran_aggregate) for more details.
## Building projects
This repository is part of the broader [**libscran**](https://github.com/libscran/libscran) library,
so users are recommended to use the latter in their projects.
**libscran** developers should just use CMake with `FetchContent`:
### CMake with `FetchContent`
If you're using CMake, you just need to add something like this to your `CMakeLists.txt`:
```cmake
include(FetchContent)
FetchContent_Declare(
scran_aggregate_across_cells
GIT_REPOSITORY https://github.com/libscran/aggregate_across_cells
scran_aggregate
GIT_REPOSITORY https://github.com/libscran/scran_aggregate
GIT_TAG master # or any version of interest
)
FetchContent_MakeAvailable(scran_aggregate_across_cells)
FetchContent_MakeAvailable(scran_aggregate)
```

Then you can link to **scran_aggregate** to make the headers available during compilation:

```cmake
# For executables:
target_link_libraries(myexe scran_aggregate_across_cells)
target_link_libraries(myexe libscran::scran_aggregate)
# For libaries
target_link_libraries(mylib INTERFACE scran_aggregate_across_cells)
target_link_libraries(mylib INTERFACE libscran::scran_aggregate)
```

### CMake with `find_package()`

```cmake
find_package(libscran_scran_aggregate CONFIG REQUIRED)
target_link_libraries(mylib INTERFACE libscran::scran_aggregate)
```

To install the library, use:

```sh
mkdir build && cd build
cmake .. -DSCRAN_AGGREGATE_TESTS=OFF
cmake --build . --target install
```

By default, this will use `FetchContent` to fetch all external dependencies.
If you want to install them manually, use `-DSCRAN_AGGREGATE_FETCH_EXTERN=OFF`.
See the tags in [`extern/CMakeLists.txt`](extern/CMakeLists.txt) to find compatible versions of each dependency.

### Manual

If you're not using CMake, the simple approach is to just copy the files in `include/` - either directly or with Git submodules - and include their path during compilation with, e.g., GCC's `-I`.
This requires the external dependencies listed in [`extern/CMakeLists.txt`](extern/CMakeLists.txt), which also need to be made available during compilation.
6 changes: 6 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(tatami_tatami 3.0.0 CONFIG REQUIRED)

include("${CMAKE_CURRENT_LIST_DIR}/libscran_scran_aggregateTargets.cmake")
15 changes: 0 additions & 15 deletions include/scran/scran.hpp

This file was deleted.

Loading

0 comments on commit cba5747

Please sign in to comment.