Mercurial > repos > eric-rasche > circos
annotate unified-histogram.py @ 4:4ff5ff4c84fa draft
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit e4192d8d51efd2bf52c8094df65c164d90168e66
author | eric-rasche |
---|---|
date | Sun, 05 Mar 2017 17:02:17 -0500 |
parents | b56f47c58779 |
children | b25b3518c2ce |
rev | line source |
---|---|
0
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
1 #!/usr/bin/env python |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
2 from BCBio import GFF |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
3 import wiggle |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
4 import sys |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
5 import logging |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
6 logging.basicConfig(level=logging.INFO) |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
7 log = logging.getLogger() |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
8 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
9 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
10 MODE = sys.argv[1] |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
11 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
12 # Pair up (file, extension) pairs from sys.argv |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
13 files = zip(sys.argv[2:][0::2], sys.argv[2:][1::2]) |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
14 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
15 # Our output data structure. This could be much more efficient. |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
16 data = {} |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
17 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
18 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
19 def bed(idx, path): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
20 # chrom - The name of the chromosome (e.g. chr3, chrY, chr2_random) or scaffold (e.g. scaffold10671). |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
21 # chromStart - The starting position of the feature in the chromosome or scaffold. The first base in a chromosome is numbered 0. |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
22 # 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. |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
23 # 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. |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
24 # 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: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
25 # strand - Defines the strand - either '+' or '-'. |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
26 # 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. |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
27 # thickEnd - The ending position at which the feature is drawn thickly (for example, the stop codon in gene displays). |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
28 # 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. |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
29 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
30 with open(path, 'r') as handle: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
31 for line in handle: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
32 lineData = line.strip().split() |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
33 chrom = lineData[0] |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
34 chromStart = lineData[1] |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
35 chromEnd = lineData[2] |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
36 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
37 if chrom not in data: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
38 data[chrom] = {} |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
39 |
4
4ff5ff4c84fa
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit e4192d8d51efd2bf52c8094df65c164d90168e66
eric-rasche
parents:
3
diff
changeset
|
40 for i in range(chromStart, chromEnd): |
0
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
41 if i not in data[chrom]: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
42 data[chrom][i] = {} |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
43 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
44 data[chrom][i][idx] = lineData[5] |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
45 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
46 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
47 # Handlers |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
48 def gff3(idx, path): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
49 for record in GFF.parse(path): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
50 if len(record.features) == 0: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
51 continue |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
52 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
53 if record.id not in data: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
54 data[record.id] = {} |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
55 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
56 for feature in record.features: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
57 if 'score' in feature.qualifiers: |
4
4ff5ff4c84fa
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit e4192d8d51efd2bf52c8094df65c164d90168e66
eric-rasche
parents:
3
diff
changeset
|
58 for i in range(feature.location.start, feature.location.end): |
0
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
59 if i not in data[record.id]: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
60 data[record.id][i] = {} |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
61 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
62 data[record.id][i][idx] = feature.qualifiers['score'][0] |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
63 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
64 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
65 def wig(idx, path): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
66 walker = wiggle.Wiggle() |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
67 with open(path, 'r') as handle: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
68 for region, position, value in walker.walk(handle): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
69 if region not in data: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
70 data[region] = {} |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
71 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
72 if position not in data[region]: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
73 data[region][position] = {} |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
74 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
75 data[region][position][idx] = value |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
76 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
77 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
78 if __name__ == '__main__': |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
79 mode_tiles_possible = True |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
80 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
81 for idx, (file_path, file_type) in enumerate(files): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
82 log.info("Processing %s.%s", file_path, file_type) |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
83 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
84 if file_type in globals(): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
85 func = globals()[file_type] |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
86 func(idx, file_path) |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
87 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
88 if file_type == 'wig': |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
89 mode_tiles_possible = False |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
90 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
91 if MODE == 'tile' and not mode_tiles_possible: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
92 raise Exception("You requested a 'tile' plot with wig data, which is impossible") |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
93 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
94 # Max number of files |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
95 max_idx = range(len(files)) |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
96 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
97 serialized_values = None |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
98 region_start, region_end = (None, None) |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
99 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
100 for genome in data: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
101 for position in sorted(data[genome]): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
102 values = [ |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
103 '' if x not in data[genome][position] else data[genome][position][x] |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
104 for x in max_idx |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
105 ] |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
106 if serialized_values is None: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
107 serialized_values = values |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
108 if region_start is None: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
109 region_start = position |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
110 region_end = position |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
111 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
112 if values == serialized_values: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
113 region_end = position |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
114 else: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
115 if MODE == 'histogram': |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
116 # histogram |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
117 # hs4 0 1999999 5.0000,3.0000,1.0000,19.0000 |
3
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
118 sys.stdout.write(' '.join( |
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
119 (genome, region_start, region_end, ','.join(values)) |
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
120 ) + '\n') |
0
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
121 elif MODE == 'heatmap': |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
122 # heatmap |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
123 # hs1 2000000 3999999 0.0000 id=hs4 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
124 # hs1 4000000 5999999 2.0000 id=hs1 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
125 # hs1 4000000 5999999 0.0000 id=hs2 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
126 # hs1 4000000 5999999 0.0000 id=hs3 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
127 # hs1 4000000 5999999 0.0000 id=hs4 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
128 # hs1 6000000 7999999 4.0000 id=hs2 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
129 for x in max_idx: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
130 if x in data[genome][position]: |
3
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
131 sys.stdout.write(' '.join( |
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
132 (genome, region_start, region_end, data[genome][position][x], 'id=hm%s' % x) |
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
133 ) + '\n') |
0
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
134 else: |
3
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
135 sys.stdout.write(' '.join( |
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
136 (genome, region_start, region_end, 0.0, 'id=hm%s' % x) |
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
137 ) + '\n') |
0
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
138 elif MODE == 'line': |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
139 # multiple=False |
3
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
140 sys.stdout.write(' '.join( |
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
141 (genome, region_start, region_end, data[genome][position][0]) |
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
142 ) + '\n') |
0
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
143 elif MODE == 'scatter': |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
144 # multiple=False |
3
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
145 sys.stdout.write(' '.join( |
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
146 (genome, region_start, region_end, data[genome][position][0]) |
b56f47c58779
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 4503a4ca99e65aa821e2c953f2f18eaadeed170a
eric-rasche
parents:
0
diff
changeset
|
147 ) + '\n') |
0
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
148 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
149 # Update start of next array |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
150 region_start = position |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
151 region_end = position |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
152 # And update with new array |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
153 serialized_values = values |