annotate tiles-from-gff3.py @ 7:4b519282a05b draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit ef20b4968a6d00c49209de6b723f8b96d8bd128a"
author iuc
date Mon, 25 May 2020 10:52:02 -0400
parents 740057a5126d
children
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],
6
740057a5126d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 1584882716a1d2c598e8485da9d73bcf80d9b29a"
iuc
parents: 2
diff changeset
27 "type": feature.type,
2
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
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
30 line = [
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
31 record.id,
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.start)),
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
33 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
34 ",".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
35 ]
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
36
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("\t".join(line))
014a21767ac4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 076837a2e9c2b6ececcea4aa286ea7a412387a96"
iuc
parents:
diff changeset
38 sys.stdout.write("\n")