Ejemplo n.º 1
0
    def loads(self, source):
        """
        Loads the data saved in the provided string

        @param source: The string to load form
        @type source: String
        @return: Dictionary loaded from string
        @rtype: Dictionary
        """
        return pyyaml.load(source)
Ejemplo n.º 2
0
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
 def load(cls, string):
     _, fm, content = cls.__regex.split(string, 2)
     metadata = load(fm, Loader=FullLoader)
     return cls(metadata, content)
Ejemplo n.º 4
0
def print_used_values(cfg, log):
    def print_value(cfg, section, param, pretty_param="", margin="  "):
        if not pretty_param:
            pretty_param = param.capitalize().replace("_", " ")
        line = margin + pretty_param
        if param in cfg[section].__dict__:
            line += ": " + str(cfg[section].__dict__[param])
        else:
            if param.find("offset") != -1:
                line += " will be auto-detected"
        log.info(line)

    log.info("")

    # system info
    log.info("System information:")
    try:
        log.info("  SPAdes version: " + str(spades_version))
        log.info(
            "  Python version: "
            + str(sys.version_info[0])
            + "."
            + str(sys.version_info[1])
            + "."
            + str(sys.version_info[2])
        )
        # for more details: '[' + str(sys.version_info) + ']'
        log.info("  OS: " + platform.platform())
        # for more deatils: '[' + str(platform.uname()) + ']'
    except:
        log.info("  Problem occurred when getting system information")
    log.info("")

    # main
    print_value(cfg, "common", "output_dir", "", "")
    if ("error_correction" in cfg) and (not "assembly" in cfg):
        log.info("Mode: ONLY read error correction (without assembling)")
    elif (not "error_correction" in cfg) and ("assembly" in cfg):
        log.info("Mode: ONLY assembling (without read error correction)")
    else:
        log.info("Mode: read error correction and assembling")
    if ("common" in cfg) and ("developer_mode" in cfg["common"].__dict__):
        if cfg["common"].developer_mode:
            log.info("Debug mode turned ON")
        else:
            log.info("Debug mode turned OFF")
    log.info("")

    # dataset
    if "dataset" in cfg:
        log.info("Dataset parameters:")

        if cfg["dataset"].single_cell:
            log.info("  Single-cell mode")
        else:
            log.info(
                "  Multi-cell mode (you should set '--sc' flag if input data"
                " was obtained with MDA (single-cell) technology"
            )

        # TODO: nice output of reads
        log.info("  Reads:")
        support.pretty_print_reads(pyyaml.load(file(cfg["dataset"].yaml_filename, "r")), log)

    # error correction
    if "error_correction" in cfg:
        log.info("Read error correction parameters:")
        print_value(cfg, "error_correction", "tmp_dir", "Dir for temp files")
        print_value(cfg, "error_correction", "max_iterations", "Iterations")
        print_value(cfg, "error_correction", "qvoffset", "PHRED offset")

        if cfg["error_correction"].gzip_output:
            log.info("  Corrected reads will be compressed (with gzip)")
        else:
            log.info("  Corrected reads will NOT be compressed (with gzip)")

    # assembly
    if "assembly" in cfg:
        log.info("Assembly parameters:")
        print_value(cfg, "assembly", "iterative_K", "k")

    log.info("Other parameters:")
    print_value(cfg, "common", "max_threads", "Threads")
    print_value(cfg, "common", "max_memory", "Memory limit (in Gb)", "  ")
    log.info("")
Ejemplo n.º 5
0
        elif opt == "--test":
            options_storage.set_test_options()
            support.add_to_dataset("-1", os.path.join(spades_home, "test_dataset/ecoli_1K_1.fq.gz"), dataset_data)
            support.add_to_dataset("-2", os.path.join(spades_home, "test_dataset/ecoli_1K_2.fq.gz"), dataset_data)
            # break
        else:
            raise ValueError

    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):
Ejemplo n.º 6
0
import pyyaml

with open('./setup-config.yml') as f:
    config = pyyaml.load(f)

#taiga source code
BACKEND_SRC_PATH = '{0}/src'.format(config['back-end']['path'])
BACKEND_GIT_REPO = config['back-end']['git_repo']

#os.popen
Ejemplo n.º 7
0
  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")