annotate pplacer.py @ 7:b6ece07bec6a draft

planemo upload commit 45906ba522c7c319067e93d5cd5d7161223c3336
author bcclaywell
date Mon, 12 Oct 2015 15:59:59 -0400
parents d4690e65afcd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
1 import json
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
2 from galaxy.datatypes.data import Text
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
3 from galaxy.datatypes.images import Html
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
4
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
5 class Jplace(Text):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
6 file_ext = "jplace"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
7
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
8 def sniff(self, filename):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
9 try:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
10 with open(filename, "r") as f:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
11 data = json.load(f)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
12 if all (k in data for k in ("version", "tree", "placements", "fields")):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
13 return True
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
14 except:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
15 pass
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
16
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
17 return False
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
18
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
19 def get_mime(self):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
20 return "application/json"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
21
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
22 class AutoPrimaryComposite(Html):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
23 composite_type = "auto_primary_file"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
24
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
25 def __init__(self, **kwd):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
26 Html.__init__(self, **kwd)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
27
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
28 def regenerate_primary_file(self,dataset):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
29 """
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
30 cannot do this until we are setting metadata
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
31 """
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
32 bn = dataset.metadata.base_name
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
33 efp = dataset.extra_files_path
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
34 flist = os.listdir(efp)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
35 rval = ['<html><head><title>Files for Composite Dataset %s</title></head><body><p/>Composite %s contains:<p/><ul>' % (dataset.name,dataset.name)]
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
36 for i,fname in enumerate(flist):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
37 sfname = os.path.split(fname)[-1]
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
38 f,e = os.path.splitext(fname)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
39 rval.append( '<li><a href="%s">%s</a></li>' % ( sfname, sfname) )
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
40 rval.append( '</ul></body></html>' )
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
41 f = file(dataset.file_name,'w')
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
42 f.write("\n".join( rval ))
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
43 f.write('\n')
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
44 f.close()
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
45
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
46 def set_meta(self, dataset, **kwd):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
47 Html.set_meta(self, dataset, **kwd)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
48 self.regenerate_primary_file(dataset)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
49
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
50 def get_mime(self):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
51 return "text/html"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
52
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
53 class BasicHtmlComposite(Html):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
54 composite_type = "basic"