Paired-end_match_sam.c: Return an exitcode of 1 instead of 0, when a fatal error happens.
Return an exitcode of 1 instead of 0, when a fatal error happens.
This way we can check if Paired-end_match_sam failed when called
from another script/program (like SplitReadAll_lite).
Before with my run_command patch applied to ./SplitReadAll_lite:
$ ./SplitReadAll_lite 1 2 3 4 5 6 7 8 9 10 11 12 13 14
mrsfast --search 1 --seq 11 -e 5 -o 12 -u 13
Error: Cannot Open the file 11
Paired-end_match_sam -i 12 -o 14 -l 7 -u 8 -m 9
Error opening file 12 in r mode.
rm 12
rm: cannot remove `12': No such file or directory
Command: 'rm 12' failed with exitcode: 256
With this patch:
$ ./SplitReadAll_lite 1 2 3 4 5 6 7 8 9 10 11 12 13 14
mrsfast --search 1 --seq 11 -e 5 -o 12 -u 13
Error: Cannot Open the file 11
Paired-end_match_sam -i 12 -o 14 -l 7 -u 8 -m 9
Error opening file 12 in r mode.
Command: 'Paired-end_match_sam -i 12 -o 14 -l 7 -u 8 -m 9' failed with exitcode: 256
As you can see "mrsfast" has the same problem.
--- a/Paired-end_match_sam.c
+++ b/Paired-end_match_sam.c
@@ -172,24 +172,24 @@ int main (int argc, char **argv) {
if (inputfilename[0] == 0){
fprintf(stderr, "Need inputfilename (-i)\n");
- return 0;
+ exit(1);
}
if (outputfilename[0] == 0){
fprintf(stderr, "Need outputfilename (-o)\n");
- return 0;
+ exit(1);
}
if (upper == -1){
fprintf(stderr, "Need upper bound (-u)\n");
- return 0;
+ exit(1);
}
if (lower == -1){
fprintf(stderr, "Need lower bound (-l)\n");
- return 0;
+ exit(1);
}
if (maxdist == -1){
fprintf(stderr, "Need maximum distance (-m)\n");
- return 0;
+ exit(1);
}
input = myfopen(inputfilename, "r",0);
@@ -231,7 +231,9 @@ int main (int argc, char **argv) {
fclose(trans);
fclose(everted);
fclose(input);
- fclose(output);
+ fclose(output);
+
+ return 0;
}
FILE *myfopen(char *name, char *mode, int GZ){
@@ -242,7 +244,7 @@ FILE *myfopen(char *name, char *mode, int GZ){
ret = gzopen(name, mode);
if (ret == NULL){
fprintf(stderr, "Error opening file %s in %s mode.\n", name, mode);
- exit(0);
+ exit(1);
}
return ret;
}
@@ -273,25 +275,25 @@ void alloc_table(int seqcnt){
if (forward == NULL){
fprintf(stderr, "Unable to allocate space for forward table.\n");
- exit(0);
+ exit(1);
}
if (reverse == NULL){
fprintf(stderr, "Unable to allocate space for reverse table.\n");
- exit(0);
+ exit(1);
}
if (names == NULL){
fprintf(stderr, "Unable to allocate space for names list.\n");
- exit(0);
+ exit(1);
}
if (fwdcnt == NULL){
fprintf(stderr, "Unable to allocate space for forward count.\n");
- exit(0);
+ exit(1);
}
if (revcnt == NULL){
fprintf(stderr, "Unable to allocate space for reverse count.\n");
- exit(0);
+ exit(1);
}
for (i=0;i<allocseq;i++){
@@ -499,7 +501,7 @@ struct hit *alloc_hit(void){
ret = (struct hit *) malloc(sizeof(struct hit));
if (ret == NULL){
fprintf(stderr, "Unable to allocate memory for the hit structure.\n");
- exit(0);
+ exit(1);
}
ret->next = NULL;