Coverage for biobb_godmd/godmd/common.py: 61%
28 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-25 07:50 +0000
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-25 07:50 +0000
1""" Common functions for package biobb_godmd.godmd """
2from pathlib import Path, PurePath
3from biobb_common.tools import file_utils as fu
6# CHECK INPUT PARAMETERS
7def check_input_path(path, argument, optional, out_log, classname):
8 """ Checks input file """
9 if optional and not path:
10 return None
11 if not Path(path).exists():
12 fu.log("Path: " + path)
13 fu.log("Path " + path + " --- " + classname + ': Unexisting %s file, exiting' % argument, out_log)
14 raise SystemExit(classname + ': Unexisting %s file' % argument)
15 file_extension = PurePath(path).suffix
16 if not is_valid_file(file_extension[1:], argument):
17 fu.log(classname + ': Format %s in %s file is not compatible' % (file_extension[1:], argument), out_log)
18 raise SystemExit(classname + ': Format %s in %s file is not compatible' % (file_extension[1:], argument))
19 return path
22def check_output_path(path, argument, optional, out_log, classname):
23 """ Checks output file """
24 if optional and not path:
25 return None
26 if PurePath(path).parent and not Path(PurePath(path).parent).exists():
27 fu.log(classname + ': Unexisting %s folder, exiting' % argument, out_log)
28 raise SystemExit(classname + ': Unexisting %s folder' % argument)
29 file_extension = PurePath(path).suffix
30 if not is_valid_file(file_extension[1:], argument):
31 fu.log(classname + ': Format %s in %s file is not compatible' % (file_extension[1:], argument), out_log)
32 raise SystemExit(classname + ': Format %s in %s file is not compatible' % (file_extension[1:], argument))
33 return path
36def is_valid_file(ext, argument):
37 """ Checks if file format is compatible """
38 formats = {
39 'input_pdb_orig_path': ['pdb'],
40 'input_pdb_target_path': ['pdb'],
41 'input_aln_orig_path': ['aln', 'txt'],
42 'input_aln_target_path': ['aln', 'txt'],
43 'input_config_path': ['in', 'txt'],
44 'output_aln_orig_path': ['aln', 'txt'],
45 'output_aln_target_path': ['aln', 'txt'],
46 'output_log_path': ['log', 'out', 'txt'],
47 'output_ene_path': ['log', 'out', 'txt'],
48 'output_trj_path': ['x', 'trj', 'crd', 'mdcrd'],
49 'output_pdb_path': ['pdb']
50 }
51 return ext in formats[argument]