print('\n Analysing the following folders:\n')
print(expDirs)

# generate fly color map
numFlies = len(expDirs)

# Go through directories of experiments with different flies ...........................................................
for currExpDir in expDirs:

    expDir = dataDir + currExpDir + sep
    print('\n Analysing the following folder:\n')
    print(expDir)

    FODataFiles = [filepath.split(sep)[-1] for filepath in glob(expDir + '*.txt')]
    FODataFiles = sorted(FODataFiles)

    print('\n Analysing the following log files:\n')
    print(FODataFiles)

    # Run single trial analysis on each file in folder .....................................................
    for fileToAnalyse in FODataFiles:

        flyID = fileToAnalyse.split('_')[0]
        trial = FODataFiles.index(fileToAnalyse) + 1

        returnVal = singleVRStripeTrialAnalysis(expDir + fileToAnalyse)
        print('Ran analysis, now loading saved *.npy file.')
        FODatLoad = np.load(expDir + fileToAnalyse[:-3] + 'npy')[()]

print('Analysis ran successfully')
root.withdraw()
# choose experiment folder
expDir = askdirectory(initialdir=baseDir, title='Select experiment directory of a single fly') + sep
dataDir = sep.join(expDir.split(sep)[0:-2]) + sep
flyID = expDir.split(sep)[-2]

# create analysis dir
analysisDir = sep.join(dataDir.split(sep)[:-2]) + sep + 'analysis' + sep
try:
    mkdir(analysisDir)
except OSError:
    print('Analysis directory already exists.')

FODataFiles = [filepath.split(sep)[-1] for filepath in glob(expDir + '*.txt')]
FODataFiles = sorted(FODataFiles)

print('\n Analysing the following log files:\n')
print(FODataFiles)

for FODataFile in FODataFiles:
    # ------------------------------------------------------------------------------------------------------------------
    # Run for each file in folder
    # ------------------------------------------------------------------------------------------------------------------
    returnVal = singleVRStripeTrialAnalysis(expDir+FODataFile)

    # test that npy file got saved
    FODatLoad = np.load(expDir + FODataFile[:-3] + 'npy')[()]

    print('Analysis ran successfully!')