PageRenderTime 24ms CodeModel.GetById 20ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/galaxy/datatypes/coverage.py

https://bitbucket.org/h_morita_dbcls/galaxy-central
Python | 66 lines | 41 code | 10 blank | 15 comment | 0 complexity | 825029d4ba2c06e4a06df647e5486db8 MD5 | raw file
 1"""
 2Coverage datatypes
 3
 4"""
 5import pkg_resources
 6pkg_resources.require( "bx-python" )
 7
 8import logging, os, sys, time, tempfile, shutil
 9import data
10from galaxy import util
11from galaxy.datatypes.sniff import *
12from galaxy.web import url_for
13from cgi import escape
14import urllib
15from bx.intervals.io import *
16from galaxy.datatypes import metadata
17from galaxy.datatypes.metadata import MetadataElement
18from galaxy.datatypes.tabular import Tabular
19import math
20
21log = logging.getLogger(__name__)
22
23class LastzCoverage( Tabular ):
24    file_ext = "coverage"
25    
26    MetadataElement( name="chromCol", default=1, desc="Chrom column", param=metadata.ColumnParameter )
27    MetadataElement( name="positionCol", default=2, desc="Position column", param=metadata.ColumnParameter )
28    MetadataElement( name="forwardCol", default=3, desc="Forward or aggregate read column", param=metadata.ColumnParameter )
29    MetadataElement( name="reverseCol", desc="Optional reverse read column", param=metadata.ColumnParameter, optional=True, no_value=0 )
30    MetadataElement( name="columns", default=3, desc="Number of columns", readonly=True, visible=False )
31
32    def get_track_window(self, dataset, data, start, end):
33        """
34        Assumes we have a numpy file.
35        """
36        # Maybe if we import here people will still be able to use Galaxy when numpy kills it
37        pkg_resources.require("numpy>=1.2.1")
38        #from numpy.lib import format
39        import numpy
40
41        range = end - start
42        # Determine appropriate resolution to plot ~1000 points
43        resolution = ( 10 ** math.ceil( math.log10( range / 1000 ) ) )
44        # Restrict to valid range
45        resolution = min( resolution, 10000 )
46        resolution = max( resolution, 1 )
47        # Memory map the array (don't load all the data)
48        data = numpy.load( data )
49        # Grab just what we need
50        t_start = math.floor( start / resolution )
51        t_end = math.ceil( end / resolution )
52        x = numpy.arange( t_start, t_end ) * resolution
53        y = data[ t_start : t_end ]
54    
55        return zip(x.tolist(), y.tolist())
56
57    def get_track_resolution( self, dataset, start, end):
58        range = end - start
59        # Determine appropriate resolution to plot ~1000 points
60        resolution = math.ceil( 10 ** math.ceil( math.log10( range / 1000 ) ) )
61        # Restrict to valid range
62        resolution = min( resolution, 10000 )
63        resolution = max( resolution, 1 )
64        return resolution
65
66