Mercurial > repos > greg > gene_family_phylogeny_builder
comparison utils.py @ 0:f4361d941aa3 draft
Uploaded
| author | greg |
|---|---|
| date | Tue, 11 Apr 2017 11:05:24 -0400 |
| parents | |
| children | eb3eb139be22 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:f4361d941aa3 |
|---|---|
| 1 import os | |
| 2 import shutil | |
| 3 import sys | |
| 4 | |
| 5 | |
| 6 def check_execution_errors(rc, stderr): | |
| 7 if rc != 0: | |
| 8 stop_err(stderr.read()) | |
| 9 | |
| 10 | |
| 11 def move_directory_files(source_dir, destination_dir): | |
| 12 source_directory = os.path.abspath(source_dir) | |
| 13 destination_directory = os.path.abspath(destination_dir) | |
| 14 if not os.path.isdir(destination_directory): | |
| 15 os.makedirs(destination_directory) | |
| 16 for dir_entry in os.listdir(source_directory): | |
| 17 source_entry = os.path.join(source_directory, dir_entry) | |
| 18 shutil.move(source_entry, destination_directory) | |
| 19 | |
| 20 | |
| 21 def stop_err(msg): | |
| 22 sys.stderr.write(msg) | |
| 23 sys.exit(1) | |
| 24 | |
| 25 | |
| 26 def write_html_output(output, title, dir): | |
| 27 with open(output, 'w') as fh: | |
| 28 fh.write('<html><head><h3>%s</h3></head>\n' % title) | |
| 29 fh.write('<body><p/><table cellpadding="2">\n') | |
| 30 fh.write('<tr><th>Size</th><th>Name</th></tr>\n') | |
| 31 for index, fname in enumerate(sorted(os.listdir(dir))): | |
| 32 if index % 2 == 0: | |
| 33 bgcolor = '#D8D8D8' | |
| 34 else: | |
| 35 bgcolor = '#FFFFFF' | |
| 36 try: | |
| 37 size = str(os.path.getsize(os.path.join(dir, fname))) | |
| 38 except: | |
| 39 size = 'unknown' | |
| 40 link = '<a href="%s" type="text/plain">%s</a>\n' % (fname, fname) | |
| 41 fh.write('<tr bgcolor="%s"><td>%s</td><td>%s</td></tr>\n' % (bgcolor, size, link)) | |
| 42 fh.write('</table></body></html>\n') |
