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

vidjil.cpp, core/germline.cpp: simplify handling of '-g' option

Defers to core/germline.cpp the possible failure in opening the file.
Completes the previous commit to fix #2134.
parent 4d823656
......@@ -269,12 +269,22 @@ void MultiGermline::build_from_json(string path, string json_filename_and_filter
systems_filter = "," + json_filename_and_filter.substr(pos_lastcolon+1) + "," ;
}
//parse .g file
ifstream germline_data(path + "/" + json_filename);
string content( (std::istreambuf_iterator<char>(germline_data) ),
(std::istreambuf_iterator<char>() ) );
json germlines = json::parse(content);
//open and parse .g file
json germlines ;
try {
ifstream germline_data(path + "/" + json_filename);
string content( (std::istreambuf_iterator<char>(germline_data) ),
(std::istreambuf_iterator<char>() ) );
germlines = json::parse(content);
} catch (const invalid_argument e) {
cerr << ERROR_STRING << "Vidjil cannot open .g file " << path + "/" + json_filename << ": " << e.what() << endl;
exit(1);
}
species = germlines["species"].get<std::string>();
species_taxon_id = germlines["species_taxon_id"];
......
......@@ -451,6 +451,7 @@ int main (int argc, char **argv)
case 'g':
multi_germline = true;
germline_system = "multi" ;
{
string arg = string(optarg);
struct stat buffer;
......@@ -460,20 +461,14 @@ int main (int argc, char **argv)
{
// argument is a directory
multi_germline_paths_and_files.push_back(make_pair(arg, DEFAULT_MULTI_GERMLINE_FILE)) ;
}
else
{
multi_germline_paths_and_files.push_back(make_pair(extract_dirname(arg), extract_basename(arg, false)));
break ;
}
}
else
{
cerr << ERROR_STRING << "A path or a file must be given with -g" << endl ;
exit(1);
}
// argument is not a directory (and basename can include ':' with a filter)
multi_germline_paths_and_files.push_back(make_pair(extract_dirname(arg), extract_basename(arg, false)));
break ;
}
germline_system = "multi" ;
break;
case 'd':
several_D = true;
......
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