@blueprint.route('/')
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=BAM%"PyBamView - %s")

        if not (os.path.exists(BAM+".bai") or os.path.exists(BAM.replace(".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. Check read groups are properly assigned.",
                 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)
    # 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)
dataset/ETHPy150Open mgymrek/pybamview/pybamview/browser/views.py/listsamples/swapped operands of `%`