-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch_mkdir_tiltseries.py
42 lines (34 loc) · 1.25 KB
/
batch_mkdir_tiltseries.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 8, 2021
All .mrc & mrc.mdoc, log file should be in 1 folder
Move .mrc file into folders
@author: Huy Bui, McGill
"""
import argparse, os, glob, shutil
if __name__=='__main__':
parser = argparse.ArgumentParser(description='Organize tilt series into folders\n. E.g.: batch_mkdir_tiltseries.py --i \"CU482_0*.mrc\"')
parser.add_argument('--i', help='Input Tilt Series Wild Card',required=True)
args = parser.parse_args()
tsList = glob.glob(args.i)
for tiltseries in tsList:
if not tiltseries.endswith('.mrc'):
print('Processing ' + tiltseries + ': ERROR! Only mrc file supported')
break
tsName = tiltseries.replace('.mrc', '')
mrcDoc = tiltseries.replace('.mrc', '.mrc.mdoc')
log = tiltseries.replace('.mrc', '.log')
try:
os.mkdir(tsName)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
pass
# Move tilt series
print('mv ' + tiltseries + ' ' + os.path.join(tsName, tiltseries))
shutil.move(tiltseries, os.path.join(tsName, tiltseries))
print('mv ' + mrcDoc + ' ' + os.path.join(tsName, mrcDoc))
shutil.move(mrcDoc, os.path.join(tsName, mrcDoc))
print('mv ' + log + ' ' + os.path.join(tsName, mrcDoc))
shutil.move(log, os.path.join(tsName, log))