Mercurial > repos > kevyin > homer
comparison homerDatatypes.py @ 2:7268cbc535e5 draft
findpeaks and maketagdirectory
author | kevyin |
---|---|
date | Fri, 23 Nov 2012 00:30:27 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:59d58008c40d | 2:7268cbc535e5 |
---|---|
1 """ | |
2 homer composite datatypes | |
3 Use at your peril | |
4 Kevin Ying | |
5 for the homer wrapper | |
6 | |
7 Nov 2012 | |
8 """ | |
9 | |
10 import logging, os, sys, time, tempfile, shutil, string, glob | |
11 import data | |
12 from galaxy import util | |
13 from cgi import escape | |
14 import urllib, binascii | |
15 from galaxy.web import url_for | |
16 from galaxy.datatypes import metadata | |
17 from galaxy.datatypes.metadata import MetadataElement | |
18 from galaxy.datatypes.data import Text | |
19 from galaxy.datatypes.tabular import Tabular | |
20 from galaxy.datatypes.images import Html | |
21 from galaxy.datatypes.interval import Interval | |
22 from galaxy.util.hash_util import * | |
23 | |
24 gal_Log = logging.getLogger(__name__) | |
25 verbose = False | |
26 | |
27 class HomerTagDirectory(Html): | |
28 """ | |
29 base class to use for homer tag directory datatypes | |
30 composite datatype elements | |
31 stored in extra files path | |
32 """ | |
33 | |
34 #MetadataElement( name="base_name", desc="base name for all transformed versions of this genetic dataset", default='HomerTagDirectory', | |
35 #readonly=True, set_in_upload=False) | |
36 | |
37 composite_type = 'auto_primary_file' | |
38 #allow_datatype_change = False | |
39 file_ext = 'homerTagDirectory' | |
40 | |
41 def __init__(self, **kwd): | |
42 Html.__init__(self, **kwd) | |
43 self.add_composite_file('tagInfo.txt', description="tagInfo") | |
44 self.add_composite_file('tagAutocorrelation.txt', description="tagAutocorrelation") | |
45 self.add_composite_file('tagCountDistribution.txt', description="tagCountDistribution") | |
46 self.add_composite_file('tagLengthDistribution.txt', description="tagLengthDistribution") | |
47 | |
48 def generate_primary_file(self, dataset=None): | |
49 rval = ['<html><head><title>Homer Tag Directory Galaxy Composite Dataset </title></head><p/>'] | |
50 rval.append('<div>This composite dataset is composed of the following files:<p/><ul>') | |
51 for composite_name, composite_file in self.get_composite_files( dataset = dataset ).iteritems(): | |
52 fn = composite_name | |
53 opt_text = '' | |
54 if composite_file.optional: | |
55 opt_text = ' (optional)' | |
56 if composite_file.get('description'): | |
57 rval.append( '<li><a href="%s" type="application/binary">%s (%s)</a>%s</li>' % ( fn, fn, composite_file.get('description'), opt_text ) ) | |
58 else: | |
59 rval.append( '<li><a href="%s" type="application/binary">%s</a>%s</li>' % ( fn, fn, opt_text ) ) | |
60 rval.append( '</ul></div></html>' ) | |
61 return "\n".join( rval ) | |
62 | |
63 | |
64 def regenerate_primary_file(self,dataset): | |
65 """ | |
66 cannot do this until we are setting metadata | |
67 """ | |
68 #bn = dataset.metadata.base_name | |
69 efp = dataset.extra_files_path | |
70 flist = os.listdir(efp) | |
71 rval = ['<html><head><title>Files for Composite Dataset %s</title></head><body><p/>Composite %s contains:<p/><ul>' % (dataset.name,dataset.name)] | |
72 for i,fname in enumerate(flist): | |
73 sfname = os.path.split(fname)[-1] | |
74 f,e = os.path.splitext(fname) | |
75 rval.append( '<li><a href="%s">%s</a></li>' % ( sfname, sfname) ) | |
76 rval.append( '</ul></body></html>' ) | |
77 f = file(dataset.file_name,'w') | |
78 f.write("\n".join( rval )) | |
79 f.write('\n') | |
80 f.close() | |
81 | |
82 def get_mime(self): | |
83 """Returns the mime type of the datatype""" | |
84 return 'text/html' | |
85 | |
86 def set_meta( self, dataset, **kwd ): | |
87 | |
88 """ | |
89 for homer maketagdirectory eg | |
90 | |
91 """ | |
92 Html.set_meta( self, dataset, **kwd ) | |
93 if kwd.get('overwrite') == False: | |
94 if verbose: | |
95 gal_Log.debug('@@@ HomerTagDirectory set_meta called with overwrite = False') | |
96 return True | |
97 try: | |
98 efp = dataset.extra_files_path | |
99 except: | |
100 if verbose: | |
101 gal_Log.debug('@@@ HomerTagDirectory set_meta failed %s - dataset %s has no efp ?' % (sys.exc_info()[0], dataset.name)) | |
102 return False | |
103 try: | |
104 flist = os.listdir(efp) | |
105 except: | |
106 if verbose: gal_Log.debug('@@@ HomerTagDirectory set_meta failed %s - dataset %s has no efp ?' % (sys.exc_info()[0],dataset.name)) | |
107 return False | |
108 if len(flist) == 0: | |
109 if verbose: | |
110 gal_Log.debug('@@@ HomerTagDirectory set_meta failed - %s efp %s is empty?' % (dataset.name,efp)) | |
111 return False | |
112 self.regenerate_primary_file(dataset) | |
113 if not dataset.info: | |
114 dataset.info = 'Galaxy HomerTagDirectory datatype object' | |
115 if not dataset.blurb: | |
116 dataset.blurb = 'Composite file - Homer Galaxy toolkit' | |
117 return True | |
118 |