Skip to content

Commit

Permalink
Add formatter check
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 11, 2023
1 parent 3958d5d commit 68a3d57
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 121 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Ruff
on: [ push, pull_request ]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
66 changes: 5 additions & 61 deletions jbrowse_jupyter/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,14 @@
}
},
},
"tracks": [
{
"type": "FeatureTrack",
"trackId": "ncbi_refseq_109_hg38",
"name": "NCBI RefSeq (GFF3Tabix)",
"assemblyNames": ["GRCh38"],
"category": ["Annotation"],
"adapter": {
"type": "Gff3TabixAdapter",
"gffGzLocation": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GCA_000001405.15_GRCh38_full_analysis_set.refseq_annotation.sorted.gff.gz"
},
"index": {
"location": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GCA_000001405.15_GRCh38_full_analysis_set.refseq_annotation.sorted.gff.gz.tbi"
}
},
},
}
],
"tracks": [],
"location": "10:29,838,737..29,838,819",
"defaultSession": {
"name": "My session",
"view": {
"id": "linearGenomeView",
"type": "LinearGenomeView",
"tracks": [
{
"type": "ReferenceSequenceTrack",
"configuration": "GRCh38-ReferenceSequenceTrack",
"displays": [
{
"type": "LinearReferenceSequenceDisplay",
"configuration": "GRCh38-ReferenceSequenceTrack-LinearReferenceSequenceDisplay",
}
],
}
],
"tracks": [],
},
},
}
Expand Down Expand Up @@ -152,39 +122,13 @@
}
},
},
"tracks": [
{
"type": "FeatureTrack",
"trackId": "repeats_hg19",
"name": "Repeats",
"assemblyNames": ["hg19"],
"category": ["Annotation"],
"adapter": {
"type": "BigBedAdapter",
"bigBedLocation": {
"uri": "https://jbrowse.org/genomes/hg19/repeats.bb",
"locationType": "UriLocation",
},
},
}
],
"tracks": [],
"defaultSession": {
"name": "test",
"view": {
"id": "aU9Nqje1U",
"type": "LinearGenomeView",
"tracks": [
{
"type": "ReferenceSequenceTrack",
"configuration": "hg19-ReferenceSequenceTrack",
"displays": [
{
"type": "LinearReferenceSequenceDisplay",
"configuration": "hg19-ReferenceSequenceTrack-LinearReferenceSequenceDisplay",
}
],
}
],
"tracks": [],
},
},
"location": "1:68654694..68654738",
Expand Down Expand Up @@ -284,7 +228,7 @@ def get_name_regex(assembly_file):

def get_default(name, view_type="LGV"):
"""Returns the configuration object given a genome name."""
if name == "hg383838":
if name == "hg38":
if view_type == "CGV":
return hg38_cgv
else:
Expand Down
96 changes: 36 additions & 60 deletions tests/test_tracks.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import pytest
import pandas as pd
from jbrowse_jupyter.tracks import (
make_location,
check_track_data,
get_track_data
)
from jbrowse_jupyter.tracks import make_location, check_track_data, get_track_data
from jbrowse_jupyter.jbrowse_config import create

# test files
base = "https://s3.amazonaws.com/jbrowse.org/genomes/"
cram = base + "hg19/skbr3/reads_lr_skbr3.fa_ngmlr-0.2.3_mapped.down.cram"
bam = base + "hg19/amplicon_deep_seq/out.marked.bam"
gff3 = base + "hg19/ncbi_refseq/GRCh37_latest_genomic.sort.gff"
gff3Tabix = base + "GRCh38/ncbi_refseq/GCA_000001405.15_GRCh38_full" \
"_analysis_set.refseq_annotation.sorted.gff.gz"
vcf = "https://ftp.ncbi.nlm.nih.gov/pub/" \
"clinvar/vcf_GRCh37/clinvar.vcf"
vcfGz = "https://ftp.ncbi.nlm.nih.gov/pub/" \
"clinvar/vcf_GRCh38/clinvar.vcf.gz"
bigWig = "http://hgdownload.cse.ucsc.edu/goldenpath/hg38/" \
"phyloP100way/hg38.phyloP100way.bw"
gff3_tabix_index = gff3Tabix + ".tbi"
cram = "https://s3.amazonaws.com/jbrowse.org/genomes/hg19/skbr3/reads_lr_skbr3.fa_ngmlr-0.2.3_mapped.down.cram"
bam = (
"https://s3.amazonaws.com/jbrowse.org/genomes/hg19/amplicon_deep_seq/out.marked.bam"
)
gff3 = "https://s3.amazonaws.com/jbrowse.org/genomes/hg19/ncbi_refseq/GRCh37_latest_genomic.sort.gff"
gff3Tabix = "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GCA_000001405.15_GRCh38_full_analysis_set.refseq_annotation.sorted.gff.gz"
gff3TabixIndex = "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GCA_000001405.15_GRCh38_full_analysis_set.refseq_annotation.sorted.gff.gz.tbi"
bigWig = (
"http://hgdownload.cse.ucsc.edu/goldenpath/hg38/phyloP100way/hg38.phyloP100way.bw"
)
vcf = "https://ftp.ncbi.nlm.nih.gov/pub/clinvar/vcf_GRCh37/clinvar.vcf"
vcfGz = "https://ftp.ncbi.nlm.nih.gov/pub/clinvar/vcf_GRCh37/clinvar.vcf.tbi"


def test_make_location():
Expand All @@ -39,7 +33,6 @@ def test_add_track_fail():

def test_alignments():
conf = create("LGV", genome="hg19")
# BAM or CRAM alignment data
conf.add_track(cram, name="alignments cram track example")
conf.add_track(bam, name="alignments bam track example")
cram_track = conf.get_track("alignments cram track example")
Expand All @@ -51,11 +44,9 @@ def test_alignments():
def test_feature():
conf = create("LGV", genome="hg38")
track_error = "Adapter type is not recognized"
# gff is not supported
with pytest.raises(TypeError) as excinfo:
conf.add_track(gff3, name="gff feature")
assert track_error in str(excinfo)
# gff3 is supported
conf.add_track(gff3Tabix, name="gff3 feature")
gff3_track = conf.get_track("gff3 feature")
assert gff3_track[0]["type"] == "FeatureTrack"
Expand All @@ -71,33 +62,33 @@ def test_add_track_type_fail():

def test_add_track_overwrite():
conf = create("LGV", genome="hg38")
overwrite_err = "track with trackId: " \
'"GRCh38-test" already exists inconfig.' \
' Set overwrite to True to overwrite it.'
conf.add_track(gff3Tabix, name='test')
overwrite_err = (
"track with trackId: "
'"GRCh38-test" already exists inconfig.'
" Set overwrite to True to overwrite it."
)
conf.add_track(gff3Tabix, name="test")
with pytest.raises(TypeError) as excinfo:
conf.add_track(gff3Tabix, name='test')
conf.add_track(gff3Tabix, name="test")
assert overwrite_err in str(excinfo)
conf.add_track(gff3Tabix, name='test', overwrite=True)
conf.add_track(gff3Tabix, name="test", overwrite=True)
tracks = conf.get_tracks()
# should have one track from hg38 conf + test track == 2
assert len(tracks) == 2
assert len(tracks) == 1


def test_add_track_with_index():
conf = create("LGV", genome="hg38")
conf.add_track(gff3Tabix, name="test")
conf2 = create("LGV", genome="hg38")
conf2.add_track(gff3Tabix, name="test", index=gff3_tabix_index)
conf2.add_track(gff3Tabix, name="test", index=gff3TabixIndex)
index_one = conf.get_track("test")
idx = index_one[0]['adapter']['index']['location']['uri']
idx = index_one[0]["adapter"]["index"]["location"]["uri"]
index_two = conf2.get_track("test")
idx2 = index_two[0]['adapter']['index']['location']['uri']
idx2 = index_two[0]["adapter"]["index"]["location"]["uri"]
assert idx == idx2


def test_variant():
# VCF data
conf = create("LGV", genome="hg19")
conf.add_track(vcf, name="vcf track")
conf.add_track(vcfGz, name="vcfgz track")
Expand All @@ -106,68 +97,53 @@ def test_variant():


def test_wiggle():
# bigWig data (quantitative/wiggle)
conf = create("LGV", genome="hg19")
conf.add_track(bigWig, name="wiggle track")
bigwig_track = conf.get_track("wiggle track")
assert bigwig_track[0]["type"] == "QuantitativeTrack"


# ==== dataframe track ======
def test_data_frame_track():
hg38 = create('LGV', genome='hg38')
assert len(hg38.get_tracks()) == 1
hg38 = create("LGV", genome="hg38")
assert len(hg38.get_tracks()) == 0
data_frame = {
"refName": ["1", "1"],
"start": [123, 456],
"end": [780, 101112],
"name": ["feature1", "feature2"]
"name": ["feature1", "feature2"],
}
df = pd.DataFrame(data_frame)
hg38.add_df_track(df, 'data_frame_track_name')
data_empty = {
"refName": [],
"start": [],
"end": [],
"name": []
}
assert len(hg38.get_tracks()) == 2
# throw error if the dataframe is empty
hg38.add_df_track(df, "data_frame_track_name")
data_empty = {"refName": [], "start": [], "end": [], "name": []}
assert len(hg38.get_tracks()) == 1
df_empty = pd.DataFrame(data_empty)
df_error = "DataFrame must not be empty."
with pytest.raises(TypeError) as excinfo:
hg38.add_df_track(df_empty, 'empty_data_frame_track')
hg38.add_df_track(df_empty, "empty_data_frame_track")
assert df_error in str(excinfo)


def test_check_track_data():
# Test track from dataframe
df_error = "Track data must be a DataFrame"
invalid_df = {
"refName": "1",
"start": 123,
"end": 789,
"name": "feature1"
}
invalid_df = {"refName": "1", "start": 123, "end": 789, "name": "feature1"}
with pytest.raises(TypeError) as excinfo:
check_track_data(invalid_df)
assert df_error in str(excinfo)
data_frame = {
"refName": ["1", "1"],
"start": [123, 456],
"end": [780, 101112],
"name": ["feature1", "feature2"]
"name": ["feature1", "feature2"],
}
pd.DataFrame(data_frame)


def test_check_columns():
# missing start column
column_error = "DataFrame must contain all required columns."
invalid_df = {
"refName": ["1", "1"],
"end": [780, 101112],
"name": ['feature1', 'feature2']
"name": ["feature1", "feature2"],
}
df = pd.DataFrame(invalid_df)
with pytest.raises(TypeError) as excinfo:
Expand All @@ -180,7 +156,7 @@ def test_get_df_features():
"refName": ["1", "1"],
"start": [123, 456],
"end": [780, 101112],
"name": ["feature1", "feature2"]
"name": ["feature1", "feature2"],
}
df = pd.DataFrame(data_frame)
features = get_track_data(df)
Expand Down

0 comments on commit 68a3d57

Please sign in to comment.