annotate TrackHub.py @ 49:193e94a43f0f draft

planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
author yating-l
date Wed, 29 Mar 2017 14:46:23 -0400
parents 6803152ea92a
children 3e5b6f6a9abe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
1 #!/usr/bin/env python
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
2
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
3 import os
31
d8049deb0c97 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit faeedda55e23f1197bc454d3db2d52af29d786e8-dirty
yating-l
parents: 26
diff changeset
4 import subprocess
d8049deb0c97 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit faeedda55e23f1197bc454d3db2d52af29d786e8-dirty
yating-l
parents: 26
diff changeset
5 import shutil
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
6 import utils
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
7
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
8
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
9 class TrackHub:
42
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
10 def __init__(self, inputFiles, reference, outputDirect, tool_dir, genome, extra_files_path, metaData):
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
11 self.input_files = inputFiles.tracks
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
12 self.outfile = outputDirect
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
13 self.outfolder = extra_files_path
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
14 self.out_path = os.path.join(extra_files_path, genome)
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
15 self.reference = reference
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
16 self.tool_dir = tool_dir
42
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
17 self.metaData = metaData
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
18 self.raw = os.path.join(self.out_path, 'raw')
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
19 self.json = os.path.join(self.out_path, 'json')
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
20 try:
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
21 if os.path.exists(self.json):
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
22 shutil.rmtree(self.json)
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
23 os.makedirs(self.json)
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
24 except OSError as e:
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
25 print "Cannot create json folder error({0}): {1}".format(e.errno, e.strerror)
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
26 else:
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
27 print "Create jbrowse folder {}".format(self.out_path)
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
28
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
29 def createHub(self):
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
30 self.prepareRefseq()
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
31 for input_file in self.input_files:
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
32 self.addTrack(input_file)
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
33 self.indexName()
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
34 self.makeArchive()
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
35 self.outHtml()
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
36 print "Success!\n"
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
37
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
38 def prepareRefseq(self):
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
39 try:
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
40 #print os.path.join(self.tool_dir, 'prepare-refseqs.pl') + ", '--fasta', " + self.reference +", '--out', self.json])"
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
41 p = subprocess.Popen(['prepare-refseqs.pl', '--fasta', self.reference, '--out', self.json])
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
42 # Wait for process to terminate.
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
43 p.communicate()
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
44 except OSError as e:
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
45 print "Cannot prepare reference error({0}): {1}".format(e.errno, e.strerror)
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
46 #TODO: hard coded the bam and bigwig tracks. Need to allow users to customize the settings
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
47 def addTrack(self, track):
45
15b4a74722d1 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 73ede51a133dc8914812195a1b4cd512bfb8f23d
yating-l
parents: 44
diff changeset
48 #print "false_path" , track['false_path']
42
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
49 if track['false_path'] in self.metaData.keys():
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
50 metadata = self.metaData[track['false_path']]
39
75edbc203532 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit faeedda55e23f1197bc454d3db2d52af29d786e8-dirty
yating-l
parents: 37
diff changeset
51 else:
42
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
52 metadata = {}
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
53 self.SetMetadata(track, metadata)
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
54 if track['dataType'] == 'bam':
42
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
55 self.Bam(track, metadata)
37
046c5bfc0413 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit faeedda55e23f1197bc454d3db2d52af29d786e8-dirty
yating-l
parents: 31
diff changeset
56 # print "add bam track\n"
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
57 elif track['dataType'] == 'bigwig':
42
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
58 self.BigWig(track, metadata)
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
59 else:
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
60 gff3_file = os.path.join(self.raw, track['fileName'])
45
15b4a74722d1 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 73ede51a133dc8914812195a1b4cd512bfb8f23d
yating-l
parents: 44
diff changeset
61 if track['dataType'] == 'bedSpliceJunctions' or track['dataType'] == 'gtf' or track['dataType'] == 'blastxml':
42
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
62 p = subprocess.Popen(['flatfile-to-json.pl', '--gff', gff3_file, '--trackType', metadata['type'], '--trackLabel', metadata['label'], '--Config', '{"glyph": "JBrowse/View/FeatureGlyph/Segments", "category" : "%s"}' % metadata['category'], '--clientConfig', '{"color" : "%s"}' % metadata['color'], '--out', self.json])
12
e1f188b43750 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 5
diff changeset
63 elif track['dataType'] == 'gff3_transcript':
42
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
64 p = subprocess.Popen(['flatfile-to-json.pl', '--gff', gff3_file, '--trackType', metadata['type'], '--trackLabel', metadata['label'], '--Config', '{"transcriptType": "transcript", "category" : "%s"}' % metadata['category'], '--clientConfig', '{"color" : "%s"}' % metadata['color'], '--out', self.json])
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
65 else:
42
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
66 p = subprocess.Popen(['flatfile-to-json.pl', '--gff', gff3_file, '--trackType', metadata['type'], '--trackLabel', metadata['label'], '--Config', '{"category" : "%s"}' % metadata['category'], '--clientConfig', '{"color" : "%s"}' % metadata['color'], '--out', self.json])
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
67 p.communicate()
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
68
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
69 def indexName(self):
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
70 p = subprocess.Popen(['generate-names.pl', '-v', '--out', self.json])
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
71 p.communicate()
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
72 print "finished name index \n"
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
73
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
74 def makeArchive(self):
49
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
75 shutil.make_archive(self.out_path, 'zip', self.out_path)
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
76 data_folder = '/var/www/html/JBrowse-1.12.1/jbrowse_hub'
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
77 try:
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
78 if os.path.exists(data_folder):
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
79 if os.path.isdir(data_folder):
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
80 shutil.rmtree(data_folder)
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
81 else:
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
82 os.remove(data_folder)
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
83 except OSError as oserror:
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
84 print "Cannot create data folder({0}): {1}".format(oserror.errno, oserror.strerror)
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
85 shutil.copytree(self.out_path, data_folder)
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
86 p = subprocess.Popen(['chmod', '-R', 'o+rx', '/var/www/html/JBrowse-1.12.1/jbrowse_hub'])
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
87 p.communicate()
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
88 shutil.rmtree(self.out_path)
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
89
15
8627394693c6 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 12
diff changeset
90 #TODO: this will list all zip files in the filedir and sub-dirs. worked in Galaxy but all list zip files in test-data when
8627394693c6 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 12
diff changeset
91 #run it locally. May need modify
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
92 def outHtml(self):
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
93 with open(self.outfile, 'w') as htmlfile:
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
94 htmlstr = 'The JBrowse Hub is created: <br>'
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
95 zipfiles = '<li><a href = "%s">Download</a></li>'
49
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
96 jbrowse_hub = '<li><a href = "http://192.168.56.11/JBrowse-1.12.1/index.html?data=jbrowse_hub/json" target="_blank">View JBrowse Hub</a></li>'
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
97 filedir_abs = os.path.abspath(self.outfile)
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
98 filedir = os.path.dirname(filedir_abs)
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
99 filedir = os.path.join(filedir, self.outfolder)
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
100 for root, dirs, files in os.walk(filedir):
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
101 for file in files:
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
102 if file.endswith('.zip'):
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
103 relative_directory = os.path.relpath(root, filedir)
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
104 relative_file_path = os.path.join(relative_directory, file)
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
105 htmlstr += zipfiles % relative_file_path
49
193e94a43f0f planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 88aa9133c8eccdb21dbc755eb9643c9e7b09449e-dirty
yating-l
parents: 48
diff changeset
106 htmlstr += jbrowse_hub
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
107 htmlfile.write(htmlstr)
0
e4f3f2ed4fa5 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff changeset
108
26
a4a54b925c73 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit e81fecac281f299db00cfc88a068e056b031ae9d-dirty
yating-l
parents: 25
diff changeset
109 def createTrackList(self):
a4a54b925c73 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit e81fecac281f299db00cfc88a068e056b031ae9d-dirty
yating-l
parents: 25
diff changeset
110 trackList = os.path.join(self.json, "trackList.json")
a4a54b925c73 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit e81fecac281f299db00cfc88a068e056b031ae9d-dirty
yating-l
parents: 25
diff changeset
111 if not os.path.exists(trackList):
a4a54b925c73 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit e81fecac281f299db00cfc88a068e056b031ae9d-dirty
yating-l
parents: 25
diff changeset
112 os.mknod(trackList)
42
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
113
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
114 def Bam(self, track, metadata):
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
115 #create trackList.json if not exist
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
116 self.createTrackList()
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
117 json_file = os.path.join(self.json, "trackList.json")
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
118 bam_track = dict()
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
119 bam_track['type'] = 'JBrowse/View/Track/Alignments2'
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
120 bam_track['storeClass'] = 'JBrowse/Store/SeqFeature/BAM'
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
121 bam_track['urlTemplate'] = os.path.join('../raw', track['fileName'])
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
122 bam_track['baiUrlTemplate'] = os.path.join('../raw', track['index'])
44
37422f705e9b planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 42
diff changeset
123 bam_track['label'] = metadata['label']
37422f705e9b planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 42
diff changeset
124 bam_track['category'] = metadata['category']
42
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
125 utils.add_tracks_to_json(json_file, bam_track, 'add_tracks')
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
126
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
127 def BigWig(self, track, metadata):
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
128 #create trackList.json if not exist
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
129 self.createTrackList()
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
130 json_file = os.path.join(self.json, "trackList.json")
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
131 bigwig_track = dict()
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
132 bigwig_track['urlTemplate'] = os.path.join('../raw', track['fileName'])
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
133 bigwig_track['type'] = 'JBrowse/View/Track/Wiggle/XYPlot'
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
134 bigwig_track['storeClass'] = 'JBrowse/Store/SeqFeature/BigWig'
44
37422f705e9b planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 42
diff changeset
135 bigwig_track['label'] = metadata['label']
37422f705e9b planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 42
diff changeset
136 bigwig_track['style'] = metadata['style']
37422f705e9b planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 42
diff changeset
137 bigwig_track['category'] = metadata['category']
42
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
138 utils.add_tracks_to_json(json_file, bigwig_track, 'add_tracks')
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
139
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
140 #If the metadata is not set, use the default value
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
141 def SetMetadata(self, track, metadata):
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
142 if 'label' not in metadata.keys() or metadata['label'] == '':
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
143 metadata['label'] = track['fileName']
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
144 if 'color' not in metadata.keys() or metadata['color'] == '':
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
145 metadata['color'] = "#daa520"
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
146 if track['dataType'] == 'bigwig':
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
147 if 'style' not in metadata.keys():
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
148 metadata['style'] = {}
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
149 if 'pos_color' not in metadata['style'] or metadata['style']['pos_color'] == '':
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
150 metadata['pos_color'] = "#FFA600"
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
151 if 'neg_color' not in metadata['style'] or metadata['style']['neg_color'] == '':
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
152 metadata['neg_color'] = "#005EFF"
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
153 if 'category' not in metadata.keys() or metadata['category'] == '':
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
154 metadata['category'] = "Default group"
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
155 if track['dataType'] == 'blastxml':
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
156 metadata['type'] = "G-OnRamp_plugin/BlastAlignment"
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
157 elif track['dataType'] == 'gff3_transcript' or track['dataType'] == 'gff3_mrna':
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
158 metadata['type'] = "G-OnRamp_plugin/GenePred"
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
159 else:
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
160 metadata['type'] = "CanvasFeatures"
a5108e5010b4 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 149c5cbda82f49f260767b5710f0c2160eebc881-dirty
yating-l
parents: 39
diff changeset
161
31
d8049deb0c97 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit faeedda55e23f1197bc454d3db2d52af29d786e8-dirty
yating-l
parents: 26
diff changeset
162
26
a4a54b925c73 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit e81fecac281f299db00cfc88a068e056b031ae9d-dirty
yating-l
parents: 25
diff changeset
163
5
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
164
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
165
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
166
e7c80e9b70ae planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents: 0
diff changeset
167