Пример #1
0
def listsamples(methods=['POST', 'GET']):
    # If a single file, jump right to the view for that file
    BAM = current_app.config['BAM']
    BAMDIR = current_app.config['BAMDIR']
    if BAM:
        if not os.path.exists(BAM) or not pybamview.CheckBam(BAM):
            return render_template("error.html",
                                   message="%s not a valid BAM file" % BAM)
        try:
            samplesToBam = pybamview.GetSamplesFromBamFiles(
                [os.path.abspath(BAM)])
        except ValueError, e:
            return render_template("error.html",
                                   message="Problem parsing BAM file: %s" % e,
                                   title="PyBamView - %s" % BAM)
        if not os.path.exists(BAM + ".bai"):
            return render_template("error.html",
                                   message="No index found for %s" % BAM)
        if len(samplesToBam.keys()) == 0:
            return render_template("error.html",
                                   message="No samples found in BAM file",
                                   title="PyBamView - %s" % BAM)
        argstring = "&".join([
            "samplebams=%s:%s" % (sample, os.path.abspath(BAM))
            for sample in samplesToBam
        ])
        return redirect(url_for("display_bam") + "?" + argstring)
Пример #2
0
        argstring = "&".join(["samplebams=%s:%s"%(sample, os.path.abspath(BAM)) for sample in samplesToBam])
        return redirect(url_for(".display_bam")+"?"+argstring)
    # If given a directory to look for bams, determine which samples are present
    else:
        bamfiles = request.args.getlist("bamfiles")
        samples = request.args.getlist("samples")
        if len(bamfiles) > 0 and len(samples) > 0:
            return display_bam(samples)
        try:
            files = os.listdir(BAMDIR)
        except OSError: files = []
        bamfiles = [f for f in files if re.match(".*.bam$", f) is not None]
        bamfiles = [f for f in bamfiles if ((f+".bai") in files or \
                f.replace(".bam",".bai") in files)]
        try:
            samplesToBam = pybamview.GetSamplesFromBamFiles([os.path.join(os.path.abspath(BAMDIR), b) for b in bamfiles])
        except ValueError, e:
            return render_template("error.html", message="Problem parsing BAM file: %s"%e, title="PyBamView - %s"%BAMDIR)
        return render_template("index.html", samplesToBam=samplesToBam, title="PyBamView - %s"%BAMDIR)

@blueprint.route('/bamview', methods=['POST', 'GET'])
def display_bam():
    samplebams = request.args.getlist("samplebams")
    zoomlevel = request.args.get("zoomlevel")
    if len(samplebams) == 0:
        samples_toinclude = list(set(request.args.getlist("samples")))
        bamfiles_toinclude = list(set(request.args.getlist("bamfiles")))
    else:
        samples_toinclude = []
        bamfiles_toinclude = []
        for s in samplebams: