diff --git a/greedyFAS/calcFAS.py b/greedyFAS/calcFAS.py index eac7974..0125fd4 100644 --- a/greedyFAS/calcFAS.py +++ b/greedyFAS/calcFAS.py @@ -284,7 +284,8 @@ def fas(opts): option_dict["old_json"] = False if args.oldJson: if os.path.exists(os.path.abspath(args.oldJson)): - print(f'### NOTE: existing output given ({os.path.abspath(args.oldJson)}). Only new pairs of proteins will be considered!') + if not args.silent: + print(f'### NOTE: existing output given ({os.path.abspath(args.oldJson)}). Only new pairs of proteins will be considered!') option_dict["old_json"] = os.path.abspath(args.oldJson) if not args.silent: diff --git a/greedyFAS/calcFASmulti.py b/greedyFAS/calcFASmulti.py index 017c098..e36a54a 100644 --- a/greedyFAS/calcFASmulti.py +++ b/greedyFAS/calcFASmulti.py @@ -33,9 +33,12 @@ from greedyFAS import calcFAS from pkg_resources import get_distribution import multiprocessing as mp +import subprocess from tqdm import tqdm import json import shutil +import glob +from datetime import date def get_options(): @@ -96,6 +99,10 @@ def get_options(): "--phyloprofile") outargs.add_argument("--json", dest="json", action="store_true", help="create json output") + outargs.add_argument("--mergeJson", action="store_true", + help="merge multiple json outputs") + outargs.add_argument("--outName", default=None, type=str, + help="name for merged output file, if none is given the name will be created by the date") outargs.add_argument("--phyloprofile", dest="phyloprofile", default=None, type=str, help="activate phyloprofile output, needs mapping file for all query proteins") outargs.add_argument("--domain", dest="domain", action="store_false", @@ -245,8 +252,29 @@ def main(): pass pool.close() + if args.mergeJson: + out_name = args.outName + out_dir = os.path.abspath(args.out_dir) + if not args.outName: + today = date.today() + out_name = f"fas_{today.strftime('%y%m%d')}" + print(f'==> merge outputs into {out_name}...') + os.makedirs(f'{out_dir}/tmp', exist_ok = True) + for json_file in glob.glob(os.path.join(out_dir, '*.json')): + shutil.move(json_file, f'{out_dir}/tmp/') + if args.oldJson: + if os.path.exists(os.path.abspath(args.oldJson)): + os.symlink(os.path.abspath(args.oldJson), f'{out_dir}/tmp/oldJson.json') + cmd = f'fas.mergeJson -i {out_dir}/tmp/ -n {out_name} -o {out_dir}' + try: + mergedOut = subprocess.run([cmd], shell=True, capture_output=True, check=True) + except: + sys.exit(f'Error running\n{cmd}') + if not args.keep: shutil.rmtree(f'{args.out_dir}/split_inputs') + if args.mergeJson: + shutil.rmtree(f'{args.out_dir}/tmp') print('==> DONE!') if __name__ == '__main__': diff --git a/setup.py b/setup.py index 0e7c86a..932f0f0 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ setup( name='greedyFAS', - version='1.18.1', + version='1.18.2', python_requires='>=3.7.0', description='A tool to compare protein feature architectures', long_description=long_description,