Ejemplo n.º 1
0
def browser(request, index, url, galaxy_url, dataid=0):
    ""
    global FORM_DEFAULTS

    # incoming parameters cast into a dictionary
    incoming = dict( request.POST.items() )

    # alters the incoming parameters based on user interaction
    incoming = browserutils.modify_incoming(incoming, FORM_DEFAULTS)

    # create the necessary forms
    forms  = html.Params()
    forms.search  = formspec.make_form(index.labels)(incoming)
    forms.navbar  = formspec.NavbarForm()
    forms.fitting = formspec.FitForm(  incoming )
    forms.peaks   = formspec.PeakForm( incoming )

    # extract the search parameters
    params = browserutils.parse_parameters(forms=forms, defaults=formspec.ALL_DEFAULTS)

    # run the tool or return an image
    if 'runtool' in incoming:
        # need to run the tool
        # form the url with dictionary substitution
        
        # TODO make parameters names consistent across Galaxy, GeneTrack and script!
        strand = 'all' if params.strand=='ALL' else 'two'
        mode = 'nolap' if params.smoothing_func =='GK' else 'all'

        urlparams = dict(
            strand = strand,
            exclusion=params.feature_width,
            level=int(params.minimum_peak),
            mode=mode,
            sigma=int(params.sigma),
            input=dataid,
            method='gauss',
            runtool_btn="Execute"
        )

        url = "%s&%s" % (galaxy_url, urllib.urlencode( urlparams ))
        return html.redirect(url)
       
    # creates the multiplot
    multi = dataview_multiplot(index=index, params=params, debug=False)
    params.image_height = multi.h
    
    # close the data
    index.close()

    # trigger the occasional cache cleaning
    webutil.cache_clean(age=1, chance=10)

    # creates a file representation and a name
    image_name, image_path = webutil.cache_file(ext='png')

    # saves the multiplot
    multi.save(image_path)
    params.image_name = image_name

    return html.template( request=request, name='data-browse.html', forms=forms, params=params, url=url)