comparison TrackHub.py @ 3:eda851e52060 draft

planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 479fc6490e24ca0e5034ae6c3579882e97e095e6-dirty
author yating-l
date Wed, 31 May 2017 15:45:47 -0400
parents 25ad6770359e
children 7e471cdd9e71
comparison
equal deleted inserted replaced
2:25ad6770359e 3:eda851e52060
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import os 3 import os
4 import subprocess 4 import subprocess
5 import shutil 5 import shutil
6 import zipfile
6 import json 7 import json
7 import utils 8 import utils
8 9
9 10
10 class TrackHub: 11 class TrackHub:
70 def indexName(self): 71 def indexName(self):
71 subprocess.call(['generate-names.pl', '-v', '--out', self.json]) 72 subprocess.call(['generate-names.pl', '-v', '--out', self.json])
72 print "finished name index \n" 73 print "finished name index \n"
73 74
74 def makeArchive(self): 75 def makeArchive(self):
75 shutil.make_archive(self.out_path, 'zip', self.out_path)
76 file_dir = os.path.abspath(self.outfile) 76 file_dir = os.path.abspath(self.outfile)
77 source_dir = os.path.dirname(file_dir) 77 source_dir = os.path.dirname(file_dir)
78 folder_name = os.path.basename(self.outfolder) 78 folder_name = os.path.basename(self.outfolder)
79 source_name = os.path.basename(self.out_path) 79 source_name = os.path.basename(self.out_path)
80 source = os.path.join(source_dir, folder_name, source_name) 80 source = os.path.join(source_dir, folder_name, source_name)
86 except OSError as oserror: 86 except OSError as oserror:
87 print "Cannot create symlink to the data({0}): {1}".format(oserror.errno, oserror.strerror) 87 print "Cannot create symlink to the data({0}): {1}".format(oserror.errno, oserror.strerror)
88 os.symlink(source, slink) 88 os.symlink(source, slink)
89 return slink 89 return slink
90 90
91 #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
92 #run it locally. May need modify
93 def outHtml(self, slink): 91 def outHtml(self, slink):
94 with open(self.outfile, 'w') as htmlfile: 92 with open(self.outfile, 'w') as htmlfile:
95 htmlstr = 'The JBrowse Hub is created: <br>' 93 htmlstr = 'The JBrowse Hub is created: <br>'
96 zipfiles = '<li><a href = "%s">Download</a></li>'
97 url = self.jbrowse_host + "/JBrowse-1.12.1/index.html?data=%s" 94 url = self.jbrowse_host + "/JBrowse-1.12.1/index.html?data=%s"
98 jbrowse_hub = '<li><a href = "%s" target="_blank">View JBrowse Hub</a></li>' % url 95 jbrowse_hub = '<li><a href = "%s" target="_blank">View JBrowse Hub</a></li>' % url
99 filedir_abs = os.path.abspath(self.outfile)
100 filedir = os.path.dirname(filedir_abs)
101 filedir = os.path.join(filedir, self.outfolder)
102 for root, dirs, files in os.walk(filedir):
103 for file in files:
104 if file.endswith('.zip'):
105 relative_directory = os.path.relpath(root, filedir)
106 relative_file_path = os.path.join(relative_directory, file)
107 htmlstr += zipfiles % relative_file_path
108 link_name = os.path.basename(slink) 96 link_name = os.path.basename(slink)
109 relative_path = os.path.join('data', link_name + '/json') 97 relative_path = os.path.join('data', link_name + '/json')
110 htmlstr += jbrowse_hub % relative_path 98 htmlstr += jbrowse_hub % relative_path
111 htmlfile.write(htmlstr) 99 htmlfile.write(htmlstr)
112 100