Exemple #1
0
def compute(allPaths, counter, human_readable, output, filter_zero=False):
    for (path, isfile) in allPaths:
        if isfile:
            analyzeFile(path, counter)
        else:
            util.process_directory(path, lambda file, printInfo: analyzeFile(file, counter))

    list = counter.keys()
    if filter_zero:
        list = [ k for k in list if counter[k] > 0 ]
    list.sort(key = lambda k: counter[k])
    padding = len(str(counter[list[len(list) - 1]])) if list else 0
    total = 0
    try:
        for id in list:
            num = counter[id]
            total += num
            if human_readable:
                print('{0:{width}}'.format(num, width=padding) + ' ' + id, file=output)
            else:
                print(id, file=output)
        if human_readable:
            print('', file=output)
            print('time: '+str(time.clock() - starttime)+'s', file=output)
            print('ids: '+str(len(list)), file=output)
            print('entries: '+str(total), file=output)
            print('mean: '+str(total / len(list)), file=output)
    except IOError as e:
        if e.errno != 32:
            raise
Exemple #2
0
def compute(allPaths, counter, human_readable, output, filter_zero=False):
    for (path, isfile) in allPaths:
        if isfile:
            analyzeFile(path, counter)
        else:
            util.process_directory(
                path, lambda file, printInfo: analyzeFile(file, counter))

    list = counter.keys()
    if filter_zero:
        list = [k for k in list if counter[k] > 0]
    list.sort(key=lambda k: counter[k])
    padding = len(str(counter[list[len(list) - 1]])) if list else 0
    total = 0
    try:
        for id in list:
            num = counter[id]
            total += num
            if human_readable:
                print('{0:{width}}'.format(num, width=padding) + ' ' + id,
                      file=output)
            else:
                print(id, file=output)
        if human_readable:
            print('', file=output)
            print('time: ' + str(time.clock() - starttime) + 's', file=output)
            print('ids: ' + str(len(list)), file=output)
            print('entries: ' + str(total), file=output)
            print('mean: ' + str(total / len(list)), file=output)
    except IOError as e:
        if e.errno != 32:
            raise
Exemple #3
0
def processAll(qm, cohort, path_tuples):
    candidates = {}
    id_column = cms_get_patient.input_format["patient_id"]
    for (path, isfile) in path_tuples:
        if isfile:
            processFile(path, id_column, qm, candidates, not debug_inspect)
        else:
            util.process_directory(path, lambda file, printInfo: processFile(file, id_column, qm, candidates, not debug_inspect and printInfo), not debug_inspect)
    for c in candidates.values():
        if qm.isMatch(c):
            cohort.append(c.getPid())
    cohort.sort()
Exemple #4
0
def main(file):
    """Start the localization cleanup program.
    For more information, do `python localization.py --help`.
    """

    directory = os.path.join(MOD_DIRECTORY, "localisation")
    process_directory(directory, EXTENSIONS, clean_localization)

    localization_group.set_prompt_file(file)

    try:
        localization_group.filter()
    except click.Abort:
        click.echo()

    try:
        localization_group.prompt_export()
    except click.Abort:
        pass
Exemple #5
0

def clean_style(lines: List[str]) -> bool:
    """Adjust the file information to be stylistically cleaner.
    This leaves no newlines at the start of the file and only one
    at the end of the file.
    """

    style_changed = False

    # remove any extra newlines at the start of the file
    while lines and lines[0].isspace():
        del lines[0]
        style_changed = True

    # remove any extra newlines at the end of the file.
    while lines and lines[-1].isspace():
        del lines[-1]
        style_changed = True

    # add a newline to the end of the file if not exists.
    if lines and not lines[-1].endswith(b"\n"):
        lines[-1] += "\n"
        style_changed = True

    return style_changed


if __name__ == '__main__':
    process_directory(MOD_DIRECTORY, EXTENSIONS, clean_file)