Example #1
0
def test_find_files():
    path = os.path.join(os.getcwd(),'tests','tests_file_io')
    expect = [os.path.join(os.getcwd(),'tests','tests_file_io', 'test_find_files.py')]

    assert(find_files(substring='test_find_files', path=path) == expect)
    
    # find recursive
    assert(find_files(substring='test_find_files.py', path=os.getcwd(), recursive=True) == expect)
    
    # find files and check extension
    assert(find_files(substring='test_find_files.py', path=path, check_ext='.py') == expect)
    assert(find_files(substring='test_find_files.py', path=path, check_ext='.txt') == [])
def get_index_in_folder(input_filepath, input_basename, folder):
    """Loop through all .dat files in a folder, calling
    `get_index_from_filename` on each file"""
    path = os.path.join(input_filepath, folder)
    files = find_files(input_basename, path=path, check_ext='.dat')
    idxs = []
    for f in files:
        idxs.append(get_index_from_filename(f))
    return idxs
Example #3
0
def test_find_files():
    path = os.path.join(os.getcwd(), 'tests', 'tests_file_io')
    expect = [
        os.path.join(os.getcwd(), 'tests', 'tests_file_io',
                     'test_find_files.py')
    ]

    assert (find_files(substring='test_find_files', path=path) == expect)

    # find recursive
    assert (find_files(substring='test_find_files.py',
                       path=os.getcwd(),
                       recursive=True) == expect)

    # find files and check extension
    assert (find_files(substring='test_find_files.py',
                       path=path,
                       check_ext='.py') == expect)
    assert (find_files(substring='test_find_files.py',
                       path=path,
                       check_ext='.txt') == [])
def get_results_from_training(path):

    files = find_files('training', path=path, recursive=True, check_ext='.log')
    if len(files) == 0:
        return None
    header = [
        'network', 'n_nodes', 'extra_dense', 'upper_cutoff', 'lower_cutoff',
        'smoothing', 'basename', 'best_val_loss', 'best_val_acc', 'best_epoch',
        'holdout_acc', 'holdout_loss'
    ]
    missing_holdout = None
    result_dict = {el: list() for el in header}
    for logpath in tqdm(files):
        #do analysis
        try:
            df_log = pd.read_csv(logpath)
        except IOError:
            tqdm.write("Can't read: " + logpath)
            continue
        idx = find_best_epoch(df_log)
        best_val_loss, best_val_acc = df_log.loc[idx, ['val_loss', 'val_acc']]
        log_filename = os.path.basename(logpath)
        basename, _ = os.path.splitext(log_filename)
        params = basename.split('__')[:-1]
        basename = '__'.join(params)
        params.append(basename)
        params.append(best_val_loss)
        params.append(best_val_acc)
        params.append(idx)

        try:
            # Get holdout performance
            holdout_acc, holdout_loss = get_holdout_performance(logpath)
            params.append(holdout_acc)
            params.append(holdout_loss)
        except:
            if missing_holdout is None:
                tqdm.write("At least one trace missing holdout performance")
                missing_holdout = True
            continue

        for head, par in zip(header, params):
            result_dict[head].append(par)
    return result_dict
Example #5
0
def test_ignore_substring():
    path = os.path.join(os.getcwd(), 'tests', 'tests_file_io')
    assert (find_files(substring='test_find_files',
                       path=path,
                       ignore_substring='test_find') == [])
Example #6
0
out = subprocess.call(['sphinx-apidoc', '-o', rst_path, '/Users/sebastian/github/mlxtend/mlxtend', '-e', '-f', '--full', '--follow-links', '--maxdepth', '8'])

# Convert reStructuredText to markdown
files = [(os.path.join(rst_path, f), os.path.join(mkd_path, os.path.splitext(f)[0] + '.md')) for f in os.listdir(rst_path) if f.endswith('.rst')]
for f in files:
    out = subprocess.call(['pandoc', f[0], '--from=rst', '--to=markdown', '-o', f[1]])

# Get submodules

files = [f for f in os.listdir(mkd_path) if f.endswith('.md') and len(f.split('.'))>2]
for f in files:
    print("- ['api/%s', '%s']" % (f, os.path.splitext(f)[0]))
'''

py_files = find_files(substring='',
                      path=mlxtend_path,
                      check_ext='.py',
                      recursive=True)
py_files = [p for p in py_files if not '__init__.py' in p]
print(py_files)

for f in py_files:
    with open(f, 'r') as fd:
        file_contents = fd.read()
    module = ast.parse(file_contents)
    function_definitions = [
        node for node in module.body if isinstance(node, ast.FunctionDef)
    ]
    class_definitions = [
        node for node in module.body if isinstance(node, ast.ClassDef)
    ]
Example #7
0
def test_ignore_substring():
    path = os.path.join(os.getcwd(),'tests','tests_file_io')
    assert(find_files(substring='test_find_files', path=path, ignore_substring='test_find') == [])
Example #8
0
os.remove
out = subprocess.call(['sphinx-apidoc', '-o', rst_path, '/Users/sebastian/github/mlxtend/mlxtend', '-e', '-f', '--full', '--follow-links', '--maxdepth', '8'])

# Convert reStructuredText to markdown
files = [(os.path.join(rst_path, f), os.path.join(mkd_path, os.path.splitext(f)[0] + '.md')) for f in os.listdir(rst_path) if f.endswith('.rst')]
for f in files:
    out = subprocess.call(['pandoc', f[0], '--from=rst', '--to=markdown', '-o', f[1]])

# Get submodules

files = [f for f in os.listdir(mkd_path) if f.endswith('.md') and len(f.split('.'))>2]
for f in files:
    print("- ['api/%s', '%s']" % (f, os.path.splitext(f)[0]))
'''

py_files = find_files(substring='', path=mlxtend_path, check_ext='.py', recursive=True)
py_files = [p for p in py_files if not '__init__.py' in p]
print(py_files)

for f in py_files:
    with open(f, 'r') as fd:
         file_contents = fd.read()
    module = ast.parse(file_contents)
    function_definitions = [node for node in module.body if isinstance(node, ast.FunctionDef)]
    class_definitions = [node for node in module.body if isinstance(node, ast.ClassDef)]

    for fu in function_definitions:
        print(ast.get_docstring(fu))

    for cl in class_definitions:
        print(ast.get_docstring(cl))
Example #9
0
if not args.input:
    print('Please provide an input directory via the -i flag. \n')
    args.help() 
    quit()

if not args.output:
    print('Please provide an input directory via the -o flag. \n')
    args.help() 
    quit()
    
if not os.path.isdir(args.output):
    os.mkdir(args.output)
    
mol2_files = find_files(substring='', 
               path=args.input, 
               recursive=args.recursive, 
               check_ext='.mol2', 
               ignore_invisible=True)
               
               
pbar = pyprind.ProgBar(len(mol2_files))

for path in mol2_files:
    
    mol2_name = os.path.basename(path)
    
    if args.recursive:
        case_dir = os.path.split(os.path.split(path)[0])[1]
        new_dir = os.path.join(args.output, case_dir)
    
    else: