SplitReadAll_lite.c: Add run_command function and exit when the executed command fails.
Add run_command function.
This function will print the command that will be executed.
If the executed command fails (exitcode different from 0),
it will terminate the SplitReadAll_lite program.
--- a/SplitReadAll_lite.c
+++ b/SplitReadAll_lite.c
@@ -7,6 +7,26 @@
#define binarydir "" //Directory that contains the executables of the SPLITREAD
#define samtoolsexec "samtools" //Location of the samtools executable
+
+int run_command(char * cmdline) {
+
+ int exitcode;
+
+ // Print commandline.
+ printf("%s\n",cmdline);
+ fflush(stdout);
+
+ // Execute command.
+ exitcode = system(cmdline);
+
+ // Exit SplitReadAll if the command failed.
+ if (exitcode!=0) {
+ printf("\nCommand: '%s' failed with exitcode: %d\n\n", cmdline, exitcode);
+ exit(1);
+ }
+}
+
+
int main(int argc, char** argv) {
int res;
@@ -93,233 +113,154 @@ int main(int argc, char** argv) {
strcpy(outmap,argv[12]);
strcpy(outunmap,argv[13]);
strcpy(outdir,argv[14]);
-
+
+
sprintf(cmd,"%s --search %s --seq %s -e %d -o %s -u %s",mrsFASTexec,ref,seq,edit_distance,outmap,outunmap);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"%sPaired-end_match_sam -i %s -o %s -l %s -u %s -m %s",binarydir,outmap,outdir,low,up,max);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s",outmap);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s",outunmap);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
-
- //Transform the outdir to bam and remove intermediate files
-
+ run_command(cmd);
+
+
+ // Transform the outdir to bam and remove intermediate files.
+
sprintf(cmd,"%s view -bt %s %s > %s.bam\n",samtoolsexec,refindex,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"%s sort %s.bam %s.sorted\n",samtoolsexec,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
-
+ run_command(cmd);
+
sprintf(cmd,"rm %s",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s.bam",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
+
- //Transform the outdir.inv.evert.txt to bam and remove intermediate files
+ // Transform the outdir.inv.evert.txt to bam and remove intermediate files.
sprintf(cmd,"%s view -bt %s %s.inv.evert.txt > %s.inv.evert.bam\n",samtoolsexec,refindex,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"%s sort %s.inv.evert.bam %s.inv.evert.sorted\n",samtoolsexec,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
-
+ run_command(cmd);
+
sprintf(cmd,"rm %s.inv.evert.txt",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s.inv.evert.bam",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
- //Transform the outdir.transchr.txt to bam and remove intermediate files
+
+ // Transform the outdir.transchr.txt to bam and remove intermediate files.
sprintf(cmd,"%s view -bt %s %s.transchr.txt > %s.transchr.bam\n",samtoolsexec,refindex,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"%s sort %s.transchr.bam %s.transchr.sorted\n",samtoolsexec,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
-
+ run_command(cmd);
+
sprintf(cmd,"rm %s.transchr.txt",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s.transchr.bam",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"awk '{print $1}' %s.single.txt | uniq > %s.oea.name",outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"%sfastqdeloea -i %s -r %s.oea.name -o %s.oea.fq -clean",binarydir,seq,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"%sbreakReads -i %s.oea.fq -o %s.split.fq PAIR",binarydir,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"%s --search %s --seq %s.split.fq -e %d -o %s.split.map -u %s.split.unmapped",mrsFASTexec,wholeref,outdir,distance,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
-
+ run_command(cmd);
+
sprintf(cmd,"%ssplit_match_sam -i %s.split.map -o %s.split.match -l %d -u %d -m %s",binarydir,outdir,outdir,readlen,readlen,max);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s.oea.name",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
-
+ run_command(cmd);
+
sprintf(cmd,"rm %s.oea.fq",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s.split.map",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s.split.unmapped",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"%spair_match_v5 -i %s.single.txt -fq %s -split %s.split.match -o %s.pair -l %s -u %s -m %s",binarydir,outdir,seq,outdir,outdir,low,up,max);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s.pair.single.txt",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"cat %s.single.txt %s.split.match.single.txt > %s.all.oea",outdir,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
-
+ run_command(cmd);
+
sprintf(cmd,"%sSplitOEA_match -i %s.all.oea -o %s.all.oea.match -l %s -u %s -m %s",binarydir,outdir,outdir,low,up,max);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
-
+ run_command(cmd);
+
sprintf(cmd,"rm %s.all.oea",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s.all.oea.match.single.txt",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
- //Transform the outdir.split.match to bam and remove intermediate files
+
+ // Transform the outdir.split.match to bam and remove intermediate files.
sprintf(cmd,"%s view -bt %s %s.split.match > %s.split.match.bam\n",samtoolsexec,refindex,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"%s sort %s.split.match.bam %s.split.match.sorted\n",samtoolsexec,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
-
+ run_command(cmd);
+
sprintf(cmd,"rm %s.split.match",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s.split.match.bam",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
+
- //Transform the outdir.split.match.single.txt to bam and remove intermediate files
+ // Transform the outdir.split.match.single.txt to bam and remove intermediate files.
sprintf(cmd,"%s view -bt %s %s.split.match.single.txt > %s.split.match.single.bam\n",samtoolsexec,refindex,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"%s sort %s.split.match.single.bam %s.split.match.single.sorted\n",samtoolsexec,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
-
+ run_command(cmd);
+
sprintf(cmd,"rm %s.split.match.single.txt",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s.split.match.single.bam",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
- //Transform the outdir.single.txt to bam and remove intermediate files
+
+ // Transform the outdir.single.txt to bam and remove intermediate files.
sprintf(cmd,"%s view -bt %s %s.single.txt > %s.single.bam\n",samtoolsexec,refindex,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
+ run_command(cmd);
sprintf(cmd,"%s sort %s.single.bam %s.single.sorted\n",samtoolsexec,outdir,outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res = system(cmd);
-
+ run_command(cmd);
+
sprintf(cmd,"rm %s.single.txt",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
sprintf(cmd,"rm %s.single.bam",outdir);
- printf("%s\n",cmd);
- fflush(stdout);
- //res =system(cmd);
+ run_command(cmd);
return 0;
}