Mercurial > repos > yating-l > hubarchivecreatortest
annotate trackHub/tracks_partial.py @ 3:fa990284327b draft default tip
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit ac73da32d59853ca563e7939d05016a6f3a6899e-dirty
| author | yating-l | 
|---|---|
| date | Mon, 30 Oct 2017 11:58:31 -0400 | 
| parents | 85195e0d4b71 | 
| children | 
| rev | line source | 
|---|---|
| 1 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 1 """ | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 2 HubAssembly datatype | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 3 """ | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 4 import logging | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 5 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 6 from galaxy.datatypes.text import Html | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 7 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 8 log = logging.getLogger( __name__ ) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 9 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 10 # !!! README !!! The content of this file should be added in tracks.py, but do it carefully! | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 11 # Don't erase the existing content | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 12 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 13 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 14 class UCSCTrackHub( Html ): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 15 """ | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 16 derived class for BioC data structures in Galaxy | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 17 """ | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 18 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 19 file_ext = 'trackhub' | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 20 composite_type = 'auto_primary_file' | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 21 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 22 def __init__( self, **kwd ): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 23 Html.__init__( self, **kwd ) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 24 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 25 def generate_primary_file( self, dataset=None ): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 26 """ | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 27 This is called only at upload to write the html file | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 28 cannot rename the datasets here - they come with the default unfortunately | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 29 """ | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 30 rval = [ | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 31 '<html><head><title>Files for Composite Dataset (%s)</title></head><p/>\ | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 32 This composite dataset is composed of the following files:<p/><ul>' % ( | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 33 self.file_ext)] | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 34 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 35 def create_tree(path, tree): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 36 if path[0] in tree: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 37 create_tree(path[1:], tree[path[0]]) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 38 else: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 39 tree[path[0]] = {} | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 40 if len(path) == 1: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 41 return | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 42 else: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 43 create_tree(path[1:], tree[path[0]]) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 44 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 45 def print_tree(tree, level): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 46 if len(tree) == 0: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 47 return | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 48 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 49 for vertex in tree: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 50 composite_name = vertex | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 51 bullet_point = '<li><a href="{0}>{0}</a></li>'.format(composite_name) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 52 rval.append(bullet_point) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 53 # Parent, so need to create a sub <ul> | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 54 if len(tree[vertex]) > 0: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 55 rval.append('<ul>') | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 56 print_tree(tree[vertex], level+1) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 57 rval.append('</ul>') | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 58 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 59 walkable_tree = {} | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 60 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 61 for composite_name_full_path, composite_file in self.get_composite_files(dataset=dataset).iteritems(): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 62 paths = composite_name_full_path.split('/') | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 63 # Prepare the tree from to perform a Depth First Search | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 64 create_tree(paths, walkable_tree) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 65 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 66 # Perform a Depth First Search to print all the directory and files properly | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 67 print_tree(walkable_tree, 0) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 68 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 69 # rval.append('<li><a href="%s">%s</a>%s' % (composite_name, composite_name, opt_text)) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 70 rval.append('</ul></html>') | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 71 return "\n".join(rval) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 72 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 73 def set_peek( self, dataset, is_multi_byte=False ): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 74 if not dataset.dataset.purged: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 75 dataset.peek = "Track Hub structure: Visualization in UCSC Track Hub" | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 76 else: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 77 dataset.peek = 'file does not exist' | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 78 dataset.blurb = 'file purged from disk' | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 79 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 80 def display_peek( self, dataset ): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 81 try: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 82 return dataset.peek | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 83 except: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 84 return "Track Hub structure: Visualization in UCSC Track Hub" | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 85 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 86 def sniff( self, filename ): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 87 return False | 
