Skip to content

Commit

Permalink
🚀 98 percent done with storage backend
Browse files Browse the repository at this point in the history
  • Loading branch information
amilworks committed Aug 29, 2023
1 parent bf0858b commit 0b51411
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 35 deletions.
15 changes: 5 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,13 @@ repos:
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id : isort
args : ["--profile", "black", "--filter-files"]
- repo: https://github.com/asottile/blacken-docs
rev: v1.12.0
hooks:
- id: blacken-docs
additional_dependencies: [black==20.8b0]
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: [flake8-docstrings]
# - repo: https://github.com/pycqa/flake8
# rev: 4.0.1
# hooks:
# - id: flake8
# additional_dependencies: [flake8-docstrings]
61 changes: 52 additions & 9 deletions cells/streamlit/cellgeometry/pages/1-Load_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
get_files_from_folder,
check_file_extensions,
parse_coordinates,
get_file_or_folder_type,
)
import plotly.graph_objects as go
import streamlit as st
Expand All @@ -22,6 +23,7 @@
# REMOVE BRUH
if username is None:
username = "bruh"
st.session_state["username"] = username
#########################################

current_time = time.localtime()
Expand Down Expand Up @@ -163,30 +165,71 @@ def handle_uploaded_file(uploaded_file, destination_folder):
# previewVisualization(st.session_state["cells_list"])

elif config_option == "Choose an Uploaded File":

if upload_folder and os.path.exists(upload_folder):

# List all files in the directory
# files = [f for f in os.listdir(upload_folder) if os.path.isfile(os.path.join(upload_folder, f))]

files = [
f
for f in os.listdir(upload_folder)
if os.path.isfile(os.path.join(upload_folder, f))
if os.path.exists(os.path.join(upload_folder, f))
]
if files:
selected_file = st.selectbox("Select a previously uploaded file:", files)
st.session_state["selected_dataset"] = selected_file
st.info(f"You selected {selected_file}")
build_and_load_data(upload_folder)
# previewVisualization(st.session_state["cells_list"])
else:

if not files:
st.warning("No files found in the directory!")
# st.stop()

# Display the files in a dropdown
selected_file = st.selectbox("Choose a file:", files)
st.session_state["selected_dataset"] = os.path.join(
upload_folder, selected_file
)
selection_type = get_file_or_folder_type(st.session_state["selected_dataset"])
build_and_load_data(st.session_state["selected_dataset"])
st.info(f"{selection_type} Selected: {selected_file}")

# if "Folder" in selection_type:

# selected_folder_files = [f for f in os.listdir(st.session_state["selected_dataset"]) if os.path.isfile(os.path.join(st.session_state["selected_dataset"], f))]
# view_selected_folder_files = st.selectbox("Choose a file:", selected_folder_files)

# files = [
# f
# for f in os.listdir(upload_folder)
# if os.path.isfile(os.path.join(upload_folder, f))
# ]
# st.write(files)
# if files:
# selected_file = st.selectbox("Select a previously uploaded file:", files)
# st.session_state["selected_dataset"] = selected_file
# st.info(f"You selected {selected_file}")
# build_and_load_data(upload_folder)
# # previewVisualization(st.session_state["cells_list"])
# else:
# st.warning("No files found in the directory!")
else:
st.warning("No files have been uploaded yet.")


if st.session_state.cells_list == True:
st.warning("Please upload a zipped file of ROIs or a CSV/TXT file.")
st.stop()


st.markdown("## Preview of Cell Data")

st.warning(
"⚠️ This is a preview your uploaded raw data. We have not preprocessed your data yet to close the curves and remove duplicates. Please continue to the next page to preprocess your data."
)

(
col1,
col2,
) = st.columns(2)


# Sanity check visualization
cell_num = st.number_input(
f"Visualize a cell. Pick a number between 0 and {len(st.session_state.cells_list)-1}",
Expand All @@ -201,7 +244,7 @@ def handle_uploaded_file(uploaded_file, destination_folder):
) # Using a constant value for z, placing the line on the "floor" of the 3D space

# Define a custom color for the line plot
line_color = "rgb(31, 119, 180)" # Adjust the RGB values as per your preference
line_color = "rgb(255, 0, 191)" # Adjust the RGB values as per your preference

# Create a 3D trace for the cell data
trace = go.Scatter3d(
Expand Down
10 changes: 10 additions & 0 deletions cells/streamlit/cellgeometry/utils/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ def perimeter(xy):
xy : array-like, shape=[n_points, 2]
Polygon, such that:
x = xy[:, 0]; y = xy[:, 1]
Examples
--------
>>> import numpy as np
>>> xy = np.array([[0, 0], [0, 1], [1, 1], [1, 0]])
>>> np.isclose(perimeter(xy), 4.0)
True
>>> xy = np.array([[0, 0], [0, 3], [4, 3], [4, 0]])
>>> np.isclose(perimeter(xy), 14.0)
True
"""
first_point = gs.expand_dims(gs.array(xy[0]), axis=0)
xy1 = gs.concatenate([xy[1:], first_point], axis=0)
Expand Down
33 changes: 33 additions & 0 deletions cells/streamlit/cellgeometry/utils/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,36 @@ def parse_coordinates(file_path):
coordinates[cell_id] = np.array(cell_data)

return coordinates


def get_file_or_folder_type(path):
"""Determine whether a given path points to a file, a folder, or neither.
Parameters
----------
path : str
The path to the item (file or folder) you want to check.
Returns
-------
str
A string indicating the type of the item:
- 'File' if the path points to a file.
- 'Folder' if the path points to a folder.
- 'Neither' if the path does not point to a file or folder.
Examples
--------
>>> get_file_or_folder_type('/path/to/your/selected/file_or_folder')
'Folder'
>>> get_file_or_folder_type('/path/to/your/selected/example.txt')
'File'
>>> get_file_or_folder_type('/path/to/nonexistent/item')
'Neither'
"""
if os.path.isfile(path):
return ":page_facing_up: File"
elif os.path.isdir(path):
return ":file_folder: Folder"
else:
return "Neither"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Unit tests for the basic shape features."""

import dyn.features.basic as basic
import cells.streamlit.cellgeometry.utils.basic as basic
import geomstats.backend as gs


Expand Down
File renamed without changes.
15 changes: 0 additions & 15 deletions pyproject.toml

This file was deleted.

0 comments on commit 0b51411

Please sign in to comment.