Coverage for PanACoTA/bin/run_panacota.py: 0%

56 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# ############################################################################### 

6# This file is part of PanACOTA. # 

7# # 

8# Authors: Amandine Perrin # 

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

10# See the COPYRIGHT file for details. # 

11# # 

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

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

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

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

16# - Uniformly annotate all genomes # 

17# - Do a Pan-genome # 

18# - Do a Core or Persistent genome # 

19# - Align all Core/Persistent families # 

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

21# # 

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

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

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

25# any later version. # 

26# # 

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

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

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

30# for more details. # 

31# # 

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

33# along with PanACOTA (COPYING file). # 

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

35# ############################################################################### 

36 

37 

38import sys 

39from textwrap import dedent 

40 

41from PanACoTA import __version__ as version 

42 

43from PanACoTA.subcommands import all_modules 

44from PanACoTA.subcommands import prepare 

45from PanACoTA.subcommands import annotate 

46from PanACoTA.subcommands import pangenome 

47from PanACoTA.subcommands import corepers 

48from PanACoTA.subcommands import align 

49from PanACoTA.subcommands import tree 

50 

51def main(): 

52 """ 

53 Start program according to arguments given by user. 

54 """ 

55 action, args = parse_arguments(sys.argv[1:]) 

56 action(args) 

57 

58 

59def parse_arguments(argv): 

60 """ 

61 Extract command-line arguments for different actions. 

62 """ 

63 import argparse 

64 

65 header = ''' 

66 

67 

68 

69 ___ _____ ___ _____ _____ 

70( _`\ ( _ )( _`\ (_ _)( _ ) 

71| |_) ) _ _ ___ | (_) || ( (_) _ | | | (_) | 

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

73| | ( (_| || ( ) || | | || (_( )( (_) )| | | | | | 

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

75 

76 

77 Large scale comparative genomics tools 

78 

79 ------------------------------------------- 

80 ''' 

81 

82 footer = "For more details, see PanACoTA documentation." 

83 

84 # Create main parser 

85 # TITLE with ascii art PanACoTA 

86 # footer for doc 

87 parser = argparse.ArgumentParser(epilog=footer, 

88 formatter_class=argparse.RawDescriptionHelpFormatter, 

89 description=dedent(header)) 

90 

91 

92 parser.add_argument('-V', '--version', action='version', 

93 version='PanACoTA - v. ' + str(version), 

94 help="Print the version number and exit") 

95 

96 # Create subparsers, for all submodules 

97 subparsers = parser.add_subparsers(dest='subparser_called') 

98 # dest: to be able to get the subparser called with args.subparser_called 

99 actions = {} # to add the action to do according to the subparser called 

100 checks = {} # to add the function to call to check the subparser arguments 

101 

102 # Running all modules at once. Start with ASCII art title, + small description of subcommand 

103 parser_all = subparsers.add_parser('all', 

104 formatter_class=argparse.RawDescriptionHelpFormatter, 

105 description=(dedent(header) + 

106 "\n=> Run all PanACoTA modules"), 

107 epilog=footer, 

108 help="Run all PanACoTA modules", 

109 add_help=False) 

110 all_modules.build_parser(parser_all) 

111 actions["all"] = all_modules.main_from_parse 

112 checks["all"] = all_modules.check_args 

113 # checks["all_modules"] = all_modules.check_args 

114 

115 # Preparation part. Start with ASCII art title, + small description of subcommand 

116 parser_prepare = subparsers.add_parser('prepare', 

117 formatter_class=argparse.RawDescriptionHelpFormatter, 

118 description=(dedent(header) + 

119 "\n=> Prepare draft dataset"), 

120 epilog=footer, 

121 help="Prepare draft dataset", 

122 add_help=False) 

123 prepare.build_parser(parser_prepare) 

124 actions["prepare"] = prepare.main_from_parse 

125 checks["prepare"] = prepare.check_args 

126 

127 # QC and annotation part. Start with ASCII art title, + small description of subcommand 

128 parser_annotate = subparsers.add_parser('annotate', 

129 formatter_class=argparse.RawDescriptionHelpFormatter, 

130 description=(dedent(header) + 

131 "\n=> Quality control and annotation of genomes"), 

132 epilog=footer, 

133 help="Quality control and annotation of genomes", 

134 add_help=False) 

135 annotate.build_parser(parser_annotate) 

136 actions["annotate"] = annotate.main_from_parse 

137 checks["annotate"] = annotate.check_args 

138 

139 # Pan genome part. Start with ASCII art title, + small description of subcommand 

140 parser_pan = subparsers.add_parser('pangenome', 

141 formatter_class=argparse.RawDescriptionHelpFormatter, 

142 description=(dedent(header) + 

143 "\n=> Generate a pan-genome of your dataset"), 

144 epilog=footer, help="Generate a pan-genome of your dataset", 

145 add_help=False) 

146 pangenome.build_parser(parser_pan) 

147 actions["pangenome"] = pangenome.main_from_parse 

148 

149 # Persistent genome part. Start with ASCII art title, + small description of subcommand 

150 parser_corepers = subparsers.add_parser('corepers', 

151 formatter_class=argparse.RawDescriptionHelpFormatter, 

152 description=(dedent(header) + 

153 "\n=> Compute a Core or Persistent genome of your " 

154 "dataset"), 

155 epilog=footer, 

156 help="Compute a Core or Persistent genome of your " 

157 "dataset", 

158 add_help=False) 

159 corepers.build_parser(parser_corepers) 

160 actions["corepers"] = corepers.main_from_parse 

161 checks["corepers"] = corepers.check_args 

162 

163 # Alignment part. Start with ASCII art title, + small description of subcommand 

164 parser_align = subparsers.add_parser('align', 

165 formatter_class=argparse.RawDescriptionHelpFormatter, 

166 description=(dedent(header) + 

167 "\n=> Align Core/Persistent families"), 

168 epilog=footer, 

169 help="Align Core/Persistent families", 

170 add_help=False) 

171 align.build_parser(parser_align) 

172 actions["align"] = align.main_from_parse 

173 

174 # tree part. Start with ASCII art title, + small description of subcommand 

175 parser_tree = subparsers.add_parser('tree', 

176 formatter_class=argparse.RawDescriptionHelpFormatter, 

177 description=(dedent(header) + 

178 "\n=> Infer phylogenetic tree based on " 

179 "core/persistent genome"), 

180 epilog=footer, 

181 help="Infer phylogenetic tree based on " 

182 "core/persistent genome", 

183 add_help=False) 

184 tree.build_parser(parser_tree) 

185 actions["tree"] = tree.main_from_parse 

186 checks["tree"] = tree.check_args 

187 

188 # Parse arguments and execute corresponding action 

189 arguments = parser.parse_args(argv) 

190 arguments.argv = argv 

191 action_called = arguments.subparser_called 

192 # If checks are needed, do it (if some arguments are not compatible etc.) 

193 if action_called in checks: 

194 checks[action_called](parser, arguments) 

195 

196 # If subparser called does not exist, error 

197 if action_called not in actions: 

198 parser.error("too few arguments. Use '-h' to get help.") 

199 return actions[action_called], arguments 

200 

201 

202if __name__ == '__main__': 

203 main()