JWS-112 Bumping version of T-Coffee to version 11.00.8cbe486.
[jabaws.git] / binaries / src / tcoffee / t_coffee_source / fastal / fastal_opt_parsing.c
1 /******************************COPYRIGHT NOTICE*******************************/
2 /*  (c) Centro de Regulacio Genomica                                                        */
3 /*  and                                                                                     */
4 /*  Cedric Notredame                                                                        */
5 /*  12 Aug 2014 - 22:07.                                                                    */
6 /*All rights reserved.                                                                      */
7 /*This file is part of T-COFFEE.                                                            */
8 /*                                                                                          */
9 /*    T-COFFEE is free software; you can redistribute it and/or modify                      */
10 /*    it under the terms of the GNU General Public License as published by                  */
11 /*    the Free Software Foundation; either version 2 of the License, or                     */
12 /*    (at your option) any later version.                                                   */
13 /*                                                                                          */
14 /*    T-COFFEE is distributed in the hope that it will be useful,                           */
15 /*    but WITHOUT ANY WARRANTY; without even the implied warranty of                        */
16 /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                         */
17 /*    GNU General Public License for more details.                                          */
18 /*                                                                                          */
19 /*    You should have received a copy of the GNU General Public License                     */
20 /*    along with Foobar; if not, write to the Free Software                                 */
21 /*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA             */
22 /*...............................................                                           */
23 /*  If you need some more information                                                       */
24 /*  cedric.notredame@europe.com                                                             */
25 /*...............................................                                           */
26 /******************************COPYRIGHT NOTICE*******************************/
27
28 #include "string.h"
29 #include "stdio.h"
30 #include "stdlib.h"
31 #include "fastal_lib_header.h"
32
33
34 void
35 tree_parse(struct Fastal_arguments *arguments, char* param)
36 {
37         char delims[] = "";
38         arguments->tree_method = strtok(param,delims);
39         if (arguments->tree_method == "parttree")
40         {
41                 arguments->tree_param1 = 6;
42                 arguments->tree_param2 = 150;
43         }
44         char *tmp = strtok(NULL,delims);
45         if (tmp != NULL)
46         {
47                 arguments->tree_param1 = atoi(tmp);
48                 arguments->tree_param2 = atoi(strtok(NULL,delims));
49         }
50 //      printf("A: %s %i %i", arguments->tree_method, arguments->tree_param1, arguments->tree_param2);
51 }
52
53
54
55 void
56 arg_parse (int argc, char **argv, struct Fastal_arguments *arguments)
57 {
58 //      default values
59
60         arguments->diag_method = "blast";
61         arguments->output_file = "out->aln";
62         arguments->tree_file = NULL;
63         arguments->gep = -1;
64         arguments->gop = -10;
65         arguments->method = "fast";
66         arguments->tree_method = "oligotree";
67         arguments->mat="dna_idmat";
68         arguments->tree_only = 0;
69         arguments->evaluate = 0;
70         arguments->score = 0;
71 //      arguments->retree = 0;
72         arguments->agreement_score = 0;
73         arguments->num_ref_aln = 0;
74         arguments->is_dna = 1;
75         arguments->aln_ref = NULL;
76         arguments->aln2test = NULL;
77         arguments->tree_out = 0;
78         arguments->gap_iterate = 0;
79
80
81         int i = 1;
82         char *param;
83
84         for (i = 0; i < argc; ++i)
85         {
86                 param = argv[i];
87                 if ( ( !strcmp(param, "-d" )) || ( !strcmp(param, "--is_dna")))
88                 {
89                         arguments->is_dna = 1;
90                         arguments->mat = "dna_idmat";
91                 }
92                 else if ( ( !strcmp(param, "-a" )) || ( !strcmp(param, "--is_aa")))
93                 {
94                         arguments->is_dna = 0;
95                         arguments->mat = "blosum62mt";
96
97                 }
98 //              printf("%s\n", arguments->mat);
99         }
100         if (arguments->is_dna)
101         {
102                 arguments->tree_param1 = 2;
103                 arguments->tree_param2 = 5;
104         }
105         else
106         {
107                 arguments->tree_param1 = 1;
108                 arguments->tree_param2 = 10;
109         }
110
111
112         i = 1;
113         while (i < argc)
114         {
115                 param = argv[i];
116                 if ( ( !strcmp(param, "-i" )) || ( !strcmp(param, "--in")))
117                 {
118                         arguments->sequence_file = argv[++i];
119                 }
120                 else if ( ( !strcmp(param, "-t" )) || ( !strcmp(param, "--tree_file")))
121                 {
122                         arguments->tree_file = argv[++i];
123                 }
124                 else if ( !strcmp(param, "--mat"))
125                 {
126                         arguments->mat = argv[++i];
127                 }
128                 else if ( !strcmp(param, "--tree_method"))
129                 {
130                         tree_parse(arguments, argv[++i]);
131 //                      arguments->tree_file = argv[++i];
132                 }
133                 else if ( ( !strcmp(param, "-o" )) || ( !strcmp(param, "--outfile")))
134                 {
135                         arguments->output_file = argv[++i];
136                 }
137                 else if ( ( !strcmp(param, "-m" )) || ( !strcmp(param, "--method")))
138                 {
139                         ++i;
140                         if ( (!strcmp(argv[i], "fast")) || (!strcmp(argv[i], "nw")) || (!strcmp(argv[i], "gotoh")) ||  (!strcmp(argv[i], "udisc")) )
141                                 arguments->method = argv[i];
142                         else
143                         {
144                                 printf("Method %s unknown\n", argv[i]);
145                                 exit(1);
146                         }
147                 }
148                 else if ( ( !strcmp(param, "-b" )) || ( !strcmp(param, "--diag_method")))
149                 {
150                         ++i;
151                         if ( (!strcmp(argv[i], "blast")) || (!strcmp(argv[i], "blastz")) || (!strcmp(argv[i], "blat")) || (!strcmp(argv[i], "ktup")))
152                                 arguments->diag_method = argv[i];
153                         else
154                         {
155                                 printf("DIAG Method %s unknown\n", argv[i]);
156                                 exit(1);
157                         }
158                 }
159                 else if ( ( !strcmp(param, "-d" )) || ( !strcmp(param, "--is_dna")))
160                 {
161                         arguments->is_dna = 1;
162                 }
163                 else if ( ( !strcmp(param, "-a" )) || ( !strcmp(param, "--is_aa")))
164                 {
165                         arguments->is_dna = 0;
166                 }
167                 else if ( ( !strcmp(param, "-g" )) || ( !strcmp(param, "--gop")))
168                 {
169                         arguments->gop = atof(argv[++i]);
170                 }
171 //              else if ( ( !strcmp(param, "-r" )) || ( !strcmp(param, "--retree")))
172 //              {
173 //                      arguments->retree = atoi(argv[++i]);
174 //              }
175                 else if ( ( !strcmp(param, "-e" )) || ( !strcmp(param, "--gep")))
176                 {
177                         arguments->gep = atof(argv[++i]);
178                 }
179                 else if ( ( !strcmp(param, "-k" )) || ( !strcmp(param, "--p1")))
180                 {
181                         arguments->tree_param1 = atoi(argv[++i]);
182                 }
183                 else if ( ( !strcmp(param, "-c" )) || ( !strcmp(param, "--p2")))
184                 {
185                         arguments->tree_param2 = atoi(argv[++i]);
186                 }
187                 else if ( !strcmp(param, "--eval_aln"))
188                 {
189                         arguments->evaluate = 1;
190                 }
191                 else if ( ( !strcmp(param, "-s" )) || ( !strcmp(param, "--score")))
192                 {
193                         arguments->score = 1;
194                 }
195                 else if ( !strcmp(param, "--tree_out"))
196                 {
197                         arguments->tree_out = 1;
198                 }
199                 else if ( !strcmp(param, "--tree_only"))
200                 {
201                         arguments->tree_only = 1;
202                 }
203                 else if ( !strcmp(param, "--agreement_score"))
204                 {
205                         arguments->agreement_score = 1;
206                 }
207                 else if ( !strcmp(param, "--make_ref_aln"))
208                 {
209                         arguments->num_ref_aln = atoi(argv[++i]);
210                         arguments->num_seq_in_ref = atoi(argv[++i]);
211                 }
212                 else if ( !strcmp(param, "--aln_ref"))
213                 {
214                         arguments->aln_ref = argv[++i];
215                 }
216                 else if ( !strcmp(param, "--gap_iterate"))
217                 {
218                         arguments->gap_iterate = atoi(argv[++i]);
219                 }
220                 else if ( !strcmp(param, "--aln2test"))
221                 {
222                         arguments->aln2test = argv[++i];
223                 }
224                 else if ( ( !strcmp(param, "-h" )) || ( !strcmp(param, "--help")) || ( !strcmp(param, "-?" )))
225                 {
226                         printf("Fastal - a fast alignment tool\n");
227                         printf("-i    --in              The sequence_file\n");
228                         printf("-t    --tree_file       The treefile\n");
229                         printf("      --tree_method     The method to produce the tree:\n");
230                         printf("                        oligo - very fast method\n");
231                         printf("                        parttree - method like in mafft\n");
232                         printf("-o    --outfile         The output file\n");
233                         printf("-m    --method          The method to use:\n");
234                         printf("                        fast    - fast approximate algorithm [default]\n");
235                         printf("                        nw      - needleman-wunsch\n");
236                         printf("                        gotoh   - gotoh\n");
237                         printf("-d    --is_dna          Sequence are DNA\n");
238                         printf("-a    --is_aa           Sequences are amino acids\n");
239                         printf("-g    --gop             Gap opening costs\n");
240                         printf("-e    --gep             Gap extension costs\n");
241                         printf("-r    --retree          Number of reconstructions [default=0]\n");
242                         printf("      --tree_only       only tree is produced\n");
243                         printf("      --eval_aln        calculates only the sum-of-pairs-score of a given alignment\n");
244                         printf("-s    --score           calculates the sum of paris score after construction of an alignment. Can take a long time. [default: off]\n");
245 //                      printf("      --make_ref_aln    calculates the sum of paris score after construction of an alignment. Can take a long time. [default: off]\n");
246                         exit(0);
247                 }
248                 else
249                 {
250                         printf("Argument %s unknown\n", param);
251                         exit(1);
252                 }
253                 ++i;
254         }
255 }