-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrawlmat2lmat.py
More file actions
executable file
·109 lines (100 loc) · 3.09 KB
/
rawlmat2lmat.py
File metadata and controls
executable file
·109 lines (100 loc) · 3.09 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
"""Convert output generated by pyLMAT to a proper dir tree for lmat2cmplx."""
import argparse
import os
import errno
import subprocess
# pyLMAT release information
__version__ = '0.0.7'
_verdata = 'Mar 2015'
_devflag = True
# > MAIN
# Predefined internal constants
_INPUTDIR = './kwashiorkor/'
_OUTPUTDIR = './LMAT'
# Argument Parser Configuration
parser = argparse.ArgumentParser(
description='From pyLMAT output to lmat[sc]2cmplx input',
epilog='rawlmat2lmat - DLS team - by J.Mn.Marti - ' + _verdata
)
parser.add_argument(
'-V', '--version',
action='version',
version='rawlmat2lmat release ' + __version__ + ' - ' + _verdata
)
parser.add_argument(
'-v', '--verbose',
action='count',
help='increase output verbosity (-v or -vv)'
)
parser.add_argument(
'-i', '--inputdir',
action='store',
metavar='PATH',
default=_INPUTDIR,
help=('relative path of the LMAT processed directories (if omitted, \'' +
_INPUTDIR + '\' will be tried)')
)
parser.add_argument(
'-o', '--outputdir',
action='store',
metavar='PATH',
default=_OUTPUTDIR,
help=('relative path of the output directory (if omitted, \'' +
_OUTPUTDIR + '\' will be tried)')
)
# Parse arguments
args = parser.parse_args()
idir = args.inputdir
odir = args.outputdir
verb = (args.verbose if args.verbose is not None else 0)
# Program Header
print('\n=-= rawlmat2lmat =-= v' + __version__ + ' =-= ' +
_verdata + ' =-= by DLS team =-=')
if(_devflag):
print('\n>>> WARNING! THIS IS JUST A DEVELOPMENT SUBRELEASE.'
' USE AT YOUR OWN RISK!\n')
(root, dirs, files) = next(os.walk(idir))
dirdone = 0
numdirs = len(dirs)
# Main loop: every subdir in idir
for d in dirs:
dirsplit = d.split('.')
dataset = dirsplit[0]
time = dirsplit[1]
try:
itime = int(time)
except ValueError:
time = '0' + time
else:
if itime < 10:
time = '0' + time
try:
os.makedirs(odir + '/' + dataset)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
(root_, dirs_, files_) = next(os.walk(idir + '/' + d))
dirdone += 1
# 2ndary loop: file in every subdir of idir
if verb == 0:
workdone = dirdone / numdirs
print(("\rProgress: " +
"[\033[92m{0:50s}\033[0m] " +
"{1:.1f}%").format('#' * int(workdone * 50), workdone * 100),
end="",
flush=True)
else:
print('(', dirdone, 'of', numdirs,
') Looking for target files in: ', root_)
for f in files_:
if (('.fastsummary.' in f) or f.endswith('.genesummary') and
('.html' not in f) and ('.log' not in f) and
('_kmer_cov' not in f)):
c = subprocess.call('cp ' + idir + '/' + d + '/' + f +
' ' + odir + '/' + dataset + '/' +
dataset + '.' + time + '.' + f, shell=True)
if not c and verb > 1:
print('Dataset:', dataset, ' Time:', time,
' Copied file:', f)
print('\n')