Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test, don't merge #41

Closed
wants to merge 117 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
75ffef8
changed pages to vpages in main
almanilsson Nov 14, 2024
03b586e
Updating vpages comment
almanilsson Nov 14, 2024
9d13a98
Merge remote-tracking branch 'upstream/main'
almanilsson Nov 15, 2024
c386947
fix: changed default height of tree
hannamlmv Nov 18, 2024
ccb66ab
Merge pull request #38 from hannamlmv/trees_page
hannamlmv Nov 18, 2024
f2419db
feat: changed tree position to range
hannamlmv Nov 18, 2024
8761669
fix: update tree size
hannamlmv Nov 18, 2024
ccb194d
fix: non-overlapping intervals
hannamlmv Nov 18, 2024
9844bc1
feat: added warning for unvalid inputs
hannamlmv Nov 18, 2024
a5a7cae
feat: added warning for tree index bounds
hannamlmv Nov 18, 2024
8b20036
fix: unable to move past highest index
hannamlmv Nov 18, 2024
9e6d0a2
chore: formatting
hannamlmv Nov 18, 2024
50f4c17
fix: long line
hannamlmv Nov 18, 2024
cb61f61
chore: rename variables
hannamlmv Nov 18, 2024
4685723
test
hannamlmv Nov 18, 2024
c8a51ba
test2
hannamlmv Nov 18, 2024
b037609
chore: formatting
hannamlmv Nov 18, 2024
b93b863
feat: added options to choose to search by position or index
hannamlmv Nov 19, 2024
be84c6c
style: some styling of toggle group
hannamlmv Nov 19, 2024
7898363
style: formatting
hannamlmv Nov 19, 2024
1b8f3d4
fix: variable name error
hannamlmv Nov 19, 2024
532b296
fix: casing error
hannamlmv Nov 19, 2024
7e07ceb
chore: reformatting
hannamlmv Nov 19, 2024
992f619
fix: put plots in a column
hannamlmv Nov 19, 2024
8beeee6
Fixing gap between map and toolbar, and removing sidebar options
almanilsson Nov 19, 2024
188bdf8
feat: made plots resizable
hannamlmv Nov 19, 2024
36f72d5
chore: formatting
hannamlmv Nov 19, 2024
6d473fa
fixing table alignment
almanilsson Nov 19, 2024
b9c9045
making geomap height static to make it more compatible with smaller b…
almanilsson Nov 19, 2024
67ef3a7
Merge pull request #39 from hannamlmv/trees_page
hannamlmv Nov 19, 2024
948309d
Merge pull request #43 from hannamlmv/structure_page
hannamlmv Nov 19, 2024
83b7117
reformat maps.py
almanilsson Nov 19, 2024
de5726d
removing comment " # TODO: Should make it based on what the user is …
almanilsson Nov 19, 2024
b2c4769
Changing "toggle" to a multiselect
almanilsson Nov 19, 2024
d1a00bc
Multiselect changed to multichoice
almanilsson Nov 19, 2024
a608eae
remormatting map and datastore
almanilsson Nov 19, 2024
0c43f01
fix: page setting functional
hannamlmv Nov 20, 2024
d3bc39d
feat: warning when entering existing name
hannamlmv Nov 20, 2024
c8b6b55
feat: colors added randomly to new samples
hannamlmv Nov 20, 2024
ede415e
chore: clean code
hannamlmv Nov 20, 2024
67fc91a
chore: fix order of imports
hannamlmv Nov 20, 2024
47ef80e
chore: formatting
hannamlmv Nov 20, 2024
5fb8961
fix: removed dark mode button
ThereseBjorkman Nov 20, 2024
819a5eb
chore: reformatted
ThereseBjorkman Nov 20, 2024
fd88825
Merge pull request #48 from hannamlmv/dark_mode
ThereseBjorkman Nov 20, 2024
5cb108b
fix: resizing of haplotype plot
hannamlmv Nov 20, 2024
ef22010
fix: changed order of sidebar menus
hannamlmv Nov 20, 2024
6627974
modified sample set ID change with better descriptions and an update …
almanilsson Nov 20, 2024
3521564
Merge pull request #46 from hannamlmv/sample_sets_page
hannamlmv Nov 20, 2024
cdfe002
Checking sample selection type validity
almanilsson Nov 20, 2024
8d5c628
changed individuals test dues to changes in layout
almanilsson Nov 20, 2024
df74b61
change in tests.. they are complaining that "Individuals table option…
almanilsson Nov 20, 2024
f4ea83d
reformat datastore
almanilsson Nov 20, 2024
0bec654
feat: dropdown for sort order
hannamlmv Nov 20, 2024
73fb531
adding default pair of selected sample groups to make structure page …
almanilsson Nov 20, 2024
bb83db6
commented out "Data modification" check in tests due to it not recogn…
almanilsson Nov 20, 2024
aa64073
feat: sort order ascending/descending
hannamlmv Nov 20, 2024
406bda7
fix: descending order sort
hannamlmv Nov 20, 2024
f9336dc
chore: reformatting
hannamlmv Nov 20, 2024
2acfa1e
feat: sorting ascending + descending always
hannamlmv Nov 21, 2024
941cf57
Merge pull request #49 from hannamlmv/ignn_page
hannamlmv Nov 21, 2024
ae307ba
Improved filters (though panels bool is a bit broken). Set map height
almanilsson Nov 21, 2024
3a96f7d
Merge pull request #41 from hannamlmv/individuals_page
almanilsson Nov 21, 2024
bfd9046
fix: changed sidebar menus to open
hannamlmv Nov 21, 2024
14dd395
fix: added y-axis labels to plots
hannamlmv Nov 21, 2024
15ed7ce
fix: removed window sizing option
hannamlmv Nov 21, 2024
3965cd6
chore: formatting
hannamlmv Nov 21, 2024
6446b5e
fix: added warning message when no samples selected
hannamlmv Nov 21, 2024
0b29197
fix: the warning pane had dissapeared from the trees page
hannamlmv Nov 21, 2024
36d91b6
chore:reformatting
hannamlmv Nov 21, 2024
44170ca
fix: long line
hannamlmv Nov 21, 2024
8b78928
fix: shortening line
hannamlmv Nov 21, 2024
9124cb8
Merge pull request #62 from hannamlmv/trees_page
hannamlmv Nov 21, 2024
c6eae50
fix: take bake window size
hannamlmv Nov 21, 2024
704bf6d
feat: added titles even when warnings are displayed
hannamlmv Nov 21, 2024
e7820df
fix: uncommented tests
hannamlmv Nov 21, 2024
0844cc8
fix: extended sleep time in tests
hannamlmv Nov 21, 2024
f210fdf
chore: undo some changes
hannamlmv Nov 21, 2024
657530b
initialising individuals data with nothing selected
almanilsson Nov 21, 2024
86a8135
removing remnant height and width params
almanilsson Nov 21, 2024
a58bb1e
Making the map depend on the individuals table - still very buggy but…
almanilsson Nov 21, 2024
9fe12b3
Merge pull request #64 from hannamlmv/tests
almanilsson Nov 22, 2024
ed85796
Merge pull request #61 from hannamlmv/structure_page
hannamlmv Nov 22, 2024
c7cc54b
Merge pull request #59 from hannamlmv/ignn_page
hannamlmv Nov 22, 2024
55144fc
Merge branch 'main' of https://github.com/hannamlmv/tseda into indivu…
almanilsson Nov 22, 2024
6bb6d87
fix: added warning for vbar when no samples selected
hannamlmv Nov 22, 2024
286b17e
feat: added warning for haplotype plot
hannamlmv Nov 22, 2024
b9446cb
chore:reformatting
hannamlmv Nov 22, 2024
35b658b
Merge pull request #65 from hannamlmv/ignn_page
hannamlmv Nov 22, 2024
9164060
change sample set selection default
almanilsson Nov 25, 2024
89451bf
Add empty map when no sets selected
almanilsson Nov 25, 2024
e90089f
fix issues #67, #69 and #70
almanilsson Nov 25, 2024
2251f00
update test sleep time
almanilsson Nov 25, 2024
60ac5ff
update test sleep time to 20
almanilsson Nov 25, 2024
9fc3009
Merge pull request #71 from hannamlmv/individuals_fix
almanilsson Nov 25, 2024
40e70e9
Merge branch 'main' of https://github.com/hannamlmv/tseda into indivu…
almanilsson Nov 26, 2024
8e46f3f
Merge remote-tracking branch 'upstream/main'
hannamlmv Nov 26, 2024
8f8a48b
fix: removed selection of sample sets, only using active sets
hannamlmv Nov 21, 2024
085b483
feat: warning pane when no samples selected
hannamlmv Nov 21, 2024
7d493ea
Fix error message when branch mode selected for uncalibrated data
hannamlmv Nov 25, 2024
7e276dc
reformat
hannamlmv Nov 25, 2024
bbd11b6
remove sample select on multiway plot
hannamlmv Nov 25, 2024
436f89d
test
hannamlmv Nov 25, 2024
dc583ac
test
hannamlmv Nov 25, 2024
f321dab
fix error
hannamlmv Nov 25, 2024
14be67f
add multichoice for comparisons
hannamlmv Nov 25, 2024
5e47e1d
add functional comparisons menu
hannamlmv Nov 26, 2024
b3e5a40
fix order of imports
hannamlmv Nov 26, 2024
362775b
remove commented line
hannamlmv Nov 26, 2024
a141556
fix graph updates automatically when comparison selection changes
hannamlmv Nov 26, 2024
21cf2f4
fix error when no samples chosen
hannamlmv Nov 26, 2024
aede969
Fix #15: Connect map and table with refresh button
almanilsson Nov 26, 2024
3ebed4d
Fix missing import
almanilsson Nov 26, 2024
c061b2e
Update GeoMap: Use parameters from dictionary
almanilsson Nov 26, 2024
1902a34
Merge pull request #63 from hannamlmv/statistics_page
hannamlmv Nov 27, 2024
c971f09
Merge pull request #72 from hannamlmv/indivuduals_map_table_connection
almanilsson Nov 27, 2024
6d6f1be
test
hannamlmv Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/tseda/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

logger = daiquiri.getLogger("tseda")

# test comment

def make_individuals_table(tsm):
result = []
Expand Down Expand Up @@ -107,7 +108,6 @@ class IndividualsTable(Viewer):
"type": "tickCross",
"tristate": True,
"indeterminateValue": None,
"placeholder": "Enter True/False",
},
}

Expand Down Expand Up @@ -136,10 +136,6 @@ def tooltip(self):
),
)

def sample_set_indices(self):
"""Return indices of sample groups."""
return sorted(self.data.rx.value["sample_set_id"].unique().tolist())

def sample_sets(self):
sample_sets = {}
samples = []
Expand All @@ -161,6 +157,14 @@ def get_sample_sets(self, indexes=None):
return [sample_sets[i] for i in indexes]
return [sample_sets[i] for i in sample_sets]

def sample_set_indices(self):
"""Return indices of sample groups."""
return sorted(self.data.rx.value["sample_set_id"].unique().tolist())

def selected_sample_set_indices(self):
samples, sample_sets = self.sample_sets()
return list(sample_sets.keys())

@property
def sample2ind(self):
"""Map sample (tskit node) ids to individual ids"""
Expand All @@ -183,16 +187,14 @@ def loc(self, i):

@pn.depends("page_size", "sample_select.value", "mod_update_button.value")
def __panel__(self):
self.data.rx.value["selected"] = False
if (
isinstance(self.sample_select.value, list)
and self.sample_select.value
):
if isinstance(self.sample_select.value, list):
self.data.rx.value["selected"] = False
for sample_set_id in self.sample_select.value:
self.data.rx.value.loc[
self.data.rx.value.sample_set_id == sample_set_id,
"selected",
] = True

if self.sample_set_to is not None:
if self.population_from is not None:
try:
Expand Down
4 changes: 2 additions & 2 deletions src/tseda/vpages/individuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
class IndividualsPage(View):
key = "individuals"
title = "Individuals"
geomap = param.ClassSelector(class_=GeoMap)
data = param.ClassSelector(class_=IndividualsTable)
geomap = param.ClassSelector(class_=GeoMap)

def __init__(self, **params):
super().__init__(**params)
self.geomap = GeoMap(datastore=self.datastore)
self.data = self.datastore.individuals_table
self.geomap = GeoMap(datastore=self.datastore)

def __panel__(self):
return pn.Column(self.geomap, self.data)
Expand Down
44 changes: 32 additions & 12 deletions src/tseda/vpages/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import geopandas
import hvplot.pandas # noqa
import pandas as pd
import panel as pn
import param
import xyzservices.providers as xyz
Expand All @@ -34,17 +35,15 @@


class GeoMap(View):
height = param.Integer(default=400, doc="Height of the map")
width = param.Integer(default=1200, doc="Width of the map")

tiles_selector = param.Selector(
default="WorldPhysical",
objects=list(tiles_options.keys()),
doc="Select XYZ tiles for map",
)
tiles = tiles_options[tiles_selector.default]
refresh_button = pn.widgets.Button(name="Refresh map")

@pn.depends("tiles_selector", "height", "width")
@pn.depends("refresh_button.value")
def __panel__(self):
self.tiles = tiles_options[self.tiles_selector]
df = self.datastore.individuals_table.data.rx.value
Expand All @@ -56,24 +55,45 @@ def __panel__(self):
)
color = color.loc[~gdf.geometry.is_empty.values]
gdf = gdf[~gdf.geometry.is_empty]
return gdf.hvplot.points(

kw = {
"geo": True,
"tiles": self.tiles,
"tiles_opts": {"alpha": 0.5},
"responsive": True,
"max_height": 200,
"min_height": 199,
"xlim": (-180, 180),
"ylim": (-60, 70),
"tools": ["wheel_zoom", "box_select", "tap", "pan", "reset"],
}

if gdf.empty:
gdf = geopandas.GeoDataFrame(
pd.DataFrame(index=[0]),
geometry=geopandas.points_from_xy([0.0], [0.0]),
)
return gdf.hvplot(
**kw,
hover_cols=None,
size=100,
color=None,
fill_alpha=0.0,
line_color=None,
)
return gdf.hvplot(
**kw,
hover_cols=["name", "population", "sample_set_id"],
geo=True,
tiles=self.tiles,
tiles_opts={"alpha": 0.5},
max_height=self.height,
min_height=self.height,
size=100,
color=color,
tools=["wheel_zoom", "box_select", "tap", "pan", "reset"],
fill_alpha=0.5,
line_color="black",
responsive=True,
)

def sidebar(self):
return pn.Card(
self.param.tiles_selector,
self.refresh_button,
collapsed=False,
title="Map options",
header_background=config.SIDEBAR_BACKGROUND,
Expand Down
116 changes: 67 additions & 49 deletions src/tseda/vpages/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import ast
import itertools

import holoviews as hv
import pandas as pd
Expand All @@ -25,9 +26,10 @@


# TODO: make sure this is safe
def eval_sample_sets(sample_sets):
"""Evaluate sample sets parameter."""
return ast.literal_eval(sample_sets)
def eval_comparisons(comparisons):
"""Evaluate comparisons parameter."""
evaluated = ast.literal_eval(str(comparisons).replace("-", ","))
return [tuple(map(int, item.split(","))) for item in evaluated]


def eval_indexes(indexes):
Expand All @@ -37,9 +39,10 @@ def eval_indexes(indexes):

class OnewayStats(View):
mode = param.Selector(
objects=["branch", "site"],
objects=["site"],
default="site",
doc="Select mode for statistics.",
doc="""Select mode (site or branch) for statistics.
Branch mode is only available for calibrated data.""",
)
statistic = param.Selector(
objects=["Tajimas_D", "diversity"],
Expand All @@ -49,9 +52,11 @@ class OnewayStats(View):
window_size = param.Integer(
default=10000, bounds=(1, None), doc="Size of window"
)
sample_sets = param.String(
default="[0,1]",
doc="Comma-separated list of sample sets (0-indexed) to plot.",

sample_select_warning = pn.pane.Alert(
"""Select at least 1 sample set to see this plot.
Sample sets are selected on the Individuals page""",
alert_type="warning",
)

@property
Expand All @@ -63,19 +68,23 @@ def tooltip(self):
)
)

@param.depends("mode", "statistic", "window_size", "sample_sets")
def __init__(self, **params):
super().__init__(**params)
if self.datastore.tsm.ts.time_units != "uncalibrated":
self.param.mode.objects = ["branch", "site"]

@param.depends("mode", "statistic", "window_size")
def __panel__(self):
data = None
windows = make_windows(
self.window_size, self.datastore.tsm.ts.sequence_length
)
sample_sets_list = eval_sample_sets(self.sample_sets)
try:
sample_sets = self.datastore.individuals_table.get_sample_sets(
sample_sets_list
)
except KeyError:
return pn.pane.Alert("Sample set error. Check sample set indexes.")
sample_sets_list = (
self.datastore.individuals_table.selected_sample_set_indices()
)
if len(sample_sets_list) < 1:
return self.sample_select_warning
sample_sets = self.datastore.individuals_table.get_sample_sets()

if self.statistic == "Tajimas_D":
data = self.datastore.tsm.ts.Tajimas_D(
Expand Down Expand Up @@ -120,7 +129,6 @@ def sidebar(self):
self.param.mode,
self.param.statistic,
self.param.window_size,
self.param.sample_sets,
collapsed=False,
title="Oneway statistics plotting options",
header_background=config.SIDEBAR_BACKGROUND,
Expand All @@ -131,9 +139,10 @@ def sidebar(self):

class MultiwayStats(View):
mode = param.Selector(
objects=["branch", "site"],
objects=["site"],
default="site",
doc="Select mode for statistics.",
doc="""Select mode (site or branch) for statistics.
Branch mode is only available for calibrated data.""",
)
statistic = param.Selector(
objects=["Fst", "divergence"],
Expand All @@ -143,16 +152,14 @@ class MultiwayStats(View):
window_size = param.Integer(
default=10000, bounds=(1, None), doc="Size of window"
)
sample_sets = param.String(
default="[0,1,2]",
doc="Comma-separated list of sample sets (0-indexed) to compare.",
comparisons = pn.widgets.MultiChoice(
name="Comparisons", description="Choose indexes to compare."
)
indexes = param.String(
default="[(0,1), (0,2), (1,2)]",
doc=(
"Comma-separated list of tuples of sample sets "
"(0-indexed) indexes to compare."
),

sample_select_warning = pn.pane.Alert(
"""Select at least 2 sample sets to see this plot.
Sample sets are selected on the Individuals page""",
alert_type="warning",
)
cmaps = {
cm.name: cm
Expand All @@ -167,6 +174,11 @@ class MultiwayStats(View):
doc="Holoviews colormap for sample set pairs",
)

def __init__(self, **params):
super().__init__(**params)
if self.datastore.tsm.ts.time_units != "uncalibrated":
self.param.mode.objects = ["branch", "site"]

@property
def tooltip(self):
return pn.widgets.TooltipIcon(
Expand All @@ -176,42 +188,49 @@ def tooltip(self):
)
)

def set_multichoice_options(self):
all_comparisons = list(
f"{x}-{y}"
for x, y in itertools.combinations(
self.datastore.individuals_table.selected_sample_set_indices(),
2,
)
)
self.comparisons.options = all_comparisons
if self.comparisons.value == [] and all_comparisons != []:
self.comparisons.value = [all_comparisons[0]]

@pn.depends(
"mode",
"statistic",
"window_size",
"sample_sets",
"indexes",
"colormap",
"mode", "statistic", "window_size", "colormap", "comparisons.value"
)
def __panel__(self):
self.set_multichoice_options()

data = None
tsm = self.datastore.tsm
sample_sets_list = []
windows = []
indexes_list = []
colormap_list = []
windows = make_windows(self.window_size, tsm.ts.sequence_length)
sample_sets_list = eval_sample_sets(self.sample_sets)
indexes_list = eval_indexes(self.indexes)
try:
sample_sets = self.datastore.individuals_table.get_sample_sets(
sample_sets_list
)
except KeyError:
return pn.pane.Alert("Sample set error. Check sample set indexes.")
comparisons = eval_comparisons(self.comparisons.value)

sample_sets_list = (
self.datastore.individuals_table.selected_sample_set_indices()
)
if len(sample_sets_list) < 2:
return self.sample_select_warning
sample_sets = self.datastore.individuals_table.get_sample_sets()
if self.statistic == "Fst":
data = tsm.ts.Fst(
sample_sets,
windows=windows,
indexes=indexes_list,
indexes=comparisons,
mode=self.mode,
)
elif self.statistic == "divergence":
data = tsm.ts.divergence(
sample_sets,
windows=windows,
indexes=indexes_list,
indexes=comparisons,
mode=self.mode,
)
else:
Expand All @@ -226,7 +245,7 @@ def __panel__(self):
sample_sets_table.loc(j)["name"],
]
)
for i, j in indexes_list
for i, j in comparisons
],
)
position = hv.Dimension(
Expand Down Expand Up @@ -255,8 +274,7 @@ def sidebar(self):
self.param.mode,
self.param.statistic,
self.param.window_size,
self.param.sample_sets,
self.param.indexes,
self.comparisons,
self.param.colormap,
collapsed=False,
title="Multiway statistics plotting options",
Expand Down
Loading