Commit 2ff7f8d9 authored by Mathieu Giraud's avatar Mathieu Giraud

core/labels.{h,cpp}: load_into_map_from_json()

See #3839
parent 50fc5e97
...@@ -4,6 +4,35 @@ ...@@ -4,6 +4,35 @@
#include <cstdlib> #include <cstdlib>
#include "tools.h" #include "tools.h"
#include "lib/json.hpp"
using nlohmann::json;
json load_into_map_from_json(map <string, string> &the_map, string json_file)
{
if (!json_file.size())
return {};
cout << " <== " << json_file << endl ;
std::ifstream json_file_stream(json_file);
json j;
json_file_stream >> j;
json jj = j["config"]["labels"] ;
int n = 0;
for(json::iterator label = jj.begin(); label != jj.end(); ++label) {
string name = (*label)["name"].get<std::string>();
string sequence = (*label)["sequence"].get<std::string>();
the_map[sequence] = name;
n++ ;
}
cout << " ==> " << n << " labels" << endl;
return jj;
}
void load_into_map(map <string, string> &the_map, string map_file, string default_value) void load_into_map(map <string, string> &the_map, string map_file, string default_value)
{ {
......
...@@ -7,4 +7,4 @@ ...@@ -7,4 +7,4 @@
#include "bioreader.hpp" #include "bioreader.hpp"
void load_into_map(map <string, string> &the_map, string map_file, string default_value); void load_into_map(map <string, string> &the_map, string map_file, string default_value);
json load_into_map_from_json(map <string, string> &the_map, string json_file);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment