Skip to content

Commit

Permalink
Change run_server->run and remove restrictions on dataframe naming (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinebridge authored Dec 13, 2023
1 parent d7222c4 commit 18debb1
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/source/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ app.layout = html.Div(
)

if __name__ == "__main__":
app.run_server(port=8081, debug=True)
app.run(port=8081, debug=True)

```

Expand Down
2 changes: 1 addition & 1 deletion examples/cgv_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@
)

if __name__ == "__main__":
app.run_server(port=3003, debug=True)
app.run(port=3003, debug=True)
2 changes: 1 addition & 1 deletion examples/dash_callbacks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
}
],
"source": [
"app.run_server(mode=\"external\", use_reloader=False, debug=True, port=3039)"
"app.run(mode=\"external\", use_reloader=False, debug=True, port=3039)"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion examples/non_notebook_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ component = create_component(config)
app.layout = html.Div([component], id="test")

if __name__ == "__main__":
app.run_server(port=3001, debug=True)
app.run(port=3001, debug=True)
2 changes: 1 addition & 1 deletion examples/skbr3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
}
],
"source": [
"app.run_server(mode=\"inline\", height=1000, use_reloader=False, debug=True, port=3031)\n"
"app.run(mode=\"inline\", height=1000, use_reloader=False, debug=True, port=3031)\n"
]
}
],
Expand Down
23 changes: 18 additions & 5 deletions jbrowse_jupyter/tracks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re
import uuid
import pandas as pd
import numpy as np
import numbers


def make_location(location, protocol, **kwargs):
Expand Down Expand Up @@ -459,16 +461,17 @@ def check_track_data(df):
raise TypeError("DataFrame must not be empty.")

if not check_columns(df):
raise TypeError("DataFrame must contain all required columns.")
raise TypeError("DataFrame must contain all required columns (refName, start, end, name).")

ref_names = df.dtypes["refName"]
names = df.dtypes["name"]
start = df.dtypes["start"]
end = df.dtypes["end"]
correct_string = ref_names == object and names == object
correct_numbers = start == int and end == int
# allows uints and ints
correct_numbers = np.issubdtype(start, np.integer) and np.issubdtype(end, np.integer)
if not (correct_numbers and correct_string):
col_err = "One or more columns do not have the correct data type."
col_err = "One or more columns do not have the correct data type (int)."
raise TypeError(col_err)


Expand All @@ -482,6 +485,15 @@ def check_columns(df):
:rtype: boolean
"""
required = ["refName", "start", "end", "name"]
# accomodates for a dataframe created from a bigwig file without requiring the user to mutate their columns
mapper = {
"chrom": "refName",
"value": "score"
}
# assigns arbitrary name to name column if it doesn't exist for a feature track from df
if 'name' not in df:
df['name'] = 'feature' + df.index.astype(str)
df.rename(mapper=mapper, axis=1, inplace=True)
return all(col in df for col in required)


Expand Down Expand Up @@ -517,8 +529,9 @@ def get_track_data(df):
df["additional"] = ""
if "score" in df:
required.append("score")
if df.dtypes["score"] != int:
raise TypeError("Score column must be an integer")
# if df.dtypes["score"] != int:
if isinstance(df.dtypes["score"], numbers.Number):
raise TypeError("Score column must be a number.")
filtered = df[required]
rows = filtered.to_dict("records")
features = []
Expand Down
2 changes: 1 addition & 1 deletion jbrowse_jupyter/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def launch(conf, **kwargs):
)
else:
raise TypeError(f"The {dash_comp} component is not supported.")
app.run_server(
app.run(
port=comp_port,
host=comp_host,
height=comp_height,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_check_track_data():


def test_check_columns():
column_error = "DataFrame must contain all required columns."
column_error = "DataFrame must contain all required columns (refName, start, end, name)."
invalid_df = {
"refName": ["1", "1"],
"end": [780, 101112],
Expand Down

0 comments on commit 18debb1

Please sign in to comment.