File size: 2,280 Bytes
40249ab
489bd70
40249ab
489bd70
cb99418
489bd70
74f6990
489bd70
 
 
 
 
 
 
 
40249ab
489bd70
2b158eb
489bd70
 
 
40249ab
 
 
 
 
489bd70
 
 
9b875e2
 
 
cb99418
 
 
1fb077a
74f6990
1fb077a
 
 
9b875e2
74f6990
1fb077a
 
 
 
2b158eb
1fb077a
 
 
 
74f6990
 
 
 
 
 
 
1fb077a
74f6990
1fb077a
 
2b158eb
40249ab
74f6990
40249ab
 
 
 
 
489bd70
637c5bb
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import io
import gradio as gr
import tempfile

from uniprot_data import create_dataframe, get_uniprot_data


def process_uniprot_id(uniprot_id):
    """
    Main function to process a UniProt ID.

    Args:
        uniprot_id: The UniProt ID.

    Returns:
        Tuple of (DataFrame, downloadable file) or error message
    """
    protein_sequence, annotations = get_uniprot_data(uniprot_id)

    if protein_sequence and annotations:
        df = create_dataframe(protein_sequence, annotations)
        # Create Excel file
        temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.xlsx')
        df.to_excel(temp_file.name, index=False)
        return df, temp_file.name
    return "Could not retrieve or process data for the given Uniprot ID", None


# Gradio Interface
with gr.Blocks() as demo:
    with gr.Column():
        gr.Markdown("# Protein Sequence Analysis")
        gr.Markdown(
            "This app fetches protein sequence and annotation data from UniProt using a UniProt ID and prints a copy-pasteable table for note-taking. **DO NOT TRUST, THIS IS A CODING EXPERIMENT**"
        )
        input_text = gr.Textbox(
            label="UniProt ID",
            placeholder="Enter UniProt ID (e.g., P53_HUMAN)",
            value="",  # Empty default value
        )
        submit_btn = gr.Button("Submit")

        # Add examples
        gr.Examples(
            examples=[
                ["P06280"],  # Alpha-galactosidase A
                ["P07550"],  # beta-2 AR
                ["P01308"],  # Insulin
                ["Q8WZ42"],  # Titin
                ["P0DTC2"],  # SARS-CoV-2 Spike protein
            ],
            example_labels=[
                "Alpha-galactosidase A",
                "Beta-2 adrenergic receptor",
                "Insulin",
                "Titin",
                "SARS-CoV-2 Spike protein",
            ],
            inputs=input_text,
            label="Example UniProt IDs",
        )

        output_df = gr.Dataframe(interactive=False)
        download_btn = gr.DownloadButton(label="Download Excel")

        outputs = submit_btn.click(
            fn=process_uniprot_id, 
            inputs=input_text, 
            outputs=[output_df, download_btn]
        )

if __name__ == "__main__":
    demo.launch()