Example #1
0
filter_list = ['TR > 2.0', 'FD < .3']
modality = 'bold'

T1apicsv = os.path.join(here, 'demo_api', 'T1w_demo.csv')
T2apicsv = os.path.join(here, 'demo_api', 'T2w_demo.csv')
boldapicsv = os.path.join(here, 'demo_api', 'bold_demo.csv')

if modality == 'T1w':
    api_file = T1apicsv
elif modality == 'T2w':
    api_file = T1apicsv
elif modality == 'bold':
    api_file = boldapicsv

# load user csv as df #
userdf = load_groupfile(group_file)

# load and filter api csv as df #
apidf = pd.read_csv(api_file)
filtered_apidf = filterIQM(apidf, filter_list)

# merge dataframes together #
vis_ready_df = merge_dfs(userdf, filtered_apidf)

IQM_to_plot = ['fwhm_avg', 'fber']

v = make_vio_plot(vis_ready_df, IQM_to_plot, "")
# print(vis_ready_df.head)

# for col in userdf.columns:
#     print(col)
Example #2
0
def main(argv=sys.argv):
    arg_parser = argparse.ArgumentParser(
        description=prog_desc,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    # Check for arguments. #
    if len(sys.argv[1:]) == 0:
        print('\nArguments required. Use -h option to print FULL usage.\n')

    arg_parser.add_argument('-g',
                            metavar='GROUP_FILE',
                            action='store',
                            type=os.path.abspath,
                            required=True,
                            help=('FULL path to your group csv/tsv file - '
                                  'the output from MRIQC.'),
                            dest='group_file')
    arg_parser.add_argument('-s',
                            metavar='SEARCH_PHRASE',
                            action='store',
                            type=str,
                            required=True,
                            help=('Search phrase to filter API query.'
                                  'Format: xxxx xxxxx xxxxxx xxxxxx'),
                            dest='search_phrase')
    arg_parser.add_argument('-t',
                            metavar='SCAN_TYPE',
                            action='store',
                            type=str,
                            choices=['bold', 'T1w', 'T2w'],
                            required=False,
                            default='T1w',
                            help=('Scan type to query. Can choose from bold,'
                                  ' T1w, or T2w.'),
                            dest='scan_type')
    args = arg_parser.parse_args()

    #################################################
    ## Script Argument Verification and Assignment ##
    #################################################
    if os.path.isfile(args.group_file):
        pass
    else:
        print('The groupfile you are trying to use was not found. Exiting...')
        sys.exit()

    #################################################
    ##          Global Variable Assignment         ##
    #################################################
    start_time = time.time()
    time.sleep(1)
    today_date = datetime.datetime.now().strftime('%m%d%Y')

    print('Querying API for ' + args.scan_type + ' scans.')

    ## GROUP FILE COULD TURN INTO A LIST OF FILES!!! Just need a way to keep track and name them...perhaps turn it into a tuple
    ## of (name,path) or maybe even a key: val?
    ## Check that this dataframe is the same format as the result_df output from the query_api function!!
    loaded_df = load_groupfile(args.group_file)

    # result_df = query_api(args.scan_type,'MultibandAccelerationFactor>3','RepetitionTime>1')
    # result_df = query_api(args.scan_type, ['MultibandAccelerationFactor>3', 'EchoTime>1'])
    result_df = query_api(args.scan_type,
                          'MultibandAccelerationFactor>3&EchoTime>1')

    ## Scater plot/visualization functions would go below here and pass result_df as well as loaded_df pandas dataframes
    # something like this:
    # scatter(loaded_df, result_df)

    full_runtime = time.time() - start_time
    print('\nFull Script Runtime: ', datetime.timedelta(seconds=full_runtime),
          '\n')
Example #3
0
def main(argv=sys.argv):
    arg_parser = argparse.ArgumentParser(description=prog_desc,
                                         formatter_class=
                                         argparse.ArgumentDefaultsHelpFormatter)
    # Check for arguments. #
    if len(sys.argv[1:]) == 0:
        print('\nArguments required. Use -h option to print FULL usage.\n')

    arg_parser.add_argument('-g', metavar='GROUP_FILE', action='store',
                            type=os.path.abspath, required=True,
                            help=('FULL path to your group csv/tsv file - '
                                  'the output from MRIQC.'),
                            dest='group_file'
                            )
    # arg_parser.add_argument('-s', metavar='SEARCH_PHRASE', action='store', type=str,
    #                         required=True, help=('Search phrase to filter API query.'
    #                                              'Format: xxxx xxxxx xxxxxx xxxxxx'),
    #                         dest='search_phrase'
    #                         )
    # arg_parser.add_argument('-t', metavar='SCAN_TYPE', action='store', type=str,
    #                         choices=['bold', 'T1w', 'T2w'], required=False,
    #                         default='T1w',
    #                         help=('Scan type to query. Can choose from bold,'
    #                               ' T1w, or T2w.'),
    #                         dest='scan_type'
                            # )
    args = arg_parser.parse_args()

    #################################################
    ## Script Argument Verification and Assignment ##
    #################################################
    if os.path.isfile(args.group_file):
        pass
    else:
        print('The groupfile you are trying to use was not found. Exiting...')
        sys.exit()

    #################################################
    ##          Global Variable Assignment         ##
    #################################################    
    start_time = time.time()
    time.sleep(1)
    today_date = datetime.datetime.now().strftime('%m%d%Y')

    # print('Querying API for ' + args.scan_type + ' scans.')


    filter_list = ['TR > 1.0','FD < .3']
    modality = 'bold'

    here = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
    T1apicsv = os.path.join(here, 'demo_api', 'T1w_demo.csv')
    T2apicsv = os.path.join(here, 'demo_api', 'T2w_demo.csv')
    boldapicsv = os.path.join(here, 'demo_api', 'bold_demo.csv')

    if modality == 'T1w':
        group_file = T1apicsv
    elif modality == 'T2w':
        group_file = T1apicsv
    elif modality == 'bold':
        group_file = boldapicsv

    # load user csv as df #
    userdf = load_groupfile(group_file)

    # load and filter api csv as df #
    apidf = pd.read_csv(group_file)
    filtered_apidf = filterIQM(,apidf,filter_list)

    # merge dataframes together #
    vis_ready_df = merge_dfs(userdf, filtered_apidf)







    # result_df = query_api(args.scan_type,'MultibandAccelerationFactor>3','RepetitionTime>1')
    # # result_df = query_api(args.scan_type, ['MultibandAccelerationFactor>3', 'EchoTime>1'])
    # result_df = query_api(args.scan_type, 'MultibandAccelerationFactor>3&EchoTime>1')

    ## Scater plot/visualization functions would go below here and pass result_df as well as loaded_df pandas dataframes
    # something like this:
    # scatter(loaded_df, result_df)


    full_runtime = time.time() - start_time
    print('\nFull Script Runtime: ', datetime.timedelta(seconds=full_runtime), '\n')
Example #4
0
def main(argv=sys.argv):
    arg_parser = argparse.ArgumentParser(
        description=prog_desc, formatter_class=argparse.RawTextHelpFormatter)

    arg_parser.add_argument('-i',
                            '--input',
                            metavar='GROUP_FILE',
                            action='store',
                            type=os.path.abspath,
                            required=True,
                            help=("""
            FULL path to your group csv/tsv file - the output from MRIQC.
            """),
                            dest='group_file')

    arg_parser.add_argument('-t',
                            '--type',
                            metavar='SCAN_TYPE',
                            action='store',
                            type=str,
                            choices=['bold', 'T1w', 'T2w'],
                            required=True,
                            help=("""
            Scan type to query. Can choose from bold, T1w, or T2w.
            """),
                            dest='scan_type')

    arg_parser.add_argument('-f',
                            '--filter',
                            metavar='FILTER_LIST',
                            action='append',
                            type=str,
                            required=True,
                            help=("""
            Strings to filter the queried database.
            Several filters can be given at the same time.
            The string formats should be:
            -f "(VAR) (Operator) (Value)"; Example:
            "-f 'TR == 3.0' " or "-f 'TR > 1.0' -f 'TR < 3.0' -f 'FD < .3' "
            Note: Each element in each string is separated by SPACES
            The IQMs depend on the --type argument given:
            BOLD:
               {SNR; TSNR; DVAR; FD; FWHM; GSR_X; GSR_Y;
                   TESLA; TE; TR}
            T1W | T2W:
               {SNR; SNR_GM; SNR_WM; SNR_CSF; CNR; EFC; FWHM;
                   TESLA; TE; TR}
            """),
                            dest='filter_list')

    args = arg_parser.parse_args()

    #################################################
    ## Script Argument Verification and Assignment ##
    #################################################
    # Check for arguments. #
    if len(sys.argv) == 1:
        arg_parser.print_help()
        sys.exit(0)
    elif os.path.isfile(args.group_file):
        pass
    else:
        print('The groupfile you are trying to use was not found. Exiting...')
        sys.exit()

    #################################################
    ##          Global Variable Assignment         ##
    #################################################
    start_time = time.time()
    time.sleep(1)
    today_date = datetime.datetime.now().strftime('%m%d%Y')

    # print('Querying API for ' + args.scan_type + ' scans.')

    #  filter_list = ['TR > 1.0','FD < .3']
    #  modality = 'bold'

    here = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
    T1apicsv = os.path.join(here, 'demo_api', 'T1w_demo.csv')
    T2apicsv = os.path.join(here, 'demo_api', 'T2w_demo.csv')
    boldapicsv = os.path.join(here, 'demo_api', 'bold_demo.csv')

    if args.scan_type.lower() == 't1w':
        group_file = T1apicsv
    elif args.scan_type.lower() == 't2w':
        group_file = T1apicsv
    elif args.scan_type.lower() == 'bold':
        group_file = boldapicsv

    # load user csv as df #
    userdf = load_groupfile(group_file)

    # load and filter api csv as df #
    apidf = pd.read_csv(group_file)

    # Make the filter_list
    filter_list = []
    filtered_apidf = filterIQM(apidf, args.scan_type, args.filter_list)

    # merge dataframes together #
    #  vis_ready_df = merge_dfs(userdf, filtered_apidf)
    return filtered_apidf