|
1 | 1 | # R2DT-Web |
2 | 2 |
|
3 | | -This is an embeddable component that you can include into your website to visualise RNA secondary structures. |
| 3 | +This is an embeddable component that you can include in your website to visualise RNA secondary structures. |
4 | 4 |
|
5 | 5 | ## How to use |
6 | 6 |
|
7 | | -To use the latest stable version without worrying about updates, use the component's javascript package available at |
| 7 | +Only two lines of code are needed to use this widget: one line with the r2dt-web tag and another with the script |
| 8 | +for this component, for example: |
| 9 | + |
| 10 | +``` |
| 11 | +<r2dt-web/> |
| 12 | +<script type="text/javascript" src="/path/to/r2dt-web.js"></script> |
| 13 | +``` |
| 14 | +And then the component provides a simple input box where you can paste an RNA/DNA sequence, URL or job ID. |
| 15 | + |
| 16 | + |
| 17 | +To use the latest stable version without worrying about updates, use the component's JavaScript package available at |
8 | 18 | GitHub: |
9 | 19 |
|
10 | 20 | `<script type="text/javascript" src="https://rnacentral.github.io/r2dt-web/dist/r2dt-web.js"></script>` |
11 | 21 |
|
12 | | -If you prefer to install this package and perform the updates manually, see the [Installation](#Installation) section. |
| 22 | +If you prefer to install this package and perform the updates manually, see the [Installation](#Installation) section. |
13 | 23 |
|
14 | | -This tool can be used in two ways: |
| 24 | +### Other methods of use |
15 | 25 |
|
16 | | -**1- Allow the user to enter a sequence and search for the secondary structure**. |
17 | | - |
18 | | -For that, you just need to insert this html tag somewhere in your html: |
| 26 | +If you already have an external URL that returns an SVG generated by R2DT, you can provide it through the |
| 27 | +`search` attribute as a JSON object. |
19 | 28 |
|
20 | 29 | ``` |
21 | | -<r2dt-web /> |
| 30 | +<r2dt-web search='{"url": "https://example.com/svg"}'></r2dt-web> |
22 | 31 | ``` |
23 | 32 |
|
24 | | -To show some examples, use: |
| 33 | +To load an RNAcentral identifier (URS), pass it in the same way: |
25 | 34 |
|
26 | 35 | ``` |
27 | | -<r2dt-web |
28 | | - examples='[ |
29 | | - {"description": "RNA5S1-8", "sequence": "GUCUACGGCCAUACCACCCUGAACGCGCCCGAUCUCGUCUGAUCUCGGAAGCUAAGCAGGGUCGGGCCUGGUUAGUACUUGGAUGGGAGACCGCCUGGGAAUACCGGGUGCUGUAGGCUUU"}, |
30 | | - {"description": "TRT-TGT2-1", "sequence": "GGCTCCATAGCTCAGTGGTTAGAGCACTGGTCTTGTAAACCAGGGGTCGCGAGTTCGATCCTCGCTGGGGCCT"} |
31 | | - ]' |
32 | | -/> |
| 36 | +<r2dt-web search='{"urs": "URS0000049E57"}'></r2dt-web> |
33 | 37 | ``` |
34 | 38 |
|
35 | | -You can also customise some elements of this embeddable component. See what you can change [here](#layout). |
36 | | -The example below changes the color of the buttons: |
37 | | - |
38 | | -``` |
39 | | -<r2dt-web |
40 | | - customStyle='{ |
41 | | - "searchButtonColor": "#007c82", |
42 | | - "clearButtonColor": "#6c757d" |
43 | | - }' |
44 | | -/> |
45 | | -``` |
46 | | - |
47 | | -For a minimal example, see [index.html](./index.html). |
48 | | - |
49 | | -**2- Given a specific URS, show the secondary structure** |
50 | | - |
51 | | -To show the secondary structure for a specific sequence, you need to pass the **U**nique **R**NA **S**equence |
52 | | -identifier (URS), for example: |
53 | | - |
54 | | -``` |
55 | | -<r2dt-web search='{"urs": "URS000044DFF6"}' /> |
56 | | -``` |
| 39 | + |
57 | 40 |
|
58 | 41 | Click [here](https://rnacentral.org/help#how-to-find-rnacentral-id) to see how you can find an RNAcentral identifier |
59 | 42 | for an RNA sequence. |
60 | 43 |
|
61 | | -Obviously, you can automate this process by passing the URS as a variable, for example: |
| 44 | +If neither `url` nor `urs` is provided, the component will display a search field. You can optionally display example |
| 45 | +sequences using the `examples` attribute. |
62 | 46 |
|
63 | 47 | ``` |
64 | | -<r2dt-web search='{"urs": "{{ variable }}"}' /> |
| 48 | +<r2dt-web |
| 49 | + examples='[ |
| 50 | + {"description": "RNA5S1-8", "sequence": "GUCUACGGCCAUACCACCCUGAACGCGCCCGAUCUCGUCUGAUCUCGGAAGCUAAGCAGGGUCGGGCCUGGUUAGUACUUGGAUGGGAGACCGCCUGGGAAUACCGGGUGCUGUAGGCUUU"}, |
| 51 | + {"description": "TRT-TGT2-1", "sequence": "GGCTCCATAGCTCAGTGGTTAGAGCACTGGTCTTGTAAACCAGGGGTCGCGAGTTCGATCCTCGCTGGGGCCT"} |
| 52 | + ]' |
| 53 | +/> |
65 | 54 | ``` |
66 | 55 |
|
67 | | -For a minimal example, see [urs-example.html](./urs-example.html). |
| 56 | + |
68 | 57 |
|
69 | 58 | ## Installation |
70 | 59 |
|
71 | | -Download this package directly from GitHub. |
| 60 | +Clone this repository from GitHub. |
72 | 61 |
|
73 | 62 | `git clone https://github.com/RNAcentral/r2dt-web.git` |
74 | 63 |
|
75 | | -Now you can add the component's javascript bundle (it contains all the styles and fonts) to your web page either |
| 64 | +Now you can add the component's JavaScript bundle (it contains all the styles and fonts) to your web page either |
76 | 65 | directly or through an import with Webpack: |
77 | 66 |
|
78 | 67 | `<script type="text/javascript" src="/r2dt-web/dist/r2dt-web.js"></script>` |
79 | 68 |
|
80 | | -You will need to run the `git pull` command whenever there are updates. |
81 | | - |
82 | 69 | ## Attributes/parameters |
83 | 70 |
|
84 | 71 | This component accepts a number of attributes. You pass them as html attributes and their values are strings |
85 | 72 | (this is a requirement of Web Components): |
86 | 73 |
|
87 | | -#### layout |
88 | | - |
89 | | -Parameters that you can use to customise some elements of this embeddable component |
90 | | - |
91 | | -| parameter | description | |
92 | | -|-------------------|------------------------------------------------------------------------------------------| |
93 | | -| fixCss | fix the CSS. Use *"fixCss": "true"* if the button sizes are different | |
94 | | -| linkColor | change the color of the links | |
95 | | -| searchButtonColor | change the color of the `Search` button | |
96 | | -| clearButtonColor | change the color of the `Clear` button | |
97 | | -| titleColor | change the color of the `Secondary structure` text | |
98 | | -| titleSize | change the size of the `Secondary structure` text | |
99 | | -| hideTitle | Use *"hideTitle": "true"* to hide the title | |
100 | | -| legendLocation | Use *"legendLocation": "right"* to show the legend side by side with secondary structure | |
101 | | - |
102 | | -## Developer details |
103 | | - |
104 | | -When integrating the r2dt-web component into your webpage, please be aware that its styles might conflict |
105 | | -with the existing styles of your page. To prevent such CSS conflicts and ensure proper isolation of the |
106 | | -component's styles, you can add the following lines to your webpage's CSS file: |
107 | | - |
108 | | -``` |
109 | | -r2dt-web { |
110 | | - all: initial; |
111 | | -} |
112 | | -``` |
113 | | - |
114 | | -This will reset all inherited styles for the r2dt-web component, minimizing the chances of unintended |
115 | | -style interference. |
| 74 | +| parameter | description | |
| 75 | +|-----------|------------------------------------------------------------------------| |
| 76 | +| search | JSON object with `url` or `urs` attributes | |
| 77 | +| examples | Array of example sequences with `description` and `sequence` | |
| 78 | +| legend | Legend position (left by default). Can be `left`, `right` and `center` | |
116 | 79 |
|
117 | 80 | ### Local development |
118 | 81 |
|
119 | 82 | 1. `npm install` |
120 | 83 |
|
121 | | -2. `npm run serve` to start a server on http://localhost:8080/ |
122 | | - |
123 | | -3. `npm run clean` to clean the dist folder of old assets |
| 84 | +2. `npm run update-templates` to use the latest models from the R2DT repository |
124 | 85 |
|
125 | | -4. `npm run build` to generate a new distribution. |
| 86 | +3. `npm start` to start a server on http://localhost:9000/ |
126 | 87 |
|
127 | | -### Notes |
| 88 | +4. `npm run build` to generate a new distribution |
128 | 89 |
|
129 | | -This embed is implemented as a Web Component, wrapping a piece of code in React/Redux. |
130 | | -The CSS styles and fonts are bundled into the javascript inline via Webpack build system, see webpack.config.js file. |
131 | | -Upon load of r2dt-web.js, the component registers itself in the custom elements registry. |
| 90 | +5. `npm test` to run unit tests |
132 | 91 |
|
133 | | -Web Components accept input parameters as strings. That means that we have to parse parameters in Web Component |
134 | | -initialization code and pass the resulting objects as props to React. Here are some examples of passing the |
135 | | -parameters to the Web Component or from Web Component to React: |
| 92 | +### Notes |
136 | 93 |
|
137 | | -* https://hackernoon.com/how-to-turn-react-component-into-native-web-component-84834315cb24 |
138 | | -* https://stackoverflow.com/questions/50404970/web-components-pass-data-to-and-from/50416836 |
| 94 | +- Implemented as a Web Component using pure JavaScript — no React or Redux dependencies. |
| 95 | +- If both `url` and `urs` are provided, `urs` takes precedence. |
0 commit comments