Skip to content

Commit f752993

Browse files
author
Jon Palmer
committed
fix xmlcombiner function
1 parent 4aa2602 commit f752993

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

funannotate/aux_scripts/iprscan-local.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import time
1010
import shutil
1111
import funannotate.library as lib
12+
from xml.etree import ElementTree as et
1213

1314

1415
class MyFormatter(argparse.ArgumentDefaultsHelpFormatter):
@@ -38,6 +39,19 @@ def __init__(self, prog):
3839
args = parser.parse_args()
3940

4041

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+
4155
def checkDocker():
4256
try:
4357
proc = subprocess.Popen(
@@ -341,22 +355,9 @@ def runMultiProgress(function, inputList, cpus):
341355
elif file.endswith('.log'):
342356
logfiles.append(os.path.join(tmpdir, file))
343357

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+
360361

361362
# sometimes docker fails because can't mount from this directory, i.e. if not in docker preferences, check logfile
362363
doublecheck = True

0 commit comments

Comments
 (0)