54
|
1 """
|
|
2 HOMER special datatypes
|
|
3 """
|
|
4
|
|
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
|
55
|
11 class TagDirectory( Text ):
|
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):
|
|
19 Text.__init__( self, **kwd )
|
|
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 """
|
|
32 cannot do this until we are setting metadata
|
|
33 """
|
|
34 flist = os.listdir(dataset.extra_files_path)
|
|
35 rval = ['<html><head><title>CuffDiff Output</title></head>']
|
|
36 rval.append('<body>')
|
|
37 rval.append('<p/>CuffDiff Outputs:<p/><ul>')
|
|
38 for i,fname in enumerate(flist):
|
|
39 sfname = os.path.split(fname)[-1]
|
|
40 rval.append( '<li><a href="%s" type="text/html">%s</a>' % ( sfname, sfname ) )
|
|
41 rval.append( '</ul></body></html>' )
|
|
42 f = file(dataset.file_name,'w')
|
|
43 f.write("\n".join( rval ))
|
|
44 f.write('\n')
|
|
45 f.close()
|
|
46
|
|
47 def set_meta( self, dataset, **kwd ):
|
|
48 Text.set_meta( self, dataset, **kwd )
|
|
49 self.regenerate_primary_file(dataset)
|
|
50
|
|
51
|
54
|
52 def generate_primary_file( self, dataset = None ):
|
|
53 rval = ['<html><head><title>HOMER database files</title></head><ul>']
|
|
54 for composite_name, composite_file in self.get_composite_files( dataset = dataset ).iteritems():
|
|
55 opt_text = ''
|
|
56 if composite_file.optional:
|
|
57 opt_text = ' (optional)'
|
|
58 rval.append( '<li><a href="%s">%s</a>%s' % ( composite_name, composite_name, opt_text ) )
|
|
59 rval.append( '</ul></html>' )
|
|
60 return "\n".join( rval )
|
|
61
|
|
62 def display_data(self, trans, data, preview=False, filename=None,
|
|
63 to_ext=None, size=None, offset=None, **kwd):
|
|
64 """Apparently an old display method, but still gets called.
|
|
65
|
|
66 This allows us to format the data shown in the central pane via the "eye" icon.
|
|
67 """
|
|
68 return "This is a HOMER database."
|
|
69
|
|
70 def set_peek( self, dataset, is_multi_byte=False ):
|
|
71 """Set the peek and blurb text."""
|
|
72 if not dataset.dataset.purged:
|
|
73 dataset.peek = "HOMER database (multiple files)"
|
|
74 dataset.blurb = "HOMER database (multiple files)"
|
|
75 else:
|
|
76 dataset.peek = 'file does not exist'
|
|
77 dataset.blurb = 'file purged from disk'
|
|
78
|
|
79 def display_peek( self, dataset ):
|
|
80 """Create HTML content, used for displaying peek."""
|
|
81 try:
|
|
82 return dataset.peek
|
|
83 except:
|
|
84 return "HOMER database (multiple files)"
|
|
85
|
|
86 def get_mime(self):
|
|
87 """Returns the mime type of the datatype (pretend it is text for peek)"""
|
|
88 return 'text/plain'
|
|
89
|
|
90 def merge(split_files, output_file):
|
|
91 """Merge HOMER databases (not implemented)."""
|
|
92 raise NotImplementedError("Merging HOMER databases is not supported")
|
|
93
|
|
94 def split( cls, input_datasets, subdir_generator_function, split_params):
|
|
95 """Split a HOMER database (not implemented)."""
|
|
96 if split_params is None:
|
|
97 return None
|
|
98 raise NotImplementedError("Can't split HOMER databases")
|
|
99
|