annotate cuffdata.py @ 4:57c13cd32044

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