def display_bam_region(bamfiles, samples, region, zoomlevel):
    bamdir = current_app.config["BAMDIR"]
    reffile = current_app.config["REFFILE"]
    settings = current_app.config["SETTINGS"]
    bamfile_to_bamview = current_app.config["BAMFILE_TO_BAMVIEW"]
    if region == "error":
        return render_template("error.html", message="No aligned reads found in the selected BAM files")
    for bam in bamfiles:
        if not os.path.exists(join(bamdir,bam)):
            message("bam file %s does not exist"%join(bamdir, bam), "warning")
    if bamfile_to_bamview not in ";".join(bamfiles):
        bv = pybamview.BamView([join(bamdir, bam) for bam in bamfiles], reffile)
        bamfile_to_bamview[";".join(bamfiles)] = bv
    else:
        bv = bamfile_to_bamview[";".join(bamfiles)]
    try:
        chrom, pos = region.split(":")
        pos = int(pos)
    except:
        return render_template("error.html", message="Invalid region specified %s. Region must be of the form chrom:position."%region)
    bv.LoadAlignmentGrid(chrom, pos, _samples=samples, _settings=settings)
    positions = bv.GetPositions(pos)
    region = "%s:%s" % (chrom, pos)
    return render_template("bamview.html",
        title="PyBamView - %s" % region,
        BAM_FILES=bamfiles,
        REF_FILE=reffile,
        REGION=region,
        SAMPLES=bv.GetSamples(),
        SAMPLE_HASHES=bv.GetSampleHashes(),
        BUFFER=settings["NUMCHAR"],
        MAXZOOM=settings["MAXZOOM"],
        ZOOMLEVEL=zoomlevel,
        REFERENCE=bv.GetReferenceTrack(pos),
        ALIGNMENTS=bv.GetAlignmentTrack(pos),
        TARGETPOS=pos,
        POSITIONS=positions,
        NUC_TO_COLOR=NUC_TO_COLOR,
        CHROM=chrom,
        TARGET_LIST=current_app.config.get("TARGET_LIST", [])
    )
dataset/ETHPy150Open mgymrek/pybamview/pybamview/browser/views.py/display_bam_region/swapped operands of `not in`