Spaces:
Running
Running
File size: 1,585 Bytes
c5361c7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import gradio as gr
from gradio_igv import IGV, IGVContext, AlignmentTrackLoad, FeatureContext, parse_locus
import pandas as pd
public_cram = "https://s3.amazonaws.com/1000genomes/data/HG00103/alignment/HG00103.alt_bwamem_GRCh38DH.20150718.GBR.low_coverage.cram"
default_igv_context = IGVContext(
genome="hg38",
).update_locus("BRCA1").add_track(
AlignmentTrackLoad(
name="HG00103",
url=public_cram,
indexURL=f"{public_cram}.crai",
order=1,
height=200,
colorBy="strand",
oauthToken=None, # Public file so no auth needed; otherwise inferred by URL type using environment
)
)
def summarize_visible_alignments(igv_context):
loci = parse_locus(igv_context.locus)
feature_ctx = FeatureContext(
files=[public_cram],
names=["HG00103"],
loci=loci,
)
reads = list(feature_ctx.features["HG00103"])
df = pd.DataFrame({
"Read Name": [read.query_name for read in reads],
"Pos": [read.reference_start for read in reads],
"MAPQ": [read.mapq for read in reads],
}).sort_values(by='Pos')
return df.head(20)
with gr.Blocks() as demo:
with gr.Row():
with gr.Column(scale=3):
igv_component = IGV(value=default_igv_context, label="IGV Browser")
with gr.Column(scale=1):
alignment_summary = gr.DataFrame(value=pd.DataFrame(), label="Alignment Summary", max_height=800)
igv_component.locuschange(summarize_visible_alignments, [igv_component], [alignment_summary])
if __name__ == "__main__":
demo.launch() |