54
|
1 """
|
|
2 HOMER special datatypes
|
|
3 """
|
56
|
4 import os
|
54
|
5 from galaxy.datatypes.data import get_file_peek
|
|
6 from galaxy.datatypes.data import Text, Data
|
|
7 from galaxy.datatypes.metadata import MetadataElement
|
|
8 from galaxy.datatypes.images import Html
|
|
9
|
|
10
|
56
|
11 class TagDirectory( Html ):
|
54
|
12 """Base class for HOMER's Tag Directory datatype."""
|
|
13
|
|
14 file_ext = 'homer_tagdir'
|
|
15 composite_type = 'auto_primary_file'
|
|
16 allow_datatype_change = False
|
|
17
|
|
18 def __init__(self, **kwd):
|
56
|
19 Html.__init__( self, **kwd )
|
54
|
20 #self.add_composite_file('tagInfo.txt', description = 'basic configuration information', mimetype = 'text/html') # Contains basic configuration information
|
|
21 self.add_composite_file('tagLengthDistribution.txt', description = 'histogram of read lengths used for alignment', mimetype = 'text/html') # File contains a histogram of read lengths used for alignment.
|
|
22 self.add_composite_file('tagCountDistribution.txt', description = 'histogram of clonal read depth, showing the number of reads per unique position', mimetype = 'text/html') # File contains a histogram of clonal read depth, showing the number of reads per unique position.
|
|
23 self.add_composite_file('tagAutocorrelation.txt', description = 'distribution of distances between adjacent reads in the genome', mimetype = 'text/html') # The autocorrelation routine creates a distribution of distances between adjacent reads in the genome.
|
|
24 self.add_composite_file('tagFreq.txt', description = "nucleotide and dinucleotide frequencies as a function of distance from the 5' end of all reads", mimetype = 'text/html', optional=True) # Calculates the nucleotide and dinucleotide frequencies as a function of distance from the 5' end of all reads.
|
|
25 self.add_composite_file('tagFreqUniq.txt', description = "nucleotide and dinucleotide frequencies as a function of distance from the 5' end of all reads (counted only once)", mimetype = 'text/html', optional=True) # Same as tagFreq.txt, however individual genomic positions are only counted once.
|
|
26 self.add_composite_file('tagGCcontent.txt', description = 'Distribution of fragment GC%-content', mimetype = 'text/html', optional=True) # Distribution of fragment GC%-content.
|
|
27 self.add_composite_file('genomeGCcontent.txt', description = 'Distribution of fragment GC%-content at each location in the genome', mimetype = 'text/html', optional=True) # Distribution of fragment GC%-content at each location in the genome.
|
|
28
|
55
|
29
|
|
30 def regenerate_primary_file(self,dataset):
|
|
31 """
|
56
|
32 regenerate the index file after metadata generation
|
55
|
33 """
|
56
|
34 rval = ['<html><head><title>HOMER database files</title></head>']
|
55
|
35 rval.append('<body>')
|
|
36 rval.append('<p/>CuffDiff Outputs:<p/><ul>')
|
56
|
37 for fname in os.listdir(dataset.extra_files_path):
|
55
|
38 sfname = os.path.split(fname)[-1]
|
|
39 rval.append( '<li><a href="%s" type="text/html">%s</a>' % ( sfname, sfname ) )
|
|
40 rval.append( '</ul></body></html>' )
|
56
|
41 f = file( dataset.file_name, 'w' )
|
|
42 f.write( '%s\n' % '\n'.join( rval ) )
|
55
|
43 f.close()
|
56
|
44 if not dataset.info:
|
|
45 dataset.info = 'HOMER datatype object'
|
|
46 if not dataset.blurb:
|
|
47 dataset.blurb = 'Composite file - HOMER'
|
|
48 return True
|
55
|
49
|
54
|
50 def generate_primary_file( self, dataset = None ):
|
|
51 rval = ['<html><head><title>HOMER database files</title></head><ul>']
|
|
52 for composite_name, composite_file in self.get_composite_files( dataset = dataset ).iteritems():
|
|
53 opt_text = ''
|
|
54 if composite_file.optional:
|
|
55 opt_text = ' (optional)'
|
|
56 rval.append( '<li><a href="%s">%s</a>%s' % ( composite_name, composite_name, opt_text ) )
|
|
57 rval.append( '</ul></html>' )
|
|
58 return "\n".join( rval )
|
|
59
|
56
|
60 def set_meta( self, dataset, **kwd ):
|
|
61 Html.set_meta( self, dataset, **kwd )
|
|
62 self.regenerate_primary_file(dataset)
|
|
63
|
|
64
|
54
|
65 def display_data(self, trans, data, preview=False, filename=None,
|
|
66 to_ext=None, size=None, offset=None, **kwd):
|
|
67 """Apparently an old display method, but still gets called.
|
|
68
|
|
69 This allows us to format the data shown in the central pane via the "eye" icon.
|
|
70 """
|
|
71 return "This is a HOMER database."
|
|
72
|
|
73 def set_peek( self, dataset, is_multi_byte=False ):
|
|
74 """Set the peek and blurb text."""
|
|
75 if not dataset.dataset.purged:
|
|
76 dataset.peek = "HOMER database (multiple files)"
|
|
77 dataset.blurb = "HOMER database (multiple files)"
|
|
78 else:
|
|
79 dataset.peek = 'file does not exist'
|
|
80 dataset.blurb = 'file purged from disk'
|
|
81
|
|
82 def display_peek( self, dataset ):
|
|
83 """Create HTML content, used for displaying peek."""
|
|
84 try:
|
|
85 return dataset.peek
|
|
86 except:
|
|
87 return "HOMER database (multiple files)"
|
|
88
|
|
89 def get_mime(self):
|
|
90 """Returns the mime type of the datatype (pretend it is text for peek)"""
|
|
91 return 'text/plain'
|
|
92
|
|
93 def merge(split_files, output_file):
|
|
94 """Merge HOMER databases (not implemented)."""
|
|
95 raise NotImplementedError("Merging HOMER databases is not supported")
|
|
96
|
|
97 def split( cls, input_datasets, subdir_generator_function, split_params):
|
|
98 """Split a HOMER database (not implemented)."""
|
|
99 if split_params is None:
|
|
100 return None
|
|
101 raise NotImplementedError("Can't split HOMER databases")
|
|
102
|