Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove copy-pasted code in LibV2-LibV3 #314

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions efel/cppcore/FillFptrTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ int FillFptrTable() {
*/

// AP parameter
FptrTableV2["AP_begin_indices"] = &LibV2::AP_begin_indices;
FptrTableV2["AP_rise_indices"] = &LibV2::AP_rise_indices;
FptrTableV2["AP_end_indices"] = &LibV2::AP_end_indices;
FptrTableV2["AP_fall_indices"] = &LibV2::AP_fall_indices;
// eFeatures
FptrTableV2["AP_duration"] = &LibV2::AP_duration;
Expand Down Expand Up @@ -139,33 +137,12 @@ int FillFptrTable() {
//****************** end of FptrTableV2 *****************************

//****************** FptrTableV3 *****************************
FptrTableV3["interpolate"] = &LibV3::interpolate;
FptrTableV3["trace_check"] = &LibV3::trace_check;
FptrTableV3["peak_indices"] = &LibV3::peak_indices;
FptrTableV3["ISI_values"] = &LibV3::ISI_values;
FptrTableV3["ISI_CV"] = &LibV3::ISI_CV;
FptrTableV3["peak_voltage"] = &LibV3::peak_voltage;
FptrTableV3["mean_frequency"] = &LibV3::firing_rate;
FptrTableV3["peak_time"] = &LibV3::peak_time;
FptrTableV3["time_to_first_spike"] = &LibV3::first_spike_time;
FptrTableV3["spike_half_width"] = &LibV3::spike_width1;
FptrTableV3["min_AHP_indices"] = &LibV3::min_AHP_indices;
FptrTableV3["min_AHP_values"] = &LibV3::min_AHP_values;
FptrTableV3["AHP_depth_abs"] = &LibV3::AHP_depth_abs;
FptrTableV3["voltage_base"] = &LibV3::rest_voltage_value;
FptrTableV3["adaptation_index2"] = &LibV3::adaptation_index2;
FptrTableV3["AP_height"] = &LibV3::AP_height;
FptrTableV3["AP_amplitude"] = &LibV3::AP_amplitude;
FptrTableV3["AP_width"] = &LibV3::AP_width;
FptrTableV3["doublet_ISI"] = &LibV3::doublet_ISI;

FptrTableV3["AP_begin_indices"] = &LibV3::AP_begin_indices;
FptrTableV3["AP_rise_indices"] = &LibV3::AP_rise_indices;
FptrTableV3["AP_end_indices"] = &LibV3::AP_end_indices;
FptrTableV3["AP_fall_indices"] = &LibV3::AP_fall_indices;
// eFeatures
FptrTableV3["AP_duration"] = &LibV3::AP_duration;

FptrTableV3["depolarized_base"] = &LibV3::depolarized_base;

//****************** end of FptrTableV3 *****************************
Expand Down
149 changes: 0 additions & 149 deletions efel/cppcore/LibV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,155 +33,6 @@ using std::transform;

// AP parameters
//
// *** AP begin indices ***
//
static int __AP_begin_indices(const vector<double>& t, const vector<double>& v,
double stimstart, double stimend,
const vector<int>& ahpi, vector<int>& apbi) {
// derivative at peak start according to eCode specification 10mV/ms
// according to Shaul 12mV/ms
const double derivativethreshold = 12.;
// constant time steps due to 'interpolate'
vector<double> dvdt(v.size());
vector<double> dv;
vector<double> dt;
getCentralDifferenceDerivative(1., v, dv);
getCentralDifferenceDerivative(1., t, dt);
transform(dv.begin(), dv.end(), dt.begin(), dvdt.begin(), std::divides<double>());

// restrict to time interval where stimulus is applied
vector<int> minima;
int stimbeginindex = distance(
t.begin(),
find_if(t.begin(), t.end(), bind2nd(greater_equal<double>(), stimstart)));
minima.push_back(stimbeginindex);
for (size_t i = 0; i < ahpi.size(); i++) {
if (ahpi[i] > stimbeginindex) {
minima.push_back(ahpi[i]);
}
if (t[ahpi[i]] > stimend) {
break;
}
}
// if the AHP_indices are already restricted make sure that we do not miss
// the last spike
if (t[minima.back()] < stimend) {
int stimendindex =
distance(t.begin(), find_if(t.begin() + minima.back(), t.end(),
bind2nd(greater_equal<double>(), stimend)));
minima.push_back(stimendindex);
}
for (size_t i = 0; i < minima.size() - 1; i++) {
// assure that the width of the slope is bigger than 4
int newbegin = minima[i];
int begin = minima[i];
int width = 5;
bool skip = false;
do {
begin = distance(
dvdt.begin(),
find_if(dvdt.begin() + newbegin, dvdt.begin() + minima[i + 1],
bind2nd(greater_equal<double>(), derivativethreshold)));
if (begin == minima[i + 1]) {
// could not find a spike in between these minima
skip = true;
break;
}
newbegin = begin + 1;
} while (find_if(dvdt.begin() + begin, dvdt.begin() + begin + width,
bind2nd(std::less<double>(), derivativethreshold)) !=
dvdt.begin() + begin + width);
if (skip) {
continue;
}
apbi.push_back(begin);
}
return apbi.size();
}
int LibV2::AP_begin_indices(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
int retVal;
int nSize;
retVal = CheckInMap(IntFeatureData, StringData, "AP_begin_indices",
nSize);
if (retVal) {
return nSize;
}
vector<double> t;
retVal = getVec(DoubleFeatureData, StringData, "T", t);
if (retVal < 0) return -1;
vector<double> v;
retVal = getVec(DoubleFeatureData, StringData, "V", v);
if (retVal < 0) return -1;
vector<double> stimstart;
retVal = getVec(DoubleFeatureData, StringData, "stim_start", stimstart);
if (retVal < 0) return -1;
vector<double> stimend;
retVal = getVec(DoubleFeatureData, StringData, "stim_end", stimend);
if (retVal < 0) return -1;
vector<int> ahpi;
retVal = getVec(IntFeatureData, StringData, "min_AHP_indices", ahpi);
if (retVal < 0) return -1;
vector<int> apbi;
retVal = __AP_begin_indices(t, v, stimstart[0], stimend[0], ahpi, apbi);
if (retVal >= 0) {
setVec(IntFeatureData, StringData, "AP_begin_indices", apbi);
}
return retVal;
}

// *** AP end indices ***
//
static int __AP_end_indices(const vector<double>& t, const vector<double>& v,
const vector<int>& pi, vector<int>& apei) {
// derivative at peak end according to eCode specification -10mV/ms
// according to Shaul -12mV/ms
const double derivativethreshold = -12.;
// assume constant time steps
double timestep = t[1] - t[0];
vector<double> dvdt;
getCentralDifferenceDerivative(timestep, v, dvdt);

apei.resize(pi.size());
vector<int> picopy(pi.begin(), pi.end());
picopy.push_back(v.size() - 1);
for (size_t i = 0; i < apei.size(); i++) {
// assure that the width of the slope is bigger than 4
apei[i] = distance(
dvdt.begin(),
find_if(dvdt.begin() + picopy[i] + 1, dvdt.begin() + picopy[i + 1],
bind2nd(greater_equal<double>(), derivativethreshold)));
}
return apei.size();
}
int LibV2::AP_end_indices(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
int retVal;
int nSize;
retVal = CheckInMap(IntFeatureData, StringData, "AP_end_indices", nSize);
if (retVal) {
return nSize;
}

vector<double> t;
retVal = getVec(DoubleFeatureData, StringData, "T", t);
if (retVal < 0) return -1;
vector<double> v;
retVal = getVec(DoubleFeatureData, StringData, "V", v);
if (retVal < 0) return -1;
vector<int> pi;
retVal = getVec(IntFeatureData, StringData, "peak_indices", pi);
if (retVal < 0) return -1;
vector<int> apei;
retVal = __AP_end_indices(t, v, pi, apei);
if (retVal >= 0) {
setVec(IntFeatureData, StringData, "AP_end_indices", apei);
}
return retVal;
}

// *** AP rise indices ***
//
static int __AP_rise_indices(const vector<double>& v, const vector<int>& apbi,
Expand Down
7 changes: 0 additions & 7 deletions efel/cppcore/LibV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ namespace LibV2 {
// AP parameters of eCode Specification 1.04
// partly reimplemented Shaul's matlab code ap_points.m
//
int AP_begin_indices(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData);

int AP_rise_indices(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData);
Expand All @@ -42,9 +38,6 @@ int AP_fall_indices(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData);

int AP_end_indices(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData, mapStr2Str& StringData);

// eFeatures
int AP_duration(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData, mapStr2Str& StringData);
Expand Down
Loading
Loading