diff trackHub/tracks_partial.py @ 16:3233451a3bd6 draft

planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit fc73ec22a0db3ab09c4ac13dc58f0b54ae37845c
author rmarenco
date Sun, 25 Sep 2016 11:25:38 -0400
parents fb5e60d4d18a
children
line wrap: on
line diff
--- a/trackHub/tracks_partial.py	Fri Sep 02 15:41:51 2016 -0400
+++ b/trackHub/tracks_partial.py	Sun Sep 25 11:25:38 2016 -0400
@@ -31,11 +31,42 @@
             '<html><head><title>Files for Composite Dataset (%s)</title></head><p/>\
             This composite dataset is composed of the following files:<p/><ul>' % (
                 self.file_ext)]
-        for composite_name, composite_file in self.get_composite_files(dataset=dataset).iteritems():
-            opt_text = ''
-            if composite_file.optional:
-                opt_text = ' (optional)'
-            rval.append('<li><a href="%s">%s</a>%s' % (composite_name, composite_name, opt_text))
+
+        def create_tree(path, tree):
+            if path[0] in tree:
+                create_tree(path[1:], tree[path[0]])
+            else:
+                tree[path[0]] = {}
+                if len(path) == 1:
+                    return
+                else:
+                    create_tree(path[1:], tree[path[0]])
+
+        def print_tree(tree, level):
+            if len(tree) == 0:
+                return
+
+            for vertex in tree:
+                    composite_name = vertex
+                    bullet_point = '<li><a href="{0}>{0}</a></li>'.format(composite_name)
+                    rval.append(bullet_point)
+                    # Parent, so need to create a sub <ul>
+                    if len(tree[vertex]) > 0:
+                        rval.append('<ul>')
+                        print_tree(tree[vertex], level+1)
+                        rval.append('</ul>')
+
+        walkable_tree = {}
+
+        for composite_name_full_path, composite_file in self.get_composite_files(dataset=dataset).iteritems():
+            paths = composite_name_full_path.split('/')
+            # Prepare the tree from to perform a Depth First Search
+            create_tree(paths, walkable_tree)
+
+        # Perform a Depth First Search to print all the directory and files properly
+        print_tree(walkable_tree, 0)
+
+        # rval.append('<li><a href="%s">%s</a>%s' % (composite_name, composite_name, opt_text))
         rval.append('</ul></html>')
         return "\n".join(rval)