comparison 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
comparison
equal deleted inserted replaced
0:965674d88d34 1:4a7f4b0cc0a3
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 import argparse 2 import argparse
3 import collections
3 import csv 4 import csv
4 import sys 5 import sys
5 6
6 from BCBio import GFF 7 from BCBio import GFF
7 from Bio.Seq import Seq 8 from Bio.Seq import Seq
30 score=None, 31 score=None,
31 frame=None, 32 frame=None,
32 a=None, 33 a=None,
33 strand_column=None, 34 strand_column=None,
34 strand_value=None, 35 strand_value=None,
36 strand_infer=False,
35 ): 37 ):
36 38
37 records = {} 39 records = collections.OrderedDict()
38 40
39 for row in csv.reader(table, delimiter="\t"): 41 for row in csv.reader(table, delimiter="\t"):
40 # print(', '.join(row)) 42 # print(', '.join(row))
41 43
42 # if we haven't seen this record before, populate it. 44 # if we haven't seen this record before, populate it.
49 if c(row, score) is not None: 51 if c(row, score) is not None:
50 q["score"] = float(c(row, score)) 52 q["score"] = float(c(row, score))
51 53
52 q["source"] = c(row, source, "tbl2gff3") 54 q["source"] = c(row, source, "tbl2gff3")
53 55
56 begin_i = int(c(row, begin))
57 end_i = int(c(row, end))
58
59 begin_f = min(begin_i, end_i)
60 end_f = max(begin_i, end_i)
61
54 _str = None 62 _str = None
55 if strand_column is not None: 63 if strand_column is not None:
56 _str = int(c(row, strand_column)) 64 _str = int(c(row, strand_column))
57 elif strand_value is not None: 65 elif strand_value is not None:
58 _str = int(strand_value) 66 _str = int(strand_value)
67 if strand_infer:
68 if begin_i > begin_f:
69 _str = -1
70 else:
71 _str = 1
59 72
60 for x in a: 73 if a is not None:
61 k, v = x.split(":", 1) 74 for x in a:
62 _v = c(row, v) 75 k, v = x.split(":", 1)
63 if k in q: 76 _v = c(row, v)
64 q[k].append(_v) 77 if k in q:
65 else: 78 q[k].append(_v)
66 q[k] = [_v] 79 else:
80 q[k] = [_v]
67 81
68 f = SeqFeature( 82 f = SeqFeature(
69 FeatureLocation(int(c(row, begin)), int(c(row, end))), 83 FeatureLocation(begin_f, end_f),
70 type=c(row, type), 84 type=c(row, type),
71 strand=_str, 85 strand=_str,
72 qualifiers=q, 86 qualifiers=q,
73 ) 87 )
74 r.features.append(f) 88 r.features.append(f)
83 parser.add_argument("begin", help="begin column") 97 parser.add_argument("begin", help="begin column")
84 parser.add_argument("end", help="end column") 98 parser.add_argument("end", help="end column")
85 parser.add_argument("--type", help="feature type column") 99 parser.add_argument("--type", help="feature type column")
86 parser.add_argument("--score", help="score column") 100 parser.add_argument("--score", help="score column")
87 parser.add_argument("--source", help="source column") 101 parser.add_argument("--source", help="source column")
102 parser.add_argument("--strand_infer", action='store_true', help="infer strand")
88 parser.add_argument("--strand_column", help="strand column") 103 parser.add_argument("--strand_column", help="strand column")
89 parser.add_argument("--strand_value", help="strand value") 104 parser.add_argument("--strand_value", help="strand value")
90 # parser.add_argument('--frame', help='frame column') 105 # parser.add_argument('--frame', help='frame column')
91 parser.add_argument("-a", action="append", help="attribute column (-a k:v)") 106 parser.add_argument("-a", action="append", help="attribute column (-a k:v)")
92 args = parser.parse_args() 107 args = parser.parse_args()