annotate tiles-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 740057a5126d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
1 #!/usr/bin/env python
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
2 import logging
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
3 import sys
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
4
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
5 from BCBio import GFF
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
6
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
7 logging.basicConfig(level=logging.INFO)
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
8 log = logging.getLogger()
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
9
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
10
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
11 if __name__ == "__main__":
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
12 attr = sys.argv[2]
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
13
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
14 for record in GFF.parse(sys.argv[1]):
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
15 if len(record.features) == 0:
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
16 continue
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
17
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
18 for feature in sorted(record.features, key=lambda x: x.location.start):
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
19 # chrom chromStart chromEnd
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
20 # name score strand
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
21 # thickStart thickEnd itemRgb
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
22
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
23 kv = {
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
24 "strand": 0 if not feature.location.strand else feature.location.strand,
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
25 "name": feature.qualifiers.get(attr, ["None"])[0] or feature.id,
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
26 "value": feature.qualifiers.get("score", [0])[0],
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
27 }
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
28
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
29 line = [
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
30 record.id,
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
31 str(int(feature.location.start)),
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
32 str(int(feature.location.end)),
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
33 ",".join(["%s=%s" % x for x in sorted(kv.items())]),
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
34 ]
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
35
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
36 sys.stdout.write("\t".join(line))
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
37 sys.stdout.write("\n")