Coverage for PanACoTA/subcommands/all_modules.py: 100%

238 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-20 14:37 +0000

1#!/usr/bin/env python3 

2# coding: utf-8 

3 

4# ############################################################################### 

5# This file is part of PanACOTA. # 

6# # 

7# Authors: Amandine Perrin # 

8# Copyright © 2018-2020 Institut Pasteur (Paris). # 

9# See the COPYRIGHT file for details. # 

10# # 

11# PanACOTA is a software providing tools for large scale bacterial comparative # 

12# genomics. From a set of complete and/or draft genomes, you can: # 

13# - Do a quality control of your strains, to eliminate poor quality # 

14# genomes, which would not give any information for the comparative study # 

15# - Uniformly annotate all genomes # 

16# - Do a Pan-genome # 

17# - Do a Core or Persistent genome # 

18# - Align all Core/Persistent families # 

19# - Infer a phylogenetic tree from the Core/Persistent families # 

20# # 

21# PanACOTA is free software: you can redistribute it and/or modify it under the # 

22# terms of the Affero GNU General Public License as published by the Free # 

23# Software Foundation, either version 3 of the License, or (at your option) # 

24# any later version. # 

25# # 

26# PanACOTA is distributed in the hope that it will be useful, but WITHOUT ANY # 

27# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # 

28# FOR A PARTICULAR PURPOSE. See the Affero GNU General Public License # 

29# for more details. # 

30# # 

31# You should have received a copy of the Affero GNU General Public License # 

32# along with PanACOTA (COPYING file). # 

33# If not, see <https://www.gnu.org/licenses/>. # 

34# ############################################################################### 

35 

36""" 

37'all' is a module of PanACoTA, allowing to run the whole pipeline at once. 

38 

39 

40@author gem 

41October 2020 

42""" 

43 

44import os 

45import sys 

46from termcolor import colored 

47import sys 

48 

49from PanACoTA import utils 

50from PanACoTA import utils_argparse 

51from PanACoTA.subcommands import prepare 

52from PanACoTA.subcommands import annotate 

53from PanACoTA.subcommands import pangenome 

54from PanACoTA.subcommands import corepers 

55from PanACoTA.subcommands import align 

56from PanACoTA.subcommands import tree 

57from PanACoTA import __version__ as version 

58 

59 

60def main_from_parse(args): 

61 """ 

62 Call main function from the arguments given by parser 

63 

64 verbosity: 

65 

66 - defaut 0 : stdout contains INFO, stderr contains ERROR. 

67 - 1: stdout contains INFO, stderr contains WARNING and ERROR 

68 - 2: stdout contains (DEBUG), DETAIL and INFO, stderr contains WARNING and ERROR 

69 - >=15: Add DEBUG in stdout 

70 

71 Parameters 

72 ---------- 

73 args_all : tuple 

74 arguments common to all modules: output directory (str), 

75 threads (int), verbose (int), quiet (bool) 

76 args_prepare : tuple 

77 arguments for prepare module (see subcommands.prepare.py): NCBI_species (str),  

78 NCBI_species_taxid (int), NCBI_taxid (int), strains (str),  

79 levels (str), NCBI_section (str), tmp_dir (str), norefseq (bool), db_dir (str), 

80 only_mash (bool), info_file (str), l90 (int), nbcont (int), cutn (int), 

81 min_dist (float), max_dist (float) 

82 args_annot : tuple 

83 arguments for annotate module (see subcommands/annotate.py): name (str), qc_only (bool), 

84 date (str), prodigal_only (bool), small (bool) 

85 args_pan : tuple 

86 arguments for pangenome module (see subcommands/pangenome.py): min_id (float), 

87 clust_mode (int), spe_dir (str), outfile (str) 

88 args_corepers : tuple 

89 arguments for corepers module (see subcommands.corepers.py): tol (float), mixed (bool), 

90 multi (bool), floor (bool) 

91 args_align : tuple 

92 arguments for align module (see subcommands.align.py): prot_ali (bool) 

93 args_tree : tuple 

94 arguments for tree module (see subcommands.tree.py): soft (str), model (str), boot (bool), 

95 write_boot (bool), memory (str), fast (bool) 

96 """ 

97 cmd = "PanACoTA " + ' '.join(args.argv) 

98 args_all = (args.outdir, args.threads, args.verbose, args.quiet) 

99 args_prepare = (args.ncbi_species_name, args.ncbi_species_taxid, args.ncbi_taxid, args.strains, args.levels, 

100 args.ncbi_section, args.tmp_dir, args.norefseq, args.db_dir, args.only_mash, 

101 args.info_file, args.l90, args.nbcont, args.cutn, args.min_dist, args.max_dist) 

102 args_annot = (args.name, args.qc_only, args.date, args.prodigal_only, args.small) 

103 args_pan = (args.min_id, args.clust_mode, args.spedir, args.outfile) 

104 args_cp = (args.tol, args.mixed, args.multi, args.floor) 

105 args_align = (args.prot_ali) 

106 args_tree = (args.soft, args.model, args.boot, args.write_boot, args.write_mat, args.memory, args.fast) 

107 main(cmd, args_all, args_prepare, args_annot, args_pan, args_cp, args_align, args_tree) 

108 

109 

110def main(cmd, args_all, args_prepare, args_annot, args_pan, args_corepers, args_align, args_tree): 

111 """ 

112 Call all modules, one by one, using output of one as input for the next one 

113 

114 Parameters 

115 ---------- 

116 cmd : str 

117 command line used to launch the program 

118 args_all : tuple 

119 arguments common to all modules: output directory (str), 

120 threads (int), verbose (int), quiet (bool) 

121 args_prepare : tuple 

122 arguments for prepare module (see subcommands.prepare.py): NCBI_species_taxid (int), 

123 NCBI_species_name (str), NCBI_species_taxid (int), NCBI_taxid (int), NCBI_strains (str), levels (str), NCBI_section (str), 

124 tmp_dir (str), norefseq (bool), db_dir (str), 

125 only_mash (bool), info_file (str), l90 (int), nbcont (int), cutn (int), 

126 min_dist (float), max_dist (float) 

127 args_annot : tuple 

128 arguments for annotate module (see subcommands/annotate.py): name (str), qc_only (bool), 

129 date (str), prodigal_only (bool), small (bool) 

130 args_pan : tuple 

131 arguments for pangenome module (see subcommands/pangenome.py): min_id (float), 

132 clust_mode (int), spe_dir (str), outfile (str) 

133 args_corepers : tuple 

134 arguments for corepers module (see subcommands.corepers.py): tol (float), mixed (bool), 

135 multi (bool), floor (bool) 

136 args_align : tuple 

137 arguments for align module (see subcommands.align.py): prot_ali (bool) 

138 args_tree : tuple 

139 arguments for tree module (see subcommands.tree.py): soft (str), model (str), boot (bool), 

140 write_boot (bool), memory (str), fast (bool) 

141 """ 

142 outdir, threads, verbose, quiet = args_all 

143 os.makedirs(outdir, exist_ok=True) 

144 # Initialize logger 

145 import logging 

146 # set level of logger: level is the minimum level that will be considered. 

147 if verbose <= 1: 

148 level = logging.INFO 

149 # for verbose = 2, ignore only debug 

150 if verbose >= 2 and verbose < 15: 

151 level = utils.detail_lvl() # int corresponding to detail level 

152 # for verbose >= 15, write everything 

153 if verbose >= 15: 

154 level = logging.DEBUG 

155 logfile_base = os.path.join(outdir, "PanACoTA-all_modules") 

156 logfile_base = utils.init_logger(logfile_base, level, name='all_modules', 

157 verbose=verbose, quiet=quiet) 

158 logger = logging.getLogger('all_modules') 

159 logger.info(f'PanACoTA version {version}') 

160 logger.info("Command used\n \t > " + cmd) 

161 

162 # Run prepare module 

163 outdir_prepare = os.path.join(outdir, "1-prepare_module") 

164 (NCBI_species_name, NCBI_species_taxid, NCBI_taxid, NCBI_strains, levels, NCBI_section, 

165 tmp_dir, norefseq, db_dir, only_mash, info_file, 

166 l90, nbcont, cutn, min_dist, max_dist) = args_prepare 

167 logger.info("prepare step") 

168 info_file = prepare.main("PanACoTA prepare", NCBI_species_name, NCBI_species_taxid, 

169 NCBI_taxid, NCBI_strains, levels, NCBI_section, 

170 outdir_prepare, tmp_dir, threads, norefseq, db_dir, only_mash, 

171 info_file, l90, nbcont, cutn, min_dist, max_dist, verbose, quiet) 

172 

173 # Run annotate module 

174 list_file = "" 

175 db_path = "" 

176 tmp_dir = "" 

177 force = False 

178 outdir_annotate = os.path.join(outdir, "2-annotate_module") 

179 (name, qc_only, date, prodigal_only, small) = args_annot 

180 res_annot_dir = None 

181 

182 logger.info("annotate step") 

183 lstinfo, nbgenomes = annotate.main("PanACoTA annotate", list_file, db_path, outdir_annotate, 

184 name, date, l90, nbcont, cutn, threads, force, qc_only, 

185 info_file, tmp_dir, res_annot_dir, verbose, quiet, 

186 prodigal_only=prodigal_only, small=small) 

187 if qc_only: 

188 return "QC_only done" 

189 

190 # Pangenome step 

191 name_pan = f"{name}_{nbgenomes}" 

192 outdir_pan = os.path.join(outdir, "3-pangenome_module") 

193 dbpath = os.path.join(outdir_annotate, "Proteins") 

194 (min_id, clust_mode, spe_dir, outfile) = args_pan 

195 logger.info("pangenome step") 

196 panfile = pangenome.main("PanACoTA pangenome", lstinfo, name_pan, dbpath, min_id, outdir_pan, 

197 clust_mode, spe_dir, threads, outfile, verbose=verbose, 

198 quiet=quiet) 

199 

200 # Coregenome step 

201 outdir_corpers = os.path.join(outdir, "4-corepers_module") 

202 logger.info("corepers step") 

203 (tol, mixed, multi, floor) = args_corepers 

204 lstinfo_file = "" # include all genomes in core 

205 corepers_file = corepers.main("PanACoTA corepers", panfile, tol, multi, mixed, outdir_corpers, 

206 lstinfo_file, floor, verbose, quiet) 

207 # Align step 

208 outdir_align = os.path.join(outdir, "5-align_module") 

209 force = False 

210 logger.info("align step") 

211 (prot_ali) = args_align 

212 align_file = align.main("PanACoTA align", corepers_file, lstinfo, name_pan, outdir_annotate, 

213 outdir_align, prot_ali, threads, force, verbose=verbose, quiet=quiet) 

214 

215 

216 # Tree step 

217 (soft, model, boot, write_boot, write_mat, memory, fast) = args_tree 

218 outdir_tree = os.path.join(outdir, "6-tree_module") 

219 logger.info("tree step") 

220 tree.main("PanACoTA tree", align_file, outdir_tree, soft, model, threads, boot, 

221 write_boot, write_mat, memory, fast, verbose=verbose, quiet=quiet) 

222 logger.info("All modules of PanACOTA are finished.") 

223 return 0 

224 

225 

226def build_parser(parser): 

227 """ 

228 Method to create a parser for command-line options 

229 

230 Parameters 

231 ---------- 

232 parser : argparse.ArgumentParser 

233 The parser to configure 

234 

235 """ 

236 import argparse 

237 from PanACoTA import utils_argparse 

238 

239 # Create command-line parser for all options and arguments to give 

240 general = parser.add_argument_group("General arguments") 

241 general.add_argument("-c", dest="configfile", 

242 help=("Path to your configuration file, defining values of parameters.") 

243 ) 

244 general.add_argument("-o", dest="outdir", required=True, 

245 help=("Path to your output folder, where all results " 

246 "from all 6 modules will be saved.") 

247 ) 

248 general.add_argument("--threads", dest="threads", type=utils_argparse.thread_num, 

249 help="Specify how many threads can be used (default=1)") 

250 # prepare arguments 

251 pprepare = parser.add_argument_group("'prepare' module arguments") 

252 pprepare.add_argument("-T", dest="ncbi_species_taxid", 

253 help=("Species taxid to download, corresponding to the " 

254 "'species taxid' provided by the NCBI. A comma-separated " 

255 "list of taxid can also be provided.") 

256 ) 

257 pprepare.add_argument("-s", dest="ncbi_species", 

258 help=("Species to download, corresponding to the " 

259 "'organism name' provided by the NCBI. Give name between " 

260 "quotes (for example \"escherichia coli\")") 

261 ) 

262 pprepare.add_argument("-l", "--assembly_level", dest="levels", 

263 help=("Assembly levels of genomes to download (default: all). " 

264 "Possible levels are: 'all', 'complete', 'chromosome', " 

265 "'scaffold', 'contig'." 

266 "You can also provide a comma-separated list of assembly " 

267 "levels. For ex: 'complete,chromosome'") 

268 ) 

269 pprepare_annote = parser.add_argument_group("Common arguments to 'prepare' " 

270 "and 'annotate' modules") 

271 pprepare_annote.add_argument("--cutn", dest="cutn", type=utils_argparse.positive_int, 

272 

273 help=("By default, each genome will be cut into new contigs when " 

274 "at least 5 'N' in a row are found in its sequence. " 

275 "If you don't want to " 

276 "cut genomes into new contigs when there are rows of 'N', " 

277 "put 0 to this option. If you want to cut from a different number " 

278 "of 'N' in a row, put this value to this option.") 

279 ) 

280 pprepare_annote.add_argument("--l90", dest="l90", type=int, 

281 help=("Maximum value of L90 allowed to keep a genome. " 

282 "Default is 100.") 

283 ) 

284 pprepare_annote.add_argument("--nbcont", dest="nbcont", type=utils_argparse.cont_num, 

285 help=("Maximum number of contigs allowed to " 

286 "keep a genome. Default is 999.")) 

287 

288 pannote = parser.add_argument_group("'annotate' module arguments") 

289 pannote.add_argument("--prodigal", dest="prodigal_only", action="store_true", 

290 help="Add this option if you only want syntactical annotation, given " 

291 "by prodigal, and not functional annotation requiring prokka and " 

292 "is slower.") 

293 pannote.add_argument("-n", dest="name", required=True, type=utils_argparse.gen_name, 

294 help=("Choose a name for your annotated genomes. This name should " 

295 "contain 4 alphanumeric characters. Generally, they correspond " 

296 "to the 2 first letters of genus, and 2 first letters of " 

297 "species, e.g. ESCO for Escherichia Coli.")) 

298 

299 ppangenome = parser.add_argument_group("'pangenome' module arguments") 

300 ppangenome.add_argument("-i", dest="min_id", type=utils_argparse.perc_id, 

301 help=("Minimum sequence identity to be considered in the same " 

302 "cluster (float between 0 and 1). Default is 0.8.")) 

303 

304 pcorepers = parser.add_argument_group("'corepers' module arguments") 

305 pcorepers.add_argument("--tol", dest="tol", type=utils_argparse.percentage, 

306 help=("min %% of genomes having at least 1 member in a family to " 

307 "consider the family as persistent (between 0 and 1, " 

308 "default is 1 = 100%% of genomes = Core genome)." 

309 "By default, the minimum number of genomes will be " 

310 "ceil('tol'*N) (N being the total number of genomes). If " 

311 "you want to use floor('tol'*N) instead, add the '-F' option.")) 

312 pcorepers.add_argument("-Mu", dest="multi", action='store_true', 

313 help=("Add this option if you allow several members in any genome " 

314 "of a family. By default, only 1 (or 0 if tol<1) member " 

315 "per genome are allowed in all genomes. If you want to allow " 

316 "exactly 1 member in 'tol'%% of the genomes, and 0, 1 " 

317 "or several members in the '1-tol'%% left, use the option -X " 

318 "instead of this one: -M and -X options are not compatible.")) 

319 pcorepers.add_argument("-X", dest="mixed", action='store_true', 

320 help="Add this option if you want to allow families having several " 

321 "members only in '1-tol'%% of the genomes. In the other genomes, " 

322 "only 1 member exactly is allowed. This option is not compatible " 

323 "with -M (which is allowing multigenic families: having several " 

324 "members in any number of genomes).") 

325 

326 ptree = parser.add_argument_group("'tree' module arguments") 

327 softs = ["fasttree", "fastme", "quicktree", "iqtree", "iqtree2"] 

328 ptree.add_argument("--soft", dest="soft", choices=softs, 

329 help=("Choose with which software you want to infer the " 

330 "phylogenetic tree. Default is IQtree.")) 

331 

332 helper = parser.add_argument_group('Others') 

333 helper.add_argument("-v", "--verbose", dest="verbose", action="count", 

334 help="Increase verbosity in stdout/stderr.") 

335 helper.add_argument("-q", "--quiet", dest="quiet", action="store_true", 

336 help=("Do not display anything to stdout/stderr. log files will " 

337 "still be created.")) 

338 helper.add_argument("-h", "--help", dest="help", action="help", 

339 help="show this help message and exit") 

340 

341 

342def parse(parser, argu): 

343 """ 

344 parse arguments given to parser 

345 

346 Parameters 

347 ---------- 

348 parser : argparse.ArgumentParser 

349 the parser used 

350 argu : [str] 

351 command-line given by user, to parse using parser 

352 

353 Returns 

354 ------- 

355 argparse.Namespace 

356 Parsed arguments 

357 """ 

358 import argparse 

359 args = parser.parse_args(argu) 

360 return check_args(parser, args) 

361 

362 

363def check_args(parser, argv): 

364 """ 

365 Check arguments given by user 

366 

367 Parameters 

368 ---------- 

369 parser : argparse.ArgumentParser 

370 the parser used 

371 argv : argparse.Namespace 

372 parsed command-line given by user 

373 

374 Returns 

375 ------- 

376 argv : argparse.Namespace 

377 parsed command-line  

378 """ 

379 from argparse import Namespace 

380 

381 # Get arguments given in command line 

382 # If an argument was not in the user command-line, it still exists in argv, 

383 # but is set to 'None' -> ignore it 

384 # If a bool argument (quiet, mixed, multi, prodigal_only) is not in the user command-line, 

385 # it still exists in argv but is set to False -> ignore it to replace by info from 

386 # config file if any, or default otherwise 

387 dict_argv = {key:val for key,val in vars(argv).items() if val is not None and val != False} 

388 final_dict = {} 

389 

390 # PREPARE STEP 

391 prep_dict = get_prepare(dict_argv) 

392 final_dict.update(prep_dict) # put new arguments to final_dict 

393 a = Namespace(**final_dict) 

394 prepare.check_args(parser, a) # Check compatibility 

395 # dict1.update(dict2): 

396 # dict1 will contain key/values from dict2 that did not exist 

397 # dict1 will have values of dict2 for existing keys  

398 

399 # ANNOTATE STEP 

400 annot_dict = get_annotate(dict_argv) 

401 final_dict.update(annot_dict) 

402 a = Namespace(**final_dict) 

403 annotate.check_args(parser, a) 

404 

405 # PANGENOME STEP 

406 pan_dict = get_pangenome(dict_argv) 

407 final_dict.update(pan_dict) 

408 # Add default arguments if not found in commandline nor config file 

409 

410 # COREPERS STEP 

411 cp_dict = get_corepers(dict_argv) 

412 final_dict.update(cp_dict) 

413 a = Namespace(**final_dict) 

414 corepers.check_args(parser, a) 

415 

416 # ALIGN STEP 

417 ali_dict = get_align(dict_argv) 

418 final_dict.update(ali_dict) 

419 

420 # TREE STEP 

421 tree_dict = get_tree(dict_argv) 

422 # If we chose soft==quicktree, check_args will return error if threads > 1. So, 

423 # we put threads = 1 during check_args, and put back the value after 

424 th_save = tree_dict["threads"] 

425 a = Namespace(**tree_dict) 

426 checked_a = tree.check_args(parser, a) 

427 # Variable can be changed by check_args (like put default model if not given) 

428 tree_dict.update(vars(checked_a)) 

429 tree_dict["threads"] = th_save 

430 final_dict.update(tree_dict) 

431 

432 # Combine files 

433 # Put new args values in argv 

434 for key, val in final_dict.items(): 

435 vars(argv)[key] = val 

436 return argv 

437 

438 

439def get_prepare(dict_argv): 

440 """ 

441 Check that arguments given for prepare step are compatible 

442 """ 

443 # Get arguments from config file and add them (overwrite if needed) 

444 if not "configfile" in dict_argv: 

445 conf_conffile = utils_argparse.Conf_all_parser("",["prepare"]) 

446 else: 

447 conf_conffile = utils_argparse.Conf_all_parser(dict_argv['configfile'], 

448 readsec=["prepare"]) 

449 # Add arguments from commandline 

450 conf_conffile.update(dict_argv, "prepare") 

451 # Add default arguments if not found in cmd line nor config file 

452 defaults = {"verbose": 0, "threads": 1, "cutn": 5, "l90": 100, "nbcont":999, 

453 "levels": "all", "quiet": False, "ncbi_species_name": "", 

454 "ncbi_species_taxid": "", "ncbi_taxid": "", "strains": "", "tmp_dir": "", "db_dir": "", 

455 "info_file": "", "min_dist": 1e-4, "max_dist": 0.06, 

456 "norefseq": False, "only_mash": False, "ncbi_section": "refseq"} 

457 conf_conffile.add_default(defaults, "prepare") 

458 # Change to expected types (boolean, int, float) 

459 conf_conffile.set_boolean("prepare", "quiet") 

460 conf_conffile.set_boolean("prepare", "only_mash") 

461 conf_conffile.set_boolean("prepare", "norefseq") 

462 conf_conffile.set_int("prepare", "threads") 

463 conf_conffile.set_int("prepare", "verbose") 

464 conf_conffile.set_int("prepare", "cutn") 

465 conf_conffile.set_int("prepare", "l90") 

466 conf_conffile.set_int("prepare", "nbcont") 

467 conf_conffile.set_float("prepare", "min_dist") 

468 conf_conffile.set_float("prepare", "max_dist") 

469 prep_dict = conf_conffile.get_section_dict("prepare") 

470 return prep_dict 

471 

472 

473def get_annotate(dict_argv): 

474 """ 

475 Check that arguments given for annotate step are compatible 

476 """ 

477 # Get arguments from config file and add them (overwrite if needed) 

478 if not "configfile" in dict_argv: 

479 conf_conffile = utils_argparse.Conf_all_parser("",["annotate"]) 

480 else: 

481 conf_conffile = utils_argparse.Conf_all_parser(dict_argv['configfile'], 

482 readsec=["annotate"]) 

483 # Add arguments from commandline 

484 not_allowed = ["l90", "nbcont", "cutn"] 

485 for param in not_allowed: 

486 if param in conf_conffile.get_section_dict("annotate").keys(): 

487 print(f"{param} not allowed in annotate section.") 

488 sys.exit(1) 

489 conf_conffile.update(dict_argv, "annotate") 

490 if "date" not in dict(conf_conffile["annotate"]): 

491 import time 

492 date = time.strftime("%m%y") 

493 conf_conffile.update({"date": date}, "annotate") 

494 # Add default arguments if not found in commandline nor config file 

495 defaults = {"verbose": 0, "threads": 1, 

496 "quiet": False, "prodigal_only": False, "small": False, "qc_only": False, 

497 "list_file": "list_file", "db_path": "db_path", "from_info": False} 

498 conf_conffile.add_default(defaults, "annotate") 

499 conf_conffile.set_boolean("annotate", "quiet") 

500 conf_conffile.set_boolean("annotate", "prodigal_only") 

501 conf_conffile.set_boolean("annotate", "small") 

502 conf_conffile.set_boolean("annotate", "qc_only") 

503 conf_conffile.set_int("annotate", "verbose") 

504 conf_conffile.set_int("annotate", "threads") 

505 annot_dict = conf_conffile.get_section_dict("annotate") 

506 return annot_dict 

507 

508 

509def get_pangenome(dict_argv): 

510 """ 

511 Check that arguments given for pangenome step are compatible 

512 """ 

513 # Get arguments from config file and add them (overwrite if needed) 

514 if not "configfile" in dict_argv: 

515 conf_conffile = utils_argparse.Conf_all_parser("",["pangenome"]) 

516 else: 

517 conf_conffile = utils_argparse.Conf_all_parser(dict_argv['configfile'], 

518 readsec=["pangenome"]) 

519 # Add arguments from commandline 

520 conf_conffile.update(dict_argv, "pangenome") 

521 # Add default arguments if not found in commandline nor config file 

522 defaults = {"verbose": 0, "threads": 1, "min_id": 0.8, "quiet": False, "clust_mode": 1, 

523 "outfile": "", "spedir": ""} 

524 conf_conffile.add_default(defaults, "pangenome") 

525 conf_conffile.set_boolean("pangenome", "quiet") 

526 conf_conffile.set_int("pangenome", "verbose") 

527 conf_conffile.set_int("pangenome", "threads") 

528 conf_conffile.set_float("pangenome", "min_id") 

529 pan_dict = conf_conffile.get_section_dict("pangenome") 

530 return pan_dict 

531 

532 

533def get_corepers(dict_argv): 

534 """ 

535 Check that arguments given for corepers step are compatible 

536 """ 

537 # Get arguments from config file and add them (overwrite if needed) 

538 if not "configfile" in dict_argv: 

539 conf_conffile = utils_argparse.Conf_all_parser("",["corepers"]) 

540 else: 

541 conf_conffile = utils_argparse.Conf_all_parser(dict_argv['configfile'], 

542 readsec=["corepers"]) 

543 # Add arguments from commandline 

544 conf_conffile.update(dict_argv, "corepers") 

545 # Add default arguments if not found in commandline nor config file 

546 defaults = {"verbose": 0, "quiet": False, "tol": 1, "mixed": False, "multi": False, 

547 "floor": False, "threads": 1} 

548 conf_conffile.add_default(defaults, "corepers") 

549 conf_conffile.set_boolean("corepers", "quiet") 

550 conf_conffile.set_boolean("corepers", "floor") 

551 conf_conffile.set_boolean("corepers", "mixed") 

552 conf_conffile.set_boolean("corepers", "multi") 

553 conf_conffile.set_int("corepers", "verbose") 

554 conf_conffile.set_float("corepers", "tol") 

555 conf_conffile.set_int("corepers", "threads") 

556 corepers_dict = conf_conffile.get_section_dict("corepers") 

557 return corepers_dict 

558 

559 

560def get_align(dict_argv): 

561 """ 

562 Check that arguments given for align step are compatible 

563 """ 

564 # Get arguments from config file and add them (overwrite if needed) 

565 if not "configfile" in dict_argv: 

566 conf_conffile = utils_argparse.Conf_all_parser("",["align"]) 

567 else: 

568 conf_conffile = utils_argparse.Conf_all_parser(dict_argv['configfile'], 

569 readsec=["align"]) 

570 # Add arguments from commandline 

571 conf_conffile.update(dict_argv, "align") 

572 # Add default arguments if not found in commandline nor config file 

573 defaults = {"prot_ali": False} 

574 conf_conffile.add_default(defaults, "align") 

575 conf_conffile.set_boolean("align", "prot_ali") 

576 ali_dict = conf_conffile.get_section_dict("align") 

577 return ali_dict 

578 

579 

580def get_tree(dict_argv): 

581 """ 

582 Check that arguments given for tree step are compatible 

583 """ 

584 # Get arguments from config file and add them (overwrite if needed) 

585 if not "configfile" in dict_argv: 

586 conf_conffile = utils_argparse.Conf_all_parser("",["tree"]) 

587 else: 

588 conf_conffile = utils_argparse.Conf_all_parser(dict_argv['configfile'], readsec=["tree"]) 

589 # Add arguments from commandline 

590 conf_conffile.update(dict_argv, "tree") 

591 # Add default arguments if not found in commandline nor config file 

592 defaults = {"verbose": 0, "quiet": False, "threads": 1, 

593 "soft": "iqtree", "model": None, "boot": 0, "write_boot": False, 

594 "memory": None, "fast": False, "write_mat": False} 

595 conf_conffile.add_default(defaults, "tree") 

596 conf_conffile.set_boolean("tree", "quiet") 

597 conf_conffile.set_boolean("tree", "fast") 

598 conf_conffile.set_boolean("tree", "write_boot") 

599 conf_conffile.set_int("tree", "boot") 

600 conf_conffile.set_int("tree", "verbose") 

601 conf_conffile.set_int("tree", "threads") 

602 tree_dict = conf_conffile.get_section_dict("tree") 

603 return tree_dict 

604 

605 

606if __name__ == '__main__': 

607 import argparse 

608 from textwrap import dedent 

609 header = ''' 

610 ___ _____ ___ _____ _____ 

611 ( _`\ ( _ )( _`\ (_ _)( _ ) 

612 | |_) ) _ _ ___ | (_) || ( (_) _ | | | (_) | 

613 | ,__/'/'_` )/' _ `\| _ || | _ /'_`\ | | | _ | 

614 | | ( (_| || ( ) || | | || (_( )( (_) )| | | | | | 

615 (_) `\__,_)(_) (_)(_) (_)(____/'`\___/'(_) (_) (_) 

616 

617 

618 Large scale comparative genomics tools 

619 

620 ------------------------------------------- 

621 ''' 

622 my_parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, 

623 description=dedent(header), add_help=False) 

624 build_parser(my_parser) 

625 OPTIONS = parse(my_parser, sys.argv[1:]) 

626 main_from_parse(OPTIONS)