def test_cli_config_set_default_motif(tmp_dir): args = parser.parse_args( ["config", "--set-default-motif", "/path/to/motif/root"]) config_file = os.path.join(tmp_dir, "test_cli_config.motifscanrc") run(args=args, config_file=config_file) config = Config(config_file) assert config.get_motif_dir() == "/path/to/motif/root"
def install_motif(args, config_file=None): config = Config(config_file) if config.has_motif_set(args.name): logger.error(f"Motif set {args.name!r} already exists!") sys.exit(1) motif_dir = os.path.abspath( args.output_dir or os.path.join(config.get_motif_dir(), args.name)) logger.info(f"Installing motif set {args.name!r} into {motif_dir}") if not os.path.isdir(motif_dir): os.makedirs(motif_dir) if os.listdir(motif_dir): logger.error("Directory not empty! Please specify another directory " "or delete files under it.") sys.exit(1) pfms_path = pfms_path_fmt.format(motif_dir, args.name) if args.remote: try: db = JasparDatabase() if args.database == 'jaspar_core': dst_pfms = db.download_core(args.remote, motif_dir) else: dst_pfms = db.download_other_collections( args.remote, motif_dir) logger.debug( f"Renaming downloaded file to {os.path.basename(pfms_path)}") shutil.move(dst_pfms, pfms_path) except RemoteMotifPFMsNotFoundError as e: logger.error(e) sys.exit(1) else: logger.info("Copying the PFMs file(s)") merge_files(args.pfm_files, pfms_path) logger.info("Updating the config file") config.set_motif_path(args.name, motif_dir) config.write() logger.info("Successfully installed!") if args.genome: build_motif(args, config_file)