Esempio n. 1
0
def main():
    """Runs functions in fpho_setup, processes config.yml

    Parameters
    ----------
    config.yml
        To use this driver, update the config.yml file, then
        run the following bash command:
        python fpho_config.py --config config.yml

    Returns
    -------
        Pandas dataframe of parsed fiber photometry data
        Writes an output CSV/XLXS to specified file name
        Outputs specified plots and analysis
    """
    parser = argparse.ArgumentParser()

    parser.add_argument('--config', type=str, required=True)
    args = parser.parse_args()

    # Opens and reads config file to process
    f = open(args.config, 'r')
    config = yaml.load(f, Loader=yaml.FullLoader)
    f.close()

    # Generate the dataframe with data
    fpho_df = fpho_setup.import_fpho_data(
        input_filename=(config['input_filename']),
        output_filename=(config['output_filename']),
        n_fibers=(config['n_fibers']),
        f1greencol=(config['f1greencol']),
        f2greencol=(config['f2greencol']),
        animal_ID=(config['animal_ID']),
        exp_date=(config['exp_date']),
        exp_desc=(config['exp_desc']),
        write_xlsx=(config['write_xlsx']))

    # Plot raw signal if specified
    if config['plot_raw_signal'] is True:
        fpho_setup.raw_signal_trace(fpho_df, config['output_filename'])

    # Plots isosbestic fit if specified
    if config['plot_iso_fit'] is True:
        fpho_setup.plot_isosbestic_norm(fpho_df, config['output_filename'])

    # Plots fitted exponent if specified
    if config['plot_fit_exp'] is True:
        fpho_setup.plot_fitted_exp(fpho_df, config['output_filename'])

    # Imports behavior data if specified
    behaviorData = pd.DataFrame()
    if config['import_behavior'] is True:
        behaviorData = behavior_setup.import_behavior_data(
            config['BORIS_file'], config['timestamp_file'])

    # Plots z-score analysis of behavior if specified
    if config['plot_zscore'] is True:
        behavior_setup.plot_zscore(behaviorData, config['output_filename'])
    def test_raw_signal_trace(self):
        df_test = fpho_setup.import_fpho_data(input_filename='Python/TestData'
                                              '/1FiberTesting.csv',
                                              output_filename='my_file_name',
                                              n_fibers=1,
                                              f1greencol=3,
                                              animal_ID='vole1',
                                              exp_date='2020-09-01',
                                              exp_desc="testing",
                                              f2greencol=None,
                                              write_xlsx=False)

        fpho_setup.raw_signal_trace(fpho_dataframe=df_test,
                                    output_filename='testing_unit',
                                    data_row_index=0)
        self.assertTrue(path.exists('testing_unit_RawSignal_f1Red.png'))
 def test_raw_signal_trace_errors(self):
     df_test = fpho_setup.import_fpho_data(input_filename='Python/TestData'
                                           '/1FiberTesting.csv',
                                           output_filename='my_file_name',
                                           n_fibers=1,
                                           f1greencol=3,
                                           animal_ID='vole1',
                                           exp_date='2020-09-01',
                                           exp_desc="testing",
                                           f2greencol=None,
                                           write_xlsx=False)
     with self.assertRaises(SystemExit) as cm:
         # Use the user input: userinputfailure
         fpho_setup.raw_signal_trace(fpho_dataframe=df_test,
                                     output_filename='testing_unit.png',
                                     data_row_index=0)
     self.assertEqual(cm.exception.code, 1)
def main():
    """Runs functions in fpho_setup, processes config.yml

    Parameters
    ----------
    config.yml
        To use this driver, update the config.yml file, then
        run the following bash command:
        python fpho_config.py --config config.yml

    Returns
    -------
        Pandas dataframe of parsed fiber photometry data
        Writes an output CSV/XLXS to specified file name
        Outputs specified plots and analysis
    """
    parser = argparse.ArgumentParser()

    parser.add_argument('--config', type=str, required=True)
    args = parser.parse_args()

    # Opens and reads config file to process
    f = open(args.config, 'r')
    config = yaml.load(f, Loader=yaml.FullLoader)
    f.close()

    #initializes a dictionary, that will hold a dataframe for each fiberphotometry file
    all_data = {}

    # Generate the dataframe with new data
    if config['import_new'] is True:
        fpho_df = fpho_setup.import_fpho_data(
            input_filename=(config['input_filename']),
            output_filename=(config['output_filename']),
            f1greencol=(config['f1greencol']),
            f1redcol=(config['f1redcol']),
            f2greencol=(config['f2greencol']),
            f2redcol=(config['f2redcol']),
            animal_ID=(config['animal_ID']),
            exp_date=(config['exp_date']),
            exp_desc=(config['exp_desc']))
        if config['write_xlsx'] is True:
            output_xlsx = config['output_filename'] + '_Summary.csv'
            if path.exists(output_xlsx):
                answer = input('Are you sure you want to overwrite' +
                               output_xlsx + '(y or n)')
                if answer != 'y':
                    print('Did not overwrite' + output_xlsx)
                    print(
                        'Change output_filename or write_xlsx value and rerun')
                    sys.exit()

            fpho_df.to_csv(output_xlsx, index=False)
            print('Summary CSV file has been saved to ' +
                  config['output_filename'] + '_Summary.csv')

        #Imports behavior data associated with the newly imported file if specified
        if config['import_behavior'] is True:
            fpho_df = behavior_setup.import_behavior_data(
                config['BORIS_file'], fpho_df)
            if config['write_xlsx'] is True:
                output_xlsx = key
                if path.exists(output_xlsx):
                    answer = input('Are you sure you want to overwrite' +
                                   output_xlsx + '(y or n)')
                    if answer != 'y':
                        print('Did not overwrite' + output_xlsx)
                        print(
                            'Change output_filename or write_xlsx value and rerun'
                        )
                        sys.exit()
                else:
                    fpho_df.to_csv(output_xlsx, index=False)
                    print('Behavior data has been added to the summary file')

        all_data['output_xlsx'] = fpho_df

    #reads in one or more dataframes and assigns them to a dictionary using the file name as the key
    if config['reload_data'] is True:
        for file in config['reload_filenames']:
            fpho_df = pd.read_csv(file)
            all_data[file] = fpho_df
            print('data was reloaded from', file)

    #Runs plots and analyses as specified on all fiberpho data sets
    for key in all_data:
        fpho_df = all_data[key]
        output_xlsx = key
        # Plot raw signal if specified
        if config['plot_raw_signal'] is True:
            fpho_setup.raw_signal_trace(fpho_df, key)

        # Normalizes signals of interest and plots normalization process
        if config['normalize_data'] is True:
            fpho_df = fpho_setup.plot_fitted_exp(
                fpho_df,
                key,
                signals=config['all_signals'],
                references=config['all_references'])
            if config['write_xlsx'] is True:
                fpho_df.to_csv(output_xlsx, index=False)
                print(key, 'has been updated to include normalized data')

        if config['plot_behavior'] is True:
            behavior_setup.plot_behavior(fpho_df, key, config['all_signals'])

        #Plot the discrete fourier transform of you're channels of interest
        if config['fourier_transform'] is True:
            correlation_setup.plot_FFT(fpho_df, key, config['channels'])

        # Plots z-score analysis of behavior if specified
        if config['plot_zscore'] is True:
            behavior_setup.plot_zscore(fpho_df, key, config['all_signals'],
                                       config['zscore_behs'])

        if config['within_trial_pearsons'] is True:
            print(
                correlation_setup.within_trial_pearsons(
                    fpho_df, key, config['channels']))

        if config['behavior_specific_pearsons'] is True:
            print(
                correlation_setup.behavior_specific_pearsons(
                    fpho_df, key, config['channels'], config['behaviors']))

        all_data[key] = fpho_df
def main():
    """Runs functions in fpho_setup, asks for what analysis to perform

    Parameters
    ----------
    input_filename: string
            Name of input file containing fiber photometry data

    output_filename: string
            Name you'd like for the output CSV file. Should include
            file path if different than current file

    animal_ID: int
            Number of the animal corresponding to fluoresence data

    exp_date: YYYY-MM-DD
            Date of exp/date data was gathered

    exp_desc: string
            Brief explantation of experiment/what
            type of information data contains

    plot_raw_signal: boolean
            optional plot of raw data for a
            particular fiber

    plot_iso_fit: boolean
            optional isosbestic plot

    plot_fit_exp: boolean
            optional fitted exponent plot

    Returns
    -------
    Pandas dataframe of parsed fiber photometry data

    Optional output:
        - Excel file of dataframe (.xlsx)
        - Raw signal plot (.png)
        - Isobestic plot (.png)
        - Fitted exponent plot (.png)
    """
    # use with config.txt
    # run bash command: python fpho_driver.py @config.txt
    parser = argparse.ArgumentParser(fromfile_prefix_chars='@')

    parser = argparse.ArgumentParser(
        description=('Parse fiber photometry data' +
                     'to prepare for analyses'))

    parser.add_argument('--input_filename',
                        dest='input_filename',
                        type=str,
                        required=True,
                        help='Name of input file as string')

    parser.add_argument('--output_filename',
                        dest='output_filename',
                        type=str,
                        required=True,
                        help='Name for output file as string')

    parser.add_argument('--n_fibers',
                        dest='n_fibers',
                        type=int,
                        required=True,
                        help='Number of fibers in input data')

    parser.add_argument('--f1greencol',
                        dest='f1greencol',
                        type=int,
                        required=True,
                        help='column index of f1green')

    parser.add_argument('--f2greencol',
                        dest='f2greencol',
                        type=int,
                        default=None,
                        required=False,
                        help='column index of f1green')

    parser.add_argument('--animal_ID',
                        dest='animal_ID',
                        type=int,
                        required=True,
                        help='Animal number for fluroesence data')

    parser.add_argument('--exp_date',
                        dest='exp_date',
                        type=str,
                        required=True,
                        help='Date of experiment as YYYY-MM-DD')

    parser.add_argument('--exp_desc',
                        dest='exp_desc',
                        type=str,
                        required=True,
                        help='Brief description for context')

    parser.add_argument('--write_xlsx',
                        dest='write_xlsx',
                        type=bool,
                        default=False,
                        help="add --write_xlsx to command line")

    parser.add_argument('--plot_raw_signal',
                        dest='plot_raw_signal',
                        action='store_true',
                        help='add --plot_raw_signal to command line')

    parser.add_argument('--plot_iso_fit',
                        dest='plot_iso_fit',
                        action='store_true',
                        help='add --plot_iso_fit to command line')

    parser.add_argument('--plot_fit_exp',
                        dest='plot_fit_exp',
                        action='store_true',
                        help='add --plot_fit_exp to command line')

    args = parser.parse_args()

    # Generate the dataframe with data
    fpho_df = fpho_setup.import_fpho_data(input_filename=args.input_filename,
                                          output_filename=args.output_filename,
                                          write_xlsx=args.write_xlsx,
                                          n_fibers=args.n_fibers,
                                          f1greencol=args.f1greencol,
                                          f2greencol=args.f2greencol,
                                          animal_ID=args.animal_ID,
                                          exp_date=args.exp_date,
                                          exp_desc=args.exp_desc)

    # Plot raw signal if specified in command line
    if args.plot_raw_signal:
        sys.stdin = open("Python/fpho_ftest_driver_input.txt")
        fpho_setup.raw_signal_trace(fpho_dataframe=fpho_df,
                                    output_filename=args.output_filename)

    # Prints isosbestic fit if specified
    if args.plot_iso_fit:
        sys.stdin = open("Python/fpho_ftest_driver_input.txt")
        fpho_setup.plot_isosbestic_norm(fpho_dataframe=fpho_df,
                                        output_filename=args.output_filename)

    # Prints fitted exponent if specified
    if args.plot_fit_exp:
        sys.stdin = open("Python/fpho_ftest_driver_input.txt")
        fpho_setup.plot_fitted_exp(fpho_dataframe=fpho_df,
                                   output_filename=args.output_filename)
def main():
    """Runs functions in fpho_setup, asks for what analysis to perform

    Parameters
    ----------
    input_filename: string
            Name of input file containing fiber photometry data

    output_filename: string
            Name you'd like for the output CSV file. Should include
            file path if different than current file

    animal_ID: int
               Number of the animal corresponding to fluoresence data

    exp_date: YYYY-MM-DD
              Date of exp/date data was gathered

    exp_desc: string
              Brief explantation of experiment/what
              type of information data contains

    plot_raw_signal: boolean
                     optional plot of raw data for a
                     particular fiber and color

    plot_iso_fit: boolean
                  optional isosbestic plot

    plot_fit_exp: boolean
                  optional fitted exponent plot

    Returns
    -------
    Pandas dataframe of parsed fiber photometry data
    Writes an output CSV to specified file name
    """
    # use with config.txt
    # run bash command: python fpho_driver.py @config.txt
    parser = argparse.ArgumentParser(fromfile_prefix_chars='@')

    parser = argparse.ArgumentParser(description=('Parse fiber photometry data'
                                                  + 'to prepare for analyses'))

    parser.add_argument('--input_filename',
                        dest='input_filename',
                        type=str,
                        required=True,
                        help='Name of input file as string')

    parser.add_argument('--output_filename',
                        dest='output_filename',
                        type=str,
                        required=True,
                        help='Name for output file as string')

    parser.add_argument('--animal_ID',
                        dest='animal_ID',
                        type=int,
                        required=True,
                        help='Animal number for fluroesence data')

    parser.add_argument('--exp_date',
                        dest='exp_date',
                        type=str,
                        required=True,
                        help='Date of experiment as YYYY-MM-DD')

    parser.add_argument('--exp_desc',
                        dest='exp_desc',
                        type=str,
                        required=True,
                        help='Brief description for context')

    parser.add_argument('--plot_raw_signal',
                        dest='plot_raw_signal',
                        action='store_true',
                        help='Type 1 to plot raw signal trace')

    parser.add_argument('--plot_iso_fit',
                        dest='plot_iso_fit',
                        action='store_true',
                        help='Type 1 to plot iso fitted trace')

    parser.add_argument('--plot_fit_exp',
                        dest='plot_fit_exp',
                        action='store_true',
                        help='Type 1 to plot fitted exponent')

    args = parser.parse_args()

    # Generate the dataframe with data
    fpho_df = fpho_setup.import_fpho_data(input_filename=args.input_filename,
                                          output_filename=args.output_filename,
                                          animal_ID=args.animal_ID,
                                          exp_date=args.exp_date,
                                          exp_desc=args.exp_desc)

    # Plot raw signal if specified in commandline
    if args.plot_raw_signal:
        fpho_setup.raw_signal_trace(fpho_df, args.output_filename)

    # Prints isosbestic fit if specified
    if args.plot_iso_fit:
        fpho_setup.plot_1fiber_norm_iso(fpho_df)

    # Prints fitted exponent if specified
    if args.plot_fit_exp:
        fpho_setup.plot_1fiber_norm_fitted(fpho_df)
Esempio n. 7
0
def main():
    """Runs functions in fpho_setup, asks for what analysis to perform
    
    Parameters
    ----------
    input_filename: string
            Name of input file containing fiber photometry data

    output_filename: string
            Name you'd like for the output CSV file. Should include 
            file path if different than current file
    animal_number: int
            Number of the animal corresponding to fluoresence data

    Returns
    -------
    Pandas dataframe of parsed fiber photometry data
    Writes an output CSV to specified file name
    """

    parser = argparse.ArgumentParser(
        description=('Parse fiber photometry data' +
                     'to prepare for analyses'))

    parser.add_argument('--input_filename',
                        dest='input_filename',
                        type=str,
                        required=True,
                        help='Name of input file as string')

    parser.add_argument('--output_filename',
                        dest='output_filename',
                        type=str,
                        required=True,
                        help='Name for output file as string')
    parser.add_argument(
        '--animal_num',
        dest='animal_num',
        type=int,
        required=False,  # make required
        help='Animal number for fluroesence data')
    parser.add_argument('--plot_raw_signal',
                        dest='plot_raw_signal',
                        type=bool,
                        required=False,
                        help='Type 1 to plot raw signal trace')
    parser.add_argument('--plot_iso_fit',
                        dest='plot_iso_fit',
                        type=bool,
                        required=False,
                        help='Type 1 to plot iso fitted trace')

    args = parser.parse_args()

    print(args.output_filename)

    fpho_df = fpho_setup.import_fpho_data(input_filename=args.input_filename,
                                          output_filename=args.output_filename)
    # prints raw signal
    if args.plot_raw_signal:
        fpho_setup.raw_signal_trace(fpho_df, args.output_filename)

    # prints isosbestic fit
    if args.plot_iso_fit:
        fpho_setup.plot_1fiber_norm_iso(fpho_df)