comparison gd_composite.py @ 0:2c498d40ecde

Uploaded
author miller-lab
date Mon, 09 Apr 2012 12:03:06 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:2c498d40ecde
1 #!/usr/bin/env python
2
3 from galaxy import eggs
4 import pkg_resources
5 pkg_resources.require( "Cheetah" )
6 from Cheetah.Template import Template
7
8 import errno
9 import os
10 from datetime import datetime
11
12 ################################################################################
13
14 def die(message):
15 print >> sys.stderr, message
16 sys.exit(1)
17
18 def mkdir_p(path):
19 try:
20 os.makedirs(path)
21 except OSError, e:
22 if e.errno <> errno.EEXIST:
23 raise
24
25 ################################################################################
26
27 class Display(object):
28 def display(self, parameter):
29 print parameter
30
31 class DisplayFile(Display):
32 def display(self, parameter):
33 return '<a href="{0}">{1}</a>'.format(parameter.value, parameter.name)
34
35 class DisplayValue(Display):
36 def display(self, parameter):
37 if parameter.value is not None:
38 return '{0}: {1}'.format(parameter.description, parameter.value)
39 else:
40 return '{0}'.format(parameter.description)
41
42 class DisplayTagList(Display):
43 def display(self, parameter):
44 rv = []
45 if parameter.name:
46 rv.append(parameter.name)
47 rv.append('<ol>')
48 for tag in parameter.value:
49 col, individual_name = tag.split(':')
50 rv.append('<li>{0}</li>'.format(individual_name))
51 rv.append('</ol>')
52 return '\n'.join(rv)
53
54 class DisplayPopulationList(Display):
55 def display(self, parameter):
56 rv = []
57 rv.append('Populations')
58 rv.append('<ul>')
59 for population in parameter.value:
60 rv.append('<li>')
61 if population.name is not None:
62 rv.append(population.name)
63 rv.append('<ol>')
64 for name in population.individual_names():
65 rv.append('<li>{0}</li>'.format(name))
66 rv.append('</ol>')
67 rv.append('</li>')
68 rv.append('</ul>')
69 return '\n'.join(rv)
70
71 # def display(self, parameter, name=''):
72 # print '<ul> {0}'.format(name)
73 # for individual_name in parameter.individual_names():
74 # print '<li>{0}>/li>'.format(individual_name)
75 # print '</ul>'
76
77
78 class Parameter(object):
79 def __init__(self, name=None, value=None, description=None, display_type=None):
80 self.name = name
81 self.value = value
82 self.description = description
83 if display_type is None:
84 self.display_type = Display()
85 else:
86 self.display_type = display_type
87
88 def display(self):
89 return self.display_type.display(self)
90
91 class InfoPage(object):
92 _realpath = os.path.realpath(__file__)
93 _script_dir = os.path.dirname(_realpath)
94 template_file = os.path.join(_script_dir, 'gd_composite_template.html')
95 def __init__(self):
96 self.timestamp = datetime.now().strftime('%Y-%m-%d %I:%M:%S %p')
97 self.title = 'Genome Diversity Composite Dataset'
98 self.inputs = []
99 self.outputs = []
100 self.misc = ''
101 self.template = self.load_template()
102
103 def load_template(self):
104 with open(self.template_file) as f:
105 return f.read().rstrip('\r\n')
106
107 def set_title(self, title):
108 self.title = title
109
110 def add_input_parameter(self, parameter):
111 self.inputs.append(parameter)
112
113 def add_output_parameter(self, parameter):
114 self.outputs.append(parameter)
115
116 def add_misc(self, misc):
117 self.misc = misc
118
119 def render(self):
120 return Template(self.template, searchList=[{'tool': self}])
121
122
123
124
125
126
127
128