Skip to content

Commit

Permalink
Apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-berchet committed Nov 25, 2022
1 parent 12b5fb9 commit c1dd45f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 119 deletions.
16 changes: 8 additions & 8 deletions include/morphio/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ enum LogLevel { ERROR, WARNING, INFO, DEBUG };
/** The list of modifier flags that can be passed when loading a morphology
* See morphio::mut::modifiers for more information **/
enum Option {
NO_MODIFIER = 0b0000000000000000, //!< Read morphology as is without any modification
TWO_POINTS_SECTIONS = 0b0000000000000001, //!< Keep only the first and last points of sections
SOMA_SPHERE = 0b0000000000000010, //!< Interpret morphology soma as a sphere
NO_DUPLICATES = 0b0000000000000100, //!< Skip duplicating points
NRN_ORDER = 0b0000000000001000, //!< Order of neurites will be the same as in NEURON simulator
ALLOW_ROOT_BIFURCATIONS = 0b0000000000010000, //!< Bifurcations at first point are allowed
ALLOW_SOMA_BIFURCATIONS = 0b0000000000100000, //!< Bifurcations in soma are allowed
ALLOW_MULTIPLE_SOMATA = 0b0000000001000000 //!< Multiple somata are allowed
NO_MODIFIER = 0b0000000000000000, //!< Read morphology as is without any modification
TWO_POINTS_SECTIONS = 0b0000000000000001, //!< Keep only the first and last points of sections
SOMA_SPHERE = 0b0000000000000010, //!< Interpret morphology soma as a sphere
NO_DUPLICATES = 0b0000000000000100, //!< Skip duplicating points
NRN_ORDER = 0b0000000000001000, //!< Order of neurites will be the same as in NEURON simulator
ALLOW_ROOT_BIFURCATIONS = 0b0000000000010000, //!< Bifurcations at first point are allowed
ALLOW_SOMA_BIFURCATIONS = 0b0000000000100000, //!< Bifurcations in soma are allowed
ALLOW_MULTIPLE_SOMATA = 0b0000000001000000 //!< Multiple somata are allowed
};

/**
Expand Down
3 changes: 2 additions & 1 deletion include/morphio/errorMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ class ErrorMessages
std::string WARNING_WRONG_DUPLICATE(const std::shared_ptr<morphio::mut::Section>& current,
const std::shared_ptr<morphio::mut::Section>& parent) const;
/** Writing empty section warning message */
std::string WARNING_APPENDING_EMPTY_SECTION(const std::shared_ptr<morphio::mut::Section>& section) const;
std::string WARNING_APPENDING_EMPTY_SECTION(
const std::shared_ptr<morphio::mut::Section>& section) const;
/** Writing single child section warning message */
std::string WARNING_ONLY_CHILD(const DebugInfo& info,
unsigned int parentId,
Expand Down
3 changes: 2 additions & 1 deletion src/errorMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ std::string ErrorMessages::WARNING_APPENDING_EMPTY_SECTION(
std::string ErrorMessages::WARNING_ROOT_BIFURCATION(const Sample& sample) const {
return errorMsg(sample.lineNumber,
ErrorLevel::WARNING,
"Warning: root bifurcation kept for point with id: " + std::to_string(sample.id));
"Warning: root bifurcation kept for point with id: " +
std::to_string(sample.id));
}

std::string ErrorMessages::WARNING_WRONG_DUPLICATE(
Expand Down
24 changes: 7 additions & 17 deletions src/readers/morphologyASC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ class NeurolucidaParser
int32_t _create_soma_or_section(const Header& header,
std::vector<Point>& points,
std::vector<morphio::floatType>& diameters,
unsigned int& options
) {
unsigned int& options) {
int32_t return_id = -1;
morphio::Property::PointLevel properties;
properties._points = points;
Expand All @@ -143,28 +142,19 @@ class NeurolucidaParser
} else if (header.token == Token::CELLBODY) {
if (!nb_.soma()->points().empty()) {
if (options & ALLOW_SOMA_BIFURCATIONS) {
printError(
Warning::SOMA_BIFURCATION,
err_.WARNING_SOMA_BIFURCATION()
);
printError(Warning::SOMA_BIFURCATION, err_.WARNING_SOMA_BIFURCATION());
} else if (options & ALLOW_MULTIPLE_SOMATA) {
printError(
Warning::MULTIPLE_SOMATA,
err_.WARNING_MULTIPLE_SOMATA()
);
printError(Warning::MULTIPLE_SOMATA, err_.WARNING_MULTIPLE_SOMATA());
} else {
throw SomaError(err_.ERROR_SOMA_ALREADY_DEFINED(lex_.line_num()));
}
nb_.soma()->properties()._points.insert(
nb_.soma()->properties()._points.end(),
properties._points.begin(),
properties._points.end()
);
nb_.soma()->properties()._points.insert(nb_.soma()->properties()._points.end(),
properties._points.begin(),
properties._points.end());
nb_.soma()->properties()._diameters.insert(
nb_.soma()->properties()._diameters.end(),
properties._diameters.begin(),
properties._diameters.end()
);
properties._diameters.end());
} else {
nb_.soma()->properties() = properties;
}
Expand Down
13 changes: 3 additions & 10 deletions src/readers/morphologySWC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ class SWCBuilder

if (soma_bifurcations.size() > 1) {
if (options & ALLOW_SOMA_BIFURCATIONS) {
printError(
Warning::SOMA_BIFURCATION,
err.WARNING_SOMA_BIFURCATION()
);
printError(Warning::SOMA_BIFURCATION, err.WARNING_SOMA_BIFURCATION());
} else {
throw morphio::SomaError(err.ERROR_SOMA_BIFURCATION(sample, soma_bifurcations));
}
Expand Down Expand Up @@ -340,12 +337,8 @@ class SWCBuilder
// Bifurcation right at the start
if (isRootPoint(sample) && isSectionEnd(sample)) {
if (options & ALLOW_ROOT_BIFURCATIONS) {
printError(
Warning::ROOT_BIFURCATION,
err.WARNING_ROOT_BIFURCATION(sample)
);
}
else {
printError(Warning::ROOT_BIFURCATION, err.WARNING_ROOT_BIFURCATION(sample));
} else {
continue;
}
}
Expand Down
129 changes: 47 additions & 82 deletions tests/test_reader_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,56 @@

TEST_CASE("root bifurcation", "[loader_edge_cases]") {
std::vector<std::string> exts{"asc", "h5", "swc"};
for (auto&& ext : exts)
{
SECTION( "Testing mutable morphology with " + ext + " extension" )
{
auto mutable_morph_default_opts = morphio::mut::Morphology("data/edge_cases/root_bifurcation." + ext);
for (auto&& ext : exts) {
SECTION("Testing mutable morphology with " + ext + " extension") {
auto mutable_morph_default_opts = morphio::mut::Morphology(
"data/edge_cases/root_bifurcation." + ext);

if (ext == "swc") {
// By default, root bifurcations can be not loaded from SWC files
REQUIRE(mutable_morph_default_opts.rootSections().size() == 1);
REQUIRE(mutable_morph_default_opts.rootSections()[0]->points().size() == 3);
}
else if (ext == "asc" || ext == "h5") {
} else if (ext == "asc" || ext == "h5") {
// By default, root bifurcations can be loaded from ASC and H5 files
REQUIRE(mutable_morph_default_opts.rootSections().size() == 3);
REQUIRE(mutable_morph_default_opts.rootSections()[0]->points().size() == 1);
REQUIRE(mutable_morph_default_opts.rootSections()[1]->points().size() == 1);
REQUIRE(mutable_morph_default_opts.rootSections()[2]->points().size() == 3);
}
else {
throw std::invalid_argument( "Unknown extension: " + ext );
} else {
throw std::invalid_argument("Unknown extension: " + ext);
}

auto mutable_morph = morphio::mut::Morphology(
"data/edge_cases/root_bifurcation." + ext,
morphio::enums::Option::ALLOW_ROOT_BIFURCATIONS
);
auto mutable_morph =
morphio::mut::Morphology("data/edge_cases/root_bifurcation." + ext,
morphio::enums::Option::ALLOW_ROOT_BIFURCATIONS);

REQUIRE(mutable_morph.rootSections().size() == 3);
REQUIRE(mutable_morph.rootSections()[0]->points().size() == 1);
REQUIRE(mutable_morph.rootSections()[1]->points().size() == 1);
REQUIRE(mutable_morph.rootSections()[2]->points().size() == 3);
}

SECTION( "Testing immutable morphology with " + ext + " extension" )
{
auto immutable_morph_default_opts = morphio::Morphology("data/edge_cases/root_bifurcation." + ext);
SECTION("Testing immutable morphology with " + ext + " extension") {
auto immutable_morph_default_opts = morphio::Morphology(
"data/edge_cases/root_bifurcation." + ext);

if (ext == "swc") {
// By default, root bifurcations can be not loaded from SWC files
REQUIRE(immutable_morph_default_opts.rootSections().size() == 1);
REQUIRE(immutable_morph_default_opts.rootSections()[0].points().size() == 3);
}
else if (ext == "asc" || ext == "h5") {
} else if (ext == "asc" || ext == "h5") {
// By default, root bifurcations can be loaded from ASC and H5 files
REQUIRE(immutable_morph_default_opts.rootSections().size() == 3);
REQUIRE(immutable_morph_default_opts.rootSections()[0].points().size() == 1);
REQUIRE(immutable_morph_default_opts.rootSections()[1].points().size() == 1);
REQUIRE(immutable_morph_default_opts.rootSections()[2].points().size() == 3);
}
else {
throw std::invalid_argument( "Unknown extension: " + ext );
} else {
throw std::invalid_argument("Unknown extension: " + ext);
}

auto immutable_morph = morphio::Morphology(
"data/edge_cases/root_bifurcation." + ext,
morphio::enums::Option::ALLOW_ROOT_BIFURCATIONS
);
auto immutable_morph =
morphio::Morphology("data/edge_cases/root_bifurcation." + ext,
morphio::enums::Option::ALLOW_ROOT_BIFURCATIONS);

REQUIRE(immutable_morph.rootSections().size() == 3);
REQUIRE(immutable_morph.rootSections()[0].points().size() == 1);
Expand All @@ -75,109 +68,81 @@ TEST_CASE("root bifurcation", "[loader_edge_cases]") {

TEST_CASE("soma bifurcation", "[loader_edge_cases]") {
std::vector<std::string> exts{"asc", "swc"};
for (auto&& ext : exts)
{
SECTION( "testing mutable morphology with " + ext + " extension" )
{
for (auto&& ext : exts) {
SECTION("testing mutable morphology with " + ext + " extension") {
// By default, bifurcations in soma are considered as errors in ASC and SWC files
REQUIRE_THROWS(morphio::mut::Morphology("data/edge_cases/soma_bifurcation." + ext));

// Bifurcations in soma can optionaly be loaded from ASC and SWC files
auto mutable_morph = morphio::mut::Morphology(
"data/edge_cases/soma_bifurcation." + ext,
morphio::enums::Option::ALLOW_SOMA_BIFURCATIONS
);
auto mutable_morph =
morphio::mut::Morphology("data/edge_cases/soma_bifurcation." + ext,
morphio::enums::Option::ALLOW_SOMA_BIFURCATIONS);

REQUIRE(mutable_morph.soma()->points().size() == 8);
REQUIRE(mutable_morph.rootSections().size() == 1);
}

SECTION( "testing immutable morphology with " + ext + " extension" )
{
SECTION("testing immutable morphology with " + ext + " extension") {
// By default, bifurcations in soma are considered as errors in ASC and SWC files
REQUIRE_THROWS(morphio::Morphology("data/edge_cases/soma_bifurcation." + ext));

// Bifurcations in soma can optionaly be loaded from ASC and SWC files
auto immutable_morph = morphio::Morphology(
"data/edge_cases/soma_bifurcation." + ext,
morphio::enums::Option::ALLOW_SOMA_BIFURCATIONS
);
auto immutable_morph =
morphio::Morphology("data/edge_cases/soma_bifurcation." + ext,
morphio::enums::Option::ALLOW_SOMA_BIFURCATIONS);

REQUIRE(immutable_morph.soma().points().size() == 8);
REQUIRE(immutable_morph.rootSections().size() == 1);
}
}
SECTION( "testing mutable morphology with h5 extension")
{
SECTION("testing mutable morphology with h5 extension") {
// Bifurcations in soma are always considered as errors in H5 files
REQUIRE_THROWS(morphio::mut::Morphology("data/soma_bifurcation.h5"));
REQUIRE_THROWS(
morphio::mut::Morphology(
"data/soma_bifurcation.h5",
morphio::enums::Option::ALLOW_SOMA_BIFURCATIONS
)
);
REQUIRE_THROWS(morphio::mut::Morphology("data/soma_bifurcation.h5",
morphio::enums::Option::ALLOW_SOMA_BIFURCATIONS));
REQUIRE_THROWS(morphio::Morphology("data/soma_bifurcation.h5"));
REQUIRE_THROWS(
morphio::Morphology(
"data/soma_bifurcation.h5",
morphio::enums::Option::ALLOW_SOMA_BIFURCATIONS
)
);
REQUIRE_THROWS(morphio::Morphology("data/soma_bifurcation.h5",
morphio::enums::Option::ALLOW_SOMA_BIFURCATIONS));
}
}


TEST_CASE("multiple somata", "[loader_edge_cases]") {
std::vector<std::string> exts{"asc", "swc"};
for (auto&& ext : exts)
{
SECTION( "testing mutable morphology with " + ext + " extension")
{
for (auto&& ext : exts) {
SECTION("testing mutable morphology with " + ext + " extension") {
// By default, multiple somata are considered as errors in ASC and SWC files
REQUIRE_THROWS(morphio::mut::Morphology("data/multiple_soma." + ext));

// Multiple somata can optionaly be loaded from ASC and SWC files
auto mutable_morph = morphio::mut::Morphology(
"data/multiple_soma." + ext,
morphio::enums::Option::ALLOW_MULTIPLE_SOMATA
);
auto mutable_morph =
morphio::mut::Morphology("data/multiple_soma." + ext,
morphio::enums::Option::ALLOW_MULTIPLE_SOMATA);

REQUIRE(mutable_morph.soma()->points().size() == 2);
REQUIRE(mutable_morph.rootSections().size() == 2);
}

SECTION( "testing immutable morphology with " + ext + " extension" )
{
SECTION("testing immutable morphology with " + ext + " extension") {
// By default, multiple somata are considered as errors in ASC and SWC files
REQUIRE_THROWS(morphio::Morphology("data/multiple_soma." + ext));

// Multiple somata can optionaly be loaded from ASC and SWC files
auto immutable_morph = morphio::Morphology(
"data/multiple_soma." + ext,
morphio::enums::Option::ALLOW_MULTIPLE_SOMATA
);
auto immutable_morph =
morphio::Morphology("data/multiple_soma." + ext,
morphio::enums::Option::ALLOW_MULTIPLE_SOMATA);

REQUIRE(immutable_morph.soma().points().size() == 2);
REQUIRE(immutable_morph.rootSections().size() == 2);
}
}
SECTION( "testing mutable morphology with h5 extension")
{
SECTION("testing mutable morphology with h5 extension") {
// Multiple somata are always considered as errors in H5 files
REQUIRE_THROWS(morphio::mut::Morphology("data/multiple_soma.h5"));
REQUIRE_THROWS(
morphio::mut::Morphology(
"data/multiple_soma.h5",
morphio::enums::Option::ALLOW_MULTIPLE_SOMATA
)
);
REQUIRE_THROWS(morphio::mut::Morphology("data/multiple_soma.h5",
morphio::enums::Option::ALLOW_MULTIPLE_SOMATA));
REQUIRE_THROWS(morphio::Morphology("data/multiple_soma.h5"));
REQUIRE_THROWS(
morphio::Morphology(
"data/multiple_soma.h5",
morphio::enums::Option::ALLOW_MULTIPLE_SOMATA
)
);
REQUIRE_THROWS(morphio::Morphology("data/multiple_soma.h5",
morphio::enums::Option::ALLOW_MULTIPLE_SOMATA));
}
}

0 comments on commit c1dd45f

Please sign in to comment.