Commit ee695c5d authored by Mikaël Salson's avatar Mikaël Salson

Merge branch 'feature-a/4286-sigint' into 'dev'

Handle SIGINT in vidjil-algo main loops

See merge request !688
parents ed7ef722 850123fa
Pipeline #146590 failed with stages
in 46 seconds
......@@ -457,6 +457,20 @@ void json_add_warning(json &clone, string code, string msg, string level)
clone["warn"] += { {"code", code}, {"level", level}, {"msg", msg} } ;
}
// Signal handling
bool global_interrupted;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
void sigintHandler(int sig_num)
{
signal(SIGINT, sigintHandler);
global_interrupted = true;
}
#pragma GCC diagnostic pop
/*
Return the part of label before the star
For example:
......
......@@ -41,6 +41,7 @@ typedef string junction ;
#include <iomanip>
#include <string>
#include <cassert>
#include <signal.h>
#include <vector>
#include "bioreader.hpp"
#include "../lib/gzstream.h"
......@@ -96,6 +97,13 @@ inline int spaced_int(int *input, const string &seed) {
}
/* Signal handling */
extern bool global_interrupted;
void sigintHandler(int sig_num);
/*
Extract the gene name from a label. This take the whole part
before the star and returns it. If there is no star in the
......
......@@ -18,7 +18,8 @@ WindowsStorage *WindowExtractor::extract(OnlineBioReader *reads,
map<string, string> &windows_labels, bool only_labeled_windows,
bool keep_unsegmented_as_clone,
double nb_expected, int nb_reads_for_evalue,
VirtualReadScore *scorer) {
VirtualReadScore *scorer,
SampleOutput *output) {
init_stats();
WindowsStorage *windowsStorage = new WindowsStorage(windows_labels);
......@@ -27,8 +28,19 @@ WindowsStorage *WindowExtractor::extract(OnlineBioReader *reads,
unsigned long long int bp_total = 0;
global_interrupted = false ;
signal(SIGINT, sigintHandler);
while (reads->hasNext()) {
if (global_interrupted)
{
string msg = "Interrupted after processing " + string_of_int(nb_reads) + " reads" ;
if (output) output->add_warning("W09", msg, LEVEL_WARN);
cout << WARNING_STRING << msg << endl ;
break;
}
try {
reads->next();
}
......@@ -119,6 +131,7 @@ WindowsStorage *WindowExtractor::extract(OnlineBioReader *reads,
cout.flush() ;
}
}
signal(SIGINT, SIG_DFL);
cout << endl ;
......
......@@ -12,6 +12,7 @@
#include "read_storage.h"
#include "bioreader.hpp"
#include "read_score.h"
#include "output.h"
#define NB_BINS_CLONES 10
#define MAX_VALUE_BINS_CLONES 1000
......@@ -53,6 +54,7 @@ class WindowExtractor {
* @param nb_expected: maximal e-value of the segmentation
* @param nb_reads_for_evalue: number of reads, used for e-value computation. Can be approximate or faked.
* @param scorer: how reads are scored (only the best ones are keeped for large clones)
* @param output: global output, used here for warnings
* @return a pointer to a WindowsStorage that will contain all the windows.
* It is a pointer so that the WindowsStorage is not duplicated.
* @post Statistics on segmentation will be provided through the getSegmentationStats() methods
......@@ -63,7 +65,8 @@ class WindowExtractor {
map<string, string> &windows_labels, bool only_labeled_windows=false,
bool keep_unsegmented_as_clone=false,
double nb_expected = THRESHOLD_NB_EXPECTED, int nb_reads_for_evalue = 1,
VirtualReadScore *scorer = &DEFAULT_READ_SCORE);
VirtualReadScore *scorer = &DEFAULT_READ_SCORE,
SampleOutput *output = NULL);
/**
* @return the average length of sequences whose segmentation has been classified as seg
......
......@@ -1133,7 +1133,7 @@ int main (int argc, char **argv)
windows_labels, only_labeled_windows,
keep_unsegmented_as_clone,
expected_value_kmer, nb_reads_for_evalue,
readScorer);
readScorer, &output);
windowsStorage->setIdToAll();
size_t nb_total_reads = we.getNbReads();
......@@ -1308,12 +1308,22 @@ int main (int argc, char **argv)
cout << " ==> " << out_seqdir + CLONE_FILENAME + "*" << "\t(detail, by clone)" << endl ;
cout << endl ;
global_interrupted = false;
signal(SIGINT, sigintHandler);
for (list <pair<junction,size_t> >::const_iterator it = sort_clones.begin();
it != sort_clones.end(); ++it) {
junction win = it->first;
size_t clone_nb_reads = it->second;
if (global_interrupted)
{
string msg = "Interrupted after analyzing " + string_of_int(num_clone) + " clones" ;
output.add_warning("W09", msg, LEVEL_WARN);
cout << WARNING_STRING << msg << endl ;
break;
}
++num_clone ;
bool clone_on_stdout = (num_clone <= CLONES_ON_STDOUT) || verbose;
......@@ -1537,7 +1547,8 @@ int main (int argc, char **argv)
cout << endl ;
out_clone.close();
} // end for clones
signal(SIGINT, SIG_DFL);
out_edges.close() ;
delete out_clones;
......
......@@ -14,6 +14,7 @@ Warnings which were implemented ([x]) have a fixed code that should not be chang
- [ ] Outdated germlines
- [ ] Strange parameters: xxxx xxxx
- [ ] W0z Unknown error
- [x] W09 Program interrupted, output data may be not complete
## Output of a pre-process ~"server-pre-process"
- [ ] W10 Few assembled reads #2243
......
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