diff xmfa2gff3.py @ 3:97a43bcbf44d draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/progressivemauve commit fc61c9d4850614a6580d25f92e3032dc8edbc10d"
author iuc
date Fri, 26 Jun 2020 05:35:25 -0400
parents bca52822843e
children
line wrap: on
line diff
--- a/xmfa2gff3.py	Thu Feb 07 05:24:24 2019 -0500
+++ b/xmfa2gff3.py	Fri Jun 26 05:35:25 2020 -0400
@@ -16,6 +16,15 @@
 log = logging.getLogger(__name__)
 
 
+# Patch bcbio gff to work around url encoding issue. This is clearly
+# sub-optimal but we should transition to the newer library.
+def _new_format_keyvals(self, keyvals):
+    return ";".join(["%s=%s" % (k, ",".join(v)) for (k, v) in sorted(keyvals.items())])
+
+
+GFF.GFFOutput.GFF3Writer._format_keyvals = _new_format_keyvals
+
+
 def parse_xmfa(xmfa):
     """Simple XMFA parser until https://github.com/biopython/biopython/pull/544
     """
@@ -112,7 +121,7 @@
                 type="match", strand=parent['strand'],
                 qualifiers={
                     "source": "progressiveMauve",
-                    "target": label_convert.get(other['id'], other['id']),
+                    "Target": " ".join(map(str, [label_convert.get(other['id'], other['id']), other['start'], other['end'], '+' if other['strand'] > 0 else '-'])),
                     "ID": label_convert.get(other['id'], 'xmfa_' + other['rid'])
                 }
             )
@@ -158,10 +167,10 @@
 
 if __name__ == '__main__':
     parser = argparse.ArgumentParser(description='Convert XMFA alignments to gff3', prog='xmfa2gff3')
-    parser.add_argument('xmfa_file', type=file, help='XMFA File')
+    parser.add_argument('xmfa_file', type=argparse.FileType('r'), help='XMFA File')
     parser.add_argument('--window_size', type=int, help='Window size for analysis', default=1000)
     parser.add_argument('--relative_to', type=str, help='Index of the parent sequence in the MSA', default='1')
-    parser.add_argument('--sequences', type=file, nargs='+',
+    parser.add_argument('--sequences', type=argparse.FileType('r'), nargs='+',
                         help='Fasta files (in same order) passed to parent for reconstructing proper IDs')
     parser.add_argument('--version', action='version', version='%(prog)s 1.0')