def run_bh(configs_dir, execution_home, cfg, ext_python_modules_home, log): addsitedir(ext_python_modules_home) import pyyaml dst_configs = os.path.join(cfg.output_dir, "configs") if os.path.exists(dst_configs): shutil.rmtree(dst_configs) shutil.copytree(os.path.join(configs_dir, "hammer"), dst_configs) cfg_file_name = os.path.join(dst_configs, "config.info") # removing template configs for root, dirs, files in os.walk(dst_configs): for cfg_file in files: cfg_file = os.path.join(root, cfg_file) if cfg_file.endswith('.info.template'): if os.path.isfile(cfg_file.split('.template')[0]): os.remove(cfg_file) else: os.rename(cfg_file, cfg_file.split('.template')[0]) prepare_config_bh(cfg_file_name, cfg, log) command = os.path.join(execution_home, "hammer") + " " +\ os.path.abspath(cfg_file_name) log.info("\n== Running read error correction tool: " + command + "\n") support.sys_call(command, log) corrected_dataset_yaml_filename = os.path.join(cfg.tmp_dir, "corrected.yaml") corrected_dataset_data = pyyaml.load(file(corrected_dataset_yaml_filename, 'r')) if cfg.gzip_output: log.info("\n== Compressing corrected reads (with gzip)") support.move_dataset_files(corrected_dataset_data, cfg.output_dir, log, cfg.gzip_output) corrected_dataset_yaml_filename = os.path.join(cfg.output_dir, "corrected.yaml") pyyaml.dump(corrected_dataset_data, file(corrected_dataset_yaml_filename, 'w')) log.info("\n== Dataset description file created: " + corrected_dataset_yaml_filename + "\n") shutil.rmtree(cfg.tmp_dir) return corrected_dataset_yaml_filename
if not options_storage.output_dir: support.error("the output_dir is not set! It is a mandatory parameter (-o output_dir).", log) if not os.path.isdir(options_storage.output_dir): os.makedirs(options_storage.output_dir) if options_storage.dataset_yaml_filename: try: dataset_data = pyyaml.load(file(options_storage.dataset_yaml_filename, "r")) except pyyaml.YAMLError, exc: support.error( "exception caught while parsing YAML file (" + options_storage.dataset_yaml_filename + "):\n" + str(exc) ) else: dataset_data = support.correct_dataset(dataset_data) options_storage.dataset_yaml_filename = os.path.join(options_storage.output_dir, "input_dataset.yaml") pyyaml.dump(dataset_data, file(options_storage.dataset_yaml_filename, "w")) support.check_dataset_reads(dataset_data, log) if support.dataset_has_only_mate_pairs_libraries(dataset_data): support.error( "you should specify at least one paired-end or unpaired library (only mate-pairs libraries were found)!" ) if options_storage.rectangles and (len(dataset_data) > 1): support.error("rectangle graph algorithm for repeat resolution cannot work with multiple libraries!") ### FILLING cfg cfg["common"] = empty_config() cfg["dataset"] = empty_config() if not options_storage.only_assembler: cfg["error_correction"] = empty_config() if not options_storage.only_error_correction:
def create_text_and_key(self, selected_text): # The source file's pathreload source = self.view.file_name() key_link = selected_text.replace(" ", "_")[0:30].strip("_").lower() # Get the file path source_path = os.path.dirname(source) fileName = os.path.basename(source).replace(".html", "").replace(".erb", "").replace(".haml", "").strip("_") rails_view_path = os.path.dirname(source_path) rails_view_path2 = os.path.dirname(rails_view_path) rails_view_path3 = os.path.dirname(rails_view_path2) rails_view_path4 = os.path.dirname(rails_view_path3) if is_rails_view(source_path): # If we're a rails view file, change the target path to the rails root and add path to locales target_file = os.path.abspath(source_path + "/../../") + "/config/locales/en.yml" yaml_dict = pyyaml.load(file(target_file, 'r')) if not yaml_dict["en"].has_key(str(fileName)): yaml_dict["en"][str(fileName)] = {} yaml_dict["en"][str(fileName)][str(key_link)] = str(selected_text) rails_view_path = source_path if is_rails_view(rails_view_path): # If we're a rails view file, change the target path to the rails root and add path to locales target_file = os.path.abspath(source_path + "/../../../") + "/config/locales/en.yml" key = source_path.replace(rails_view_path, "").strip("/") yaml_dict = pyyaml.load(file(target_file, 'r')) if not yaml_dict["en"].has_key(str(key)): yaml_dict["en"][str(key)] = {} if not yaml_dict["en"][str(key)].has_key(str(fileName)): yaml_dict["en"][str(key)][str(fileName)] = {} yaml_dict["en"][str(key)][str(fileName)][str(key_link)] = str(selected_text) rails_view_path = rails_view_path if is_rails_view(rails_view_path2): # If we're a rails view file, change the target path to the rails root and add path to locales target_file = os.path.abspath(source_path + "/../../../../") + "/config/locales/en.yml" key = rails_view_path.replace(rails_view_path2, "").strip("/") key2 = source_path.replace(rails_view_path, "").strip("/") yaml_dict = pyyaml.load(file(target_file, 'r')) if not yaml_dict["en"].has_key(str(key)): yaml_dict["en"][str(key)] = {} if not yaml_dict["en"][str(key)].has_key(str(key2)): yaml_dict["en"][str(key)][str(key2)] = {} if not yaml_dict["en"][str(key)][str(key2)].has_key(str(fileName)): yaml_dict["en"][str(key)][str(key2)][str(fileName)] = {} yaml_dict["en"][str(key)][str(key2)][str(fileName)][str(key_link)] = str(selected_text) rails_view_path = rails_view_path2 if is_rails_view(rails_view_path3): # If we're a rails view file, change the target path to the rails root and add path to locales target_file = os.path.abspath(source_path + "/../../../../../") + "/config/locales/en.yml" key = rails_view_path.replace(rails_view_path3, "").strip("/") key2 = rails_view_path.replace(rails_view_path2, "").strip("/") key = key.replace("/"+key2, "") key3 = source_path.replace(rails_view_path, "").strip("/") yaml_dict = pyyaml.load(file(target_file, 'r')) if not yaml_dict["en"].has_key(str(key)): yaml_dict["en"][str(key)] = {} if not yaml_dict["en"][str(key)].has_key(str(key2)): yaml_dict["en"][str(key)][str(key2)] = {} if not yaml_dict["en"][str(key)][str(key2)].has_key(str(key3)): yaml_dict["en"][str(key)][str(key2)][str(key3)] = {} if not yaml_dict["en"][str(key)][str(key2)][str(key3)].has_key(str(fileName)): yaml_dict["en"][str(key)][str(key2)][str(key3)][str(fileName)] = {} yaml_dict["en"][str(key)][str(key2)][str(key3)][str(fileName)][str(key_link)] = str(selected_text) rails_view_path = rails_view_path3 if os.path.isfile(target_file): #insert key to view file stream = file(target_file, 'w') pyyaml.dump(yaml_dict, stream, default_flow_style=False) stream.close() self.insert_key_link(key_link, source) else: self.display_message(target_file + " not exist")