comparison process-cytogenetic-bands.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 c4bde687c846
comparison
equal deleted inserted replaced
1:ae9994cf526f 2:014a21767ac4
1 #!/usr/bin/env python
2 import sys
3
4 # band hs1 p36.32 p36.32 2200000 5100000 gpos25
5 # band hs1 p36.31 p36.31 5100000 6900000 gneg
6 # band hs1 p36.23 p36.23 6900000 8800000 gpos25
7 COLS = (
8 "chrom",
9 "chromStart",
10 "chromEnd",
11 "name",
12 "score",
13 "strand",
14 "thickStart",
15 "thickEnd",
16 "itemRgb",
17 )
18
19 colormap = {}
20 # Process optional cytogenetic bands
21 # band
22 # ID
23 # parentChr
24 # parentChr
25 # START
26 # END COLOR
27 with open(sys.argv[1], "r") as handle:
28 for line in handle:
29 if line.startswith("#"):
30 continue
31
32 lineData = dict(zip(COLS, line.split()))
33 color = lineData.get("itemRgb", "gpos50")
34
35 if color not in colormap:
36 # Color MUST be an RGB triplet
37 if color.count(",") != 2:
38 continue
39 tmp = color.replace(",", "")
40 # Try interpreting it, without `,`s as an integer. If it fails this
41 # test there are non-numerical values and they might try and send
42 # us an `eval()` or a colour name. We do not currently support
43 # colour names just in case.
44 try:
45 int(tmp)
46 except ValueError:
47 # Does not look like an int
48 continue
49
50 colormap[color] = "gx-karyotype-%s" % len(colormap.keys())
51
52 sys.stderr.write(
53 "{colorName} = {color}\n".format(colorName=colormap[color], color=color)
54 )
55
56 sys.stdout.write(
57 "band {chrom} {name} {name} {chromStart} {chromEnd} {color}\n".format(
58 # Can access name because requiring >bed3
59 name=lineData["name"],
60 chrom=lineData["chrom"],
61 chromStart=lineData["chromStart"],
62 chromEnd=lineData["chromEnd"],
63 # 255,0,0 is a valid colour specifier
64 color=colormap[color],
65 )
66 )
67
68
69 # chrom - The name of the chromosome (e.g. chr3, chrY, chr2_random) or scaffold (e.g. scaffold10671).
70 # chromStart - The starting position of the feature in the chromosome or scaffold. The first base in a chromosome is numbered 0.
71 # chromEnd - The ending position of the feature in the chromosome or scaffold. The chromEnd base is not included in the display of the feature. For example, the first 100 bases of a chromosome are defined as chromStart=0, chromEnd=100, and span the bases numbered 0-99.
72 # name - Defines the name of the BED line. This label is displayed to the left of the BED line in the Genome Browser window when the track is open to full display mode or directly to the left of the item in pack mode.
73 # score - A score between 0 and 1000. If the track line useScore attribute is set to 1 for this annotation data set, the score value will determine the level of gray in which this feature is displayed (higher numbers = darker gray). This table shows the Genome Browser's translation of BED score values into shades of gray:
74 # strand - Defines the strand - either '+' or '-'.
75 # thickStart - The starting position at which the feature is drawn thickly (for example, the start codon in gene displays). When there is no thick part, thickStart and thickEnd are usually set to the chromStart position.
76 # thickEnd - The ending position at which the feature is drawn thickly (for example, the stop codon in gene displays).
77 # itemRgb - An RGB value of the form R,G,B (e.g. 255,0,0). If the track line itemRgb attribute is set to "On", this RBG value will determine the display color of the data contained in this BED line. NOTE: It is recommended that a simple color scheme (eight colors or less) be used with this attribute to avoid overwhelming the color resources of the Genome Browser and your Internet browser.
78 # blockCount - The number of blocks (exons) in the BED line.
79 # blockSizes - A comma-separated list of the block sizes. The number of items in this list should correspond to blockCount.
80 # blockStarts - A comma-separated list of block starts. All of the blockStart positions should be calculated relative to chromStart. The number of items in this list should correspond to blockCount.