Mercurial > repos > yating-l > jbrowsearchivecreator
comparison TrackHub.py @ 11:45b5cb50c29e 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:42:51 -0400 |
parents | 91b3558fa73f |
children | cdc32923786d |
comparison
equal
deleted
inserted
replaced
10:91b3558fa73f | 11:45b5cb50c29e |
---|---|
71 def indexName(self): | 71 def indexName(self): |
72 subprocess.call(['generate-names.pl', '-v', '--out', self.json]) | 72 subprocess.call(['generate-names.pl', '-v', '--out', self.json]) |
73 print "finished name index \n" | 73 print "finished name index \n" |
74 | 74 |
75 def makeArchive(self): | 75 def makeArchive(self): |
76 #shutil.make_archive(self.out_path, 'zip', self.out_path) | |
77 os.chdir(os.path.dirname(self.out_path)) | |
78 with zipfile.ZipFile(self.out_path + '.zip', 'w', zipfile.ZIP_DEFLATED, allowZip64=True) as zf: | |
79 for root, _, filenames in os.walk(os.path.basename(self.out_path)): | |
80 for name in filenames: | |
81 name = os.path.join(root, name) | |
82 name = os.path.normpath(name) | |
83 zf.write(name, name) | |
84 file_dir = os.path.abspath(self.outfile) | 76 file_dir = os.path.abspath(self.outfile) |
85 source_dir = os.path.dirname(file_dir) | 77 source_dir = os.path.dirname(file_dir) |
86 folder_name = os.path.basename(self.outfolder) | 78 folder_name = os.path.basename(self.outfolder) |
87 source_name = os.path.basename(self.out_path) | 79 source_name = os.path.basename(self.out_path) |
88 source = os.path.join(source_dir, folder_name, source_name) | 80 source = os.path.join(source_dir, folder_name, source_name) |
94 except OSError as oserror: | 86 except OSError as oserror: |
95 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) |
96 os.symlink(source, slink) | 88 os.symlink(source, slink) |
97 return slink | 89 return slink |
98 | 90 |
99 #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 | |
100 #run it locally. May need modify | |
101 def outHtml(self, slink): | 91 def outHtml(self, slink): |
102 with open(self.outfile, 'w') as htmlfile: | 92 with open(self.outfile, 'w') as htmlfile: |
103 htmlstr = 'The JBrowse Hub is created: <br>' | 93 htmlstr = 'The JBrowse Hub is created: <br>' |
104 zipfiles = '<li><a href = "%s">Download</a></li>' | |
105 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" |
106 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 |
107 filedir_abs = os.path.abspath(self.outfile) | |
108 filedir = os.path.dirname(filedir_abs) | |
109 filedir = os.path.join(filedir, self.outfolder) | |
110 for root, dirs, files in os.walk(filedir): | |
111 for file in files: | |
112 if file.endswith('.zip'): | |
113 relative_directory = os.path.relpath(root, filedir) | |
114 relative_file_path = os.path.join(relative_directory, file) | |
115 htmlstr += zipfiles % relative_file_path | |
116 link_name = os.path.basename(slink) | 96 link_name = os.path.basename(slink) |
117 relative_path = os.path.join('data', link_name + '/json') | 97 relative_path = os.path.join('data', link_name + '/json') |
118 htmlstr += jbrowse_hub % relative_path | 98 htmlstr += jbrowse_hub % relative_path |
119 htmlfile.write(htmlstr) | 99 htmlfile.write(htmlstr) |
120 | 100 |