mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Made Genetrack load only if the dependencies import
This commit is contained in:
+15
-19
@@ -26,6 +26,7 @@
|
||||
<datatype extension="html" type="galaxy.datatypes.images:Html" mimetype="text/html"/>
|
||||
<datatype extension="interval" type="galaxy.datatypes.interval:Interval" display_in_upload="true">
|
||||
<converter file="interval_to_bed_converter.xml" target_datatype="bed"/>
|
||||
<converter file="interval_to_coverage.xml" target_datatype="coverage"/>
|
||||
</datatype>
|
||||
<datatype extension="jpg" type="galaxy.datatypes.images:Image" mimetype="image/jpeg"/>
|
||||
<datatype extension="laj" type="galaxy.datatypes.images:Laj"/>
|
||||
@@ -38,7 +39,6 @@
|
||||
<datatype extension="png" type="galaxy.datatypes.images:Image" mimetype="image/png"/>
|
||||
<datatype extension="qual" type="galaxy.datatypes.qualityscore:QualityScore" display_in_upload="true"/>
|
||||
<datatype extension="scf" type="galaxy.datatypes.images:Scf" mimetype="application/octet-stream" display_in_upload="true"/>
|
||||
<datatype extension="solidqual" type="galaxy.datatypes.qualityscore:SolidQualityScore" display_in_upload="true"/>
|
||||
<datatype extension="taxonomy" type="galaxy.datatypes.tabular:Taxonomy" display_in_upload="true"/>
|
||||
<datatype extension="tabular" type="galaxy.datatypes.tabular:Tabular" display_in_upload="true"/>
|
||||
<datatype extension="txt" type="galaxy.datatypes.data:Text" display_in_upload="true"/>
|
||||
@@ -173,24 +173,20 @@
|
||||
<!--
|
||||
The order in which Galaxy attempts to determine data types is
|
||||
important because some formats are much more loosely defined
|
||||
than others. The following list should be the most rigidly
|
||||
defined format first, followed by next-most rigidly defined,
|
||||
and so on.
|
||||
than others.
|
||||
-->
|
||||
<sniffer type="galaxy.datatypes.xml:BlastXml"/>
|
||||
<sniffer type="galaxy.datatypes.sequence:Maf"/>
|
||||
<sniffer type="galaxy.datatypes.sequence:Lav"/>
|
||||
<sniffer type="galaxy.datatypes.sequence:csFasta"/>
|
||||
<sniffer type="galaxy.datatypes.qualityscore:SolidQualityScore"/>
|
||||
<sniffer type="galaxy.datatypes.sequence:Fasta"/>
|
||||
<sniffer type="galaxy.datatypes.sequence:FastqSolexa"/>
|
||||
<sniffer type="galaxy.datatypes.interval:Wiggle"/>
|
||||
<sniffer type="galaxy.datatypes.images:Html"/>
|
||||
<sniffer type="galaxy.datatypes.sequence:Axt"/>
|
||||
<sniffer type="galaxy.datatypes.interval:Bed"/>
|
||||
<sniffer type="galaxy.datatypes.interval:CustomTrack"/>
|
||||
<sniffer type="galaxy.datatypes.interval:Gff"/>
|
||||
<sniffer type="galaxy.datatypes.interval:Gff3"/>
|
||||
<sniffer type="galaxy.datatypes.interval:Interval"/>
|
||||
<sniffer order="005" type="galaxy.datatypes.xml:BlastXml"/>
|
||||
<sniffer order="010" type="galaxy.datatypes.sequence:Maf"/>
|
||||
<sniffer order="015" type="galaxy.datatypes.sequence:Lav"/>
|
||||
<sniffer order="020" type="galaxy.datatypes.sequence:Fasta"/>
|
||||
<sniffer order="025" type="galaxy.datatypes.sequence:FastqSolexa"/>
|
||||
<sniffer order="030" type="galaxy.datatypes.interval:Wiggle"/>
|
||||
<sniffer order="035" type="galaxy.datatypes.images:Html"/>
|
||||
<sniffer order="040" type="galaxy.datatypes.sequence:Axt"/>
|
||||
<sniffer order="045" type="galaxy.datatypes.interval:Bed"/>
|
||||
<sniffer order="050" type="galaxy.datatypes.interval:CustomTrack"/>
|
||||
<sniffer order="055" type="galaxy.datatypes.interval:Gff"/>
|
||||
<sniffer order="060" type="galaxy.datatypes.interval:Gff3"/>
|
||||
<sniffer order="065" type="galaxy.datatypes.interval:Interval"/>
|
||||
</sniffers>
|
||||
</datatypes>
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Converter to generate 3 (or 4) column base-pair coverage from an interval file.
|
||||
|
||||
usage: %prog bed_file out_file
|
||||
-1, --cols1=N,N,N,N: Columns for chrom, start, end, strand in interval file
|
||||
-2, --cols2=N,N,N,N: Columns for chrom, start, end, strand in coverage file
|
||||
"""
|
||||
import sys
|
||||
from galaxy import eggs
|
||||
import pkg_resources; pkg_resources.require( "bx-python" )
|
||||
from bx.intervals import io
|
||||
from bx.cookbook import doc_optparse
|
||||
|
||||
INTERVAL_METADATA = ('chromCol',
|
||||
'startCol',
|
||||
'endCol',
|
||||
'strandCol',)
|
||||
|
||||
COVERAGE_METADATA = ('chromCol',
|
||||
'positionCol',
|
||||
'forwardCol',
|
||||
'reverseCol',)
|
||||
|
||||
def main( interval, coverage ):
|
||||
chroms = dict()
|
||||
for record in interval:
|
||||
if not type( record ) is io.GenomicInterval: continue
|
||||
chrom = chroms[record.chrom] = chroms.get(record.chrom, dict())
|
||||
for position in xrange(record.start, record.end):
|
||||
coverages = chrom[position] = chrom.get(position,[0,0])
|
||||
if record.strand == "-": coverages[1] += 1
|
||||
else: coverages[0] += 1
|
||||
for chrom in sorted(chroms.iterkeys()):
|
||||
positions = chroms[chrom]
|
||||
for position in sorted(positions.iterkeys()):
|
||||
coverage.write( chrom=chrom, position=position, forward=positions[position][0], reverse=positions[position][1] )
|
||||
|
||||
class CoverageWriter( object ):
|
||||
def __init__( self, out_stream=None, chromCol=0, positionCol=1, forwardCol=2, reverseCol=3 ):
|
||||
self.chromCol, self.positionCol, self.forwardCol, self.reverseCol = chromCol, positionCol, forwardCol, reverseCol
|
||||
self.nfields = max( chromCol, positionCol, forwardCol, reverseCol )+1
|
||||
self.out_stream = out_stream
|
||||
self.nlines = 0
|
||||
|
||||
def write(self, chrom="chr", position=0, forward=0, reverse=0 ):
|
||||
self.nlines += 1
|
||||
if self.nlines % 64000: self.out_stream.flush()
|
||||
outlist = [None] * self.nfields
|
||||
outlist[self.chromCol] = str(chrom)
|
||||
outlist[self.positionCol] = str(position)
|
||||
if self.reverseCol == -1: outlist[self.forwardCol] = str(forward + reverse)
|
||||
else:
|
||||
outlist[self.forwardCol] = str(forward)
|
||||
outlist[self.reverseCol] = str(reverse)
|
||||
self.out_stream.write("%s\n" % "\t".join( outlist ))
|
||||
|
||||
def flush(self):
|
||||
self.out_stream.flush()
|
||||
|
||||
if __name__ == "__main__":
|
||||
options, args = doc_optparse.parse( __doc__ )
|
||||
try:
|
||||
chr_col_1, start_col_1, end_col_1, strand_col_1 = [int(x)-1 for x in options.cols1.split(',')]
|
||||
chr_col_2, position_col_2, forward_col_2, reverse_col_2 = [int(x)-1 for x in options.cols2.split(',')]
|
||||
in_fname, out_fname = args
|
||||
except:
|
||||
doc_optparse.exception()
|
||||
|
||||
coverage = CoverageWriter( out_stream = open(out_fname, "a"),
|
||||
chromCol = chr_col_2, positionCol = position_col_2,
|
||||
forwardCol = forward_col_2, reverseCol = reverse_col_2, )
|
||||
interval = io.NiceReaderWrapper( open(in_fname, "r"),
|
||||
chrom_col=chr_col_1,
|
||||
start_col=start_col_1,
|
||||
end_col=end_col_1,
|
||||
strand_col=strand_col_1,
|
||||
fix_strand=True )
|
||||
main( interval, coverage )
|
||||
coverage.flush()
|
||||
@@ -0,0 +1,18 @@
|
||||
<tool id="CONVERTER_interval_to_coverage_0" name="Convert Genomic Intervals To COVERAGE">
|
||||
<!-- <description>__NOT_USED_CURRENTLY_FOR_CONVERTERS__</description> -->
|
||||
<!-- Used on the metadata edit page. -->
|
||||
<command interpreter="python">interval_to_coverage.py $input1 $output1
|
||||
-1 ${input1.metadata.chromCol},${input1.metadata.startCol},${input1.metadata.endCol},${input1.metadata.strandCol}
|
||||
-2 ${output1.metadata.chromCol},${output1.metadata.positionCol},${output1.metadata.forwardCol},${output1.metadata.reverseCol}
|
||||
</command>
|
||||
<inputs>
|
||||
<page>
|
||||
<param format="interval" name="input1" type="data" label="Choose intervals"/>
|
||||
</page>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<data format="coverage" name="output1"/>
|
||||
</outputs>
|
||||
<help>
|
||||
</help>
|
||||
</tool>
|
||||
@@ -28,4 +28,7 @@ class BaseController( object ):
|
||||
Root = BaseController
|
||||
"""
|
||||
Deprecated: `BaseController` used to be available under the name `Root`
|
||||
"""
|
||||
"""
|
||||
|
||||
class ControllerUnavailable( Exception ):
|
||||
pass
|
||||
@@ -28,13 +28,18 @@ def add_controllers( webapp, app ):
|
||||
them to the webapp.
|
||||
"""
|
||||
from galaxy.web.base.controller import BaseController
|
||||
from galaxy.web.base.controller import ControllerUnavailable
|
||||
import galaxy.web.controllers
|
||||
controller_dir = galaxy.web.controllers.__path__[0]
|
||||
for fname in os.listdir( controller_dir ):
|
||||
if not( fname.startswith( "_" ) ) and fname.endswith( ".py" ):
|
||||
name = fname[:-3]
|
||||
module_name = "galaxy.web.controllers." + name
|
||||
module = __import__( module_name )
|
||||
try:
|
||||
module = __import__( module_name )
|
||||
except ControllerUnavailable, exc:
|
||||
log.debug("%s could not be loaded: %s" % (module_name, str(exc)))
|
||||
continue
|
||||
for comp in module_name.split( "." )[1:]:
|
||||
module = getattr( module, comp )
|
||||
# Look for a controller inside the modules
|
||||
|
||||
@@ -1,22 +1,127 @@
|
||||
import time, glob, os
|
||||
from itertools import cycle
|
||||
|
||||
import pkg_resources
|
||||
pkg_resources.require("GeneTrack")
|
||||
|
||||
import atlas
|
||||
from atlas import sql
|
||||
from atlas import util as atlas_utils
|
||||
from atlas.web import formlib
|
||||
from mako import exceptions
|
||||
from mako.template import Template
|
||||
from mako.lookup import TemplateLookup
|
||||
from galaxy.web.base.controller import *
|
||||
|
||||
try:
|
||||
import pkg_resources
|
||||
pkg_resources.require("GeneTrack")
|
||||
import atlas
|
||||
from atlas import sql
|
||||
from atlas import hdf
|
||||
from atlas import util as atlas_utils
|
||||
from atlas.web import formlib, feature_query, feature_filter
|
||||
from atlas.web import label_cache as atlas_label_cache
|
||||
from atlas.plotting.const import *
|
||||
from atlas.plotting.tracks import prefab
|
||||
from atlas.plotting.tracks import chart
|
||||
from atlas.plotting import tracks
|
||||
except Exception, exc:
|
||||
raise ControllerUnavailable("GeneTrack could not import a required dependency: %s" % str(exc))
|
||||
|
||||
pkg_resources.require( "Paste" )
|
||||
import paste.httpexceptions
|
||||
|
||||
# Database helpers
|
||||
SHOW_LABEL_LIMIT = 10000
|
||||
color = cycle( [LIGHT, WHITE] )
|
||||
|
||||
def list_labels(session):
|
||||
"""
|
||||
Returns a list of labels that will be plotted in order.
|
||||
"""
|
||||
labels = sql.Label
|
||||
query = session.query(labels).order_by("-id")
|
||||
return query
|
||||
|
||||
def open_databases( conf ):
|
||||
"""
|
||||
A helper function that returns handles to the hdf and sql databases
|
||||
"""
|
||||
db = hdf.hdf_open( conf.HDF_DATABASE, mode='r' )
|
||||
session = sql.get_session( conf.SQL_URI )
|
||||
return db, session
|
||||
|
||||
def hdf_query(db, name, param, autosize=False ):
|
||||
"""
|
||||
Schema specific hdf query.
|
||||
Note that returns data as columns not rows.
|
||||
"""
|
||||
if not hdf.has_node(db=db, name=name):
|
||||
atlas.warn( 'missing label %s' % name )
|
||||
return [], [], [], []
|
||||
data = hdf.GroupData( db=db, name=name)
|
||||
istart, iend = data.get_indices(label=param.chrom, start=param.start, stop=param.end)
|
||||
table = data.get_table(label=param.chrom)
|
||||
if autosize:
|
||||
# attempts to reduce the number of points
|
||||
size = len( table.cols.ix[istart:iend] )
|
||||
step = max( [1, size/1200] )
|
||||
else:
|
||||
step = 1
|
||||
|
||||
ix = table.cols.ix[istart:iend:step].tolist()
|
||||
wx = table.cols.wx[istart:iend:step].tolist()
|
||||
cx = table.cols.cx[istart:iend:step].tolist()
|
||||
ax = table.cols.ax[istart:iend:step].tolist()
|
||||
return ix, wx, cx, ax
|
||||
|
||||
# Chart helpers
|
||||
def build_tracks( param, conf, data_label, fit_label, pred_label, strand, show=False ):
|
||||
"""
|
||||
Builds tracks
|
||||
"""
|
||||
# gets all the labels for a fast lookup
|
||||
label_cache = atlas_label_cache( conf )
|
||||
|
||||
# get database handles for hdf and sql
|
||||
db, session = open_databases( conf )
|
||||
|
||||
# fetching x and y coordinates for bar and fit (line) for
|
||||
# each strand plus (p), minus (m), all (a)
|
||||
bix, bpy, bmy, bay = hdf_query( db=db, name=data_label, param=param )
|
||||
fix, fpy, fmy, fay = hdf_query( db=db, name=fit_label, param=param )
|
||||
|
||||
# close the hdf database
|
||||
db.close()
|
||||
|
||||
# get all features within the range
|
||||
all = feature_query( session=session, param=param )
|
||||
|
||||
# draws the barchart and the nucleosome chart below it
|
||||
if strand == 'composite':
|
||||
bar = prefab.composite_bartrack( fix=fix, fay=fay, bix=bix, bay=bay, param=param)
|
||||
else:
|
||||
bar = prefab.twostrand_bartrack( fix=fix, fmy=fmy, fpy=fpy, bix=bix, bmy=bmy, bpy=bpy, param=param)
|
||||
|
||||
charts = list()
|
||||
charts.append( bar )
|
||||
|
||||
return charts
|
||||
|
||||
def feature_chart(param=None, session=None, label=None, label_dict={}):
|
||||
# draw the ORF tracks
|
||||
all = feature_filter(feature_query(session=session, param=param), name=label, kdict=label_dict)
|
||||
if len(all) == 0: return []
|
||||
opts = track_options(
|
||||
xscale=param.xscale, w=param.width, fgColor=PURPLE,
|
||||
show_labels=param.show_labels, ylabel=str(label),
|
||||
bgColor=color.next()
|
||||
)
|
||||
return [
|
||||
tracks.split_tracks(features=all, options=opts, split=param.show_labels, track_type='vector')
|
||||
]
|
||||
|
||||
def consolidate_charts( charts, param ):
|
||||
# create the multiplot
|
||||
opt = chart_options( w=param.width )
|
||||
multi = chart.MultiChart(options=opt, charts=charts)
|
||||
return multi
|
||||
|
||||
# SETUP Track Builders
|
||||
from mod454.trackbuilder import build_tracks
|
||||
import functools
|
||||
def twostrand_tracks( param=None, conf=None ):
|
||||
return build_tracks( data_label=conf.LABEL, fit_label=conf.FIT_LABEL, pred_label=conf.PRED_LABEL, param=param, conf=conf, strand='twostrand')
|
||||
@@ -96,6 +201,7 @@ class WebRoot(BaseController):
|
||||
"""
|
||||
Main request handler
|
||||
"""
|
||||
color = cycle( [LIGHT, WHITE] )
|
||||
data = trans.app.model.HistoryDatasetAssociation.get( dataset_id )
|
||||
if not data:
|
||||
raise paste.httpexceptions.HTTPRequestRangeNotSatisfiable( "Invalid reference dataset id: %s." % str( dataset_id ) )
|
||||
@@ -108,10 +214,15 @@ class WebRoot(BaseController):
|
||||
FIT_LABEL = "%s-SIGMA-%d" % (data.metadata.label, 20),
|
||||
PRED_LABEL = "PRED-%s-SIGMA-%d" % (data.metadata.label, 20),
|
||||
)
|
||||
from atlas import hdf
|
||||
db = hdf.hdf_open( conf.HDF_DATABASE, mode='r' )
|
||||
conf.CHROM_FIELDS = [(x,x) for x in hdf.GroupData(db=db, name=conf.LABEL).labels]
|
||||
db.close()
|
||||
session = sql.get_session( conf.SQL_URI )
|
||||
|
||||
if os.path.exists( conf.HDF_DATABASE ):
|
||||
db = hdf.hdf_open( conf.HDF_DATABASE, mode='r' )
|
||||
conf.CHROM_FIELDS = [(x,x) for x in hdf.GroupData(db=db, name=conf.LABEL).labels]
|
||||
db.close()
|
||||
else:
|
||||
query = session.execute(sql.select([sql.feature_table.c.chrom]).distinct())
|
||||
conf.CHROM_FIELDS = [(x.chrom,x.chrom) for x in query]
|
||||
|
||||
# generate a new form based on the configuration
|
||||
form = formlib.main_form( conf )
|
||||
@@ -147,14 +258,25 @@ class WebRoot(BaseController):
|
||||
# get the template and the function used to generate the tracks
|
||||
tmpl_name, track_maker = conf.PLOT_MAPPER[param.plot]
|
||||
|
||||
if track_maker is not None:
|
||||
# generate the name that the image will be stored at
|
||||
fname, fpath = atlas_utils.make_tempfile( dir=conf.IMAGE_DIR, suffix='.png')
|
||||
param.fname = fname
|
||||
charts = []
|
||||
|
||||
# generate the track
|
||||
track_chart = track_maker( param=param, conf=conf )
|
||||
track_chart.save(fname=fpath)
|
||||
fname, fpath = atlas_utils.make_tempfile( dir=conf.IMAGE_DIR, suffix='.png')
|
||||
param.fname = fname
|
||||
|
||||
# set the scale of the plot
|
||||
param.xscale = [ param.start, param.end ]
|
||||
|
||||
# when visualizing on wide scales labels are not useful
|
||||
param.show_labels = ( param.end - param.start ) <= SHOW_LABEL_LIMIT
|
||||
|
||||
if track_maker is not None and os.path.exists( conf.HDF_DATABASE ):
|
||||
# generate the fit track
|
||||
charts = track_maker( param=param, conf=conf )
|
||||
|
||||
for label in list_labels( session ):
|
||||
charts.extend( feature_chart(param=param, session=session, label=label.name, label_dict={label.name:label.id}) )
|
||||
track_chart = consolidate_charts( charts, param )
|
||||
track_chart.save(fname=fpath)
|
||||
|
||||
return trans.fill_template_mako(tmpl_name, conf=conf, form=form, param=param, dataset_id=dataset_id)
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ assert sys.version_info[:2] >= ( 2, 4 )
|
||||
new_path = [ os.path.join( os.getcwd(), "lib" ) ]
|
||||
new_path.extend( sys.path[1:] ) # remove scripts/ from the path
|
||||
sys.path = new_path
|
||||
print sys.path
|
||||
from galaxy import eggs
|
||||
import pkg_resources
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
||||
<title>${self.title()}</title>
|
||||
<link rel="stylesheet" href="${h.url_for('/static/genetrack/genetrack.css')}" type="text/css" media="screen">
|
||||
<script type="text/javascript" src="${h.url_for('/static/genetrack/genetrack.js')}">var dummy1=0;</script>
|
||||
</head>
|
||||
|
||||
<%def name="title()">
|
||||
Title
|
||||
</%def>
|
||||
|
||||
<%def name="footer()">
|
||||
<div align="center" id="footer">
|
||||
<a href="/">Home</a> | <a href="${h.url_for(controller='genetrack',action='search',dataset_id=dataset_id)}">Search</a>
|
||||
</div>
|
||||
<div align="center" id="tag">
|
||||
Powered by <a href="http://genetrack.googlecode.com">GeneTrack</a> |
|
||||
<a href="http://atlas.bx.psu.edu/">Penn State Genome Cartography (2008)</a>
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<body>
|
||||
${self.body()}
|
||||
${self.footer()}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,75 @@
|
||||
## index.html
|
||||
<%inherit file="base.html"/>
|
||||
<%def name="title()">
|
||||
Index
|
||||
</%def>
|
||||
|
||||
<h1 align="center">${conf.TITLE}</h1>
|
||||
|
||||
<form action="" method="get">
|
||||
|
||||
<table align="center" cellpadding="2" cellspacing="1" width="100%">
|
||||
|
||||
|
||||
% if form.errors():
|
||||
<tr class="error"><td align="center">
|
||||
% for ekey, evalue in form.errors().items():
|
||||
<b>ERROR:</b> ${ekey}: ${evalue}<br>
|
||||
% endfor
|
||||
</td></tr>
|
||||
% endif
|
||||
|
||||
<tr class="grey">
|
||||
<td colspan="4" align="center">
|
||||
<a href="javascript:toggle('options')">More</a><img src="/static/images/thumbtack_icon.png" align="absmiddle" border="0">
|
||||
|
||||
Chromosome: ${form.chrom.tag()}
|
||||
Feature: ${form.feature.tag()}
|
||||
Width: ${form.zoom.tag()}
|
||||
Plot: ${form.plot.tag()}
|
||||
<input type="submit" name="submit" value="Display!">
|
||||
<div id="options" style="display:none" class="selected">
|
||||
<table cellpadding="3">
|
||||
<tr>
|
||||
<td>
|
||||
<!-- Nucleosome:${form.nuc_track.tag()}
|
||||
ORF:${form.orf_track.tag()}
|
||||
-->
|
||||
Fit threshold: ${form.min_fit.tag()}
|
||||
Image width: ${form.img_size.tag()}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td align="center">
|
||||
<input type="submit" name="move_left" value="<< Move Left">
|
||||
|
||||
<input type="submit" name="zoom_out" value="Shrink -">
|
||||
|
||||
<input type="submit" name="zoom_in" value="Magnify +">
|
||||
|
||||
<input type="submit" name="move_right" value="Move Right >>">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td align="center">
|
||||
<img src="${h.url_for('/static/genetrack/plots/' + param.fname)}" align="center" border="0">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td align="center">
|
||||
<!-- <a href='/search'>Search</a> -->
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<input type="hidden" id="dataset_id" name="dataset_id" value="${dataset_id}" />
|
||||
</form>
|
||||
@@ -0,0 +1,55 @@
|
||||
## search.html
|
||||
<%!
|
||||
from itertools import cycle
|
||||
colors = cycle( [ 'even', 'odd' ] )
|
||||
%>
|
||||
|
||||
<%inherit file="base.html"/>
|
||||
<%def name="title()">
|
||||
Search
|
||||
</%def>
|
||||
|
||||
<h1 align="center">Search</h1>
|
||||
|
||||
<div align="center">
|
||||
<form action="search" method="get">
|
||||
Search terms <input type="text" name="word" value="${param.word}">
|
||||
<input type="hidden" name="dataset_id" id="dataset_id" value="${dataset_id}" />
|
||||
<input type="submit" name="submit" value="Search!">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
% if param.word:
|
||||
|
||||
% if len(query)>0:
|
||||
<h4 align="center">Showing the best ${len(query)} matches</h4>
|
||||
|
||||
<table align="center" class="data_table" cellpadding="6" cellspacing="0">
|
||||
<tr align="center">
|
||||
<th width="25%">Name</td>
|
||||
<th width="25%">Chromosome</td>
|
||||
<th width="25%">Start:End</td>
|
||||
<th width="25%">Type</td>
|
||||
</tr>
|
||||
% for color, row in zip(colors, query):
|
||||
${makerow(color, row)}
|
||||
% endfor
|
||||
</table>
|
||||
|
||||
% else:
|
||||
<h4 align="center">No results found</h4>
|
||||
% endif
|
||||
|
||||
%endif
|
||||
|
||||
<br>
|
||||
<%def name="makerow(color, row)">
|
||||
<tr class="${color}" align="center">
|
||||
<td><a href="${h.url_for(controller='genetrack', action='index', chrom=row.chrom, feature=row.start, dataset_id=dataset_id)}">${row.name}</a></td>
|
||||
<td>${row.chrom}</td>
|
||||
<td>${row.start}:${row.end}</td>
|
||||
<td>${row.label.name}</td>
|
||||
</tr>
|
||||
</%def>
|
||||
|
||||
</form>
|
||||
@@ -14,15 +14,19 @@ import pkg_resources
|
||||
pkg_resources.require("GeneTrack")
|
||||
pkg_resources.require("bx-python")
|
||||
|
||||
from atlas import commands
|
||||
from bx.cookbook import doc_optparse
|
||||
import os
|
||||
import commands as oscommands
|
||||
from atlas import commands
|
||||
from atlas import sql
|
||||
from bx.cookbook import doc_optparse
|
||||
from bx.intervals import io
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
from functools import partial
|
||||
|
||||
SIGMA = 20
|
||||
WIDTH = 5 * SIGMA
|
||||
EXCLUSION_ZONE = 147
|
||||
EXCLUSION_ZONE = 147
|
||||
|
||||
def main(label, fit, feats, data_dir, output):
|
||||
os.mkdir(data_dir)
|
||||
@@ -31,14 +35,14 @@ def main(label, fit, feats, data_dir, output):
|
||||
CLOBBER = True,
|
||||
DATA_SIZE = 3*10**6,
|
||||
MINIMUM_PEAK_SIZE = 0.1,
|
||||
LOADER_ENABLED = True,
|
||||
FITTER_ENABLED = True,
|
||||
PREDICTOR_ENABLED = True,
|
||||
EXPORTER_ENABLED = True,
|
||||
LOADER_ENABLED = False,
|
||||
FITTER_ENABLED = False,
|
||||
PREDICTOR_ENABLED = False,
|
||||
EXPORTER_ENABLED = False,
|
||||
LOADER = loader,
|
||||
FITTER = fitter,
|
||||
PREDICTOR = predictor,
|
||||
EXPORTER = exporter,
|
||||
EXPORTER = partial( commands.exporter, formatter=commands.bed_formatter),
|
||||
HDF_DATABASE = os.path.join( data_dir, "data.hdf" ),
|
||||
SQL_URI = "sqlite:///%s" % os.path.join( data_dir, "features.sqlite" ),
|
||||
SIGMA = SIGMA,
|
||||
@@ -51,12 +55,23 @@ def main(label, fit, feats, data_dir, output):
|
||||
RIGHT_SHIFT = EXCLUSION_ZONE / 2,
|
||||
EXPORT_LABELS = [ "PRED-%s-SIGMA-%d" % ( label,SIGMA ) ],
|
||||
EXPORT_DIR = os.path.join( data_dir ),
|
||||
DATA_FILE=fit[1],
|
||||
DATA_FILE=fit and fit[1] or None,
|
||||
fit=fit,
|
||||
feats=feats,
|
||||
)
|
||||
if fit:
|
||||
# Turn on fit processing.
|
||||
conf.LOADER_ENABLED = True,
|
||||
conf.FITTER_ENABLED = True,
|
||||
conf.PREDICTOR_ENABLED = True,
|
||||
conf.EXPORTER_ENABLED = True,
|
||||
for feat in feats:
|
||||
load_feature_files(conf, feats)
|
||||
commands.execute(conf)
|
||||
|
||||
outname = "%s.%s.txt" % (conf.__name__, conf.EXPORT_LABELS[0] )
|
||||
if os.path.exists( os.path.join(data_dir, outname) ):
|
||||
os.rename( os.path.join(data_dir, outname), output)
|
||||
|
||||
# mod454 seems to be a module without a package. The necessary funcitons are
|
||||
# stubbed out here until I'm sure of their final home. INS
|
||||
|
||||
@@ -97,8 +112,40 @@ def predictor( conf ):
|
||||
from mod454.predictor import predictor as mod454_predictor
|
||||
return mod454_predictor( conf )
|
||||
|
||||
def exporter( conf ):
|
||||
return commands.bed_exporter(conf)
|
||||
def load_feature_files( conf, feats):
|
||||
"""
|
||||
Loads features from file names
|
||||
"""
|
||||
engine = sql.get_engine( conf.SQL_URI )
|
||||
sql.drop_indices(engine)
|
||||
conn = engine.connect()
|
||||
for label, fname, col_spec in feats:
|
||||
label_id = sql.make_label(engine, name=label, clobber=False)
|
||||
reader = io.NiceReaderWrapper( open(fname,"r"),
|
||||
chrom_col=col_spec.chromCol,
|
||||
start_col=col_spec.startCol,
|
||||
end_col=col_spec.endCol,
|
||||
strand_col=col_spec.strandCol,
|
||||
fix_strand=False )
|
||||
values = list()
|
||||
for interval in reader:
|
||||
print interval
|
||||
if not type( interval ) is io.GenomicInterval: continue
|
||||
row = {'label_id':label_id,
|
||||
'name':col_spec.nameCol == -1 and "%s-%s" % (str(interval.start), str(interval.end)) or interval.fields[col_spec.nameCol],
|
||||
'altname':"",
|
||||
'chrom':interval.chrom,
|
||||
'start':interval.start,
|
||||
'end':interval.end,
|
||||
'strand':interval.strand,
|
||||
'value':0,
|
||||
'freetext':""}
|
||||
values.append(row)
|
||||
insert = sql.feature_table.insert()
|
||||
conn.execute( insert, values)
|
||||
conn.close()
|
||||
sql.create_indices(engine)
|
||||
|
||||
|
||||
class Bunch( object ):
|
||||
def __init__(self, **kwargs):
|
||||
@@ -115,9 +162,12 @@ if __name__ == "__main__":
|
||||
options, args = doc_optparse.parse( __doc__ )
|
||||
try:
|
||||
label = options.label
|
||||
fit_name, fit_meta = options.fits.split(':')[0], [int(x)-1 for x in options.fits.split(':')[1:]]
|
||||
fit_meta = Bunch(chromCol=fit_meta[0], positionCol=fit_meta[1], forwardCol=fit_meta[2], reverseCol=fit_meta[3])
|
||||
fit = ( label, fit_name, fit_meta, )
|
||||
if options.fits:
|
||||
fit_name, fit_meta = options.fits.split(':')[0], [int(x)-1 for x in options.fits.split(':')[1:]]
|
||||
fit_meta = Bunch(chromCol=fit_meta[0], positionCol=fit_meta[1], forwardCol=fit_meta[2], reverseCol=fit_meta[3])
|
||||
fit = ( label, fit_name, fit_meta, )
|
||||
else:
|
||||
fit = []
|
||||
# split apart the string into nested lists, preserves order
|
||||
if options.feats:
|
||||
feats = [ (
|
||||
@@ -127,7 +177,7 @@ if __name__ == "__main__":
|
||||
strandCol=int(strandCol)-1, nameCol=int(nameCol)-1),
|
||||
)
|
||||
for feat_label, fname, chromCol, startCol, endCol, strandCol, nameCol
|
||||
in ( feat.split(':') for feat in options.feats.split(',') )]
|
||||
in ( feat.split(':') for feat in options.feats.split(',') if len(feat) > 0 )]
|
||||
else:
|
||||
feats = []
|
||||
data_dir = options.data
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
|
||||
<command interpreter="python">
|
||||
genetrack.py -l $data_label
|
||||
-1 ${fit_data}:${fit_data.metadata.chromCol}:${fit_data.metadata.positionCol}:${fit_data.metadata.forwardCol}:${fit_data.metadata.reverseCol}
|
||||
#if not str($fit_data) == "None"
|
||||
-1
|
||||
${fit_data}:${fit_data.metadata.chromCol}:${fit_data.metadata.positionCol}:${fit_data.metadata.forwardCol}:${fit_data.metadata.reverseCol}
|
||||
#end if
|
||||
#if $feature_data
|
||||
-2
|
||||
#end if
|
||||
@@ -23,7 +26,7 @@
|
||||
<param name="data_label" type="text" label="Track Label" size="50">
|
||||
<validator type="regex" message="Please name the track with only alphanumeric characters.">[a-zA-Z0-9]{0,25}</validator>
|
||||
</param>
|
||||
<param name="fit_data" type="data" format="coverage" label="Coverage Dataset" />
|
||||
<param name="fit_data" type="data" format="coverage" label="Coverage Dataset" optional="true" />
|
||||
<repeat name="feature_data" title="Features">
|
||||
<param name="input" type="data" format="interval" label="Dataset" />
|
||||
<param name="name" type="text" label="Feature Type (mRNA, ESTs, ORFs, etc.)" size="25">
|
||||
@@ -36,7 +39,13 @@
|
||||
<data format="genetrack" name="genetrack" />
|
||||
<data format="bed" name="bed_out" />
|
||||
</outputs>
|
||||
|
||||
|
||||
<requirements>
|
||||
<requirement type="python-module">tables</requirement>
|
||||
<requirement type="python-module">atlas</requirement>
|
||||
<requirement type="python-module">pychartdir</requirement>
|
||||
<requirement type="python-module">numpy</requirement>
|
||||
</requirements>
|
||||
<help>
|
||||
This tool takes the input Fit Data and creates a peak and curve plot showing
|
||||
the reads and fitness on each basepair. Features can be plotted below as tracks.
|
||||
|
||||
Reference in New Issue
Block a user