Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,38 +4,57 @@ import matplotlib.pyplot as plt
|
|
4 |
import fcsparser
|
5 |
|
6 |
def parse_fcs(file):
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def plot_fcs(data, x_axis, y_axis):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
19 |
|
20 |
def process_fcs(file):
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
return demo
|
39 |
|
40 |
# Gradio interface for uploading the FCS file
|
41 |
with gr.Blocks() as demo:
|
|
|
4 |
import fcsparser
|
5 |
|
6 |
def parse_fcs(file):
|
7 |
+
try:
|
8 |
+
# Parse the FCS file
|
9 |
+
meta, data = fcsparser.parse(file.name)
|
10 |
+
df = pd.DataFrame(data)
|
11 |
+
|
12 |
+
# Check if the DataFrame is empty
|
13 |
+
if df.empty:
|
14 |
+
raise ValueError("The parsed DataFrame is empty. Please check the .fcs file.")
|
15 |
+
|
16 |
+
return df
|
17 |
+
except Exception as e:
|
18 |
+
raise gr.Error(f"Error parsing .fcs file: {str(e)}")
|
19 |
|
20 |
def plot_fcs(data, x_axis, y_axis):
|
21 |
+
try:
|
22 |
+
# Plot the data
|
23 |
+
plt.figure(figsize=(10, 6))
|
24 |
+
plt.scatter(data[x_axis], data[y_axis], alpha=0.5)
|
25 |
+
plt.xlabel(x_axis)
|
26 |
+
plt.ylabel(y_axis)
|
27 |
+
plt.title(f"{x_axis} vs {y_axis}")
|
28 |
+
return plt.gcf() # Return the current figure
|
29 |
+
except Exception as e:
|
30 |
+
raise gr.Error(f"Error plotting data: {str(e)}")
|
31 |
|
32 |
def process_fcs(file):
|
33 |
+
try:
|
34 |
+
# Parse the FCS file and get the DataFrame
|
35 |
+
df = parse_fcs(file)
|
36 |
+
|
37 |
+
# Get the column names for x and y axis choices
|
38 |
+
columns = df.columns.tolist()
|
39 |
+
|
40 |
+
# Check if columns are available
|
41 |
+
if not columns:
|
42 |
+
raise ValueError("No columns found in the DataFrame.")
|
43 |
+
|
44 |
+
# Create a Gradio interface for selecting x and y axis
|
45 |
+
with gr.Blocks() as demo:
|
46 |
+
with gr.Row():
|
47 |
+
x_axis = gr.Dropdown(choices=columns, label="Select X-axis")
|
48 |
+
y_axis = gr.Dropdown(choices=columns, label="Select Y-axis")
|
49 |
+
plot = gr.Plot()
|
50 |
+
|
51 |
+
# Update the plot when the dropdowns change
|
52 |
+
x_axis.change(lambda x, y, df: plot_fcs(df, x, y), inputs=[x_axis, y_axis, gr.State(df)], outputs=plot)
|
53 |
+
y_axis.change(lambda x, y, df: plot_fcs(df, x, y), inputs=[x_axis, y_axis, gr.State(df)], outputs=plot)
|
54 |
|
55 |
+
return demo
|
56 |
+
except Exception as e:
|
57 |
+
raise gr.Error(f"Error processing .fcs file: {str(e)}")
|
|
|
|
|
58 |
|
59 |
# Gradio interface for uploading the FCS file
|
60 |
with gr.Blocks() as demo:
|