def test_import_fpho_data_errors(self): with self.assertRaises(SystemExit) as cm: fpho_setup.import_fpho_data(input_filename='TestData/1Fdlkjf', 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) 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() # 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_column_assignments_one_fiber(self): fTime, f1Red, f1Green, f2Red, f2Green = fpho_setup.import_fpho_data( '1FiberTest.csv') test_time = [ '57887085.8496', '57887107.8144', '57887132.3904', '57887157.6448', '57887182.5664', '57887207.8336', '57887232.704', '57887257.5616', '57887282.7008', '57887308.032', '57887333.1712', '57887358.0288', '57887382.9632', '57887407.9232', '57887433.3952', '57887458.0352', '57887483.136', '57887508.9536', '57887533.4016', '57887558.3104' ] self.assertEqual(fTime, test_time) test_red1 = [ '644.744558543487', '678.416060082934', '647.206535086939', '644.814607841392', '678.270266422253', '647.262916229155', '644.723486803467', '678.379611667764', '647.031696595419', '644.656285037997', '678.365943512075', '647.200270515581', '644.59420883091', '678.557867198206', '647.119970100909', '644.794675114346', '678.310701382833', '647.334674046522', '644.818024880315', '678.212746267063' ] self.assertEqual(f1Red, test_red1) test_green1 = [ '712.658962090541', '706.853029076187', '714.173102686787', '712.524225248436', '706.683430253957', '714.162738314317', '712.601486934118', '706.846433566434', '714.076996687523', '712.630695620169', '706.940655134339', '714.133529628267', '712.506323150534', '706.897313213103', '714.293706293706', '712.506323150534', '706.771056312109', '714.288995215311', '712.807832167832', '706.860566801619' ] self.assertEqual(f1Green, test_green1) test_red2 = [ '661.240182347449', '702.872228630014', '663.797440544845', '661.14175866425', '703.062045733326', '663.734168177075', '661.214990571392', '703.00814704967', '663.732410611303', '661.227293531792', '703.05911645704', '663.754087255817', '661.062668204537', '703.013419746984', '663.687299756504', '661.326888925505', '702.928470734699', '663.968510279929', '661.102506362022', '703.291700994123' ] self.assertEqual(f2Red, test_red2) test_green2 = [ '479.767687953734', '456.4006398425', '515.287149829785', '479.69746934088', '456.525983347689', '515.158525081006', '479.75784422296', '456.437389770723', '514.962962962963', '479.951437594848', '456.417702309175', '514.988556662975', '480.10959353595', '456.319265001435', '514.76740084492', '480.127968500062', '456.411139821992', '515.082400229687', '479.812969115295', '456.644108116976' ] self.assertEqual(f2Green, test_green2)
def test_plot_fitted_exp(self): df_test = fpho_setup.import_fpho_data(input_filename='Python/' 'SampleData/1fiberSignal.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.plot_fitted_exp(fpho_dataframe=df_test, output_filename='my_file_name') self.assertTrue(path.exists('my_file_name_f1GreenNormExp.png')) self.assertTrue(path.exists('my_file_name_f1RedNormExp.png'))
def test_plot_isosbestic_norm(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.plot_isosbestic_norm(fpho_dataframe=df_test, output_filename='my_file_name') self.assertTrue(path.exists('my_file_name_f1GreenNormIso.png')) self.assertTrue(path.exists('my_file_name_f1RedNormIso.png'))
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 test_import_fpho_data(self): df = fpho_setup.import_fpho_data(input_filename='Python/TestData' '/1FiberTesting.csv', output_filename='my_file_name', n_fibers=1, f1greencol=4, animal_ID='vole1', exp_date='2020-09-01', exp_desc="testing", f2greencol=None, write_xlsx=False) test_green_iso = [1640.48859543818, 1640.90076030412] self.assertEqual(df['f1GreenIso'].values[0], test_green_iso) test_green_green = [1511.23969587835, 1511.07482993197] self.assertEqual(df['f1GreenGreen'].values[0], test_green_green) test_red_iso = [1536.2730469085, 1536.54499614098] self.assertEqual(df['f1RedIso'].values[0], test_red_iso)
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)
def test_column_assignments_one_fiber(self): fTime, f1Red, f1Green = fpho_setup.import_fpho_data('1FiberTest.csv') test_time = [ '52111503.5648', '52111528.4224', '52111553.6768', '52111579.1104', '52111603.6736', '52111628.608', '52111653.696', '52111678.848', '52111704.256', '52111729.792', '52111754.176', '52111779.0592', '52111804.0832', '52111829.1584', '52111855.296', '52111879.296', '52111904.3712', '52111929.4336', '52111954.9312', '52111979.5456' ] self.assertEqual(fTime, test_time) test_red = [ '1360.02593259583', '1543.68695652174', '1888.49759025813', '1379.57643426807', '1544.10860132064', '1883.40917588543', '1379.09578938341', '1543.43963639482', '1881.64479890232', '1379.13064059686', '1543.77490781237', '1881.50361032501', '1378.9618729097', '1543.00722065003', '1880.44435297144', '1379.31223737244', '1542.8058657062', '1880.79807906698', '1379.1495755081', '1542.52636995112' ] self.assertEqual(f1Red, test_red) test_green = [ '1510.66266506603', '1649.64105642257', '1540.86554621849', '1511.04921968788', '1649.37254901961', '1539.86634653862', '1510.93917567027', '1648.68547418968', '1540.050020008', '1510.9443777511', '1648.91356542617', '1540.14965986395', '1511.02521008403', '1648.08083233293', '1539.74429771909', '1510.95918367347', '1647.96798719488', '1540.39575830332', '1511.10444177671', '1647.51860744298' ] self.assertEqual(f1Green, test_green) def test_column_assignments_one_fiber(self): fTime, f1Red, f1Green, f2Red, f2Green = fpho_setup.import_fpho_data( '1FiberTest.csv') test_time = [ '57887085.8496', '57887107.8144', '57887132.3904', '57887157.6448', '57887182.5664', '57887207.8336', '57887232.704', '57887257.5616', '57887282.7008', '57887308.032', '57887333.1712', '57887358.0288', '57887382.9632', '57887407.9232', '57887433.3952', '57887458.0352', '57887483.136', '57887508.9536', '57887533.4016', '57887558.3104' ] self.assertEqual(fTime, test_time) test_red1 = [ '644.744558543487', '678.416060082934', '647.206535086939', '644.814607841392', '678.270266422253', '647.262916229155', '644.723486803467', '678.379611667764', '647.031696595419', '644.656285037997', '678.365943512075', '647.200270515581', '644.59420883091', '678.557867198206', '647.119970100909', '644.794675114346', '678.310701382833', '647.334674046522', '644.818024880315', '678.212746267063' ] self.assertEqual(f1Red, test_red1) test_green1 = [ '712.658962090541', '706.853029076187', '714.173102686787', '712.524225248436', '706.683430253957', '714.162738314317', '712.601486934118', '706.846433566434', '714.076996687523', '712.630695620169', '706.940655134339', '714.133529628267', '712.506323150534', '706.897313213103', '714.293706293706', '712.506323150534', '706.771056312109', '714.288995215311', '712.807832167832', '706.860566801619' ] self.assertEqual(f1Green, test_green1) test_red2 = [ '661.240182347449', '702.872228630014', '663.797440544845', '661.14175866425', '703.062045733326', '663.734168177075', '661.214990571392', '703.00814704967', '663.732410611303', '661.227293531792', '703.05911645704', '663.754087255817', '661.062668204537', '703.013419746984', '663.687299756504', '661.326888925505', '702.928470734699', '663.968510279929', '661.102506362022', '703.291700994123' ] self.assertEqual(f2Red, test_red2) test_green2 = [ '479.767687953734', '456.4006398425', '515.287149829785', '479.69746934088', '456.525983347689', '515.158525081006', '479.75784422296', '456.437389770723', '514.962962962963', '479.951437594848', '456.417702309175', '514.988556662975', '480.10959353595', '456.319265001435', '514.76740084492', '480.127968500062', '456.411139821992', '515.082400229687', '479.812969115295', '456.644108116976' ] self.assertEqual(f2Green, test_green2)
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)