comparison trackHub/tracks_partial.py @ 0:f493979f1408 draft default tip

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