Beispiel #1
0
def g_execute(blast_options, outputoptions):
    """A function that takes in and executes options from the gui widgets"""
    # variables
    mp.freeze_support()
    ts = time.time()
    fomatted_time = datetime.datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S")
    print "Process Started {0}".format(fomatted_time)
    processors = outputoptions["num_procs"]
    pool = mp.Pool(processes=processors)
    file_name = outputoptions["pre_split_up_input"]
    path = outputoptions["tmp_data_directory"]
    if not os.path.exists(path):
        msg = "{0} is not found, creating directory...".format(path)
        os.makedirs(os.path.abspath(path))
        print msg

    if not os.path.exists(os.getcwd() + "/internal_data"):
        print "Copying internal data to current directory {0} to {1}".format(
            outputoptions["internal_data_directory"], os.getcwd() + "/internal_data"
        )
        shutil.copytree(outputoptions["internal_data_directory"], os.getcwd() + "/internal_data")
        raw_input()

    # split fasta file up
    all_fasta = split_fasta.split_fasta(processors, path, file_name, suffix=".tmp_fasta")
    glob_path = os.path.join(path, os.path.basename(file_name).split(".fasta")[0] + "*.tmp_fasta")

    print "Splitting up file {0} into {1}".format(file_name, path)
    split_up_starting_files = glob.glob(glob_path)

    # output options
    zip_bool = outputoptions["zip_bool"]
    output_file = outputoptions["final_outfile"]

    # manager_dict
    _manager_list = []
    _manager_dict = {}
    for i, _file in enumerate(split_up_starting_files, start=1):  # the full file name
        _manager_dict["executable"] = outputoptions["executable"]
        _manager_dict["non_split"] = file_name
        _manager_dict["split_file"] = _file
        _manager_dict["zip_bool"] = zip_bool
        _manager_dict["all_fasta"] = all_fasta
        _manager_dict["blast_options"] = blast_options  # all the blast options
        _manager_dict["output_type"] = outputoptions["output_type"]
        _manager_dict["output_file"] = output_file
        _manager_dict["output_options"] = outputoptions["output_options"]
        _manager_dict["temporary_path"] = path
        _manager_dict["proc_number"] = i
        _manager_list.append(_manager_dict)
        _manager_dict = {}

    # run_protocol

    # for i in _manager_list:
    #    run_mp_and_delete(i)

    pool.map(run_mp_and_delete, _manager_list)
    concat(_manager_list[0])
    print "Process is done"
    print "Took {0}".format(time.time() - ts)
Beispiel #2
0
def execute(argument_class):
    '''A function that takes in and executes options from the gui widgets'''
    # variables
    ts = datetime.time()
    #fomatted_time = datetime.datetime.fromtimestamp(float(ts)).strftime('%Y-%m-%d %H:%M:%S')
    print "Process Started {0}".format(ts)

    # query, path and internal database
    query_name = argument_class.get_query()
    tmp_path = argument_class.get_tmp_dir()
    processors = argument_class.get_procs()
    internal_data = argument_class.get_internal_directory()

    # output options
    zip_bool = argument_class.get_zip_bool()
    json_bool = argument_class.get_json_bool()
    concat_bool = argument_class.get_concat_bool()
    output_prefix = argument_class.get_output_prefix()
    output_options = argument_class.get_output_options()

    # blast options - all the options specific to blast executable
    executable = argument_class.get_command()
    blast_options = argument_class.get_blast_options()

    # species
    species = argument_class.get_organism()


    #germ_properties_files
    germ_properties = argument_class.get_germ_file()

    # split fasta file up
    print "Splitting up file {0} into {1}".format(os.path.abspath(query_name), tmp_path)
    split_fasta.split_fasta(processors, tmp_path, query_name, suffix=".tmp_fasta")
    glob_path = os.path.join(tmp_path, os.path.basename(query_name).split('.')[0] + "*.tmp_fasta")

    # now grab all the temporary files in the temporary directory
    split_up_starting_files = glob.glob(glob_path)

    # manager_dict and list, holds all our values so we can pass them to varias processors
    _manager_list = []
    _manager_dict = {}

    for i, _file in enumerate(split_up_starting_files, start=1):  # the full file name
        _manager_dict['executable'] = executable
        _manager_dict['non_split'] = query_name
        _manager_dict['split_file'] = _file
        _manager_dict['zip_bool'] = zip_bool
        _manager_dict['json_bool'] = json_bool
        _manager_dict['concat_bool'] = concat_bool
        _manager_dict['output_prefix'] = output_prefix
        _manager_dict['tmp_path'] = tmp_path
        _manager_dict['internal_data'] = internal_data
        _manager_dict['blast_options'] = blast_options
        _manager_dict['output_options'] = output_options
        _manager_dict['species'] = species
        _manager_dict['proc_number'] = i
        _manager_dict['germ_properties'] = germ_properties
        _manager_list.append(_manager_dict)
        _manager_dict = {}

    # run_protocol
    for i in _manager_list:
        run_mp_and_delete(i)

    #pool = mp.Pool(processes=processors)
    #pool.map(run_mp_and_delete, _manager_list)
    concat(_manager_list[0])
    print "Process is done"
    print "Took {0}".format(datetime.time() - ts)
    os.removedirs(_manager_dict['tmp_path'])