@@ -18,9 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
1919*/
2020
21- #include <stdio.h>
22- #include <stdlib.h>
23- #include <string.h>
2421#include "Globals.h"
2522#include "Utility.h"
2623#include "ErrorProcessing.h"
@@ -29,7 +26,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2926#include "ErrorCorrection.h"
3027#include "Reads.h"
3128#include "Correction.h"
29+
30+ #include <stdio.h>
31+ #include <stdlib.h>
32+ #include <string.h>
3233#include <libgen.h>
34+ #include <sys/types.h>
35+ #include <sys/stat.h>
36+ #include <unistd.h>
3337
3438unsigned int KMER_SIZE = 31 ;
3539
@@ -107,6 +111,19 @@ void hashReads(Correction* correction)
107111 }
108112}
109113
114+ void checkDirectoryExistsAndCreate (char * directory )
115+ {
116+ const int MISSING = -1 ;
117+
118+ struct stat st = {0 };
119+
120+ if (stat (directory , & st ) == MISSING )
121+ {
122+ printf ("Creating directory: %s\n" , directory );
123+ mkdir (directory , 0700 );
124+ }
125+ }
126+
110127void executePairedCorrection (Correction * correction ,
111128 FILE * leftCorrectedFile , FILE * rightCorrectedFile ,
112129 FILE * leftGarbageFile , FILE * rightGarbageFile , FILE * extraFile )
@@ -402,14 +419,17 @@ Correction* preprocessing(int numInputFiles, char* inputFileNames, char* outputD
402419{
403420 unsigned int LOW_COVERAGE_THRESHOLD_DEFAULT = 3 ;
404421
405- // Data Structures:
406- KMerHashTable * kmers = newKMerHashTable ();
407- Reads * * reads = (Reads * * )malloc (sizeof (Reads * ) * numInputFiles );
408- Correction * correction = (Correction * )malloc (sizeof (Correction ));
409-
410- // CREATE READS:
411- printf ("Creating read objects...\n" );
412- for (int i = 0 ; i < numInputFiles ; i ++ )
422+ // DATA STRUCTURES:
423+ KMerHashTable * kmers = newKMerHashTable ();
424+ Reads * * reads = (Reads * * )malloc (sizeof (Reads * ) * numInputFiles );
425+ Correction * correction = (Correction * )malloc (sizeof (Correction ));
426+
427+ // OUTPUT DIRECTORY:
428+ checkDirectoryExistsAndCreate (outputDirectory );
429+
430+ // CREATE READS:
431+ printf ("Creating read objects...\n" );
432+ for (int i = 0 ; i < numInputFiles ; i ++ )
413433 {
414434 char * inputFileName = & (inputFileNames [i * 200 ]);
415435 printf ("Reading file: %s\n" , inputFileName );
0 commit comments