|
9 | 9 | import time
|
10 | 10 | import shutil
|
11 | 11 | import funannotate.library as lib
|
| 12 | +from xml.etree import ElementTree as et |
12 | 13 |
|
13 | 14 |
|
14 | 15 | class MyFormatter(argparse.ArgumentDefaultsHelpFormatter):
|
@@ -38,6 +39,19 @@ def __init__(self, prog):
|
38 | 39 | args = parser.parse_args()
|
39 | 40 |
|
40 | 41 |
|
| 42 | +def combine_xml(files, output): |
| 43 | + first = None |
| 44 | + for filename in files: |
| 45 | + data = et.parse(filename).getroot() |
| 46 | + if first is None: |
| 47 | + first = data |
| 48 | + else: |
| 49 | + first.extend(data.getchildren()) |
| 50 | + tree._setroot(first) |
| 51 | + et.register_namespace("", "http://www.ebi.ac.uk/interpro/resources/schemas/interproscan5") |
| 52 | + tree.write(output, encoding='utf-8', xml_declaration=True) |
| 53 | + |
| 54 | + |
41 | 55 | def checkDocker():
|
42 | 56 | try:
|
43 | 57 | proc = subprocess.Popen(
|
@@ -341,22 +355,9 @@ def runMultiProgress(function, inputList, cpus):
|
341 | 355 | elif file.endswith('.log'):
|
342 | 356 | logfiles.append(os.path.join(tmpdir, file))
|
343 | 357 |
|
344 |
| -# apparently IPRscan XML has changed the header format in newest version [accidental?] |
345 |
| -with open(finalOut, 'w') as output: |
346 |
| - for i,x in enumerate(final_list): |
347 |
| - with open(x, 'r') as infile: |
348 |
| - lines = infile.readlines() |
349 |
| - if i == 0: |
350 |
| - if '<protein-matches xml' in lines[0]: |
351 |
| - linestart = 1 |
352 |
| - elif '<protein-matches xml' in lines[1]: |
353 |
| - linestart = 2 |
354 |
| - for line in lines[:-1]: |
355 |
| - output.write(line) |
356 |
| - else: |
357 |
| - for line in lines[linestart:-1]: |
358 |
| - output.write(line) |
359 |
| - output.write('</protein-matches>\n') |
| 358 | +# apparently IPRscan XML has changed the header format, so now combine with ElementTree so no mistakes |
| 359 | +combine_xml(final_list, finalOut) |
| 360 | + |
360 | 361 |
|
361 | 362 | # sometimes docker fails because can't mount from this directory, i.e. if not in docker preferences, check logfile
|
362 | 363 | doublecheck = True
|
|
0 commit comments