-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename_tiff_oir_cycle_files_simple.py
executable file
·53 lines (46 loc) · 1.55 KB
/
rename_tiff_oir_cycle_files_simple.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
# Rename Olympus matl experiment files with descriptions
# created: 8 September 2018
#
# For series of large cycle .oir filenames
<<<<<<< HEAD
# after converting to single .tiff
=======
# after converting to single .tiff
>>>>>>> 62675e050218d15ed7a8d444d6571f7996f34f09
#
# Run from inside target directory
#
#
# May need to modify filename output
import os
import xml.etree.ElementTree as ET
tree = ET.parse('matl.omp2info')
root = tree.getroot()
#get cwd
cwd = os.getcwd()
filenames = [file for file in os.listdir(cwd) if file.endswith('.tiff')] # input file suffix
# map matl namespace
ns = {'matl':'http://www.olympus.co.jp/hpf/protocol/matl/model/matl'}
# create a dictionary for image name and description
file_dict = {}
# add image name and description to the dictionary
for group in root.findall('matl:group', ns):
for description in group.findall('matl:description', ns):
filename = description.text
for area in group.findall('matl:area', ns):
for image in area.findall('matl:image', ns):
fileId = image.text
file_dict[fileId]= filename
# replace image name with description nameL
for i in filenames:
print "oldfile =", i
i = i.replace(i, (os.path.splitext(i)[0])+'.oir')
for fileId, filename in file_dict.items():
if i in fileId:
newfile = i.replace(i, '20180810_smFISH_screen_'+filename+'.tiff') # input file suffix
print "newfile =", newfile
#os.rename(i, newfile)
<<<<<<< HEAD
# os.rename(i, newfile)
=======
>>>>>>> 62675e050218d15ed7a8d444d6571f7996f34f09