Mercurial > repos > iuc > circos
comparison text-from-gff3.py @ 2:014a21767ac4 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
author | iuc |
---|---|
date | Tue, 17 Sep 2019 16:54:57 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:ae9994cf526f | 2:014a21767ac4 |
---|---|
1 #!/usr/bin/env python | |
2 import logging | |
3 import sys | |
4 | |
5 from BCBio import GFF | |
6 | |
7 logging.basicConfig(level=logging.INFO) | |
8 log = logging.getLogger() | |
9 | |
10 | |
11 if __name__ == "__main__": | |
12 attr = sys.argv[2] | |
13 | |
14 for record in GFF.parse(sys.argv[1]): | |
15 if len(record.features) == 0: | |
16 continue | |
17 | |
18 for feature in sorted(record.features, key=lambda x: x.location.start): | |
19 # chrom chromStart chromEnd | |
20 # name score strand | |
21 # thickStart thickEnd itemRgb | |
22 | |
23 kv = { | |
24 "strand": 0 if not feature.location.strand else feature.location.strand, | |
25 "value": feature.qualifiers.get("score", [0])[0], | |
26 } | |
27 | |
28 if attr not in feature.qualifiers: | |
29 continue | |
30 | |
31 name = feature.qualifiers[attr][0] | |
32 | |
33 line = [ | |
34 record.id, | |
35 str(int(feature.location.start)), | |
36 str(int(feature.location.end)), | |
37 name, | |
38 ",".join(["%s=%s" % x for x in sorted(kv.items())]), | |
39 ] | |
40 | |
41 sys.stdout.write("\t".join(line)) | |
42 sys.stdout.write("\n") |