Last active
September 26, 2018 19:41
-
-
Save JossWhittle/c20f6ba22237de7555a60d7a085842cb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import glob, os, re | |
| output_file_name = 'output.csv' | |
| print('Writing output to %s...' % (output_file_name)) | |
| with open(output_file_name, 'w') as output_file: | |
| file_list = glob.glob('*.txt') | |
| print('Found %d files to process...' % (len(file_list))) | |
| for file_name in file_list: | |
| with open(file_name, 'r') as input_file: | |
| for line in input_file.readlines(): | |
| m = re.match(r'Total viable cells / ml \(x 10\^6\) :(.*)', line, re.M|re.I) | |
| if (m is not None): | |
| output_line = '"%s",%s' % (file_name, m.group(1)) | |
| print(output_line) | |
| output_file.write('%s\n' % (output_line)) | |
| print('Done.') |
This file contains hidden or 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
| import glob, os, re | |
| def calum_sort(l): | |
| convert = lambda text: int(text) if text.isdigit() else text.lower() | |
| alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ] | |
| def get_d(key): | |
| m = re.match(r'.*?d(\d+)', key, re.M|re.I) | |
| return int(m.group(1)) if (m is not None) else 0, alphanum_key(key), key | |
| return sorted(l, key=get_d) | |
| output_file_name = 'output.csv' | |
| print('Writing output to %s...' % (output_file_name)) | |
| with open(output_file_name, 'w') as output_file: | |
| file_list = calum_sort(glob.glob('*.txt')) | |
| print('Found %d files to process...' % (len(file_list))) | |
| for file_name in file_list: | |
| with open(file_name, 'r') as input_file: | |
| total_cells = 'error' | |
| viable_cells = 'error' | |
| viability = 'error' | |
| for line in input_file.readlines(): | |
| m = re.match(r'Total viable cells / ml \(x 10\^6\) :(.*)', line, re.M|re.I) | |
| if (m is not None): | |
| viable_cells = m.group(1) | |
| m = re.match(r'Total cells / ml \(x 10\^6\) :(.*)', line, re.M|re.I) | |
| if (m is not None): | |
| total_cells = m.group(1) | |
| m = re.match(r'Viability \(\%\) :(.*)', line, re.M|re.I) | |
| if (m is not None): | |
| viability = m.group(1) | |
| output_line = '"%s",%s,%s,%s' % (file_name, viable_cells, total_cells, viability) | |
| print(output_line) | |
| output_file.write('%s\n' % (output_line)) | |
| print('Done.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment