Skip to content

Commit

Permalink
Modularize
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 11, 2023
1 parent 68a3d57 commit d3575d8
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 190 deletions.
3 changes: 2 additions & 1 deletion jbrowse_jupyter/dev_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def send_head(self):
last = file_len - 1
response_length = last - first + 1

self.send_header("Content-Range", "bytes %s-%s/%s" % (first, last, file_len))
self.send_header("Content-Range", "bytes %s-%s/%s" %
(first, last, file_len))
self.send_header("Content-Length", str(response_length))
self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))
self.end_headers()
Expand Down
3 changes: 1 addition & 2 deletions jbrowse_jupyter/jbrowse_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,7 @@ def add_df_track(self, track_data, name, **kwargs):
"adapter": adapter,
}
err = (
f'track with trackId: "{track_id}" already exists in config.',
"Set overwrite to True if you want to overwrite it.",
f'track with trackId: "{track_id}" already exists in config. Set overwrite to True if you want to overwrite it.',
)
if track_id in self.tracks_ids_map.keys() and not overwrite:
raise TypeError(err)
Expand Down
187 changes: 63 additions & 124 deletions jbrowse_jupyter/util.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
import re
import copy
import os

import dash_jbrowse as jb
from dash import html, Dash
from urllib.parse import urlparse


hg38_lgv = {
"assembly": {
"name": "GRCh38",
"sequence": {
"type": "ReferenceSequenceTrack",
"trackId": "GRCh38-ReferenceSequenceTrack",
"adapter": {
"type": "BgzipFastaAdapter",
"fastaLocation": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/fasta/GRCh38.fa.gz"
},
"faiLocation": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/fasta/GRCh38.fa.gz.fai"
},
"gziLocation": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/fasta/GRCh38.fa.gz.gzi"
},
hg38_assembly = {
"name": "hg38",
"sequence": {
"type": "ReferenceSequenceTrack",
"trackId": "GRCh38-ReferenceSequenceTrack",
"adapter": {
"type": "BgzipFastaAdapter",
"fastaLocation": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/fasta/GRCh38.fa.gz"
},
"faiLocation": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/fasta/GRCh38.fa.gz.fai"
},
"gziLocation": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/fasta/GRCh38.fa.gz.gzi"
},
},
"aliases": ["hg38"],
"refNameAliases": {
"adapter": {
"type": "RefNameAliasAdapter",
"location": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt"
},
}
},
},
"aliases": ["GRCh38"],
"refNameAliases": {
"adapter": {
"type": "RefNameAliasAdapter",
"location": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt"
},
}
},
}
hg38_lgv = {
"assembly": hg38_assembly,
"tracks": [],
"location": "10:29,838,737..29,838,819",
"defaultSession": {
Expand All @@ -49,38 +50,7 @@


hg38_cgv = {
"assembly": {
"name": "hg38",
"sequence": {
"type": "ReferenceSequenceTrack",
"trackId": "GRCh38-ReferenceSequenceTrack",
"adapter": {
"type": "BgzipFastaAdapter",
"fastaLocation": {
"uri": "https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz",
"locationType": "UriLocation",
},
"faiLocation": {
"uri": "https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz.fai",
"locationType": "UriLocation",
},
"gziLocation": {
"uri": "https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz.gzi",
"locationType": "UriLocation",
},
},
},
"aliases": ["GRCh38"],
"refNameAliases": {
"adapter": {
"type": "RefNameAliasAdapter",
"location": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt",
"locationType": "UriLocation",
},
}
},
},
"assembly": hg38_assembly,
"tracks": [],
"defaultSession": {
"name": "My session",
Expand All @@ -92,36 +62,36 @@
},
},
}

hg19_lgv = {
"assembly": {
"name": "hg19",
"aliases": ["GRCh37"],
"sequence": {
"type": "ReferenceSequenceTrack",
"trackId": "hg19-ReferenceSequenceTrack",
"adapter": {
"type": "BgzipFastaAdapter",
"fastaLocation": {
"uri": "https://jbrowse.org/genomes/hg19/fasta/hg19.fa.gz"
},
"faiLocation": {
"uri": "https://jbrowse.org/genomes/hg19/fasta/hg19.fa.gz.fai"
},
"gziLocation": {
"uri": "https://jbrowse.org/genomes/hg19/fasta/hg19.fa.gz.gzi"
},
hg19_assembly = {
"name": "hg19",
"aliases": ["GRCh37"],
"sequence": {
"type": "ReferenceSequenceTrack",
"trackId": "hg19-ReferenceSequenceTrack",
"adapter": {
"type": "BgzipFastaAdapter",
"fastaLocation": {
"uri": "https://jbrowse.org/genomes/hg19/fasta/hg19.fa.gz"
},
"faiLocation": {
"uri": "https://jbrowse.org/genomes/hg19/fasta/hg19.fa.gz.fai"
},
"gziLocation": {
"uri": "https://jbrowse.org/genomes/hg19/fasta/hg19.fa.gz.gzi"
},
},
"refNameAliases": {
"adapter": {
"type": "RefNameAliasAdapter",
"location": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/hg19/hg19_aliases.txt"
},
}
},
},
"refNameAliases": {
"adapter": {
"type": "RefNameAliasAdapter",
"location": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/hg19/hg19_aliases.txt"
},
}
},
}
hg19_lgv = {
"assembly": hg19_assembly,
"tracks": [],
"defaultSession": {
"name": "test",
Expand All @@ -135,38 +105,7 @@
}

hg19_cgv = {
"assembly": {
"name": "hg19",
"aliases": ["GRCh37"],
"sequence": {
"type": "ReferenceSequenceTrack",
"trackId": "Pd8Wh30ei9R",
"adapter": {
"type": "BgzipFastaAdapter",
"fastaLocation": {
"uri": "https://jbrowse.org/genomes/hg19/fasta/hg19.fa.gz",
"locationType": "UriLocation",
},
"faiLocation": {
"uri": "https://jbrowse.org/genomes/hg19/fasta/hg19.fa.gz.fai",
"locationType": "UriLocation",
},
"gziLocation": {
"uri": "https://jbrowse.org/genomes/hg19/fasta/hg19.fa.gz.gzi",
"locationType": "UriLocation",
},
},
},
"refNameAliases": {
"adapter": {
"type": "RefNameAliasAdapter",
"location": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/hg19/hg19_aliases.txt",
"locationType": "UriLocation",
},
}
},
},
"assembly": hg19_assembly,
"tracks": [],
"defaultSession": {
"name": "My session",
Expand Down Expand Up @@ -210,11 +149,11 @@ def get_name(assembly_file):
name_end = 0
name_start = 0
for i in range(0, len(assembly_file)):
if assembly_file[len(assembly_file) - i - 1 : len(assembly_file) - i] == "/":
if assembly_file[len(assembly_file) - i - 1: len(assembly_file) - i] == "/":
name_start = len(assembly_file) - i
break
for i in range(name_start, len(assembly_file)):
if assembly_file[i : i + 1] == ".":
if assembly_file[i: i + 1] == ".":
name_end = i
break

Expand All @@ -230,14 +169,14 @@ def get_default(name, view_type="LGV"):
"""Returns the configuration object given a genome name."""
if name == "hg38":
if view_type == "CGV":
return hg38_cgv
return copy.deepcopy(hg38_cgv)
else:
return hg38_lgv
return copy.deepcopy(hg38_lgv)
elif name == "hg19":
if view_type == "CGV":
return hg19_cgv
return copy.deepcopy(hg19_cgv)
else:
return hg19_lgv
return copy.deepcopy(hg19_lgv)


def create_component(conf, **kwargs):
Expand Down
3 changes: 0 additions & 3 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@

# Same as Black.
line-length = 88
indent-width = 4
Loading

0 comments on commit d3575d8

Please sign in to comment.