annotate gd_composite.py @ 27:8997f2ca8c7a

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