Skip to content

Commit

Permalink
Restored default types in user-facing functions for convenience.
Browse files Browse the repository at this point in the history
Users no longer have to fill out the templated types that can't be deduced from
the arguments, which makes the library a bit more user-friendly. To keep things
a bit more rigorous, the definitions of the default types are stored in
typedefs so that we keep them consistent throughout the library.
  • Loading branch information
LTLA committed Aug 26, 2024
1 parent 168cba6 commit fba1770
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 49 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ ref_labels;
ref_markers;

// Building the classifier.
singlepp::TrainSingleOptions<int, double> train_opt;
singlepp::TrainSingleOptions train_opt;
auto trained = singlepp::train_single(ref_mat, ref_labels.data(), train_opt);

// Running the classification on the test matrix.
singlepp::ClassifySingleOptions<double> class_opt;
auto res = singlepp::classify_single<int>(test_mat, trained, class_opt);
singlepp::ClassifySingleOptions class_opt;
auto res = singlepp::classify_single(test_mat, trained, class_opt);
```

See the [reference documentation](https://singler-inc.github.io/singlepp) for more details.
Expand All @@ -48,7 +48,7 @@ This is based on ranking the differences in median log-expression values between

```cpp
singlepp::ChooseClassicMarkersOptions mrk;
auto classic_markers = singlepp::choose_classic_markers<int>(
auto classic_markers = singlepp::choose_classic_markers(
ref_mat.get(),
ref_labels.data(),
m_opt
Expand Down Expand Up @@ -99,7 +99,7 @@ auto trained_intersect = singlepp::train_single_intersect(
Then, `classify_single_intersect()` will perform classification using only the intersection of genes:

```cpp
auto res_intersect = singlepp::classify_single_intersect<int>(
auto res_intersect = singlepp::classify_single_intersect(
test_mat,
trained_intersect,
class_opt
Expand All @@ -116,16 +116,16 @@ Let's say we have two references A and B:

```cpp
auto trainA = singlepp::train_single(refA_mat, refA_labels.data(), refA_markers, train_opt);
auto resA = singlepp::classify_single<int>(test_mat, trainA, class_opt);
auto resA = singlepp::classify_single(test_mat, trainA, class_opt);

auto trainB = singlepp::train_single(refB_mat, refB_labels.data(), refB_markers, train_opt);
auto resB = singlepp::classify_single<int>(test_mat, trainB, class_opt);
auto resB = singlepp::classify_single(test_mat, trainB, class_opt);
```

We build the integrated classifier:

```cpp
std::vector<singlepp::TrainIntegratedInput<double, int, int> > inputs;
std::vector<singlepp::TrainIntegratedInput<> > inputs;
inputs.push_back(singlepp::prepare_integrated_input(refA_mat, refA_labels.data(), preA));
inputs.push_back(singlepp::prepare_integrated_input(refB_mat, refB_labels.data(), preB));

Expand All @@ -137,7 +137,7 @@ And then we can finally run the scoring.
For each cell in the test dataset, `classify_integrated()` picks the best label among the assignments from each individual reference.

```cpp
singlepp::ClassifyIntegratedOptions<double> ci_opt;
singlepp::ClassifyIntegratedOptions ci_opt;
auto ires = single.run(test_mat, train_integrated, ci_opt);
ires.best; // index of the best reference.
```
Expand Down
1 change: 1 addition & 0 deletions docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ INPUT = ../include/singlepp/classify_single.hpp \
../include/singlepp/Markers.hpp \
../include/singlepp/Intersection.hpp \
../include/singlepp/choose_classic_markers.hpp \
../include/singlepp/defs.hpp \
../include/singlepp/singlepp.hpp \
../README.md

Expand Down
4 changes: 2 additions & 2 deletions include/singlepp/Intersection.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SINGLEPP_INTERSECTION_HPP
#define SINGLEPP_INTERSECTION_HPP

#include "macros.hpp"
#include "defs.hpp"

#include <vector>
#include <algorithm>
Expand All @@ -27,7 +27,7 @@ namespace singlepp {
*
* @tparam Index_ Integer type for the gene (row) indices.
*/
template<typename Index_>
template<typename Index_ = DefaultIndex>
using Intersection = std::vector<std::pair<Index_, Index_> >;

/**
Expand Down
4 changes: 2 additions & 2 deletions include/singlepp/Markers.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SINGLEPP_MARKERS_HPP
#define SINGLEPP_MARKERS_HPP

#include "macros.hpp"
#include "defs.hpp"

#include <vector>

Expand Down Expand Up @@ -36,7 +36,7 @@ namespace singlepp {
*
* @tparam Index_ Integer type for the gene (row) indices.
*/
template<typename Index_>
template<typename Index_ = DefaultIndex>
using Markers = std::vector<std::vector<std::vector<Index_> > >;

}
Expand Down
2 changes: 1 addition & 1 deletion include/singlepp/annotate_cells_integrated.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SINGLEPP_ANNOTATE_CELLS_INTEGRATED_HPP
#define SINGLEPP_ANNOTATE_CELLS_INTEGRATED_HPP

#include "macros.hpp"
#include "defs.hpp"

#include "tatami/tatami.hpp"

Expand Down
2 changes: 1 addition & 1 deletion include/singlepp/annotate_cells_single.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SINGLEPP_ANNOTATE_CELLS_SINGLE_HPP
#define SINGLEPP_ANNOTATE_CELLS_SINGLE_HPP

#include "macros.hpp"
#include "defs.hpp"

#include "tatami/tatami.hpp"

Expand Down
2 changes: 1 addition & 1 deletion include/singlepp/build_indices.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SINGLEPP_BUILD_INDICES_HPP
#define SINGLEPP_BUILD_INDICES_HPP

#include "macros.hpp"
#include "defs.hpp"

#include "knncolle/knncolle.hpp"
#include "tatami/tatami.hpp"
Expand Down
2 changes: 1 addition & 1 deletion include/singlepp/choose_classic_markers.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SINGLEPP_CHOOSE_CLASSIC_MARKERS_HPP
#define SINGLEPP_CHOOSE_CLASSIC_MARKERS_HPP

#include "macros.hpp"
#include "defs.hpp"

#include "tatami/tatami.hpp"

Expand Down
10 changes: 5 additions & 5 deletions include/singlepp/classify_integrated.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SINGLEPP_CLASSIFY_INTEGRATED_HPP
#define SINGLEPP_CLASSIFY_INTEGRATED_HPP

#include "macros.hpp"
#include "defs.hpp"

#include "tatami/tatami.hpp"

Expand All @@ -23,7 +23,7 @@ namespace singlepp {
* @brief Options for `classify_integrated()`.
* @tparam Float_ Floating-point type for the correlations and scores.
*/
template<typename Float_>
template<typename Float_ = DefaultFloat>
struct ClassifyIntegratedOptions {
/**
* Quantile to use to compute a per-reference score from the correlations.
Expand Down Expand Up @@ -55,7 +55,7 @@ struct ClassifyIntegratedOptions {
* @tparam RefLabel_ Integer type for the label to represent each reference.
* @tparam Float_ Floating-point type for the correlations and scores.
*/
template<typename RefLabel_, typename Float_>
template<typename RefLabel_ = DefaultRefLabel, typename Float_ = DefaultFloat>
struct ClassifyIntegratedBuffers {
/**
* Pointer to an array of length equal to the number of test cells.
Expand Down Expand Up @@ -149,7 +149,7 @@ void classify_integrated(
* @tparam RefLabel_ Integer type for the label to represent each reference.
* @tparam Float_ Floating-point type for the correlations and scores.
*/
template<typename RefLabel_, typename Float_>
template<typename RefLabel_ = DefaultRefLabel, typename Float_ = DefaultFloat>
struct ClassifyIntegratedResults {
/**
* @cond
Expand Down Expand Up @@ -198,7 +198,7 @@ struct ClassifyIntegratedResults {
*
* @return Object containing the best reference and associated scores for each cell in `test`.
*/
template<typename RefLabel_, typename Value_, typename Index_, typename Label_, typename Float_>
template<typename RefLabel_ = DefaultRefLabel, typename Value_, typename Index_, typename Label_, typename Float_>
ClassifyIntegratedResults<RefLabel_, Float_> classify_integrated(
const tatami::Matrix<Value_, Index_>& test,
const std::vector<const Label_*>& assigned,
Expand Down
12 changes: 6 additions & 6 deletions include/singlepp/classify_single.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SINGLEPP_CLASSIFY_SINGLE_HPP
#define SINGLEPP_CLASSIFY_SINGLE_HPP

#include "macros.hpp"
#include "defs.hpp"

#include "tatami/tatami.hpp"

Expand All @@ -22,7 +22,7 @@ namespace singlepp {
* @brief Options for `classify_single()` and friends.
* @tparam Float_ Floating-point type for the correlations and scores.
*/
template<typename Float_>
template<typename Float_ = DefaultFloat>
struct ClassifySingleOptions {
/**
* Quantile to use to define a per-label score for each test cell,
Expand Down Expand Up @@ -60,7 +60,7 @@ struct ClassifySingleOptions {
* @tparam Label_ Integer type for the reference labels.
* @tparam Float_ Floating-point type for the correlations and scores.
*/
template<typename Label_, typename Float_>
template<typename Label_ = DefaultLabel, typename Float_ = DefaultFloat>
struct ClassifySingleBuffers {
/**
* Pointer to an array of length equal to the number of test cells.
Expand Down Expand Up @@ -194,7 +194,7 @@ void classify_single_intersect(
* @tparam Label_ Integer type for the reference labels.
* @tparam Float_ Floating-point type for the correlations and scores.
*/
template<typename Label_, typename Float_>
template<typename Label_ = DefaultLabel, typename Float_ = DefaultFloat>
struct ClassifySingleResults {
/**
* @cond
Expand Down Expand Up @@ -266,7 +266,7 @@ ClassifySingleBuffers<Label_, Float_> results_to_buffers(ClassifySingleResults<L
*
* @return Results of the classification for each cell in the test dataset.
*/
template<typename Label_, typename Value_, typename Index_, typename Float_>
template<typename Label_ = DefaultLabel, typename Value_, typename Index_, typename Float_>
ClassifySingleResults<Label_, Float_> classify_single(
const tatami::Matrix<Value_, Index_>& test,
const TrainedSingle<Index_, Float_>& trained,
Expand All @@ -293,7 +293,7 @@ ClassifySingleResults<Label_, Float_> classify_single(
*
* @return Results of the classification for each cell in the test dataset.
*/
template<typename Label_, typename Value_, typename Index_, typename Float_>
template<typename Label_ = DefaultLabel, typename Value_, typename Index_, typename Float_>
ClassifySingleResults<Label_, Float_> classify_single_intersect(
const tatami::Matrix<Value_, Index_>& test,
const TrainedSingleIntersect<Index_, Float_>& trained,
Expand Down
2 changes: 0 additions & 2 deletions include/singlepp/correlations_to_score.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef SINGLEPP_CORRELATIONS_TO_SCORE_HPP
#define SINGLEPP_CORRELATIONS_TO_SCORE_HPP

#include "macros.hpp"

#include <vector>
#include <algorithm>
#include <limits>
Expand Down
48 changes: 48 additions & 0 deletions include/singlepp/defs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef SINGLEPP_DEFS_HPP
#define SINGLEPP_DEFS_HPP

/**
* @file defs.hpp
* @brief Common definitions for **singlepp**.
*/

#ifndef SINGLEPP_CUSTOM_PARALLEL
#include "subpar/subpar.hpp"
#define SINGLEPP_CUSTOM_PARALLEL subpar::parallelize
#endif

namespace singlepp {

/**
* Default type for the `Index_` template argument.
* This is the type for the gene (and sample) indices, typically from the row/column indices of a `tatami::Matrix`.
*/
typedef int DefaultIndex;

/**
* Default type for the `Label_` template argument.
* This is the type for the label identifiers within each reference.
*/
typedef int DefaultLabel;

/**
* Default type for the `RefLabel_` template argument.
* This is the type for the reference identifiers during integrated classification.
*/
typedef int DefaultRefLabel;

/**
* Default type for the `Float_` template argument.
* This is the type for the correlations and classification scores.
*/
typedef double DefaultFloat;

/**
* Default type for the `Value_` template argument.
* This is the type for input data in the `tatami::Matrix`.
*/
typedef double DefaultValue;

};

#endif
2 changes: 0 additions & 2 deletions include/singlepp/fill_labels_in_use.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef SINGLEPP_FILL_LABELS_IN_USE_HPP
#define SINGLEPP_FILL_LABELS_IN_USE_HPP

#include "macros.hpp"

#include <vector>
#include <algorithm>
#include <type_traits>
Expand Down
9 changes: 0 additions & 9 deletions include/singlepp/macros.hpp

This file was deleted.

2 changes: 0 additions & 2 deletions include/singlepp/scaled_ranks.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef SINGLEPP_SCALED_RANKS_HPP
#define SINGLEPP_SCALED_RANKS_HPP

#include "macros.hpp"

#include <algorithm>
#include <vector>
#include <cmath>
Expand Down
2 changes: 0 additions & 2 deletions include/singlepp/subset_to_markers.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef SINGLEPP_SUBSET_TO_MARKERS_HPP
#define SINGLEPP_SUBSET_TO_MARKERS_HPP

#include "macros.hpp"

#include "Markers.hpp"
#include "Intersection.hpp"

Expand Down
4 changes: 2 additions & 2 deletions include/singlepp/train_integrated.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SINGLEPP_TRAIN_INTEGRATED_HPP
#define SINGLEPP_TRAIN_INTEGRATED_HPP

#include "macros.hpp"
#include "defs.hpp"

#include "scaled_ranks.hpp"
#include "train_single.hpp"
Expand Down Expand Up @@ -30,7 +30,7 @@ namespace singlepp {
* @tparam Index_ Integer type for the row/column indices of the matrix.
* @tparam Label_ Integer type for the reference labels.
*/
template<typename Value_, typename Index_, typename Label_>
template<typename Value_ = DefaultValue, typename Index_ = DefaultIndex, typename Label_ = DefaultLabel>
struct TrainIntegratedInput {
/**
* @cond
Expand Down
4 changes: 2 additions & 2 deletions include/singlepp/train_single.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SINGLEPP_TRAIN_SINGLE_HPP
#define SINGLEPP_TRAIN_SINGLE_HPP

#include "macros.hpp"
#include "defs.hpp"

#include "knncolle/knncolle.hpp"
#include "tatami/tatami.hpp"
Expand All @@ -24,7 +24,7 @@ namespace singlepp {
* @tparam Index_ Integer type for the row/column indices of the matrix.
* @tparam Float_ Floating-point type for the correlations and scores.
*/
template<typename Index_, typename Float_>
template<typename Index_ = DefaultIndex, typename Float_ = DefaultFloat>
struct TrainSingleOptions {
/**
* Number of top markers to use from each pairwise comparison between labels.
Expand Down

0 comments on commit fba1770

Please sign in to comment.