-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_pramgrn.py
45 lines (42 loc) · 1.18 KB
/
sort_pramgrn.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
import pandas
from subprocess import call
import os
import ipdb
orig_folder = '/media/angela/0d1ee072-3b3c-427f-ace6-c079402463b9/gdrive/Dataset1/Animal_1/rn_sorted/pr-amgrn'
new_folder = os.path.join(orig_folder, 'postsynaptic_sorted')
csv_file = 'cells.xlsx'
df = pandas.read_excel(csv_file)
df.set_index('Cell ID', inplace=True)
for fn in os.listdir(orig_folder):
if not fn.endswith('.tif'):
continue
f = fn.replace('}', '-')
f = f.replace('_', '-')
f = f[:f.find('.tif')]
namelist = f.split('-')
while ' ' in namelist:
namelist.remove(' ')
while '' in namelist:
namelist.remove('')
if len(namelist) < 3:
print('short name: ' + fn)
continue
postsyn = namelist[2]
if not postsyn.isnumeric():
continue
try:
postrow = df.loc[int(postsyn)]
except:
print('key not found in df: ' + postsyn)
continue
#print(postsyn)
if postrow[0].lower() == 'pr-amg rn':
#print('pr-amg rn')
fpath = os.path.join(orig_folder,fn)
newpath = os.path.join(new_folder, 'pr-amgrn', fn)
call(['scp', fpath, newpath])
elif postrow[0].lower() == 'prrn':
#print('prrn')
fpath = os.path.join(orig_folder,fn)
newpath = os.path.join(new_folder, 'prrn', fn)
call(['scp', fpath, newpath])