diff tbl2gff3.py @ 1:4a7f4b0cc0a3 draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/tbl2gff3 commit db75a8489a1f61ea30abe9b91f6febac8b34204f"
author iuc
date Thu, 03 Dec 2020 16:59:23 +0000
parents 965674d88d34
children
line wrap: on
line diff
--- a/tbl2gff3.py	Tue Jul 07 04:20:40 2020 -0400
+++ b/tbl2gff3.py	Thu Dec 03 16:59:23 2020 +0000
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 import argparse
+import collections
 import csv
 import sys
 
@@ -32,9 +33,10 @@
     a=None,
     strand_column=None,
     strand_value=None,
+    strand_infer=False,
 ):
 
-    records = {}
+    records = collections.OrderedDict()
 
     for row in csv.reader(table, delimiter="\t"):
         # print(', '.join(row))
@@ -51,22 +53,34 @@
 
         q["source"] = c(row, source, "tbl2gff3")
 
+        begin_i = int(c(row, begin))
+        end_i = int(c(row, end))
+
+        begin_f = min(begin_i, end_i)
+        end_f = max(begin_i, end_i)
+
         _str = None
         if strand_column is not None:
             _str = int(c(row, strand_column))
         elif strand_value is not None:
             _str = int(strand_value)
+        if strand_infer:
+            if begin_i > begin_f:
+                _str = -1
+            else:
+                _str = 1
 
-        for x in a:
-            k, v = x.split(":", 1)
-            _v = c(row, v)
-            if k in q:
-                q[k].append(_v)
-            else:
-                q[k] = [_v]
+        if a is not None:
+            for x in a:
+                k, v = x.split(":", 1)
+                _v = c(row, v)
+                if k in q:
+                    q[k].append(_v)
+                else:
+                    q[k] = [_v]
 
         f = SeqFeature(
-            FeatureLocation(int(c(row, begin)), int(c(row, end))),
+            FeatureLocation(begin_f, end_f),
             type=c(row, type),
             strand=_str,
             qualifiers=q,
@@ -85,6 +99,7 @@
     parser.add_argument("--type", help="feature type column")
     parser.add_argument("--score", help="score column")
     parser.add_argument("--source", help="source column")
+    parser.add_argument("--strand_infer", action='store_true', help="infer strand")
     parser.add_argument("--strand_column", help="strand column")
     parser.add_argument("--strand_value", help="strand value")
     # parser.add_argument('--frame', help='frame column')