Tonic commited on
Commit
79eb1f5
1 Parent(s): 21b9510

add fasta visualizer

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. TP53_protein_sequences.fasta +0 -0
  3. space.py +2 -127
README.md CHANGED
@@ -1,7 +1,7 @@
1
 
2
  ---
3
  tags: [gradio-custom-component,gradio-template-SimpleImage,dna,fasta,nucleotide,visualize]
4
- title: gradio_fasta V0.0.5
5
  colorFrom: yellow
6
  colorTo: pink
7
  sdk: docker
 
1
 
2
  ---
3
  tags: [gradio-custom-component,gradio-template-SimpleImage,dna,fasta,nucleotide,visualize]
4
+ title: Zoonotica Fasta Visualizer
5
  colorFrom: yellow
6
  colorTo: pink
7
  sdk: docker
TP53_protein_sequences.fasta ADDED
The diff for this file is too large to render. See raw diff
 
space.py CHANGED
@@ -1,44 +1,4 @@
1
 
2
- import gradio as gr
3
- from app import demo as app
4
- import os
5
-
6
- _docs = {'FASTA': {'description': 'Creates an component that can be used to upload, preview, or edit .fasta files. These\nare commonly used to represent nucleotide or amino acid sequences.', 'members': {'__init__': {'value': {'type': 'str | None', 'default': 'None', 'description': 'A path or URL to a FASTA file. If callable, the function will be called whenever the app loads to set the initial value of the component.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': 'The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.'}, 'every': {'type': 'float | None', 'default': 'None', 'description': "If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute."}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': 'if True, will display label.'}, 'container': {'type': 'bool', 'default': 'True', 'description': 'If True, will place the component in a container - providing some extra padding around the border.'}, 'scale': {'type': 'int | None', 'default': 'None', 'description': 'relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.'}, 'min_width': {'type': 'int', 'default': '160', 'description': 'minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.'}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': 'if True, will allow users to upload and edit an image; if False, can only be used to display images. If not provided, this is inferred based on whether the component is used as an input or output.'}, 'visible': {'type': 'bool', 'default': 'True', 'description': 'If False, component will be hidden.'}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': 'An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.'}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': 'An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.'}, 'render': {'type': 'bool', 'default': 'True', 'description': 'If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.'}}, 'postprocess': {'value': {'type': 'str | pathlib.Path | None', 'description': 'Expects a `str` or `pathlib.Path` object containing the path to the FASTA file.'}}, 'preprocess': {'return': {'type': 'str | None', 'description': 'A `str` containing the path to the FASTA file.'}, 'value': None}}, 'events': {'clear': {'type': None, 'default': None, 'description': 'This listener is triggered when the user clears the FASTA using the X button for the component.'}, 'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the FASTA changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.'}, 'upload': {'type': None, 'default': None, 'description': 'This listener is triggered when the user uploads a file into the FASTA.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'FASTA': []}}}
7
-
8
- abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
-
10
- with gr.Blocks(
11
- css=abs_path,
12
- theme=gr.themes.Default(
13
- font_mono=[
14
- gr.themes.GoogleFont("Inconsolata"),
15
- "monospace",
16
- ],
17
- ),
18
- ) as demo:
19
- gr.Markdown(
20
- """
21
- # `gradio_fasta`
22
-
23
- <div style="display: flex; gap: 7px;">
24
- <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.5%20-%20orange">
25
- </div>
26
-
27
- A component that allows uploading, previewing, and editing .fasta files for nucleotide or peptide sequences. BETA!
28
- """, elem_classes=["md-custom"], header_links=True)
29
- app.render()
30
- gr.Markdown(
31
- """
32
- ## Installation
33
-
34
- ```bash
35
- pip install gradio_fasta
36
- ```
37
-
38
- ## Usage
39
-
40
- ```python
41
-
42
  import gradio as gr
43
  from gradio_fasta import FASTA
44
 
@@ -46,94 +6,9 @@ from gradio_fasta import FASTA
46
  example = FASTA().example_inputs()
47
 
48
  demo = gr.Interface(
49
- lambda x:x,
50
- FASTA(), # interactive version of your component
51
- FASTA(), # static version of your component
52
- # examples=[[example]], # uncomment this line to view the "example version" of your component
53
- )
54
 
55
 
56
  if __name__ == "__main__":
57
  demo.launch()
58
-
59
- ```
60
- """, elem_classes=["md-custom"], header_links=True)
61
-
62
-
63
- gr.Markdown("""
64
- ## `FASTA`
65
-
66
- ### Initialization
67
- """, elem_classes=["md-custom"], header_links=True)
68
-
69
- gr.ParamViewer(value=_docs["FASTA"]["members"]["__init__"], linkify=[])
70
-
71
-
72
- gr.Markdown("### Events")
73
- gr.ParamViewer(value=_docs["FASTA"]["events"], linkify=['Event'])
74
-
75
-
76
-
77
-
78
- gr.Markdown("""
79
-
80
- ### User function
81
-
82
- The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
83
-
84
- - When used as an Input, the component only impacts the input signature of the user function.
85
- - When used as an output, the component only impacts the return signature of the user function.
86
-
87
- The code snippet below is accurate in cases where the component is used as both an input and an output.
88
-
89
- - **As input:** Is passed, a `str` containing the path to the FASTA file.
90
- - **As output:** Should return, expects a `str` or `pathlib.Path` object containing the path to the FASTA file.
91
-
92
- ```python
93
- def predict(
94
- value: str | None
95
- ) -> str | pathlib.Path | None:
96
- return value
97
- ```
98
- """, elem_classes=["md-custom", "FASTA-user-fn"], header_links=True)
99
-
100
-
101
-
102
-
103
- demo.load(None, js=r"""function() {
104
- const refs = {};
105
- const user_fn_refs = {
106
- FASTA: [], };
107
- requestAnimationFrame(() => {
108
-
109
- Object.entries(user_fn_refs).forEach(([key, refs]) => {
110
- if (refs.length > 0) {
111
- const el = document.querySelector(`.${key}-user-fn`);
112
- if (!el) return;
113
- refs.forEach(ref => {
114
- el.innerHTML = el.innerHTML.replace(
115
- new RegExp("\\b"+ref+"\\b", "g"),
116
- `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
117
- );
118
- })
119
- }
120
- })
121
-
122
- Object.entries(refs).forEach(([key, refs]) => {
123
- if (refs.length > 0) {
124
- const el = document.querySelector(`.${key}`);
125
- if (!el) return;
126
- refs.forEach(ref => {
127
- el.innerHTML = el.innerHTML.replace(
128
- new RegExp("\\b"+ref+"\\b", "g"),
129
- `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
130
- );
131
- })
132
- }
133
- })
134
- })
135
- }
136
-
137
- """)
138
-
139
- demo.launch()
 
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import gradio as gr
3
  from gradio_fasta import FASTA
4
 
 
6
  example = FASTA().example_inputs()
7
 
8
  demo = gr.Interface(
9
+ FASTA(value="TP53_protein_sequences.fasta"),
10
+ )
 
 
 
11
 
12
 
13
  if __name__ == "__main__":
14
  demo.launch()