-
Notifications
You must be signed in to change notification settings - Fork 1
/
rearrange_folders.py
executable file
·61 lines (55 loc) · 2.12 KB
/
rearrange_folders.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 11 20:20:49 2020
@author: adrian
"""
import os
from shutil import copy2
import openpyxl
import sys
current_folder=sys.argv[1];
os.chdir(current_folder)
folders=['hpc','cortex']
#j=0;
for j in range(len(folders)):
#Create folder brain region
os.mkdir(folders[j])
#Read excel sheet
av=[];
file = [f for f in os.listdir('.') if folders[j]+'.xlsx' in f]
print(file)
wb_obj = openpyxl.load_workbook(file[0])
sheet = wb_obj.active
for row in sheet.iter_rows(max_row=sheet.max_row):
for cell in row:
#print(cell.value, end=" ")
av.append(cell.value)
#print()
#Run for all tetrodes
for i in range(0, len(av), 2):
#Find tetrode channels
try:
os.mkdir(os.getcwd()+'/'+folders[j]+'/'+'Tetrode_'+str(av[i]))
channels=av[i+1]
#Split channels, sometimes a comma is converted into a dot.
try:
channels=channels.split(',')
except AttributeError:
channels=str(channels)
channels=channels.split('.')
# Save tetrode .continuous files
#channels=['14','29','15','16']
append_str = '100_CH';
post_str='.continuous'
channels = [append_str + sub + post_str for sub in channels]
for x in channels:
#copy2(x,os.getcwd()+'/'+folders[j]+'/'+'Tetrode_'+str(av[i]))
os.rename(os.getcwd()+'/'+x,os.getcwd()+'/'+folders[j]+'/'+'Tetrode_'+str(av[i])+'/'+x )
copy2('all_channels.events', os.getcwd()+'/'+folders[j]+'/'+'Tetrode_'+str(av[i]))
copy2('Continuous_Data.openephys', os.getcwd()+'/'+folders[j]+'/'+'Tetrode_'+str(av[i]))
copy2('settings.xml', os.getcwd()+'/'+folders[j]+'/'+'Tetrode_'+str(av[i]))
copy2('messages.events', os.getcwd()+'/'+folders[j]+'/'+'Tetrode_'+str(av[i]))
copy2('tetrode.prb', os.getcwd()+'/'+folders[j]+'/'+'Tetrode_'+str(av[i]))
except FileExistsError:
print('Folder already exists')