-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcombinerois.py
More file actions
executable file
·31 lines (26 loc) · 913 Bytes
/
combinerois.py
File metadata and controls
executable file
·31 lines (26 loc) · 913 Bytes
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
import argparse
import os, os.path
import re
def combine_rois(rois, outfile):
if not os.path.isdir(os.path.dirname(outfile)):
os.makedirs(os.path.dirname(outfile))
outfile = open(outfile, 'w')
for f in rois:
name = os.path.splitext(os.path.basename(f))[0]
for line in open(f):
line = re.sub(r'[^,]+,', f'{name},', line, count=1)
outfile.write(line)
outfile.close()
def main():
args = argparse.ArgumentParser()
args.add_argument('outfile',
type=str,
help='The file to which to write the combined results to.')
args.add_argument('infiles',
nargs='+',
type=str,
help='The files to combine, separated by spaces.')
args = args.parse_args()
combine_rois(args.infiles, args.outfile)
if __name__ == '__main__':
main()