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