コード例 #1
0
def main():
    parser = _build_arg_parser()
    args = parser.parse_args()

    if not len(args.tractograms) == len(args.t1):
        parser.error("Not the same number of images in input.")

    all_images = np.concatenate([args.tractograms, args.t1])
    assert_inputs_exist(parser, all_images)
    assert_outputs_exist(parser, args, [args.output_report, "data", "libs"])

    if os.path.exists("data"):
        shutil.rmtree("data")
    os.makedirs("data")

    if os.path.exists("libs"):
        shutil.rmtree("libs")

    name = "Tracking"
    columns = ["Nb streamlines"]

    warning_dict = {}
    summary, stats = stats_tractogram(columns, args.tractograms)
    warning_dict[name] = analyse_qa(summary, stats, ["Nb streamlines"])
    warning_list = np.concatenate([filenames for filenames in warning_dict[name].values()])
    warning_dict[name]['nb_warnings'] = len(np.unique(warning_list))

    graphs = []
    graph = graph_tractogram("Tracking", columns, summary)
    graphs.append(graph)

    summary_dict = {}
    stats_html = dataframe_to_html(stats)
    summary_dict[name] = stats_html

    metrics_dict = {}
    subjects_dict = {}
    for subj_metric, t1 in zip(args.tractograms, args.t1):
        screenshot_path = screenshot_tracking(subj_metric, t1, "data")
        summary_html = dataframe_to_html(summary.loc[subj_metric])
        subjects_dict[subj_metric] = {}
        subjects_dict[subj_metric]['screenshot'] = screenshot_path
        subjects_dict[subj_metric]['stats'] = summary_html
    metrics_dict[name] = subjects_dict

    nb_subjects = len(args.tractograms)
    report = Report(args.output_report)
    report.generate(title="Quality Assurance tractograms",
                    nb_subjects=nb_subjects, summary_dict=summary_dict,
                    graph_array=graphs, metrics_dict=metrics_dict,
                    warning_dict=warning_dict)
コード例 #2
0
def main():
    parser = _build_arg_parser()
    args = parser.parse_args()

    assert_inputs_exist(parser, args.frf)
    assert_outputs_exist(parser, args, [args.output_report, "data", "libs"])

    if os.path.exists("data"):
        shutil.rmtree("data")
    os.makedirs("data")

    if os.path.exists("libs"):
        shutil.rmtree("libs")

    name = "FRF"
    metrics_names = ["Mean Eigen value 1", "Mean Eigen value 2", "Mean B0"]

    warning_dict = {}
    summary, stats = stats_frf(metrics_names, args.frf)
    warning_dict[name] = analyse_qa(summary, stats, metrics_names)
    warning_list = np.concatenate([filenames for filenames in warning_dict[name].values()])
    warning_dict[name]['nb_warnings'] = len(np.unique(warning_list))

    graphs = []
    graph = graph_frf("FRF", metrics_names, summary)
    graphs.append(graph)

    summary_dict = {}
    stats_html = dataframe_to_html(stats)
    summary_dict[name] = stats_html

    metrics_dict = {}
    subjects_dict = {}
    for subj_metric in args.frf:
        summary_html = dataframe_to_html(summary.loc[subj_metric])
        subjects_dict[subj_metric] = {}
        subjects_dict[subj_metric]['stats'] = summary_html
    metrics_dict[name] = subjects_dict

    nb_subjects = len(args.frf)
    report = Report(args.output_report)
    report.generate(title="Quality Assurance FRF",
                    nb_subjects=nb_subjects, summary_dict=summary_dict,
                    graph_array=graphs, metrics_dict=metrics_dict,
                    warning_dict=warning_dict)
コード例 #3
0
def _subj_parralel(subj_metric, summary, name, skip, nb_columns):
    subjects_dict = {}
    screenshot_path = screenshot_mosaic_wrapper(subj_metric,
                                                output_prefix=name,
                                                directory="data",
                                                skip=skip,
                                                nb_columns=nb_columns)

    summary_html = dataframe_to_html(summary.loc[subj_metric])
    subjects_dict[subj_metric] = {}
    subjects_dict[subj_metric]['screenshot'] = screenshot_path
    subjects_dict[subj_metric]['stats'] = summary_html
    return subjects_dict
コード例 #4
0
def _subj_parralel(images_no_bet, images_bet_mask, name, skip, summary,
                   nb_columns):
    subjects_dict = {}
    for subj_metric, mask in zip(images_no_bet, images_bet_mask):
        screenshot_path = screenshot_mosaic_blend(subj_metric,
                                                  mask,
                                                  output_prefix=name,
                                                  directory="data",
                                                  blend_val=0.3,
                                                  skip=skip,
                                                  nb_columns=nb_columns,
                                                  is_mask=True)

        summary_html = dataframe_to_html(summary.loc[subj_metric])
        subjects_dict[subj_metric] = {}
        subjects_dict[subj_metric]['screenshot'] = screenshot_path
        subjects_dict[subj_metric]['stats'] = summary_html
    return subjects_dict
コード例 #5
0
def main():
    parser = _build_arg_parser()
    args = parser.parse_args()

    if not len(args.images_no_bet) == len(args.images_bet_mask):
        parser.error("Not the same number of images in input.")

    all_images = np.concatenate([args.images_no_bet, args.images_bet_mask])
    assert_inputs_exist(parser, all_images)
    assert_outputs_exist(parser, args, [args.output_report, "data", "libs"])

    if os.path.exists("data"):
        shutil.rmtree("data")
    os.makedirs("data")

    if os.path.exists("libs"):
        shutil.rmtree("libs")

    metrics = args.images_no_bet
    name = args.image_type
    curr_metrics = ['Mean {}'.format(name), 'Median {}'.format(name)]

    summary, stats = stats_mean_median(curr_metrics, metrics)

    warning_dict = {}
    warning_dict[name] = analyse_qa(summary, stats, curr_metrics)
    warning_images = [filenames for filenames in warning_dict[name].values()]
    warning_list = np.concatenate([warning_images])
    warning_dict[name]['nb_warnings'] = len(np.unique(warning_list))

    graphs = []
    graph = graph_mean_median('Mean {}'.format(name), curr_metrics, summary)
    graphs.append(graph)

    stats_html = dataframe_to_html(stats)
    summary_dict = {}
    summary_dict[name] = stats_html

    pool = Pool(args.nb_threads)
    subjects_dict_pool = pool.starmap(
        _subj_parralel,
        zip(np.array_split(np.array(args.images_no_bet), args.nb_threads),
            np.array_split(np.array(args.images_bet_mask), args.nb_threads),
            itertools.repeat(name), itertools.repeat(args.skip),
            itertools.repeat(summary), itertools.repeat(args.nb_columns)))

    pool.close()
    pool.join()

    metrics_dict = {}
    subjects_dict = {}
    for dict_sub in subjects_dict_pool:
        for key in dict_sub:
            subjects_dict[key] = dict_sub[key]
    metrics_dict[name] = subjects_dict

    nb_subjects = len(args.images_no_bet)
    report = Report(args.output_report)
    report.generate(title="Quality Assurance BET " + args.image_type,
                    nb_subjects=nb_subjects,
                    summary_dict=summary_dict,
                    graph_array=graphs,
                    metrics_dict=metrics_dict,
                    warning_dict=warning_dict)
コード例 #6
0
def main():
    parser = _build_arg_parser()
    args = parser.parse_args()

    if args.tracking_type == "local":
        if not len(args.seeding_mask) == len(args.tracking_mask):
            parser.error("Not the same number of images in input.")
        all_images = np.concatenate([args.seeding_mask, args.tracking_mask])
    else:
        if not len(args.seeding_mask) == len(args.map_include) ==\
            len(args.map_exclude):
            parser.error("Not the same number of images in input.")
        all_images = np.concatenate(
            [args.seeding_mask, args.map_include, args.map_exclude])

    assert_inputs_exist(parser, all_images)
    assert_outputs_exist(parser, args, [args.output_report, "data", "libs"])

    if os.path.exists("data"):
        shutil.rmtree("data")
    os.makedirs("data")

    if os.path.exists("libs"):
        shutil.rmtree("libs")

    if args.tracking_type == "local":
        metrics_names = [[args.seeding_mask, 'Seeding mask'],
                         [args.tracking_mask, 'Tracking mask']]
    else:
        metrics_names = [[args.seeding_mask, 'Seeding mask'],
                         [args.map_include, 'Map include'],
                         [args.map_exclude, 'Maps exclude']]
    metrics_dict = {}
    summary_dict = {}
    graphs = []
    warning_dict = {}
    for metrics, name in metrics_names:
        columns = ["{} volume".format(name)]
        summary, stats = stats_mask_volume(columns, metrics)

        warning_dict[name] = analyse_qa(summary, stats, columns)
        warning_list = np.concatenate(
            [filenames for filenames in warning_dict[name].values()])
        warning_dict[name]['nb_warnings'] = len(np.unique(warning_list))

        graph = graph_mask_volume('{} mean volume'.format(name), columns,
                                  summary)
        graphs.append(graph)

        stats_html = dataframe_to_html(stats)
        summary_dict[name] = stats_html

        subjects_dict = {}
        pool = Pool(args.nb_threads)
        subjects_dict_pool = pool.starmap(
            _subj_parralel,
            zip(metrics, itertools.repeat(summary), itertools.repeat(name),
                itertools.repeat(args.skip),
                itertools.repeat(args.nb_columns)))
        pool.close()
        pool.join()

        for dict_sub in subjects_dict_pool:
            for key in dict_sub:
                subjects_dict[key] = dict_sub[key]
        metrics_dict[name] = subjects_dict

    nb_subjects = len(args.seeding_mask)
    report = Report(args.output_report)
    report.generate(title="Quality Assurance tracking maps",
                    nb_subjects=nb_subjects,
                    summary_dict=summary_dict,
                    graph_array=graphs,
                    metrics_dict=metrics_dict,
                    warning_dict=warning_dict)
コード例 #7
0
def main():
    parser = _build_arg_parser()
    args = parser.parse_args()

    if not len(args.t1_warped) == len(args.rgb) == len(args.wm) ==\
        len(args.gm) == len(args.csf):
        parser.error("Not the same number of images in input.")

    all_images = np.concatenate(
        [args.t1_warped, args.rgb, args.wm, args.gm, args.csf])
    assert_inputs_exist(parser, all_images)
    assert_outputs_exist(parser, args, [args.output_report, "data", "libs"])

    if os.path.exists("data"):
        shutil.rmtree("data")
    os.makedirs("data")

    if os.path.exists("libs"):
        shutil.rmtree("libs")

    name = "Register T1"
    curr_metrics = [
        'Mean {} in WM'.format(name), 'Mean {} in GM'.format(name),
        'Mean {} in CSF'.format(name), 'Max {} in WM'.format(name)
    ]

    warning_dict = {}
    summary, stats = stats_mean_in_tissues(curr_metrics, args.t1_warped,
                                           args.wm, args.gm, args.csf)
    warning_dict[name] = analyse_qa(summary, stats, curr_metrics[:3])
    warning_list = np.concatenate(
        [filenames for filenames in warning_dict[name].values()])
    warning_dict[name]['nb_warnings'] = len(np.unique(warning_list))

    graphs = []
    graph = graph_mean_in_tissues('Mean {}'.format(name), curr_metrics[:3],
                                  summary)
    graphs.append(graph)

    stats_html = dataframe_to_html(stats)
    summary_dict = {}
    summary_dict[name] = stats_html

    pool = Pool(args.nb_threads)
    subjects_dict_pool = pool.starmap(
        _subj_parralel,
        zip(args.t1_warped, args.rgb, itertools.repeat(summary),
            itertools.repeat(name), itertools.repeat(args.skip),
            itertools.repeat(args.nb_columns)))
    pool.close()
    pool.join()

    metrics_dict = {}
    subjects_dict = {}
    for dict_sub in subjects_dict_pool:
        for key in dict_sub:
            subjects_dict[key] = dict_sub[key]
    metrics_dict[name] = subjects_dict

    nb_subjects = len(args.t1_warped)
    report = Report(args.output_report)
    report.generate(title="Quality Assurance registration",
                    nb_subjects=nb_subjects,
                    summary_dict=summary_dict,
                    graph_array=graphs,
                    metrics_dict=metrics_dict,
                    warning_dict=warning_dict)
コード例 #8
0
def main():
    parser = _build_arg_parser()
    args = parser.parse_args()

    if not len(args.fa) == len(args.md) == len(args.rd) == len(args.ad) ==\
        len(args.residual) == len(args.evecs_v1) == len(args.wm) ==\
        len(args.gm) == len(args.csf):
        parser.error("Not the same number of images in input.")

    all_images = np.concatenate([
        args.fa, args.md, args.rd, args.ad, args.residual, args.evecs_v1,
        args.wm, args.gm, args.csf
    ])
    assert_inputs_exist(parser, all_images)
    assert_outputs_exist(parser, args, [args.output_report, "data", "libs"])

    if os.path.exists("data"):
        shutil.rmtree("data")
    os.makedirs("data")

    if os.path.exists("libs"):
        shutil.rmtree("libs")

    metrics_names = [[args.fa, 'FA'], [args.md, 'MD'], [args.rd, 'RD'],
                     [args.ad, 'AD'], [args.residual, "Residual"]]
    metrics_dict = {}
    summary_dict = {}
    graphs = []
    warning_dict = {}
    for metrics, name in metrics_names:
        subjects_dict = {}
        curr_metrics = [
            'Mean {} in WM'.format(name), 'Mean {} in GM'.format(name),
            'Mean {} in CSF'.format(name), 'Max {} in WM'.format(name)
        ]

        summary, stats = stats_mean_in_tissues(curr_metrics, metrics, args.wm,
                                               args.gm, args.csf)

        warning_dict[name] = analyse_qa(summary, stats, curr_metrics[:3])
        warning_list = np.concatenate(
            [filenames for filenames in warning_dict[name].values()])
        warning_dict[name]['nb_warnings'] = len(np.unique(warning_list))

        graph = graph_mean_in_tissues('Mean {}'.format(name), curr_metrics[:3],
                                      summary)
        graphs.append(graph)

        stats_html = dataframe_to_html(stats)
        summary_dict[name] = stats_html

        pool = Pool(args.nb_threads)
        subjects_dict_pool = pool.starmap(
            _subj_parralel,
            zip(metrics, itertools.repeat(summary), itertools.repeat(name),
                itertools.repeat(args.skip),
                itertools.repeat(args.nb_columns)))

        pool.close()
        pool.join()

        for dict_sub in subjects_dict_pool:
            for key in dict_sub:
                subjects_dict[key] = dict_sub[key]
        metrics_dict[name] = subjects_dict

    subjects_dict = {}
    name = "Peaks"
    for fa, evecs in zip(args.fa, args.evecs_v1):
        screenshot_path = screenshot_fa_peaks(fa, evecs, "data")

        subjects_dict[evecs] = {}
        subjects_dict[evecs]['screenshot'] = screenshot_path
    metrics_dict[name] = subjects_dict

    nb_subjects = len(args.fa)
    report = Report(args.output_report)
    report.generate(title="Quality Assurance DTI metrics",
                    nb_subjects=nb_subjects,
                    summary_dict=summary_dict,
                    graph_array=graphs,
                    metrics_dict=metrics_dict,
                    warning_dict=warning_dict)
コード例 #9
0
def main():
    parser = _build_arg_parser()
    args = parser.parse_args()

    if not len(args.bval) == len(args.bvec):
        parser.error("Not the same number of images in input.")

    all_data = np.concatenate([args.bval, args.bvec])
    assert_inputs_exist(parser, all_data)
    assert_outputs_exist(parser, args, [args.output_report, "data", "libs"])

    if os.path.exists("data"):
        shutil.rmtree("data")
    os.makedirs("data")

    if os.path.exists("libs"):
        shutil.rmtree("libs")

    name = "DWI Protocol"
    summary, stats_for_graph, stats_all, shells = dwi_protocol(args.bval)
    warning_dict = {}
    warning_dict[name] = analyse_qa(stats_for_graph, stats_all,
                                    ["Nbr shells", "Nbr directions"])
    warning_images = [filenames for filenames in warning_dict[name].values()]
    warning_list = np.concatenate(warning_images)
    warning_dict[name]['nb_warnings'] = len(np.unique(warning_list))

    stats_html = dataframe_to_html(stats_all)
    summary_dict = {}
    summary_dict[name] = stats_html

    graphs = []
    graphs.append(
        graph_directions_per_shells("Nbr directions per shell", shells))
    graphs.append(graph_subjects_per_shells("Nbr subjects per shell", shells))
    for c in ["Nbr shells", "Nbr directions"]:
        graph = graph_dwi_protocol(c, c, stats_for_graph)
        graphs.append(graph)

    subjects_dict = {}
    for bval, bvec in zip(args.bval, args.bvec):
        filename = os.path.basename(bval)
        subjects_dict[bval] = {}
        points = np.genfromtxt(bvec)
        if points.shape[0] == 3:
            points = points.T
        bvals = np.genfromtxt(bval)
        centroids, shell_idx = identify_shells(bvals)
        ms = build_ms_from_shell_idx(points, shell_idx)
        plot_proj_shell(ms,
                        centroids,
                        use_sym=True,
                        use_sphere=True,
                        same_color=False,
                        rad=0.025,
                        opacity=0.2,
                        ofile=os.path.join("data", name + filename),
                        ores=(800, 800))
        subjects_dict[bval]['screenshot'] = os.path.join(
            "data", name + filename + '.png')
    metrics_dict = {}
    for subj in args.bval:
        summary_html = dataframe_to_html(summary[subj])
        subjects_dict[subj]['stats'] = summary_html
    metrics_dict[name] = subjects_dict

    nb_subjects = len(args.bval)
    report = Report(args.output_report)
    report.generate(title="Quality Assurance DWI protocol",
                    nb_subjects=nb_subjects,
                    metrics_dict=metrics_dict,
                    summary_dict=summary_dict,
                    graph_array=graphs,
                    warning_dict=warning_dict)