Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -645,6 +645,8 @@ def compute_gene_statistics(gene_shap: np.ndarray) -> Dict[str, float]:
|
|
645 |
|
646 |
def create_simple_genome_diagram(gene_results: List[Dict[str, Any]], genome_length: int) -> Image.Image:
|
647 |
"""Create a simple genome diagram using PIL"""
|
|
|
|
|
648 |
# Validate inputs
|
649 |
if not gene_results or genome_length <= 0:
|
650 |
img = Image.new('RGB', (800, 100), color='white')
|
@@ -678,8 +680,7 @@ def create_simple_genome_diagram(gene_results: List[Dict[str, Any]], genome_leng
|
|
678 |
title_font = ImageFont.load_default()
|
679 |
|
680 |
# Draw title
|
681 |
-
draw.text((margin, margin // 2), "Genome SHAP Analysis",
|
682 |
-
fill='black', font=title_font or font)
|
683 |
|
684 |
# Draw genome line
|
685 |
line_y = height // 2
|
@@ -688,7 +689,7 @@ def create_simple_genome_diagram(gene_results: List[Dict[str, Any]], genome_leng
|
|
688 |
# Calculate scale factor
|
689 |
scale = float(width - 2 * margin) / float(genome_length)
|
690 |
|
691 |
-
# Determine a reasonable step for scale markers (avoid zero step if genome_length<10)
|
692 |
num_ticks = 10
|
693 |
if genome_length < num_ticks:
|
694 |
step = 1
|
@@ -729,8 +730,10 @@ def create_simple_genome_diagram(gene_results: List[Dict[str, Any]], genome_leng
|
|
729 |
|
730 |
# Prepare gene name label
|
731 |
label = f"{gene['gene_name']}"
|
732 |
-
|
733 |
-
|
|
|
|
|
734 |
|
735 |
# Alternate label positions above/below
|
736 |
if idx % 2 == 0:
|
@@ -796,6 +799,7 @@ def create_simple_genome_diagram(gene_results: List[Dict[str, Any]], genome_leng
|
|
796 |
|
797 |
return img
|
798 |
|
|
|
799 |
def analyze_gene_features(sequence_file: str,
|
800 |
features_file: str,
|
801 |
fasta_text: str = "",
|
|
|
645 |
|
646 |
def create_simple_genome_diagram(gene_results: List[Dict[str, Any]], genome_length: int) -> Image.Image:
|
647 |
"""Create a simple genome diagram using PIL"""
|
648 |
+
from PIL import Image, ImageDraw, ImageFont
|
649 |
+
|
650 |
# Validate inputs
|
651 |
if not gene_results or genome_length <= 0:
|
652 |
img = Image.new('RGB', (800, 100), color='white')
|
|
|
680 |
title_font = ImageFont.load_default()
|
681 |
|
682 |
# Draw title
|
683 |
+
draw.text((margin, margin // 2), "Genome SHAP Analysis", fill='black', font=title_font or font)
|
|
|
684 |
|
685 |
# Draw genome line
|
686 |
line_y = height // 2
|
|
|
689 |
# Calculate scale factor
|
690 |
scale = float(width - 2 * margin) / float(genome_length)
|
691 |
|
692 |
+
# Determine a reasonable step for scale markers (avoid zero step if genome_length < 10)
|
693 |
num_ticks = 10
|
694 |
if genome_length < num_ticks:
|
695 |
step = 1
|
|
|
730 |
|
731 |
# Prepare gene name label
|
732 |
label = f"{gene['gene_name']}"
|
733 |
+
|
734 |
+
# Fallback approach: use getmask(...) to get (width, height)
|
735 |
+
label_mask = font.getmask(label)
|
736 |
+
label_width, label_height = label_mask.size
|
737 |
|
738 |
# Alternate label positions above/below
|
739 |
if idx % 2 == 0:
|
|
|
799 |
|
800 |
return img
|
801 |
|
802 |
+
|
803 |
def analyze_gene_features(sequence_file: str,
|
804 |
features_file: str,
|
805 |
fasta_text: str = "",
|