PageRenderTime 39ms CodeModel.GetById 32ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/galaxy/datatypes/ngsindex.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 77 lines | 46 code | 11 blank | 20 comment | 4 complexity | b92b0ae2dcfed0c281de9a731443bb68 MD5 | raw file
 1"""
 2NGS indexes
 3"""
 4import os
 5import logging
 6
 7from metadata import MetadataElement
 8from images import Html
 9
10log = logging.getLogger(__name__)
11
12class BowtieIndex( Html ):
13    """
14    base class for BowtieIndex
15    is subclassed by BowtieColorIndex and BowtieBaseIndex
16    """
17    MetadataElement( name="base_name", desc="base name for this index set", default='galaxy_generated_bowtie_index', set_in_upload=True, readonly=True )
18    MetadataElement( name="sequence_space", desc="sequence_space for this index set", default='unknown', set_in_upload=True, readonly=True )
19
20    file_ext = 'bowtie_index'
21    is_binary = True
22    composite_type = 'auto_primary_file'
23    allow_datatype_change = False
24
25    def generate_primary_file( self, dataset = None ):
26        """
27        This is called only at upload to write the html file
28        cannot rename the datasets here - they come with the default unfortunately
29        """
30        return '<html><head></head><body>AutoGenerated Primary File for Composite Dataset</body></html>'
31
32    def regenerate_primary_file(self,dataset):
33        """
34        cannot do this until we are setting metadata
35        """
36        bn = dataset.metadata.base_name
37        flist = os.listdir(dataset.extra_files_path)
38        rval = ['<html><head><title>Files for Composite Dataset %s</title></head><p/>Comprises the following files:<p/><ul>' % (bn)]
39        for i,fname in enumerate(flist):
40            sfname = os.path.split(fname)[-1]
41            rval.append( '<li><a href="%s">%s</a>' % ( sfname, sfname ) )
42        rval.append( '</ul></html>' )
43        f = file(dataset.file_name,'w')
44        f.write("\n".join( rval ))
45        f.write('\n')
46        f.close()
47
48    def set_peek( self, dataset, is_multi_byte=False ):
49        if not dataset.dataset.purged:
50            dataset.peek  = "Bowtie index file (%s)" % ( dataset.metadata.sequence_space )
51            dataset.blurb = "%s space" % ( dataset.metadata.sequence_space )
52        else:
53            dataset.peek = 'file does not exist'
54            dataset.blurb = 'file purged from disk'
55    def display_peek( self, dataset ):
56        try:
57            return dataset.peek
58        except:
59            return "Bowtie index file"
60    def sniff( self, filename ):
61        return False
62
63class BowtieColorIndex( BowtieIndex ):
64    """
65    Bowtie color space index
66    """
67    MetadataElement( name="sequence_space", desc="sequence_space for this index set", default='color', set_in_upload=True, readonly=True )
68
69    file_ext = 'bowtie_color_index'
70
71class BowtieBaseIndex( BowtieIndex ):
72    """
73    Bowtie base space index
74    """
75    MetadataElement( name="sequence_space", desc="sequence_space for this index set", default='base', set_in_upload=True, readonly=True )
76
77    file_ext = 'bowtie_base_index'