annotate unified-tiles.py @ 0:e8475d0195fe draft

planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
author eric-rasche
date Wed, 01 Mar 2017 22:47:20 -0500
parents
children b56f47c58779
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 sys
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
4 import logging
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
5 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
6 log = logging.getLogger()
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
7
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 # 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
10 files = zip(sys.argv[1:][0::2], sys.argv[1:][1::2])
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
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
13 # Handlers
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
14 def bed(idx, path):
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
15 # 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
16 # 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
17 # 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
18 # 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
19 # 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
20 # 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
21 # 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
22 # 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
23 # 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
24
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
25 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
26 for line in handle:
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
27 lineData = line.strip().split()
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
28 chrom = lineData[0]
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
29 chromStart = lineData[1]
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
30 chromEnd = lineData[2]
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
31
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
32 yield (chrom, chromStart, chromEnd, lineData[4], lineData[6], lineData[5], lineData[9])
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
33
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
34
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
35 def gff3(idx, path):
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
36 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
37 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
38 continue
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
39
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
40 for feature in sorted(record.features, key=lambda x: x.location.start):
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
41 yield (
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
42 record.id,
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
43 feature.location.start,
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
44 feature.location.end,
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
45 feature.id or feature.qualifiers.get('Name', [None])[0],
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
46 feature.location.strand,
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
47 feature.qualifiers.get('score', [0.0])[0],
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
48 feature.qualifiers.get('color', [None])[0]
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
49 )
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
50
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
51
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
52 if __name__ == '__main__':
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
53 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
54 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
55
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
56 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
57 func = globals()[file_type]
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
58 for item in func(idx, file_path):
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
59 # multiple=False
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
60 # hs1 10292899 10301003 id=Conrad_993
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
61 # hs1 10297766 10301003 id=Conrad_994
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
62 lineExtra = [
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
63 'strand=%s' % item[4],
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
64 'score=%s' % item[5],
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
65 ]
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
66 if item[3] is not None:
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
67 lineExtra.append('id=%s' % item[3])
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
68 if item[6] is not None:
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
69 lineExtra.append('color=%s' % item[6])
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
70
e8475d0195fe planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff changeset
71 print item[0], item[1], item[2], ','.join(lineExtra)