Mercurial > repos > yating-l > jbrowse_hub
comparison jbrowse_hub.py @ 0:e4f3f2ed4fa5 draft
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
author | yating-l |
---|---|
date | Fri, 10 Mar 2017 13:48:19 -0500 |
parents | |
children | e7c80e9b70ae |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e4f3f2ed4fa5 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import os | |
4 import sys | |
5 import argparse | |
6 import subprocess | |
7 from bedToGff3 import bedToGff3 | |
8 import blastxmlToGff3 | |
9 import utils | |
10 import tempfile | |
11 import trackObject | |
12 import TrackHub | |
13 | |
14 def main(argv): | |
15 parser = argparse.ArgumentParser(description='Create a hub to display in jbrowse.') | |
16 | |
17 # Reference genome mandatory | |
18 parser.add_argument('-f', '--fasta', help='Fasta file of the reference genome') | |
19 | |
20 # Output folder | |
21 parser.add_argument('-o', '--out', help='Name of the HTML summarizing the content of the JBrowse Hub') | |
22 | |
23 # GFF3 | |
24 parser.add_argument('--gff3', action='append', help='GFF3 format') | |
25 | |
26 # trfBig simple repeats (BED 4+12) | |
27 parser.add_argument('--bedSimpleRepeats', action='append', help='BED 4+12 format, using simpleRepeats.as') | |
28 | |
29 # regtools (BED 12+1) | |
30 parser.add_argument('--bedSpliceJunctions', action='append', help='BED 12+1 format, using spliceJunctions.as') | |
31 | |
32 # tblastn alignment (blastxml) | |
33 parser.add_argument('--blastxml', action='append', help='blastxml format from tblastn') | |
34 | |
35 # BAM format | |
36 parser.add_argument('--bam', action='append', help='BAM format from HISAT') | |
37 # put bam index file at the same directory with bam file | |
38 # parser.add_argument('--bai', action='append', help='BAM index format from HISAT') | |
39 | |
40 # BIGWIG format | |
41 parser.add_argument('--bigwig', action='append', help='BIGWIG format to show rnaseq coverage') | |
42 | |
43 # GTF format | |
44 parser.add_argument('--gtf', action='append', help='GTF format from StringTie') | |
45 | |
46 args = parser.parse_args() | |
47 all_datatype_dictionary = dict() | |
48 all_tracks = [] | |
49 | |
50 reference = args.fasta | |
51 out_path = args.out | |
52 tool_directory = 'JBrowse-1.12.1/bin' | |
53 chrom_size = utils.getChromSizes(reference, '../ucsc_tools_340_for_HAC') | |
54 array_inputs_bam = args.bam | |
55 array_inputs_bed_simple_repeats = args.bedSimpleRepeats | |
56 array_inputs_bed_splice_junctions = args.bedSpliceJunctions | |
57 array_inputs_bigwig = args.bigwig | |
58 array_inputs_gff3 = args.gff3 | |
59 array_inputs_gtf = args.gtf | |
60 array_inputs_blastxml = args.blastxml | |
61 if array_inputs_bam: | |
62 all_datatype_dictionary['bam'] = array_inputs_bam | |
63 if array_inputs_bed_simple_repeats: | |
64 all_datatype_dictionary['bedSimpleRepeats'] = array_inputs_bed_simple_repeats | |
65 if array_inputs_bed_splice_junctions: | |
66 all_datatype_dictionary['bedSpliceJunctions'] = array_inputs_bed_splice_junctions | |
67 if array_inputs_bigwig: | |
68 all_datatype_dictionary['bigwig'] = array_inputs_bigwig | |
69 if array_inputs_gff3: | |
70 all_datatype_dictionary['gff3'] = array_inputs_gff3 | |
71 if array_inputs_gtf: | |
72 all_datatype_dictionary['gtf'] = array_inputs_gtf | |
73 if array_inputs_blastxml: | |
74 all_datatype_dictionary['blastxml'] = array_inputs_blastxml | |
75 | |
76 print all_datatype_dictionary | |
77 | |
78 for datatype, inputfiles in all_datatype_dictionary.items(): | |
79 try: | |
80 user_input = inputfiles | |
81 if not user_input: | |
82 raise ValueError('empty input, must provide track files!\n') | |
83 except IOError: | |
84 print 'Cannot open', datatype | |
85 else: | |
86 for f in inputfiles: | |
87 track = trackObject.trackObject(f, datatype, chrom_size.name) | |
88 track.addToRaw() | |
89 all_tracks.append(track) | |
90 | |
91 jbrowseHub = TrackHub.TrackHub(all_tracks, reference, out_path, tool_directory) | |
92 jbrowseHub.createHub() | |
93 | |
94 | |
95 ''' | |
96 if reference: | |
97 p = subprocess.Popen(['JBrowse-1.12.1/bin/prepare-refseqs.pl', '--fasta', reference, '--out', out_path]) | |
98 # Wait for process to terminate. | |
99 p.communicate() | |
100 else: | |
101 parser.print_help() | |
102 | |
103 | |
104 if input_simple_repeats: | |
105 bedToGff3(input_simple_repeats, chrom_size, 'trfbig', 'repeats.gff3') | |
106 label = "repeats" | |
107 p = subprocess.Popen(['JBrowse-1.12.1/bin/flatfile-to-json.pl', '--gff', 'repeats.gff3', '--trackType', 'CanvasFeatures', '--trackLabel', label, '--out', out_path]) | |
108 p.communicate() | |
109 if input_splice_junctions: | |
110 bedToGff3(input_splice_junctions, chrom_size, 'regtools', 'regtools.gff3') | |
111 label = "regtools" | |
112 p = subprocess.Popen(['JBrowse-1.12.1/bin/flatfile-to-json.pl', '--gff', 'regtools.gff3', '--trackType', 'CanvasFeatures', '--trackLabel', label, '--out', out_path]) | |
113 p.communicate() | |
114 attr = dict() | |
115 track = dict() | |
116 attr['glyph'] = 'JBrowse/View/FeatureGlyph/Segments' | |
117 track['regtools'] = attr | |
118 json_file = os.path.join(out_path, "trackList.json") | |
119 utils.add_tracks_to_json(json_file, track, 'add_attr') | |
120 if blastxml: | |
121 blastxmlToGff3.blastxml2gff3(blastxml, "blast.gff3") | |
122 label = "blast" | |
123 p = subprocess.Popen(['JBrowse-1.12.1/bin/flatfile-to-json.pl', '--gff', 'blast.gff3', '--trackType', 'CanvasFeatures', '--trackLabel', label, '--out', out_path]) | |
124 p.communicate() | |
125 if array_inputs_gff3: | |
126 for gff3 in array_inputs_gff3: | |
127 label = os.path.basename(gff3) | |
128 label = label.replace('.', '_') | |
129 p = subprocess.Popen(['JBrowse-1.12.1/bin/flatfile-to-json.pl', '--gff', gff3, '--trackType', 'CanvasFeatures', '--trackLabel', label, '--out', out_path]) | |
130 p.communicate() | |
131 if 'Augustus' in label: | |
132 attr = dict() | |
133 track = dict() | |
134 attr['transcriptType'] = 'transcript' | |
135 track['Augustus'] = attr | |
136 json_file = os.path.join(out_path, "trackList.json") | |
137 utils.add_tracks_to_json(json_file, track, 'add_attr') | |
138 if bam: | |
139 json_file = os.path.join(out_path, "trackList.json") | |
140 bam_track = dict() | |
141 bam_track['type'] = 'JBrowse/View/Track/Alignments2' | |
142 bam_track['label'] = 'alignments' | |
143 bam_track['urlTemplate'] = '../raw/HISAT_on_data_3,_data_2,_and_data_1.bam' | |
144 utils.add_tracks_to_json(json_file, bam_track, 'add_tracks') | |
145 print "add bam track\n" | |
146 if bigwig: | |
147 json_file = os.path.join(out_path, "trackList.json") | |
148 bigwig_track = dict() | |
149 bigwig_track['label'] = 'rnaseq' | |
150 bigwig_track['key'] = 'RNA-Seq Coverage' | |
151 bigwig_track['urlTemplate'] = '../raw/Convert_Bam_to_BigWig_on_data_3_and_data_15.bigwig' | |
152 bigwig_track['type'] = 'JBrowse/View/Track/Wiggle/XYPlot' | |
153 bigwig_track['variance_band'] = True | |
154 bigwig_track['style'] = dict() | |
155 bigwig_track['style']['pos_color'] = '#FFA600' | |
156 bigwig_track['style']['neg_color'] = '#005EFF' | |
157 bigwig_track['style']['clip_marker_color'] = 'red' | |
158 bigwig_track['style']['height'] = 100 | |
159 utils.add_tracks_to_json(json_file, bigwig_track, 'add_tracks') | |
160 | |
161 if gtf: | |
162 utils.gtfToGff3(gtf, 'stringtie.gff3', chrom_size) | |
163 label = os.path.basename('stringtie') | |
164 p = subprocess.Popen(['JBrowse-1.12.1/bin/flatfile-to-json.pl', '--gff', 'stringtie.gff3', '--trackType', 'CanvasFeatures', '--trackLabel', label, '--out', out_path]) | |
165 p.communicate() | |
166 attr = dict() | |
167 track = dict() | |
168 attr['glyph'] = 'JBrowse/View/FeatureGlyph/Segments' | |
169 track['stringtie'] = attr | |
170 json_file = os.path.join(out_path, "trackList.json") | |
171 utils.add_tracks_to_json(json_file, track, 'add_attr') | |
172 | |
173 # Index name, it takes a long time, exclude it for now | |
174 p = subprocess.Popen(['JBrowse-1.12.1/bin/generate-names.pl', '-v', '--out', out_path]) | |
175 p.communicate() | |
176 print "finished name index \n" | |
177 ''' | |
178 | |
179 if __name__ == "__main__": | |
180 main(sys.argv) | |
181 |