| 1 | """ |
|---|
| 2 | Coverage datatypes |
|---|
| 3 | |
|---|
| 4 | """ |
|---|
| 5 | import pkg_resources |
|---|
| 6 | pkg_resources.require( "bx-python" ) |
|---|
| 7 | |
|---|
| 8 | import logging, os, sys, time, tempfile, shutil |
|---|
| 9 | import data |
|---|
| 10 | from galaxy import util |
|---|
| 11 | from galaxy.datatypes.sniff import * |
|---|
| 12 | from galaxy.web import url_for |
|---|
| 13 | from cgi import escape |
|---|
| 14 | import urllib |
|---|
| 15 | from bx.intervals.io import * |
|---|
| 16 | from galaxy.datatypes import metadata |
|---|
| 17 | from galaxy.datatypes.metadata import MetadataElement |
|---|
| 18 | from galaxy.datatypes.tabular import Tabular |
|---|
| 19 | import math |
|---|
| 20 | |
|---|
| 21 | log = logging.getLogger(__name__) |
|---|
| 22 | |
|---|
| 23 | class 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 | |
|---|