1 /*
2     Genome-wide Efficient Mixed Model Association (GEMMA)
3     Copyright (C) 2011-2017, Xiang Zhou
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "gemma.h"
20 #include <fstream>
21 #include <iostream>
22 #include <sstream>
23 #include <sys/stat.h>
24 #include <sys/types.h>
25 
26 using namespace std;
27 
main(int argc,char * argv[])28 int main(int argc, char *argv[]) {
29   GEMMA cGemma;
30   PARAM cPar;
31 
32   gsl_set_error_handler (&gemma_gsl_error_handler);
33 
34   if (argc <= 1) {
35     cGemma.PrintHeader();
36     cGemma.PrintHelp(0);
37     return EXIT_SUCCESS;
38   }
39   if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'h') {
40     cGemma.PrintHeader();
41     cGemma.PrintHelp(0);
42     return EXIT_SUCCESS;
43   }
44   if (argc == 3 && argv[1][0] == '-' && argv[1][1] == 'h') {
45     string str;
46     str.assign(argv[2]);
47     cGemma.PrintHeader();
48     cGemma.PrintHelp(atoi(str.c_str()));
49     return EXIT_SUCCESS;
50   }
51   if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'l') {
52     cGemma.PrintHeader();
53     cGemma.PrintLicense();
54     return EXIT_SUCCESS;
55   }
56 
57   cGemma.Assign(argc, argv, cPar);
58 
59   ifstream check_dir((cPar.path_out).c_str());
60   if (!check_dir) {
61     #ifdef WINDOWS
62       mkdir((cPar.path_out).c_str());
63     #else
64       mkdir((cPar.path_out).c_str(), S_IRWXU | S_IRGRP | S_IROTH);
65     #endif
66   }
67 
68   if (!is_quiet_mode())
69     cGemma.PrintHeader();
70 
71   if (cPar.error == true) {
72     return EXIT_FAILURE;
73   }
74 
75   if (is_quiet_mode()) {
76     stringstream ss;
77     cout.rdbuf(ss.rdbuf());
78   }
79 
80   cPar.CheckParam();
81 
82   if (cPar.error == true) {
83     return EXIT_FAILURE;
84   }
85 
86   cGemma.BatchRun(cPar);
87 
88   if (cPar.error == true) {
89     return EXIT_FAILURE;
90   }
91 
92   cGemma.WriteLog(argc, argv, cPar);
93 
94   return EXIT_SUCCESS;
95 }
96