Ejemplo n.º 1
0
def test_get_config_loc():
    test_config_loc = get_config_loc()
    assert os.path.isfile(test_config_loc)
    assert type(json.loads(open(test_config_loc).read())) is dict
Ejemplo n.º 2
0
def export_config(output_file=None):
    if output_file is None:
        print(open(get_config_loc()).read())
    else:
        copy2(get_config_loc(), output_file)
Ejemplo n.º 3
0
def import_config(config_loc):
    copy2(config_loc, get_config_loc())
Ejemplo n.º 4
0
def set_database_paths(kegg_db_loc=None,
                       kofam_hmm_loc=None,
                       kofam_ko_list_loc=None,
                       uniref_db_loc=None,
                       pfam_db_loc=None,
                       pfam_hmm_dat=None,
                       dbcan_db_loc=None,
                       dbcan_fam_activities=None,
                       viral_db_loc=None,
                       peptidase_db_loc=None,
                       vogdb_db_loc=None,
                       vog_annotations=None,
                       description_db_loc=None,
                       genome_summary_form_loc=None,
                       module_step_form_loc=None,
                       etc_module_database_loc=None,
                       function_heatmap_form_loc=None,
                       amg_database_loc=None,
                       start_time=None,
                       config_loc=None,
                       use_current_locs=True,
                       update_description_db=False):
    if start_time is None:
        start_time = datetime.now()
    print('%s: Setting database paths' % str(datetime.now() - start_time))
    if use_current_locs:
        db_dict = get_database_locs()
    else:
        db_dict = {}

    db_dict = check_exists_and_add_to_location_dict(kegg_db_loc, 'kegg',
                                                    db_dict)
    db_dict = check_exists_and_add_to_location_dict(kofam_hmm_loc, 'kofam',
                                                    db_dict)
    db_dict = check_exists_and_add_to_location_dict(kofam_ko_list_loc,
                                                    'kofam_ko_list', db_dict)
    db_dict = check_exists_and_add_to_location_dict(uniref_db_loc, 'uniref',
                                                    db_dict)
    db_dict = check_exists_and_add_to_location_dict(pfam_db_loc, 'pfam',
                                                    db_dict)
    db_dict = check_exists_and_add_to_location_dict(pfam_hmm_dat,
                                                    'pfam_hmm_dat', db_dict)
    db_dict = check_exists_and_add_to_location_dict(dbcan_db_loc, 'dbcan',
                                                    db_dict)
    db_dict = check_exists_and_add_to_location_dict(dbcan_fam_activities,
                                                    'dbcan_fam_activities',
                                                    db_dict)
    db_dict = check_exists_and_add_to_location_dict(viral_db_loc, 'viral',
                                                    db_dict)
    db_dict = check_exists_and_add_to_location_dict(peptidase_db_loc,
                                                    'peptidase', db_dict)
    db_dict = check_exists_and_add_to_location_dict(vogdb_db_loc, 'vogdb',
                                                    db_dict)
    db_dict = check_exists_and_add_to_location_dict(vog_annotations,
                                                    'vog_annotations', db_dict)

    db_dict = check_exists_and_add_to_location_dict(genome_summary_form_loc,
                                                    'genome_summary_form',
                                                    db_dict)
    db_dict = check_exists_and_add_to_location_dict(module_step_form_loc,
                                                    'module_step_form',
                                                    db_dict)
    db_dict = check_exists_and_add_to_location_dict(etc_module_database_loc,
                                                    'etc_module_database',
                                                    db_dict)
    db_dict = check_exists_and_add_to_location_dict(function_heatmap_form_loc,
                                                    'function_heatmap_form',
                                                    db_dict)
    db_dict = check_exists_and_add_to_location_dict(amg_database_loc,
                                                    'amg_database', db_dict)
    print('%s: Database locations added to CONFIG' %
          str(datetime.now() - start_time))

    if update_description_db:
        if description_db_loc is None:
            description_db_loc = db_dict['description_db']
        populate_description_db(description_db_loc, db_dict, start_time)
        print('%s: Database descriptions updated' %
              str(datetime.now() - start_time))
    db_dict = check_exists_and_add_to_location_dict(description_db_loc,
                                                    'description_db', db_dict)

    # change data paths
    if config_loc is None:
        config_loc = get_config_loc()
    with open(config_loc, 'w') as f:
        f.write(json.dumps(db_dict))
    print('%s: Database locations set' % str(datetime.now() - start_time))