comparison cuffdata.py @ 0:da7241f92ecf

Uploaded
author jjohnson
date Mon, 04 Feb 2013 19:50:25 -0500
parents
children 137aab1d9ac1
comparison
equal deleted inserted replaced
-1:000000000000 0:da7241f92ecf
1 """
2 CuffData
3 """
4 import logging
5 import os,os.path,re
6 import galaxy.datatypes.data
7 from galaxy.datatypes.images import Html
8 from galaxy.datatypes.binary import Binary
9 from galaxy import util
10 from galaxy.datatypes.metadata import MetadataElement
11
12 log = logging.getLogger(__name__)
13
14 class CuffDiffData( Html ):
15 """
16 CuffDiff output files:
17 run.info
18 read_groups.info
19 cds.count_tracking
20 cds.diff
21 cds.fpkm_tracking
22 cds.read_group_tracking
23 cds_exp.diff
24 gene_exp.diff
25 genes.count_tracking
26 genes.fpkm_tracking
27 genes.read_group_tracking
28 isoform_exp.diff
29 isoforms.count_tracking
30 isoforms.fpkm_tracking
31 isoforms.read_group_tracking
32 promoters.diff
33 splicing.diff
34 tss_group_exp.diff
35 tss_groups.count_tracking
36 tss_groups.fpkm_tracking
37 tss_groups.read_group_tracking
38 """
39 file_ext = 'cuffdata'
40 is_binary = False
41 composite_type = 'auto_primary_file'
42 allow_datatype_change = False
43 def __init__( self, **kwd ):
44 Html.__init__( self, **kwd )
45 self.add_composite_file('run.info', description = 'run.info', mimetype = 'text/html', optional = True, is_binary = False )
46 self.add_composite_file('read_groups.info', description = 'read_groups.info', mimetype = 'text/html', optional = True, is_binary = False )
47 self.add_composite_file('cds.count_tracking', description = 'cds.count_tracking', mimetype = 'text/html', optional = True, is_binary = False )
48 self.add_composite_file('cds.diff', description = 'cds.diff', mimetype = 'text/html', optional = True, is_binary = False )
49 self.add_composite_file('cds.fpkm_tracking', description = 'cds.fpkm_tracking', mimetype = 'text/html', optional = True, is_binary = False )
50 self.add_composite_file('cds.read_group_tracking', description = 'cds.read_group_tracking', mimetype = 'text/html', optional = True, is_binary = False )
51 self.add_composite_file('cds_exp.diff', description = 'cds_exp.diff', mimetype = 'text/html', optional = True, is_binary = False )
52 self.add_composite_file('gene_exp.diff', description = 'gene_exp.diff', mimetype = 'text/html', optional = True, is_binary = False )
53 self.add_composite_file('genes.count_tracking', description = 'genes.count_tracking', mimetype = 'text/html', optional = True, is_binary = False )
54 self.add_composite_file('genes.fpkm_tracking', description = 'genes.fpkm_tracking', mimetype = 'text/html', optional = True, is_binary = False )
55 self.add_composite_file('genes.read_group_tracking', description = 'genes.read_group_tracking', mimetype = 'text/html', optional = True, is_binary = False )
56 self.add_composite_file('isoform_exp.diff', description = 'isoform_exp.diff', mimetype = 'text/html', optional = True, is_binary = False )
57 self.add_composite_file('isoforms.count_tracking', description = 'isoforms.count_tracking', mimetype = 'text/html', optional = True, is_binary = False )
58 self.add_composite_file('isoforms.fpkm_tracking', description = 'isoforms.fpkm_tracking', mimetype = 'text/html', optional = True, is_binary = False )
59 self.add_composite_file('isoforms.read_group_tracking', description = 'isoforms.read_group_tracking', mimetype = 'text/html', optional = True, is_binary = False )
60 self.add_composite_file('promoters.diff', description = 'promoters.diff', mimetype = 'text/html', optional = True, is_binary = False )
61 self.add_composite_file('splicing.diff', description = 'splicing.diff', mimetype = 'text/html', optional = True, is_binary = False )
62 self.add_composite_file('tss_group_exp.diff', description = 'tss_group_exp.diff', mimetype = 'text/html', optional = True, is_binary = False )
63 self.add_composite_file('tss_groups.count_tracking', description = 'tss_groups.count_tracking', mimetype = 'text/html', optional = True, is_binary = False )
64 self.add_composite_file('tss_groups.fpkm_tracking', description = 'tss_groups.fpkm_tracking', mimetype = 'text/html', optional = True, is_binary = False )
65 self.add_composite_file('tss_groups.read_group_tracking', description = 'tss_groups.read_group_tracking', mimetype = 'text/html', optional = True, is_binary = False )
66
67 def generate_primary_file( self, dataset = None ):
68 """
69 This is called only at upload to write the html file
70 cannot rename the datasets here - they come with the default unfortunately
71 """
72 rval = ['<html><head><title>CuffDiff Output</title></head>']
73 rval.append('<body>')
74 rval.append('<p/>CuffDiff Outputs:<p/><ul>')
75 for composite_name, composite_file in self.get_composite_files( dataset = dataset ).iteritems():
76 fn = composite_name
77 log.debug( "Velvet log info %s %s %s" % ('JJ generate_primary_file',fn,composite_file))
78 opt_text = ''
79 if composite_file.optional:
80 opt_text = ' (optional)'
81 if composite_file.get('description'):
82 rval.append( '<li><a href="%s" type="text/plain">%s (%s)</a>%s</li>' % ( fn, fn, composite_file.get('description'), opt_text ) )
83 else:
84 rval.append( '<li><a href="%s" type="text/plain">%s</a>%s</li>' % ( fn, fn, opt_text ) )
85 rval.append( '</ul></body></html>' )
86 return "\n".join( rval )
87
88 def regenerate_primary_file(self,dataset):
89 """
90 cannot do this until we are setting metadata
91 """
92 flist = os.listdir(dataset.extra_files_path)
93 rval = ['<html><head><title>CuffDiff Output</title></head>']
94 rval.append('<body>')
95 rval.append('<p/>CuffDiff Outputs:<p/><ul>')
96 for i,fname in enumerate(flist):
97 sfname = os.path.split(fname)[-1]
98 rval.append( '<li><a href="%s" type="text/html">%s</a>' % ( sfname, sfname ) )
99 rval.append( '</ul></body></html>' )
100 f = file(dataset.file_name,'w')
101 f.write("\n".join( rval ))
102 f.write('\n')
103 f.close()
104
105 def set_meta( self, dataset, **kwd ):
106 Html.set_meta( self, dataset, **kwd )
107 self.regenerate_primary_file(dataset)
108
109 def sniff( self, filename ):
110 return False
111
112 class CuffDataDB( Binary ):
113 file_ext = 'cuffdata'
114 is_binary = True
115 allow_datatype_change = False