-
-
Save adamjtaylor/bbadf5aa4beef9aa1d1a50d76e2c5bec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import argparse | |
import re | |
from shutil import copy | |
import os | |
import json | |
parser = argparse.ArgumentParser() | |
parser.add_argument('input', | |
type=str, | |
help='the file to parse the headers of ') | |
args = parser.parse_args() | |
with open(args.input, 'r') as f: | |
input=f.read() | |
pattern = r'(Groups.+Name\"\:\ \")(.*?)(\"\,.*?,)(.*?\]\}\])' | |
to_insert = ' "Colors": ["6000a0","d030d0"], "Channels": ["Hematoxylin","Eosin"]}]' | |
replacement_string = '\\1' + 'H&E' + '\\3' + to_insert | |
fix = re.sub(pattern, replacement_string, str(input)) | |
newname = args.input + '.bak' | |
copy(args.input, newname) | |
with open(args.input, 'w', encoding='utf-8') as f: | |
f.write(fix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment