-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcHeader.h
More file actions
91 lines (84 loc) · 3.08 KB
/
tcHeader.h
File metadata and controls
91 lines (84 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/************************************************************************
* This program is part of TimeCellScore, a set of time-cell scoring
* functions.
* Copyright (C) 2022 Upinder S. Bhalla and NCBS
* It is made available under the terms of the
* GNU Public License version 3 or later.
* See the file COPYING.LIB for the full notice.
************************************************************************/
#include <vector>
#include <cmath>
class AnalysisParams {
public:
AnalysisParams();
unsigned int numCells;
unsigned int numTrials;
unsigned int numFrames;
unsigned int csOnsetFrame;
unsigned int usOnsetFrame;
unsigned int circPad;
unsigned int circShuffleFrames;
unsigned int binFrames;
unsigned int numShuffle;
unsigned int dipFrames; // min consecutive sub-threshold frames required between peaks
double epsilon;
double frameDt; // seconds per frame
double minPeakSep; // minimum separation between peaks, seconds
double dipSdev; // dip threshold = traceMean + dipSdev * traceStd
};
/// Returns true if the mean trace dips below thresh for at least minFrames
/// consecutive samples in the open interval (from, to) — order-independent.
static inline bool hasDipBetween(
const std::vector<double>& trace,
unsigned int from, unsigned int to,
double thresh, unsigned int minFrames)
{
unsigned int lo = (from < to ? from : to) + 1;
unsigned int hi = (from < to ? to : from);
unsigned int run = 0;
for ( unsigned int ff = lo; ff < hi; ++ff ) {
run = (trace[ff] < thresh) ? run + 1 : 0;
if ( run >= minFrames ) return true;
}
return false;
}
class TiAnalysisParams {
public:
TiAnalysisParams();
double transientThresh;
double tiPercentile;
double fracTrialsFiredThresh;
double frameDt;
};
class PeqAnalysisParams {
public:
PeqAnalysisParams();
double alpha;
double beta;
double gamma;
double transientThresh;
double hitWindow; //Number of frames allowed to claim event as hit
};
struct CellScore {
double meanScore; // pk of mean trace from Mau; r2b shuffled mean, PEQ mean of all frames and trials.
double baseScore; // Raw TI score, raw r2b ratio, PEQ main score.
double percentileScore; // Temporal info from Mau; r2b bootstrap. PEQ ignores
double sdev; // Used in PEQ. Sdev of all frames and trials.
double eventWidthMean; // Used in PEQ
double eventWidthSdev; // Used in PEQ
double imprecision; // Used in PEQ
bool sigMean;
bool sigBootstrap;
double fracTrialsFired; // Hit Trial Ratio
vector< double > meanTrace;
unsigned int meanPkIdx;
// Multi-peak fields: parallel vectors, one entry per significant peak.
// allPkIndices are in frame/bin units of meanTrace.
// allPkScores: mean trace value at peak (TI/PEQ) or R2B ratio (R2B).
// allPkPvalues: fraction of shuffles NOT exceeded by real data (lower = more significant).
vector< unsigned int > allPkIndices;
vector< double > allPkScores;
vector< double > allPkPvalues;
};
// vector< CellScore > r2bScore(py::array_t<double> xs, const AnalysisParams& ap);
// vector< CellScore > tiScore( py::array_t<double> xs, const AnalysisParams& ap, const TiAnalysisParams& tip );